【问题标题】:AXIS Client v.s. AXIS2 ServiceAXIS 客户端与AXIS2 服务
【发布时间】:2012-04-01 12:20:38
【问题描述】:

我必须实现一个使用 AXIS2 1.4 方法的 AXIS 1.4 客户端。 AXIS 1.4 客户端是通过创建存根来制作的。客户端发送一个请求并从带有一些附件 (MTOM) 的服务返回一个响应。当我通过 AXIS 1.4 端口类型对象调用方法(操作)时出现错误:

org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.

我认为 MTOM 搞砸了 AXIS。那么问题来了:我是如何获得 AXIS2 1.4 (MTOM) Web 服务返回给我的附件的? TIA。

弗朗切斯科

P.S:这里是代码。有 WSDL 生成的存根。问题是:当我调用端口的存根方法时出现异常。我收到的邮件中有附件。

String codistat = "CODISTAT";    
OrdinanzeViabilitaLocator ovlocretreive = new OrdinanzeViabilitaLocator();
ovlocretreive.setOrdinanzeViabilitaHttpSoap11EndpointEndpointAddress(".. the service url + action..");
try {
  OrdinanzeViabilitaPortType ovretreive = ovlocretreive.getOrdinanzeViabilitaHttpSoap11Endpoint();
  ((Stub) ovretreive)._setProperty(javax.xml.rpc.Call.USERNAME_PROPERTY, "username");
  ((Stub) ovretreive)._setProperty(javax.xml.rpc.Call.PASSWORD_PROPERTY, "password");            
  //problems began here
  MessageReqOrdinanze mrq = new MessageReqOrdinanze();
  mrq.setCodistat(codistat);
  Calendar date_from = Calendar.getInstance();
  date_from.setTimeInMillis(0);
  Calendar date_to = Calendar.getInstance();
  date_from.setTimeInMillis(0);
  mrq.setDate_from(date_from);
  mrq.setDate_to(date_to);
  // the next line generate the exception
  MessageOrdinanze mretreive = ovretreive.getOrdinanze(mrq);
  } catch (AxisFault e) {
        e.printStackTrace();
  } catch (RemoteException e) {
        e.printStackTrace();
  } catch (FileNotFoundException e) {
        e.printStackTrace();
  } catch (IOException e) {
        e.printStackTrace();
  } catch (ServiceException e) {
        e.printStackTrace();
  }

我收到的消息有一个

<xop:include href="cid... >...< ../xop/include"/>

标签里面,它是 MTOM(我猜它会导致异常)。 希望这会有所帮助。

【问题讨论】:

  • 请发布您的代码..
  • 我发布代码。希望能给你一些提示。

标签: axis2 axis mtom


【解决方案1】:

要使 MTOM 在客户端工作,需要做两件事:

  1. 确保在存根中,xs:base64Binary 类型映射到 java.activation.DataHandler 而不是 byte[]
  2. 为使用JAFDataHandlerSerializerJAFDataHandlerDeserializer(支持MTOM)的xs:base64Binaryjava.activation.DataHandler 设置(运行时)类型映射。

第二部分相当简单。只需使用以下类型映射设置 client-config.wsddfile:

<typeMapping languageSpecificType="java:javax.activation.DataHandler" qname="xs:base64Binary"
             deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory"
             serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory" 
             encodingStyle=""/>

第一部分比较棘手,因为 Axis 1.4 中的工具 (wsdl2java) 不支持更改与给定 XML 类型关联的 Java 类型。有几种方法可以解决这个限制:

  • 手动编辑生成的存根并将byte[]更改为javax.activation.DataHandler。根据您在项目中管理生成代码的方式,这可能是也可能不是可接受的解决方案。
  • 可能(尽管我没有测试过)通过给它一个修改过的 WSDL 来欺骗 wsdl2java 使用 javax.activation.DataHandler,其中类型为 {http://www.w3.org/2001/XMLSchema}base64Binary替换为 {java}javax.activation.DataHandler。
  • 我修复了当前 Axis 主干中的工具,使其支持这种类型的配置。但是请注意,这仅在 wsdl2java Maven 插件中实现(而不是在 Ant 任务或命令行工具中)。您可以使用该插件的 1.4.1-SNAPSHOT 版本;生成的代码仍然适用于 Axis 1.4。你可以找到一些文档here

【讨论】:

    【解决方案2】:

    上述解决方案很棒。但是那些可能难以使上述代码 sn-p 工作的人,请使用xmlns:xs="http://www.w3.org/2001/XMLSchema",然后只给typeMapping sn-p 工作。

    <typeMapping qname="xs:base64Binary" languageSpecificType="java:javax.activation.DataHandler"
    deserializer="org.apache.axis.encoding.ser.JAFDataHandlerDeserializerFactory"
        serializer="org.apache.axis.encoding.ser.JAFDataHandlerSerializerFactory"
        xmlns:xs="http://www.w3.org/2001/XMLSchema" encodingStyle="" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-09-10
      相关资源
      最近更新 更多