欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

如何使用spring-ws發(fā)布webservice服務(wù)

 更新時(shí)間:2024年11月11日 10:12:34   作者:昱禹  
文章介紹了如何使用Spring-WS發(fā)布Web服務(wù),包括添加依賴、創(chuàng)建XSD文件、生成JAXB實(shí)體、配置Endpoint、啟動(dòng)服務(wù)等步驟,結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧

spring-ws

添加依賴、插件

pom.xml添加

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web-services</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
        </dependency>
        <!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
        <dependency>
            <groupId>wsdl4j</groupId>
            <artifactId>wsdl4j</artifactId>
            <version>1.6.3</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
        <dependency>
            <groupId>javax.xml.bind</groupId>
            <artifactId>jaxb-api</artifactId>
            <version>2.3.1</version>
        </dependency>
<!--            要用的時(shí)候把下面插件打開(kāi), 不用了記得注釋-->
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>3.1.0</version>
                <executions>
                    <execution>
                        <id>xjc</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <sources>
                        <source>${project.basedir}/src/main/resources/xsd/fakeBindUrl.xsd</source>
                    </sources>
                </configuration>
            </plugin>

創(chuàng)建XSD文件

對(duì)比實(shí)際輸入輸出參考修改xsd

實(shí)際輸入、輸出 輸入

<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:snr="snr">
<soapenv:Header/>
<soapenv:Body>
<snr:bindRequest soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<RequestInfo xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<Root>
<Domain>host</Domain>
<Passwd>pasdasjidojoi</Passwd>
<SrvCode>489489489445645648</SrvCode>
<Content>
<![CDATA[<?xml version='1.0' encoding='UTF-8'?><FakePassQuery><FakeCode>admin</FakeCode><Password><![CDATA[dsaiodas54545]]]]><![CDATA[></Password><FakeType>1000</FakeType></FakePassQuery>]]>
</Content>
</Root>
</RequestInfo></snr:bindRequest></soapenv:Body></soapenv:Envelope>

輸出

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
    <SOAP-ENV:Header/>
    <SOAP-ENV:Body>
        <FakePassQueryResponse>
            <ExchangeId>a79bc02ea21a4a13a7c58108cc864a9d</ExchangeId>
            <ErrorCode>00000</ErrorCode>
            <IsSuccess>T</IsSuccess>
            <FakeContent>
                <FakeId>1</FakeId>
                <FakeCode>admin</FakeCode>
                <StaffName>admin</StaffName>
                <OrgId/>
                <EffDate>2024-01-01 00:00:00</EffDate>
                <ExpDate>2125-01-08 13:28:52</ExpDate>
                <StatusCd>0</StatusCd>
                <ContactTel/>
                <SmsTel/>
            </FakeContent>
        </FakePassQueryResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

xsd

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://spring.io/guides/gs-producing-web-service"
           targetNamespace="http://spring.io/guides/gs-producing-web-service" elementFormDefault="qualified">
    <xs:element name="bindRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="RequestInfo" type="tns:RequestInfo"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="RequestInfo">
        <xs:sequence>
            <xs:element name="Root" type="tns:Root"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="Root">
        <xs:sequence>
            <xs:element name="Domain" type="xs:string"/>
            <xs:element name="Passwd" type="xs:string"/>
            <xs:element name="SrvCode" type="xs:string"/>
            <xs:element name="Content" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:complexType name="FakePassQuery">
        <xs:sequence>
            <xs:element name="FakeCode" type="xs:string"/>
            <xs:element name="Password" type="xs:string"/>
            <xs:element name="FakeType" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
    <xs:element name="FakePassQueryResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="ErrorInfo" type="xs:string"/>
                <xs:element name="ResultCode" type="xs:string"/>
                <xs:element name="ExchangeId" type="xs:string"/>
                <xs:element name="ErrorCode" type="xs:string"/>
                <xs:element name="IsSuccess" type="xs:string"/>
                <xs:element name="FakeContent" type="tns:FakeContent"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:complexType name="FakeContent">
        <xs:sequence>
            <xs:element name="FakeId" type="xs:string"/>
            <xs:element name="FakeCode" type="xs:string"/>
            <xs:element name="StaffName" type="xs:string"/>
            <xs:element name="OrgId" type="xs:string"/>
            <xs:element name="EffDate" type="xs:string"/>
            <xs:element name="ExpDate" type="xs:string"/>
            <xs:element name="StatusCd" type="xs:string"/>
            <xs:element name="ContactTel" type="xs:string"/>
            <xs:element name="SmsTel" type="xs:string"/>
        </xs:sequence>
    </xs:complexType>
