1 /*
2 * Copyright 2001-2005 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.nxqd.soap;
17
18 import java.util.logging.Level;
19 import java.util.logging.Logger;
20 import java.util.ArrayList;
21 import java.util.Map;
22 import java.util.List;
23 import java.util.Timer;
24
25 import org.w3c.dom.Document;
26
27 import net.sf.nxqd.NxqdException;
28 import net.sf.nxqd.common.NxqdUtils;
29 import net.sf.nxqd.event.NxqdEvent;
30 import net.sf.nxqd.event.NxqdContainerEvent;
31 import net.sf.nxqd.event.NxqdManagerEvent;
32 import net.sf.nxqd.event.NxqdEventListener;
33 import net.sf.nxqd.event.NxqdManagerEventListener;
34 import net.sf.nxqd.event.NxqdContainerEventListener;
35
36 // axis2 imports
37 // import org.apache.axis2.clientapi.Call;
38 // import org.apache.axis2.description.ParameterImpl;
39 // import org.apache.axis2.description.OperationDescription;
40 // import org.apache.axis2.AxisFault;
41 // import org.apache.axis2.Constants;
42 // import org.apache.axis2.addressing.EndpointReference;
43 // import org.apache.axis2.om.OMAbstractFactory;
44 // import org.apache.axis2.om.OMElement;
45 // import org.apache.axis2.om.OMFactory;
46 // import org.apache.axis2.om.OMNamespace;
47 // import org.apache.log4j.Category;
48 // import javax.xml.stream.XMLStreamWriter;
49 // import javax.xml.stream.XMLOutputFactory;
50 // import javax.xml.stream.XMLStreamException;
51 // import javax.xml.stream.FactoryConfigurationError;
52 import javax.xml.namespace.QName;
53
54 public class Axis2Connector {
55
56 /**
57 * The constant <code>NXQD_QNAME</code> describes the namespace for
58 * the SOAP server functionality.
59 *
60 */
61 private static final String NXQD_QNAME = "http://sourceforge.net/projects/nxqd";
62
63 /**
64 * The constant <code>NXQD_PROTOCOL</code> describes the communication protocol
65 * which will be used to communicate with the server.
66 *
67 */
68 private static final String NXQD_PROTOCOL = "http://";
69
70 /**
71 * The variable <code>logger</code> is used for logging events.
72 *
73 */
74 private static Logger logger = Logger.getLogger(Axis2Connector.class.getName());
75
76 private String hostName;
77
78 private String hostPort;
79
80 public Axis2Connector(String host, String port) {
81 this.hostName = host;
82 this.hostPort = port;
83 }
84
85 /**
86 * The <code>getHostName</code> method returns the host name
87 * of the machine running the Nxqd server.
88 *
89 * @return a <code>String</code> value
90 */
91 public final String getHostName() {
92 return hostName;
93 }
94
95 /**
96 * The <code>getHostPort</code> method returns the host port
97 * of the remote Nxqd server.
98 *
99 * @return an <code>String</code> value
100 */
101 public final String getHostPort() {
102 return hostPort;
103 }
104
105 public Object invoke(String operationName, Object[] parameters) throws NxqdException {
106 return invoke(operationName,
107 new String[0],
108 parameters);
109 }
110
111 // public static OMElement getPayload(String operationName,
112 // String[] parameterNames,
113 // Object[] parameterValues) {
114
115 // OMFactory fac = OMAbstractFactory.getOMFactory();
116 // OMNamespace omNs = fac.createOMNamespace(
117 // "http://sourceforge.net/projects/nxqd", "nxqd");
118 // OMElement method = fac.createOMElement(operationName, omNs);
119 // for (int i = 0; i < parameterNames.length; i++) {
120 // OMElement value = fac.createOMElement(parameterNames[i], omNs);
121 // value.addChild(fac.createText(value, parameterValues[i].toString()));
122 // method.addChild(value);
123 // }
124
125 // return method;
126 // }
127
128 public Object invoke(String operationName,
129 String[] parameterNames,
130 Object[] parameterValues) throws NxqdException {
131 try {
132 // String endpoint = NXQD_PROTOCOL+getHostName()+":"+getHostPort()+"?wsdl";
133
134 // Call call = new Call();
135 // call.setTo(new EndpointReference(endpoint));
136 // call.setTransportInfo(Constants.TRANSPORT_HTTP,Constants.TRANSPORT_HTTP,false);
137 // OperationDescription operation = new OperationDescription(new QName(NXQD_QNAME,
138 // operationName));
139 // call.setDoREST(true);
140 // OMElement result = call.invokeBlocking(operationName,
141 // getPayload(operationName,
142 // parameterNames,
143 // parameterValues));
144 // logger.info(">>>>>>>>>>>>>"+result.toString());
145 // logger.info(">>>>>>>>>>>>>"+result.getText());
146 // logger.info(">>>>>>>>>>>>>"+result.getLocalName());
147 // try {
148 // XMLStreamWriter writer = XMLOutputFactory.newInstance()
149 // .createXMLStreamWriter(System.out);
150 // result.serializeWithCache(writer);
151 // writer.flush();
152 // } catch (XMLStreamException e) {
153 // e.printStackTrace();
154 // } catch (FactoryConfigurationError e) {
155 // e.printStackTrace();
156 // }
157
158 // return result;
159 } catch (Exception e) {
160 logger.severe("Error performing invoke ("+e+")");
161 throw new NxqdException(e);
162 }
163 return null;
164 }
165
166 public Object invoke(String operationName,
167 String[] parameterNames,
168 QName[] parameterTypes,
169 Object[] parameterValues) throws NxqdException {
170 return invoke( operationName,
171 parameterNames,
172 parameterValues);
173 }
174
175 }