2014-12-03 109 views
0

我设计了一个新的带有JAX-WS和Spring的WebService。肥皂调用中的Jax-WS未知名称空间定义

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

使用我得到了一个不可用的WebMethod(在下面的例子中为unlockBusComponent),因为在生成的wsdl中是一个名为“misconfigured”的命名空间。

首先是实体:

@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实体不会转移到服务。期望的参数在服务器端是空的。如果我从总线删除总线-命名空间:busComponent -Tags,总线组件将被成功转移到该服务。

所以我的问题是:

  1. 哪些错误与buscomponent实体? (请注意带有参数ApplicationState的WebMethod“getBusComponent”工作得非常好!)
  2. 重新设计(从单个值和集合切换到buscomponent-entities的数组)后,新服务运行良好。但为什么?与之前的方法有什么不同?

现在全成工作服务:

@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; 
} 

回答

0

集合是语言的具体实施。对于集合,没有可用的等效XML数据类型。

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

LINK

使用数组沟通然后将其转换到您的收藏。

+0

我同意你的看法,那就是收藏对我来说不好。但是:WebMethod不起作用,不处理集合或数组。只需切换到数组实现“解决”它。第二件事是,即时通讯使用@SOAPBinding(style = SOAPBinding.Style.DOCUMENT,parameterStyle = SOAPBinding.ParameterStyle.WRAPPED) – Mirko 2014-12-03 09:30:22

+0

好吧,很高兴你解决了你的问题。干杯! – aurelius 2014-12-03 09:35:30