</xs:schema>

生成xsd實(shí)體

idea -> maven -> 插件 -> jaxb2 -> jaxb2:xjc
生成的文件在:target\generated-sources\jaxb

配置

@EnableWs
@Configuration
public class WebServiceConfig extends WsConfigurerAdapter {
    @Bean
    public ServletRegistrationBean<MessageDispatcherServlet> messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean<>(servlet, "/ws/*");
    }
    // 這里的BeanName就是實(shí)際訪問(wèn)路徑,當(dāng)前服務(wù)請(qǐng)求路徑: ip:port/ws/fakeBindUrl
    @Bean(name = "fakeBindUrl")
    public DefaultWsdl11Definition defaultWsdl11Definition(XsdSchema subAcctInfoForSelfBindSchema) {
        DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
        wsdl11Definition.setPortTypeName("CountriesPort");
        wsdl11Definition.setLocationUri("/ws");
        wsdl11Definition.setTargetNamespace("snr");
        wsdl11Definition.setSchema(subAcctInfoForSelfBindSchema);
        return wsdl11Definition;
    }
    @Bean
    public XsdSchema subAcctInfoForSelfBindSchema() {
        return new SimpleXsdSchema(new ClassPathResource("xsd/fakeBindUrl.xsd"));
    }
    // 多個(gè)webservice服務(wù),則注冊(cè)多個(gè)wsdl11Definition、XsdSchema
    // 這里的BeanName就是實(shí)際訪問(wèn)路徑,當(dāng)前這個(gè)就是/ws/fakeBindUrl2
    // @Bean(name = "fakeBindUrl2")
    // public DefaultWsdl11Definition defaultWsdl11Definition2(XsdSchema subAcctInfoForSelfBindSchema2) {
    // 	DefaultWsdl11Definition wsdl11Definition = new DefaultWsdl11Definition();
    // 	wsdl11Definition.setPortTypeName("CountriesPort");
    // 	wsdl11Definition.setLocationUri("/ws");
    // 	wsdl11Definition.setTargetNamespace("snr");
    // 	wsdl11Definition.setSchema(subAcctInfoForSelfBindSchema);
    // 	return wsdl11Definition;
    // }
    // @Bean
    // public XsdSchema subAcctInfoForSelfBindSchema2() {
    // 	return new SimpleXsdSchema(new ClassPathResource("xsd/fakeBindUrl.xsd"));
    // }
}

定義Endpoint

@Endpoint
@Slf4j
public class bindRequestEndpoint {
    private static final String NAMESPACE_URI = "snr";
    @Autowired
    private SubAcctBindingService subAcctBindingService;
    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "bindRequest")
    @ResponsePayload
    public FakePassQueryResponse fakeBindUrl(@RequestPayload bindRequest requestInfo) {
        try {
            log.info("收到請(qǐng)求: {}", requestInfo);
            // 解析requestInfo的XML內(nèi)容進(jìn)行業(yè)務(wù)處理
            FakePassQuery FakePassQuery = parseInnerXML(requestInfo.getRequestInfo().getRoot().getContent());
            FakePassQueryResponse result = subAcctBindingService.processBindRequest(FakePassQuery);
            return result;
        } catch (Exception e) {
            log.error("處理請(qǐng)求時(shí)發(fā)生異常: ", e);
            // 組裝錯(cuò)誤響應(yīng)
            FakePassQueryResponse response = new FakePassQueryResponse();
            response.setErrorInfo(e.getMessage());
            response.setResultCode("-1");
            response.setIsSuccess("F");
            return response;
        }
    }
}

啟動(dòng)服務(wù)

當(dāng)前服務(wù)的ip端口號(hào)
ip:port/ws/fakeBindUrl?wsdl

其他

