Java Jaxb2Marshaller和基元类型
在SpringWS中使用Jaxb2Marschaller时,是否可以使用原语或基本Java类型创建web服务操作?例如,一个如下所示的方法:Java Jaxb2Marshaller和基元类型,java,spring,jaxb,jax-ws,spring-ws,Java,Spring,Jaxb,Jax Ws,Spring Ws,在SpringWS中使用Jaxb2Marschaller时,是否可以使用原语或基本Java类型创建web服务操作?例如,一个如下所示的方法: @Override @PayloadRoot(localPart = "AddTaskRequest", namespace = "http://example.com/examplews/") public long addTask(final Task task) throws AddTaskFault { // do something retu
@Override
@PayloadRoot(localPart = "AddTaskRequest", namespace = "http://example.com/examplews/")
public long addTask(final Task task) throws AddTaskFault {
// do something
return 0;
}
我正在使用maven jaxws插件从WSDL生成接口和模型类。当我尝试调用webservice时,出现以下错误:
java.lang.IllegalStateException:端点[…]没有适配器:端点是否实现了MessageHandler或PayloadEndpoint等受支持的接口
我发现如果我将方法更改为:
@Override
@PayloadRoot(localPart = "AddTaskRequest", namespace = "http://example.com/examplews/")
public JAXBElement<Long> addTask(final JAXBElement<Task> task) throws AddTaskFault {
final ObjectFactory objectFactory = new ObjectFactory();
return objectFactory.createAddTaskResponse(0L);
}
@覆盖
@PayloadRoot(localPart=“AddTaskRequest”,命名空间=”http://example.com/examplews/")
公共JAXBElement addTask(最终JAXBElement任务)抛出AddTaskFault{
最终ObjectFactory ObjectFactory=新ObjectFactory();
返回objectFactory.createAddTaskResponse(0L);
}
我可以调用它-但是这个签名与maven jaxws插件生成的接口不兼容
如何配置SpringWS以使用第一种实现,或者告诉maven jaxws插件生成接口的第二个变体
更新:我的相关spring ws-config条目如下所示:
<bean id="marshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="contextPath" value="com.example.examplews" />
</bean>
<bean class="org.springframework.ws.server.endpoint.adapter.GenericMarshallingMethodEndpointAdapter">
<constructor-arg ref="marshaller" />
</bean>
<bean class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
<property name="order" value="1" />
</bean>
当Spring WS尝试将
端点适配器
与端点
匹配时,它会检查端点方法的所有参数及其返回值是否为Jaxb2Marshaller
所知的类型,而long
不会。从概念上讲,这是有意义的,因为JAXB不知道如何在没有更多信息的情况下将long
转换为XML(这就是JAXBElement
的用武之地)
您应该意识到SpringWS不是一个JAX-WS实现,并没有假装是。您不能期望使用JAX WS生成的工件并期望它们只在Spring_WS中工作,尽管在许多情况下Spring WS足够灵活来处理它。这里是我配置中所有相关的内容,因为我无法真正告诉您可以更改什么,它们非常不同,自从我这么做以来已经一年半了
<bean id="schemaCollection"
class="org.springframework.xml.xsd.commons.CommonsXsdSchemaCollection">
<property name="xsds" value="/my.xsd" />
<property name="inline" value="true" />
</bean>
<bean id="marshallingEndpoint"
class="....EndpointImpl">
</bean>
<oxm:jaxb2-marshaller id="marshaller" contextPath=".....schema" />
<bean id="annotationMapping" class="org.springframework.ws.server.endpoint.mapping.PayloadRootAnnotationMethodEndpointMapping">
<property name="interceptors">
<list>
<bean class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor" />
<bean class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor">
<property name="xsdSchemaCollection"
ref="schemaCollection" />
<property name="validateRequest" value="true" />
<property name="validateResponse" value="true" />
</bean>
</list>
</property>
<property name="order" value="1" />
</bean>
<sws:marshalling-endpoints />
您可以发布您的SpringXML配置吗?我有一个类似的问题,我通过配置解决了它。。。这是很久以前的事了,但是如果你发布你的配置,我可以检查我的正确配置并发布差异。好的,那么使用SpringWS和自顶向下方法的最佳方式是什么呢?我想使用maven生成必要的类,这样我就只需要实现web服务接口。我知道没有生成工具可以做到这一点,但是Spring WS的代码非常简单,所以你不会真的节省那么多输入。所以你建议使用自下而上的方式,只编写我的代码我的web服务接口?Spring WS主张先编写XML模式,然后用java编写端点,接收并响应符合该模式的文档。WSDL自然会从这个过程中消失。
xmlns:oxm="http://www.springframework.org/schema/oxm"
xmlns:sws="http://www.springframework.org/schema/web-services"
xsi:schemaLocation="
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-1.5.xsd">