日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > java >内容正文

java

Java笔记-Spring Boot中Spring WS WS-Addressing中@Action实例

發布時間:2025/3/15 java 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java笔记-Spring Boot中Spring WS WS-Addressing中@Action实例 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

此筆記為利用Spring WS的WS-Addressing發送SOAP請求及接收其響應。

WS-Addressing(Web服務尋址):傳送Web服務端點的引用的數據結構,以及一套能夠在特定的消息上關聯尋址信息的消息尋址屬性。

?

服務端

@Endpoint:此注解告訴Spring注解這是個類有資格處理soap請求。

@Action:此注解映射特定的soap行為,比如返回一個簡單的POJO類。

package cn.it1995.server;import cn.it1995.GetTestRequest; import cn.it1995.GetTestResponse; import cn.it1995.MyTest; import org.springframework.ws.server.endpoint.annotation.Endpoint; import org.springframework.ws.server.endpoint.annotation.RequestPayload; import org.springframework.ws.server.endpoint.annotation.ResponsePayload; import org.springframework.ws.soap.addressing.server.annotation.Action;@Endpoint public class IT1995Endpoint {@Action("http://it1995.cn/getTestRequest")public @ResponsePayloadGetTestResponse getTest(@RequestPayload GetTestRequest request){GetTestResponse response = new GetTestResponse();MyTest myTest = new MyTest();myTest.setId(request.getId());myTest.setName("Hello World");response.setMyTest(myTest);return response;} }

關于空的soapAction

在配置Spring ws中,默認情況下都會生成包含空的soapAction的WSDL。可以覆蓋這個映射,設置適當的soapAction屬性。

如:

DefaultWsdl11Definition.setSoapActions(soapActions)

方法

package cn.it1995.server;import org.springframework.boot.context.embedded.ServletRegistrationBean; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; import org.springframework.ws.config.annotation.EnableWs; import org.springframework.ws.transport.http.MessageDispatcherServlet; import org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition; import org.springframework.xml.xsd.SimpleXsdSchema; import org.springframework.xml.xsd.XsdSchema;import java.util.Properties;@EnableWs @Configuration public class SoapServerConfig {@Beanpublic ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext){MessageDispatcherServlet servlet = new MessageDispatcherServlet();servlet.setApplicationContext(applicationContext);servlet.setTransformWsdlLocations(true);return new ServletRegistrationBean(servlet, "/ws/*");}@Bean(name = "it1995")public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema schema){DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();wsdl11Definition.setPortTypeName("IT1995Port");wsdl11Definition.setLocationUri("/ws");wsdl11Definition.setTransportUri("http://it1995.cn/webservice");wsdl11Definition.setSchema(schema);//為動態生成的wsdl添加soap actionProperties soapActions = new Properties();soapActions.setProperty("getTest", "http://it1995.cn/getTestRequest");wsdl11Definition.setSoapActions(soapActions);return wsdl11Definition;}@Beanpublic XsdSchema it1995Schema(){return new SimpleXsdSchema(new ClassPathResource("xsd/MyData.xsd"));} }

最后是關于Spring Boot的啟動項

package cn.it1995.server;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication public class RunServer {public static void main(String[] args){SpringApplication.run(RunServer.class);} }

?

Spring WS-Addressing客戶端

配置客戶端其中WS-Addressing開啟soap請求。通過擴展WebServiceGateWaySupport創建client。通過WebServiceTemplate發送soap請求。首先創建ActionCallback提供了action url。這個location注冊了server方法及WSDL。最后通過WebServiceTemplate發送請求及獲取Response。

package cn.it1995.client;import cn.it1995.GetTestRequest; import cn.it1995.GetTestResponse; import org.springframework.ws.client.core.support.WebServiceGatewaySupport; import org.springframework.ws.soap.addressing.client.ActionCallback;import java.net.URI; import java.net.URISyntaxException;public class IT1995Client extends WebServiceGatewaySupport {public GetTestResponse getTest(int id) throws URISyntaxException {GetTestRequest request = new GetTestRequest();request.setId(id);ActionCallback callback = new ActionCallback(new URI("http://it1995.cn/getTestRequest"));return (GetTestResponse)getWebServiceTemplate().marshalSendAndReceive(request, callback);} }

配置client端,創建一個marshaller發送請求及獲取響應,初始化客戶端。

package cn.it1995.client;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.oxm.jaxb.Jaxb2Marshaller;@Configuration public class SoapClientConfig {@Beanpublic Jaxb2Marshaller marshaller(){Jaxb2Marshaller marshaller = new Jaxb2Marshaller();marshaller.setContextPath("cn.it1995");return marshaller;}@Beanpublic IT1995Client it1995Client(Jaxb2Marshaller marshaller){IT1995Client client = new IT1995Client();client.setDefaultUri("http://localhost:8080/ws/it1995");client.setMarshaller(marshaller);client.setUnmarshaller(marshaller);return client;} }

配置client端,創建一個marshaller發送請求及獲取響應,初始化客戶端。

package cn.it1995.client;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.oxm.jaxb.Jaxb2Marshaller;@Configuration public class SoapClientConfig {@Beanpublic Jaxb2Marshaller marshaller(){Jaxb2Marshaller marshaller = new Jaxb2Marshaller();marshaller.setContextPath("cn.it1995");return marshaller;}@Beanpublic IT1995Client it1995Client(Jaxb2Marshaller marshaller){IT1995Client client = new IT1995Client();client.setDefaultUri("http://localhost:8080/ws/it1995");client.setMarshaller(marshaller);client.setUnmarshaller(marshaller);return client;} }

使用AnnotationConfigApplicationContext初始化客戶端,下面是個調用例子:

package cn.it1995.client;import cn.it1995.GetTestResponse; import org.springframework.context.annotation.AnnotationConfigApplicationContext;import java.net.URISyntaxException;public class RunClient {public static void main(String[] args) throws URISyntaxException {AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SoapClientConfig.class);IT1995Client client = context.getBean(IT1995Client.class);GetTestResponse response = client.getTest(1);System.out.println(response.getMyTest().getId());System.out.println(response.getMyTest().getName());} }

