使用对象而不是模式xml时的@PayloadRoot值
||
我正在使用对象作为从客户端到服务服务器的消息。
应该如何配置端点以便找到服务?
@PayloadRoot在这里似乎不合适,因为我不使用xml模式,而是使用带注释的对象
@XmlRootElement(即街道)
我的代码:
spring-ws-servlet.xml
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<beans xmlns=\"http://www.springframework.org/schema/beans\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"
xmlns:context=\"http://www.springframework.org/schema/context\"
xmlns:sws=\"http://www.springframework.org/schema/web-services\"
xmlns:oxm=\"http://www.springframework.org/schema/oxm\"
xsi:schemaLocation=\"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/web-services http://www.springframework.org/schema/web-services/web-services-2.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd\">
<context:component-scan base-package=\"com.coral.project.endpoints\"/>
<sws:annotation-driven />
<sws:dynamic-wsdl id=\"test\" portTypeName=\"TestCase\" locationUri=\"/testService/\"
targetNamespace=\"http://www.example.org/schemasDef/test/definitions\">
<sws:xsd location=\"/WEB-INF/schemasDef/test.xsd\"/>
</sws:dynamic-wsdl>
<bean id=\"springWSClient\" class=\"com.coral.project.endpoints.SpringWSClient\">
<property name=\"defaultUri\" value=\"http://localhost:8080/parking/springServices/testService/\"/>
<property name=\"marshaller\" ref=\"marshaller\" />
<property name=\"unmarshaller\" ref=\"marshaller\" />
</bean>
<oxm:jaxb2-marshaller id=\"marshaller\">
<oxm:class-to-be-bound name=\"com.coral.project.entity.Street\"/>
</oxm:jaxb2-marshaller>
</beans>
客户端:
public class SpringWSClient extends WebServiceGatewaySupport {
public void getSum() throws SOAPException, IOException, TransformerException {
StreetDao streetDao = SpringUtils.getBean(StreetDao.class);
Street street = streetDao.findById(1);
getWebServiceTemplate().marshalSendAndReceive(street);
}
}
端点:
@Endpoint
public class SpringWsEndpoint {
@Inject
private SpringWebService springWebService;
@PayloadRoot(localPart = \"street\", namespace = \"http://blahblah\")
@ResponsePayload
public Element handleTestRequest(@RequestPayload SAXSource testRequest) throws Exception {
String fisrt = firstNum.valueOf(testRequest);
String second = secondNum.valueOf(testRequest);
String sum = springWebService.sum(Integer.parseInt(fisrt), Integer.parseInt(second)).toString();
Element responseElement = new Element(\"TestRequest\");
Element sumElement = new Element(\"sum\");
sumElement.setText(sum);
responseElement.setContent(sumElement);
return responseElement;
}
}
没有找到相关结果
已邀请:
2 个回复
拟僚疽刊剔
TestRequest.java
spring-ws-servlet.xml
SpringWsEndpoint.java
SpringWsClient.java
磐去裸猜饲
} 端点方法:
最后一步是省略WSClient部分,仅定义jaxb2 marshaller:
现在,我的端点在CDATA中返回响应字符串。实际上,它只是传递数据,对数据做最少的事情。