soap调用中的Jax-WS未知命名空间定义

时间:2014-12-03 08:35:13

标签: java xml web-services soap jax-ws

我设计了一个新的WebService,其中包含JAX-WS和Spring。

我不喜欢数组,所以我选择了java集合&方法签名中的列表。

使用我得到了一个不可用的WebMethod(在下面的示例中为unlockBusComponent),因为在生成的wsdl中是一个命名空间"配置错误"。

首先是实体:

@XmlRootElement(namespace ="appstate.entities.web.company.tld",
name="ApplicationState") 
  public class ApplicationState {
        private UUID applicationId;
        private String applicationName;
        private String hostName;
        private String status;
        public ApplicationState() {}//... public getter & setter are following

}
@XmlRootElement(namespace ="buscomponent.entities.web.company.tld") 
  public class BusComponent {
        private UUID lockId;
        private int mandantId;
        private String name;
        //... public getter & setter are following

}

现在的服务:

@WebService
public interface BusComponentInfoService {

    @WebMethod
    public Collection<BusComponent> getBusComponent(/** */
    @WebParam(name = "mandantId") final int mandantId,/** */
    @WebParam(name = "application") final ApplicationState application) throws Throwable;

    @WebMethod
    public void unlockBusComponent(/** */
    @WebParam(name = "busComponent")
    final BusComponent busComponent) throws Throwable;
}

@Component
@WebService(endpointInterface = "tld.company.BusComponentInfoService")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
public class BusComponentInfoServiceImpl extends SpringBeanAutowiringSupport implements BusComponentInfoService {

    @Override
    public Collection<BusComponent> getBusComponent(final int mandantId, final ApplicationState application) throws Throwable {
        //....
        final Collection<BusComponent> retval = new ArrayList<BusComponent>();
        return retval;
    }

    @Override
    public void unlockBusComponent(final BusComponent busComponent) throws Throwable {
        //....
    }

}

为了测试我使用SoapUI的服务,这非常有效! 请求:

<soapenv:Envelope 
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:bci="http://bci.lockserver.company.tld/">
   <soapenv:Header/>
   <soapenv:Body>
      <bci:getBusComponent>
         <mandantId>1</mandantId>
         <!--Optional:-->
         <application>
            <!--Optional:-->
            <applicationId>12345678-abcd-0987-edcb-1234567890ab</applicationId>
            <!--Optional:-->
            <applicationName>SoapUI Dummy</applicationName>
            <!--Optional:-->
            <hostName>mycomputer</hostName>
            <!--Optional:-->
            <status>?</status>
         </application>
      </bci:getBusComponent>
   </soapenv:Body>
</soapenv:Envelope>

回复:

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns3:getBusComponentResponse xmlns:ns2="buscomponent.entities.web.company.tld" xmlns:ns3="http://bci.lockserver.common.company.tld/" xmlns:ns4="appstate.entities.web.company.tld">
         <return>
            <lockId>b6226670-b7c6-43e7-bd65-5f73789ae90f</lockId>
            <mandantId>1</mandantId>
            <name>ABCDEF_001</name>
         </return>
      </ns3:getBusComponentResponse>
   </S:Body>
</S:Envelope>

上述请求工作正常。但是下面的请求unlockBusComponent是由SoapUI生成的,其中包含提交的buscompontents的命名空间。

<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
xmlns:bci="http://bci.lockserver.common.company.tld/" 
xmlns:bus="buscomponent.entities.web.company.tld">
   <soapenv:Header/>
   <soapenv:Body>
      <bci:unlockBusComponent>
         <bus:busComponent>
            <lockId>b6226670-b7c6-43e7-bd65-5f73789ae90f</lockId>
            <mandantId>1</mandantId>
            <name>ABCDEF_001</name>
         </bus:busComponent>
      </bci:unlockBusComponent>
   </soapenv:Body>
</soapenv:Envelope>

给定的BusComponent实体不会转移到该服务。服务器端的预期参数为null。如果我从总线:busComponent -Tags中删除总线 - 名称空间,则总线组件将成功转移到该服务。

所以我的问题是:

  1. buscomponent-entity有什么问题? (请注意WebMethod&#34; getBusComponent&#34;参数ApplicationState非常有效!)
  2. 在重新设计(从单个值和集合切换到buscomponent-entities的数组)之后,新服务运行良好。但为什么?与之前的方法有什么不同?
  3. 现在成功的工作服务:

    @WebService
    public interface BusComponentInfoService {
    
        @WebMethod
        public BusComponent[] getBusComponent(/** */
        @WebParam(name = "mandantId")   final int mandantId, /**     */
        @WebParam(name = "application") final ApplicationState application) throws Throwable;
    
        @WebMethod
        public void unlockBusComponents(/** */
        @WebParam(name = "busComponent")    final BusComponent[] busComponent) throws Throwable;
    }
    

1 个答案:

答案 0 :(得分:0)

集合是特定于语言的实现。对于集合,没有可用的等效XML数据类型。

JAXB的当前局限性 由于JAXB中的限制,java.util.Collection类不能与rpc / literal或document / literal BARE样式一起使用。但是,它们可以使用默认文档/文字WRAPPED样式。

LINK

使用数组进行通信,然后将其转换为您的集合。