如遇報(bào)錯(cuò)可以在入?yún)⒅袊L試加入namespace

@XmlRootElement(namespace="", ...)

1 counts of IllegalAnnotationExceptions

入?yún)⒒虺鰠⒍x有問(wèn)題
@XmlTypepropOrder與實(shí)際屬性不符等等

到此這篇關(guān)于使用spring-ws發(fā)布webservice服務(wù)的文章就介紹到這了,更多相關(guān)Spring AI Alibaba百煉平臺(tái)大模型內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Nacos1.4.0 Windows10單機(jī)模式啟動(dòng)和集群?jiǎn)?dòng)過(guò)程解析

    Nacos1.4.0 Windows10單機(jī)模式啟動(dòng)和集群?jiǎn)?dòng)過(guò)程解析

    這篇文章主要介紹了Nacos1.4.0 Windows10單機(jī)模式啟動(dòng)和集群?jiǎn)?dòng),第一次使用nacos,廢話不多說(shuō),記錄下自己?jiǎn)?dòng)Nacos遇到的坑,感興趣的朋友跟隨小編一起看看吧
    2023-10-10
  • Spring?Bean創(chuàng)建的另一條捷徑

    Spring?Bean創(chuàng)建的另一條捷徑

    這篇文章主要為大家介紹了Spring?Bean創(chuàng)建的另一條方法捷徑詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-08-08
  • 運(yùn)用示例詳細(xì)總結(jié)Java多線程

    運(yùn)用示例詳細(xì)總結(jié)Java多線程

    本文主要講解了Java多線程,該篇幅大量使用代碼以及圖片文字進(jìn)行解析,可以讓小伙伴們了解該方面的知識(shí)更加迅速快捷
    2021-08-08
  • SSM框架搭建圖文教程(推薦)

    SSM框架搭建圖文教程(推薦)

    下面小編就為大家?guī)?lái)一篇SSM框架搭建圖文教程(推薦)。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-09-09
  • 使用Java實(shí)現(xiàn)通用樹(shù)形結(jié)構(gòu)構(gòu)建工具類

    使用Java實(shí)現(xiàn)通用樹(shù)形結(jié)構(gòu)構(gòu)建工具類

    這篇文章主要為大家詳細(xì)介紹了如何使用Java實(shí)現(xiàn)通用樹(shù)形結(jié)構(gòu)構(gòu)建工具類,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起學(xué)習(xí)一下
    2025-03-03
  • Spring Boot應(yīng)用監(jiān)控的實(shí)戰(zhàn)教程

    Spring Boot應(yīng)用監(jiān)控的實(shí)戰(zhàn)教程

    Spring Boot 提供運(yùn)行時(shí)的應(yīng)用監(jiān)控和管理功能,下面這篇文章主要給大家介紹了關(guān)于Spring Boot應(yīng)用監(jiān)控的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),需要的朋友可以參考借鑒,下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2018-05-05
  • 關(guān)于Java集合框架面試題(含答案)下

    關(guān)于Java集合框架面試題(含答案)下

    Java集合框架為Java編程語(yǔ)言的基礎(chǔ),也是Java面試中很重要的一個(gè)知識(shí)點(diǎn)。這里,我列出了一些關(guān)于Java集合的重要問(wèn)題和答案。
    2015-12-12
  • Java list.remove( )方法注意事項(xiàng)

    Java list.remove( )方法注意事項(xiàng)

    這篇文章主要介紹了Java list.remove( )方法注意事項(xiàng),非常簡(jiǎn)單易懂,需要的朋友可以參考下
    2018-08-08
  • 深入了解JAVA 軟引用

    深入了解JAVA 軟引用

    這篇文章主要介紹了JAVA 軟引用的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí),感興趣的朋友可以了解下
    2020-08-08
  • 你真的會(huì)使用Java的方法引用嗎

    你真的會(huì)使用Java的方法引用嗎

    這篇文章主要給大家介紹了關(guān)于Java方法引用的相關(guān)資料,方法引用是Java8的新特性,方法引用其實(shí)也離不開(kāi)Lambda表達(dá)式,本文通過(guò)示例代碼介紹的很詳細(xì),需要的朋友可以參考下
    2021-08-08

最新評(píng)論