使用kSOAP发送自定义对象

时间:2012-07-22 17:12:30

标签: android jboss jax-ws ksoap2 jbossws

我正在使用 ksoap2 (ksoap2-android-assembly-3.0.0-RC.1-jar-with-dependencies.jar)与我的 android 应用进行通信使用 jaxoss -2.2.6-在 jboss 7 (jboss-as-7.1.1_Final& jbossws-cxf-4.0.2.GA)上设置的soap服务2-20120518。

我能够获取任何数据(任何意味着我的自定义对象),但我无法发送它们。我关注了this文章。我的对象(名为“Frame”)正在实现org.ksoap2.serialization.KvmSerializable。

我的请求包装类看起来像:

@XmlRootElement(name = "addFrame", namespace = "http://frame.service.server.android.i2.eu/")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "addFrame", namespace = "http://frame.service.server.android.i2.eu/")
public class AddFrame {

    @XmlElement(name = "arg0")
    private Frame frame;

    public Frame getFrame() {
        return frame;
    }

    public void setFrame(Frame frame) {
        this.frame = frame;
    }
}

当我尝试使用java se方法(javax.xml.namespace.QName& javax.xml.ws.Service)发送对象(不在android内)时,对象在我的mssql数据库中持久化,所以我认为有一些我的Android客户端实现的问题。

String namespace = "http://frame.service.server.android.i2.eu/";
String wsdl = "http://localhost:8080/AndroidServer/AndreyServices/FrameService?wsdl";
String action = "addFrame";
String method = "http://frame.service.server.android.i2.eu/addFrame";

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

SoapObject request = new SoapObject(namespace, action)

PropertyInfo info = new PropertyInfo();
info.setType(Frame.class);
info.setValue(frame);//frame as a java method parameter
info.setName("arg0");
request.addProperty(info);

envelope.setOutputSoapObject(request);

HttpTransportSE soapCall = new HttpTransportSE(wsdl);
soapCall.call(action, envelope);

此后我收到:

  • android log:
07-22 16:48:51.256: E/FRAME(1013): eu.i2.android.delegate.exception.DelegateException: SoapFault - faultcode: 'soap:Client' faultstring: 'Unmarshalling Error: null ' faultactor: 'null' detail: null
07-22 16:48:51.256: E/FRAME(1013): eu.i2.android.interfaces.exceptions.CommunicationException: eu.i2.android.delegate.exception.DelegateException: SoapFault - faultcode: 'soap:Client' faultstring: 'Unmarshalling Error: null ' faultactor: 'null' detail: null
07-22 16:48:51.256: E/FRAME(1013):  at eu.i2.android.communication.Communication.addFrame(Communication.java:81)
07-22 16:48:51.256: E/FRAME(1013):  at eu.u2.android.client.Client.onCreate(Client.java:54)
07-22 16:48:51.256: E/FRAME(1013):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
07-22 16:48:51.256: E/FRAME(1013):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
07-22 16:48:51.256: E/FRAME(1013):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
07-22 16:48:51.256: E/FRAME(1013):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
07-22 16:48:51.256: E/FRAME(1013):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
07-22 16:48:51.256: E/FRAME(1013):  at android.os.Handler.dispatchMessage(Handler.java:99)
07-22 16:48:51.256: E/FRAME(1013):  at android.os.Looper.loop(Looper.java:123)
07-22 16:48:51.256: E/FRAME(1013):  at android.app.ActivityThread.main(ActivityThread.java:4627)
07-22 16:48:51.256: E/FRAME(1013):  at java.lang.reflect.Method.invokeNative(Native Method)
07-22 16:48:51.256: E/FRAME(1013):  at java.lang.reflect.Method.invoke(Method.java:521)
07-22 16:48:51.256: E/FRAME(1013):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
07-22 16:48:51.256: E/FRAME(1013):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
07-22 16:48:51.256: E/FRAME(1013):  at dalvik.system.NativeStart.main(Native Method)
07-22 16:48:51.256: E/FRAME(1013): Caused by: eu.i2.android.delegate.exception.DelegateException: SoapFault - faultcode: 'soap:Client' faultstring: 'Unmarshalling Error: null ' faultactor: 'null' detail: null
07-22 16:48:51.256: E/FRAME(1013):  at eu.i2.android.delegate.delegates.FrameDelegate.addFrame(FrameDelegate.java:152)
07-22 16:48:51.256: E/FRAME(1013):  at eu.i2.android.communication.Communication.addFrame(Communication.java:79)
07-22 16:48:51.256: E/FRAME(1013):  ... 14 more
07-22 16:48:51.256: E/FRAME(1013): Caused by: SoapFault - faultcode: 'soap:Client' faultstring: 'Unmarshalling Error: null ' faultactor: 'null' detail: null
07-22 16:48:51.256: E/FRAME(1013):  at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:141)
07-22 16:48:51.256: E/FRAME(1013):  at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
07-22 16:48:51.256: E/FRAME(1013):  at org.ksoap2.transport.Transport.parseResponse(Transport.java:116)
07-22 16:48:51.256: E/FRAME(1013):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:235)
07-22 16:48:51.256: E/FRAME(1013):  at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:114)
07-22 16:48:51.256: E/FRAME(1013):  at eu.i2.android.delegate.AbstractDelegate$SoapCall.call(AbstractDelegate.java:219)
07-22 16:48:51.256: E/FRAME(1013):  at eu.i2.android.delegate.delegates.FrameDelegate.addFrame(FrameDelegate.java:141)
07-22 16:48:51.256: E/FRAME(1013):  ... 15 more
  • 服务器日志:
