我們如何通過基於Rest的項目使用Spring Maven來訪問其戰爭部署在同一臺服務器上的soap項目的wsdl。基本上,我必須訪問通過wsdl公開的API,並且我必須訪問此API,響應比需要從其他POST方法作爲JSON返回的響應。它將像REST post方法一樣,接受輸入並調用此API(來自wsdl)並將響應操作爲JSON,但我不得不在不知情的情況下跳入WebServices和Spring框架。所以,任何幫助或指示,以快速學習這些東西將不勝感激。在基於Spring REST的客戶端訪問通過wsdl公開的API
0
A
回答
-1
Hi I have used the following approach to implement the above requirement:
http://myshittycode.com/2013/10/01/using-spring-web-services-and-jaxb-to-invoke-web-service-based-on-wsdl/
1. changed the pom to add spring-ws dependency and plugin.
2. build the classes and it generated the classes from the wsdl.
3. changed the application xml :
<!--Generating web sources-->
<!-- Define the SOAP version used by the WSDL -->
<bean id="soapMessageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory">
<property name="soapVersion">
<util:constant static-field="org.springframework.ws.soap.SoapVersion.SOAP_12"/>
</property>
</bean>
<!-- The location of the generated Java files -->
<oxm:jaxb2-marshaller id="marshaller" contextPath="com.pb.pims.generatedsources"/>
<!-- Configure Spring Web Services -->
<bean id="webServiceTemplate" class="org.springframework.ws.client.core.WebServiceTemplate">
<constructor-arg ref="soapMessageFactory"/>
<property name="marshaller" ref="marshaller"/>
<property name="unmarshaller" ref="marshaller"/>
<property name="defaultUri" value="http://localhost/HSWS/services/HSService?wsdl"/>
</bean>
4. Created the Service class;
@Service
public class HSService {
@Autowired
private WebServiceTemplate webServiceTemplate;
public List<HSChild> getHSChildren(String hscode, String country,String limit) {
GetHSChildren getHSChildren= new ObjectFactory().createGetHSChildren();
getHSChildren.setCountry(country);
getHSChildren.setHsCode(hscode);
getHSChildren.setLimit(Integer.parseInt(limit));
GetHSChildrenResponse response = (GetHSChildrenResponse) webServiceTemplate.marshalSendAndReceive(getHSChildren);
return response.getGetHSChildrenReturn();
}
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
HSService hsService = context.getBean(HSService.class);
}
}
So, I am able to call this aPI from the wsdl via my client. But I am always getting the values of the getGetHSChildrenReturn. hscode and getGetHSChildrenReturn.description as null.
Please find below the getGetHSChildrenReturn.class generated in the Step1 :
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"getHSChildrenReturn"
})
@XmlRootElement(name = "getHSChildrenResponse")
public class GetHSChildrenResponse {
@XmlElement(required = true)
protected List<HSChild> getHSChildrenReturn;
public List<HSChild> getGetHSChildrenReturn() {
if (getHSChildrenReturn == null) {
getHSChildrenReturn = new ArrayList<HSChild>();
}
return this.getHSChildrenReturn;
}
Also, I verified in the service code , which we are invoking via this wsdl by putting logging, that the correct request is going and it is returning the expected response at service end. But while coming to the client, the values are set as null.
Please help, what's wrong here in the client side.
Thanks in advance.
0
你需要做到以下幾點:Spring - Consuming a SOAP service:
- 從WSDL
這可以在Spring中與下述技術acomplished創建客戶端代碼。它將生成您需要從REST API代碼中調用該服務的Java類。在這種情況下,您在同一臺服務器上調用另一項服務,您只需將端點url設置爲您的服務器即可。 - 創建您的REST API
您可以使用Spring MVC設計您的REST API並調用SOAP服務。您需要開發一個帶有不同端點和正確的請求和響應對象的Controller類。 Spring MVC會使用Jackson框架自動將這些請求和響應對象轉換爲JSON。使用本指南:Building a RESTful Web Service
這是從Java REST API消耗SOAP服務的通用方式。如果目標是簡單地將SOAP服務作爲REST服務公開,那麼您可以返回從WSDL生成的響應對象。如果這是一個選項,我會仔細考慮重構SOAP服務代碼並將其作爲REST API公開。
注意:通過直接使用JAX-WS實現消耗SOAP的美好時光,並通過Jackson公開JSON對象。
相關問題
- 1. 限制客戶端的REST API訪問
- 2. 關於通過使用Axis2的wsdl開發客戶端
- 3. 訪問WSDL文件的SOAP客戶端
- 4. 通過客戶端存根訪問WSDL時InaccessibleWSDLException
- 5. CXF Rest客戶端 - 基於代理的API和CXF WebClient API
- 6. Java Spring作爲基於Akka的REST HTTP調用的客戶端
- 7. 通過https訪問REST API
- 8. 開始爲基於Django REST API的系統開發客戶端(CORS錯誤)?
- 9. 訪問Wsdl Web服務客戶端GWT
- 10. 爲不同的客戶端公開不同的WSDL
- 11. JS客戶端的REST API
- 12. 來自WSDL的Spring-ws客戶端
- 13. 通過java客戶端的Github API訪問
- 14. 通過GridView的客戶端API訪問行數據
- 15. Facebook api通過客戶端軟件訪問用戶名/密碼
- 16. GWT客戶端端rest API
- 17. 客戶端通過Internet訪問SQL Server
- 18. iOS:從iOS客戶端訪問wsdl服務api
- 19. WSDL客戶端問題,PHP
- 20. 通用開源REST客戶端?
- 21. 創建REST客戶端API
- 22. 客戶端ID和客戶端訪問foursquare API的祕密
- 23. ASP.Net的Web API客戶端訪問
- 24. Ruby客戶端訪問Ebay API
- 25. 客戶端調用Rest API通過部署在AWS上的Tomcat公開使用https
- 26. C#REST API客戶端
- 27. Java客戶端API用於訪問Hbase的用戶
- 28. C#REST API客戶端Prestashop
- 29. C++通過COM公開C#的客戶端
- 30. 消費從ServiceStack客戶端通過SOAP公開的Java CXF WS