Java 了解SpringWS、与SpringMVC的集成以及wsdl的自动生成
我想学习自动生成wsdl文件的spring ws,我知道有很多教程,我尝试过,我最喜欢的例子是: 它工作得很好,但我试图根据我的需要调整该解决方案,但它不起作用,我不知道为什么,这是你们的问题,这里出了什么问题 我被改变了:Java 了解SpringWS、与SpringMVC的集成以及wsdl的自动生成,java,spring,web-services,wsdl,spring-ws,Java,Spring,Web Services,Wsdl,Spring Ws,我想学习自动生成wsdl文件的spring ws,我知道有很多教程,我尝试过,我最喜欢的例子是: 它工作得很好,但我试图根据我的需要调整该解决方案,但它不起作用,我不知道为什么,这是你们的问题,这里出了什么问题 我被改变了: 模型(github项目中的oxm包)-schema.xsd(github项目中的ecommerce.xsd)以及 端点类 移除类:SubscriptionPort.java和SubscriptionPortService.java(我注意到正确操作不需要这些类)(当从g
- 模型(github项目中的oxm包)-schema.xsd(github项目中的ecommerce.xsd)以及
- 端点类
- 移除类:SubscriptionPort.java和SubscriptionPortService.java(我注意到正确操作不需要这些类)(当从github项目中移除时,一切都很好)
<sws:annotation-driven />
<sws:interceptors>
<bean id="validatingInterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"
p:schema="/WEB-INF/schema.xsd"
p:validateRequest="true"
p:validateResponse="true"/>
<bean id="loggingInterceptor" class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
</sws:interceptors>
<sws:dynamic-wsdl id="subscription"
portTypeName="SubscriptionPort"
locationUri="/"
targetNamespace="http://localhost:8080/ws/schema/oss">
<sws:xsd location="/WEB-INF/schema.xsd"/>
</sws:dynamic-wsdl>
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="org.krams.tutorial.model"/>
<bean id="marshallingPayloadMethodProcessor" class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
<constructor-arg ref="jaxbMarshaller"/>
<constructor-arg ref="jaxbMarshaller"/>
</bean>
<bean id="defaultMethodEndpointAdapter" class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
<property name="methodArgumentResolvers">
<list>
<ref bean="marshallingPayloadMethodProcessor"/>
</list>
</property>
<property name="methodReturnValueHandlers">
<list>
<ref bean="marshallingPayloadMethodProcessor"/>
</list>
</property>
</bean>
当我搜索答案时,我发现答案如下:
但正如您所看到的,我的请求和响应对象具有请求和响应后缀
你知道我忘了什么吗?为什么在wsdl中我没有操作标签?看起来他没有看到端点操作,或者存在一些字母不匹配问题。问题是您的xsd是错误的。您应该将复杂类型包装到元素中
<xs:element name="deliverShortMessageRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="parameters" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="sms" type="tns:deliverShortMessage"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element />
<xs:element name="deliverShortMessageResponse">
<xs:complexType >
<xs:sequence>
<xs:element name="deliverShortMessageReturn" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>
对于初学者,删除DefaultMethodEndpointAdapter
和MarshallingPayloadMethodProcessor
,只需在
标记上设置marshaller
属性即可。请将您的xsd添加到您的帖子中。schema.xsd被添加到第一篇帖子中,我删除了DefaultMethodEndpointAdapter、MarshallingPayloadMethodProcessor(我还必须从messageDispatcher的mvc-ws-integration.xml参数中删除),但wsdl文件仍然错误您没有元素,只有complexType。您应该将复杂类型包装在
中。
@Endpoint
public class MessageEndpoint {
private static final String NAMESPACE_URI = "http://localhost:8080/ws/schema/oss";
@PayloadRoot(namespace = NAMESPACE_URI, localPart = "DeliverShortMessageRequest")
@ResponsePayload
public DeliverShortMessageResponse deliverShortMessage(@RequestPayload DeliverShortMessageRequest deliverShortMessageRequest) {
System.out.println("deliverShortMessage " + deliverShortMessageRequest);
DeliverShortMessageResponse result = new DeliverShortMessageResponse();
result.setDeliverShortMessageReturn(true);
return result;
}
}
<sws:annotation-driven />
<sws:interceptors>
<bean id="validatingInterceptor" class="org.springframework.ws.soap.server.endpoint.interceptor.PayloadValidatingInterceptor"
p:schema="/WEB-INF/schema.xsd"
p:validateRequest="true"
p:validateResponse="true"/>
<bean id="loggingInterceptor" class="org.springframework.ws.server.endpoint.interceptor.PayloadLoggingInterceptor"/>
</sws:interceptors>
<sws:dynamic-wsdl id="subscription"
portTypeName="SubscriptionPort"
locationUri="/"
targetNamespace="http://localhost:8080/ws/schema/oss">
<sws:xsd location="/WEB-INF/schema.xsd"/>
</sws:dynamic-wsdl>
<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller"
p:contextPath="org.krams.tutorial.model"/>
<bean id="marshallingPayloadMethodProcessor" class="org.springframework.ws.server.endpoint.adapter.method.MarshallingPayloadMethodProcessor">
<constructor-arg ref="jaxbMarshaller"/>
<constructor-arg ref="jaxbMarshaller"/>
</bean>
<bean id="defaultMethodEndpointAdapter" class="org.springframework.ws.server.endpoint.adapter.DefaultMethodEndpointAdapter">
<property name="methodArgumentResolvers">
<list>
<ref bean="marshallingPayloadMethodProcessor"/>
</list>
</property>
<property name="methodReturnValueHandlers">
<list>
<ref bean="marshallingPayloadMethodProcessor"/>
</list>
</property>
</bean>
<xs:element name="deliverShortMessageRequest">
<xs:complexType>
<xs:sequence>
<xs:element name="parameters" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="sms" type="tns:deliverShortMessage"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element />
<xs:element name="deliverShortMessageResponse">
<xs:complexType >
<xs:sequence>
<xs:element name="deliverShortMessageReturn" type="xs:boolean"/>
</xs:sequence>
</xs:complexType>
</xs:element>