18:48:52,057 WARNING [org.apache.cxf.phase.PhaseInterceptorChain] (http-localhost-127.0.0.1-8080-2) Interceptor for {http://frame.service.server.android.i2.eu/}AndreyServices#{http://frame.service.server.android.i2.eu/}addFrame has thrown exception, unwinding now: org.apache.cxf.interceptor.Fault: Unmarshalling Error: null 
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:808)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:642)
    at org.apache.cxf.jaxb.io.DataReaderImpl.read(DataReaderImpl.java:156)
    at org.apache.cxf.interceptor.DocLiteralInInterceptor.handleMessage(DocLiteralInInterceptor.java:109)
    at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)
    at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
    at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)
    at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:91)
    at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:169)
    at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)
    at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:754) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135)
    at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140) [jbossws-spi.jar:2.0.3.GA]
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_33]
Caused by: java.lang.NullPointerException
    at org.apache.cxf.jaxb.io.DataReaderImpl$WSUIDValidationHandler.handleEvent(DataReaderImpl.java:69)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleEvent(UnmarshallingContext.java:655)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleError(UnmarshallingContext.java:691)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.handleError(UnmarshallingContext.java:687)
    at com.sun.xml.bind.v2.runtime.unmarshaller.Loader.handleParseConversionException(Loader.java:271)
    at com.sun.xml.bind.v2.runtime.unmarshaller.LeafPropertyLoader.text(LeafPropertyLoader.java:69)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallingContext.text(UnmarshallingContext.java:514)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.processText(StAXStreamConnector.java:339)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.handleEndElement(StAXStreamConnector.java:217)
    at com.sun.xml.bind.v2.runtime.unmarshaller.StAXStreamConnector.bridge(StAXStreamConnector.java:186)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal0(UnmarshallerImpl.java:369)
    at com.sun.xml.bind.v2.runtime.unmarshaller.UnmarshallerImpl.unmarshal(UnmarshallerImpl.java:348)
    at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:778)
    ... 29 more

我没有在jboss模块中安装来自here的任何jar。

提前谢谢你!

3 个答案:

答案 0 :(得分:2)

android客户端中的null缺少SoapObjects在类中扩展,我建议在android上使用CXF客户端,因为这会自动生成类。

http://code.google.com/p/android-ws-client/

答案 1 :(得分:0)

每个字段为空的此问题主要是由于NameSpace问题。您通过SOAP发送的数据未映射到服务器端的对象元素,因此它们为空/零。

我建议使用命名空间。

如果你在这里发布你的WSDL代码,我们会给你一个明确的答案会更有帮助。

另外看看我的解决方案,我遇到了类似的问题。

passing objects to wcf soap service from android using ksoap2; it sends and receives 0

答案 2 :(得分:0)

感谢您的回答。

我设法通过编写实现org.ksoap2.serialization.Marshal的marshaller类来解决我的问题。之后,CXF拦截器流正确构建并且SOAP信封被正确序列化,因此我已将我的实现移至android项目。