java 找不到类型的解串器:错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9884872/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 22:46:25  来源:igfitidea点击:

could not find deserializer for type : Error

javaaxis

提问by Harish Kayarohanam

I have to make a SOAP call from my java program ,for which I used apache axis. My program is as follows :

我必须从我的 java 程序进行 SOAP 调用,为此我使用了 apache 轴。我的程序如下:

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;
public class Project {
   public static void main(String [] args) {

   try {

       String endpoint ="http://RequestUrl";
       Service  service = new Service();
       Call call = (Call) service.createCall();
       call.setTargetEndpointAddress( new java.net.URL(endpoint) );
       call.setOperationName(new QName(endpoint, "getFrsFileData"));
       String value = (String) call.invoke(new Object[] { "24BB7","frs1001" } );
       System.out.println(value);
       }

    catch (Exception e) {
       System.err.println(e.toString());
       }

    }
   }

This on execution gives an error as follows

这在执行时给出如下错误

  • Exception: org.xml.sax.SAXException: Deserializing parameter 'getFrsFileDataReturn': could not find deserializer for type {http://Url}FrsFileSoapDO at org.apache.axis.message.RPCHandler.onStartChild(RPCHandler.java:277) at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035) at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165) at org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:1141) at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:345) at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384) at org.apache.axis.client.Call.invoke(Call.java:2467) at org.apache.axis.client.Call.invoke(Call.java:2366) at org.apache.axis.client.Call.invoke(Call.java:1812) at Project.main(Project.java:33) org.xml.sax.SAXException: Deserializing parameter 'getFrsFileDataReturn': could not find deserializer for type {http://Url}FrsFileSoapDO
  • 异常:org.xml.sax.SAXException:反序列化参数“getFrsFileDataReturn”:在 org.apache.axis.message.RPCHandler.onStartChild(RPCHandler.java:277) 处找不到类型为 {http://Url}FrsFileSoapDO 的反序列化器org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035) at org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:165) at org.apache.axis.message.MessageElement.publishToHandler( MessageElement.java:1141) at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:345) at org.apache.axis.message.RPCElement.getParams(RPCElement.java:384) at org.apache.axis .client.Call.invoke(Call.java:2467) at org.apache.axis.client.Call.invoke(Call.java:2366) at org.apache.axis.client.Call.invoke(Call.java:1812) ) 在 Project.main(Project.java:33) org.xml。sax.SAXException:反序列化参数“getFrsFileDataReturn”:找不到类型为 {http://Url}FrsFileSoapDO 的反序列化器

Tried the same call using SOAPUI , but it did not help me debug this .

使用 SOAPUI 尝试了相同的调用,但它没有帮助我调试它。

Please help me out in debugging this java code,

请帮我调试这个java代码,

Thank You

谢谢

回答by Harish Kayarohanam

I got help from my friend and was able to arrive at the answer . The problem is that the soap call , gives a soap response which comes as a bean of type "FrsFileSoapDO" . As I have not given anything in code of how my program will understand the received bean , that gave me an error saying "could not find deserializer for type {http://Url}FrsFileSoapDO" . Now the step's to clear the problem is

我从我的朋友那里得到了帮助,并且能够得出答案。问题在于,soap 调用给出了一个soap 响应,它是一个类型为“FrsFileSoapDO”的bean。由于我没有在代码中给出任何关于我的程序将如何理解接收到的 bean 的内容,这给了我一个错误,说“找不到类型的反序列化器{http://Url}FrsFileSoapDO”。现在解决问题的步骤是

1) create a "QName" to say what is the namespace that "FrsFileSoapDO" refers to .

1)创建一个“QName”来说明“FrsFileSoapDO”所指的命名空间是什么。

2) create Bean serializer (that knows how to serialize the bean),

2)创建Bean序列化器(知道如何序列化bean),

3) create a Bean deserializer (that knows how to deserialize the bean) ,

3)创建一个Bean反序列化器(知道如何反序列化bean),

4) Do the mapping saying that the QName q maps to the class FrsFileSoapDO.class (before that make sure that you have the FrsFileSoapDO.class with you and you have imported it )

4)做映射说QName q映射到类FrsFileSoapDO.class(在此之前确保你有FrsFileSoapDO.class并且你已经导入了它)

Now lets implement this in the program , (I am repeating only the try block here)

现在让我们在程序中实现它,(我在这里只重复 try 块)

try {

   String endpoint ="http://RequestUrl";
   Service  service = new Service();
   Call call = (Call) service.createCall();
   call.setTargetEndpointAddress( new java.net.URL(endpoint) );

   QName q = new QName ("http://Url", "FrsFileSoapDO"); // step 1
   BeanSerializerFactory bsf =   new BeanSerializerFactory(FrsFileSoapDO.class,q);   // step 2
   BeanDeserializerFactory bdf = new BeanDeserializerFactory(FrsFileSoapDO.class,q);  // step 3
   call.registerTypeMapping(FrsFileSoapDO.class,q, bsf, bdf); //step 4

   call.setOperationName(new QName(endpoint, "getFrsFileData"));
   FrsFileSoapDO s = (FrsFileSoapDO) call.invoke(new Object[] { "24BB7","frs1001" } );  
   System.out.println(s.getFilename());  
   }

This works giving me the expected output.

这工作给了我预期的输出。

The document for the functions Call,BeanSerializerFactory,BeanDeserializerFactory are available at BeanSerializerFactoryand BeanDeserializerFactory

函数 Call、BeanSerializerFactory、BeanDeserializerFactory 的文档可在BeanSerializerFactoryBeanDeserializerFactory 获得

回答by Kamal Yadav

I was facing same problem. The only mistake I think in your code is below line:

我面临同样的问题。我认为您的代码中唯一的错误是以下行:

call.setOperationName(new QName(endpoint, "getFrsFileData"));

You should not use endpoint for QName constructor parameter. Either you can leave it empty if you are only sending string params but in case some complex data you should provide the mapping here from the wsdl file. Check parameters in wsdl file for this web service method and give the same mapping here. For example for me it was a file transfer so the entry in wsdl was:

您不应将端点用于 QName 构造函数参数。如果您只发送字符串参数,您可以将其留空,但如果您应该从 wsdl 文件在此处提供一些复杂数据,则可以将其留空。检查 wsdl 文件中此 Web 服务方法的参数,并在此处提供相同的映射。例如对我来说这是一个文件传输所以 wsdl 中的条目是:

<wsdl:message name="sendFileRequest">
  <wsdl:part name="in0" type="apachesoap:DataHandler"/>
  <wsdl:part name="in1" type="soapenc:string"/>
</wsdl:message>

and in the client code you have give same type like:

在客户端代码中,您提供了相同的类型,例如:

call.setOperationName( new QName("apachesoap:MatrixService", "sendFile") );
QName fileAttachment = new QName("apachesoap:MatrixService", "DataHandler");

After this you need to define map for the same using registerTypeMapping.

在此之后,您需要使用 registerTypeMapping 为其定义映射。