這里客戶端wsdl如下:

源碼打包下載地址:

https://github.com/fengfanchen/Java/tree/master/WebServiceAction

?

總結

以上是生活随笔為你收集整理的Java笔记-Spring Boot中Spring WS WS-Addressing中@Action实例的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 99国产精品国产精品九九 | 姐姐你真棒插曲快来救救我电影 | 久久窝窝 | a级黄视频 | 中国一级特黄毛片 | 日韩免费播放 | 天堂影视在线观看 | 国产在线视频网 | 美女的奶胸大爽爽大片 | 成人教育av| 成人深夜福利视频 | 国产视频欧美视频 | 岛国免费av | 熟妇人妻无码xxx视频 | 久久免费看少妇高潮 | 亚洲精品成人网 | 一区二区三区国产精品视频 | 男生插女生网站 | 亚洲wwwwww | 羞羞软件| 国产视频一区二区在线 | 韩国精品在线观看 | heyzo北岛玲在线播放 | 18精品爽国产白嫩精品 | 日韩大片一区 | 欧美国产成人精品一区二区三区 | 国产精品高清在线 | 久久九九久精品国产免费直播 | 免费一级suv好看的国产网站 | 狠狠艹av| 精品人妻无码一区二区 | 办公室大战高跟丝袜秘书经理ol | 超碰com| 69av在线| 91毛片视频 | 免费一级黄色大片 | 人妻互换一区二区激情偷拍 | 欧美成人性生活 | 日本青草视频 | 在线视频你懂得 | 亚洲一区二区蜜桃 | 亚洲国产日韩一区二区 | 国产精品秘入口18禁麻豆免会员 | 免费观看的毛片 | 亚洲国产精一区二区三区性色 | 真实乱偷全部视频 | 天天做天天操 | 男男做性免费视频网 | 成人在线手机视频 | 午夜成人鲁丝片午夜精品 | 韩日视频 | 国产尤物视频在线观看 | 看了下面会湿的视频 | 久久综合精品国产二区无码不卡 | 亚洲欧美一区二区在线观看 | 伊人资源| 超碰丝袜 | 亚洲国产精彩中文乱码av | 国产精品久久久久久久久久久免费看 | 波多野结衣亚洲视频 | 一本色道久久亚洲综合精品蜜桃 | 午夜aa | 在线免费观看国产视频 | 亚洲天堂2024| 精品久久人人妻人人做人人 | 久久噜噜 | 午夜伦理福利视频 | 日韩欧美aⅴ综合网站发布 国产成人一区二区三区小说 | 亚洲AV无码久久精品国产一区 | 人妻无码久久一区二区三区免费 | 日韩视频一区二区在线观看 | 一级中国毛片 | 青青草国产在线播放 | a级一片| 亚洲片在线观看 | 中文一区二区在线观看 | 国产 xxxx | 5566毛片 | 奇米四色影视 | 日本视频免费 | 中文av网站 | 极品美女无套呻吟啪啪 | 日本性生活一级片 | 欧美中文字幕在线 | 人成免费 | 黄色a在线观看 | av手机版| 日本老熟妇乱 | 香蕉视频入口 | 夜夜操操操 | 国产v在线观看 | 色噜噜日韩精品欧美一区二区 | 国产网友自拍 | 亚洲视频欧美 | 91久久久久久久久久久久 | 亚洲激情影院 | 原创露脸88av| 国内毛片毛片毛片毛片毛片 | 日日骚网 |