Java 如何使用axis2编写客户机以将序列化的xml对象发送到web服务?
我有一个概念上的问题,使我无法解决一个琐碎的问题。我需要向web服务发送一个对象。我有一个端点,我有可以序列化对象的代码,所以我可以创建一个org.jdom.Document或一个包含序列化对象的byte[]对象 我还可以创建一个使用axis2调用web服务的客户机代码段。 最后,我尝试将手动创建的消息发送到web服务(它没有WSDL;() 我用Charles来看看发生了什么(请求) 我不知道如何将byte[]或org.jdom.Document对象转换为OmeElement对象。显然,serviceClient.sendReceive(elem)采用OmeElement参数 以下是我到目前为止所做的尝试(我在确信OmeElement正在运行时删除了发送的OmeElement):Java 如何使用axis2编写客户机以将序列化的xml对象发送到web服务?,java,Java,我有一个概念上的问题,使我无法解决一个琐碎的问题。我需要向web服务发送一个对象。我有一个端点,我有可以序列化对象的代码,所以我可以创建一个org.jdom.Document或一个包含序列化对象的byte[]对象 我还可以创建一个使用axis2调用web服务的客户机代码段。 最后,我尝试将手动创建的消息发送到web服务(它没有WSDL;() 我用Charles来看看发生了什么(请求) 我不知道如何将byte[]或org.jdom.Document对象转换为OmeElement对象。显然,serv
使用axis2的意义在于它会处理所有事情,您只需提供一个wsdl文件,它就会生成客户端存根。 如果您没有原始的wsdl,您仍然可以自己创建一个
对您来说,最好的方法是手动创建wsdl文件,生成客户端存根并直接调用存根。没有wsdl。他们无法提供wsdl。这项工作很久以前就完成了。但是,这段代码似乎可以偶尔工作,如果请求达到某个大小,我注意到响应缺少许多子项:
package testAxis2Client01;
import java.util.Map;
import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.axis2.transport.http.HTTPConstants;
public class testAxis2Client01 {
private static final int MXMOCONNECTIONTIMEOUT = 2;//don't really know what this should be.
/**
* @param args
*/
public static void main(String[] args) {
try {
callAxisWS();
} catch (XMLStreamException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void callAxisWS() throws XMLStreamException, Exception {
//Axis2 client code to call a WS
OMElement response=null;
try{
OMFactory factory = OMAbstractFactory.getSOAP11Factory();
SOAPEnvelope theEnvelope = OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope();
theEnvelope.declareNamespace("http://www.w3.org/2001/XMLSchema","xsd");
theEnvelope.declareNamespace("http://www.w3.org/2001/XMLSchema-instance","xsi");
ServiceClient serviceClient = new ServiceClient();
Options options = serviceClient.getOptions();
options.setProperty(HTTPConstants.AUTO_RELEASE_CONNECTION, true); // Another API to release connection.
options.setTimeOutInMilliSeconds(10000); // Setting the connection timeout.
EndpointReference targetEPR = new EndpointReference(theUrl);
options.setTo(targetEPR);
options.setAction("processDocument");
serviceClient.setOptions(options);
//response = serviceClient.sendReceive(myOMElement);
response = serviceClient.sendReceive(elem)
if (response != null) {
System.out.println("SUCCESS!!");
System.out.println(response.toStringWithConsume());
}
}catch(Exception af){
af.printStackTrace();
System.out.println(af.getMessage());
}
}
}