springboot系类代码:cxf-spring-boot-starter-jaxws

2022-06-20 12:05:56

Apache CXF = Celtix + XFire,开始叫 Apache CeltiXfire,后来更名为 Apache CXF 了,以下简称为 CXF。CXF 继承了 Celtix 和 XFire 两大开源项目的精华,提供了对 JAX-WS 全面的支持,并且提供了多种 Binding 、DataBinding、Transport 以及各种 Format 的支持,并且可以根据实际项目的需要,采用代码优先(Code First)或者 WSDL 优先(WSDL First)来轻松地实现 Web Services 的发布和使用。Apache CXF已经是一个正式的Apache顶级项目。

Web Service是一个平台独立的,低耦合的,自包含的、基于可编程的web的应用程序,可使用开放的XML(标准通用标记语言下的一个子集)标准来描述、发布、发现、协调和配置这些应用程序,用于开发分布式的交互操作的应用程序。
Web Service技术, 能使得运行在不同机器上的不同应用无须借助附加的、专门的第三方软件或硬件, 就可相互交换数据或集成。依据Web Service规范实施的应用之间, 无论它们所使用的语言、 平台或内部协议是什么, 都可以相互交换数据。Web Service是自描述、 自包含的可用网络模块, 可以执行具体的业务功能。Web Service也很容易部署, 因为它们基于一些常规的产业标准以及已有的一些技术,诸如标准通用标记语言下的子集XML、HTTP。Web Service减少了应用接口的花费。Web Service为整个企业甚至多个组织之间的业务流程的集成提供了一个通用机制。

package com.programb.webservice;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublicclassApplication{publicstaticvoidmain(String[] args){
        SpringApplication.run(Application.class, args);}}
package com.programb.webservice.client;import java.net.MalformedURLException;import java.net.URL;import javax.xml.namespace.QName;import javax.xml.ws.Service;import javax.xml.ws.WebEndpoint;import javax.xml.ws.WebServiceClient;import javax.xml.ws.WebServiceException;import javax.xml.ws.WebServiceFeature;@WebServiceClient(name="CommonService", targetNamespace="http://model.webservice.programb.com/", wsdlLocation="http://localhost:8092/services/CommonService?wsdl")publicclassCommonService_ServiceextendsService{privatefinalstatic URL COMMONSERVICE_WSDL_LOCATION;privatefinalstatic WebServiceException COMMONSERVICE_EXCEPTION;privatefinalstatic QName COMMONSERVICE_QNAME=newQName("http://model.webservice.programb.com/","CommonService");static{
        URL url= null;
        WebServiceException e= null;try{
            url=newURL("http://localhost:8092/services/CommonService?wsdl");}catch(MalformedURLException ex){
            e=newWebServiceException(ex);}
        COMMONSERVICE_WSDL_LOCATION= url;
        COMMONSERVICE_EXCEPTION= e;}publicCommonService_Service(){super(__getWsdlLocation(), COMMONSERVICE_QNAME);}publicCommonService_Service(WebServiceFeature... features){super(__getWsdlLocation(), COMMONSERVICE_QNAME, features);}publicCommonService_Service(URL wsdlLocation){super(wsdlLocation, COMMONSERVICE_QNAME);}publicCommonService_Service(URL wsdlLocation, WebServiceFeature... features){super(wsdlLocation, COMMONSERVICE_QNAME, features);}publicCommonService_Service(URL wsdlLocation, QName serviceName){super(wsdlLocation, serviceName);}publicCommonService_Service(URL wsdlLocation, QName serviceName, WebServiceFeature... features){super(wsdlLocation, serviceName, features);}/**
     * 
     * @return
     *     returns CommonService
     */@WebEndpoint(name="CommonServiceImplPort")public CommonServicegetCommonServiceImplPort(){returnsuper.getPort(newQName("http://model.webservice.programb.com/","CommonServiceImplPort"), CommonService.class);}/**
     * 
     * @param features
     *     A list of {@link WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
     * @return
     *     returns CommonService
     */@WebEndpoint(name="CommonServiceImplPort")public CommonServicegetCommonServiceImplPort(WebServiceFeature... features){returnsuper.getPort(newQName("http://model.webservice.programb.com/","CommonServiceImplPort"), CommonService.class, features);}privatestatic URL__getWsdlLocation(){if(COMMONSERVICE_EXCEPTION!= null){throw COMMONSERVICE_EXCEPTION;}return COMMONSERVICE_WSDL_LOCATION;}}
package com.programb.webservice.client;import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebResult;import javax.jws.WebService;import javax.xml.bind.annotation.XmlSeeAlso;import javax.xml.ws.RequestWrapper;import javax.xml.ws.ResponseWrapper;@WebService(name="CommonService", targetNamespace="http://model.webservice.programb.com/")@XmlSeeAlso({
    ObjectFactory.class})publicinterfaceCommonService{@WebMethod@WebResult(targetNamespace="")@RequestWrapper(localName="getUser", targetNamespace="http://model.webservice.programb.com/", className="com.programb.webservice.client.GetUser")@ResponseWrapper(localName="getUserResponse", targetNamespace="http://model.webservice.programb.com/", className="com.programb.webservice.client.GetUserResponse")public UsergetUser(@WebParam(name="userName", targetNamespace="")
                    String userName);@WebMethod@WebResult(targetNamespace="")@RequestWrapper(localName="sayHello", targetNamespace="http://model.webservice.programb.com/", className="com.programb.webservice.client.SayHello")@ResponseWrapper(localName="sayHelloResponse", targetNamespace="http://model.webservice.programb.com/", className="com.programb.webservice.client.SayHelloResponse")public StringsayHello(@WebParam(name="userName", targetNamespace="")
                    String userName);}
package com.programb.webservice.client;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlType;@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name="getUser", propOrder={"userName"})publicclassGetUser{protected String userName;public StringgetUserName(){return userName;}publicvoidsetUserName(String value){this.userName= value;}}
package com.programb.webservice.client;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlElement;import javax.xml.bind.annotation.XmlType;@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name="getUserResponse", propOrder={"_return"})publicclassGetUserResponse{@XmlElement(name="return")protected User _return;public UsergetReturn(){return _return;}publicvoidsetReturn(User value){this._return= value;}}
package com.programb.webservice.client;import javax.xml.bind.JAXBElement;import javax.xml.bind.annotation.XmlElementDecl;import javax.xml.bind.annotation.XmlRegistry;import javax.xml.namespace.QName;@XmlRegistrypublicclassObjectFactory{privatefinalstatic QName _GetUser_QNAME=newQName("http://model.webservice.programb.com/","getUser");privatefinalstatic QName _GetUserResponse_QNAME=newQName("http://model.webservice.programb.com/","getUserResponse");privatefinalstatic QName _SayHello_QNAME=newQName("http://model.webservice.programb.com/","sayHello");privatefinalstatic QName _SayHelloResponse_QNAME=newQName("http://model.webservice.programb.com/","sayHelloResponse");publicObjectFactory(){}public GetUserResponsecreateGetUserResponse(){returnnewGetUserResponse();}public SayHellocreateSayHello(){returnnewSayHello();}public GetUsercreateGetUser(){returnnewGetUser();}public SayHelloResponsecreateSayHelloResponse(){returnnewSayHelloResponse();}public UsercreateUser(){returnnewUser();}@XmlElementDecl(namespace="http://model.webservice.programb.com/", name="getUser")public JAXBElement<GetUser>createGetUser(GetUser value){returnnewJAXBElement<GetUser>(_GetUser_QNAME, GetUser.class, null, value);}@XmlElementDecl(namespace="http://model.webservice.programb.com/", name="getUserResponse")public JAXBElement<GetUserResponse>createGetUserResponse(GetUserResponse value){returnnewJAXBElement<GetUserResponse>(_GetUserResponse_QNAME, GetUserResponse.class, null, value);}@XmlElementDecl(namespace="http://model.webservice.programb.com/", name="sayHello")public JAXBElement<SayHello>createSayHello(SayHello value){returnnewJAXBElement<SayHello>(_SayHello_QNAME, SayHello.class, null, value);}@XmlElementDecl(namespace="http://model.webservice.programb.com/", name="sayHelloResponse")public JAXBElement<SayHelloResponse>createSayHelloResponse(SayHelloResponse value){returnnewJAXBElement<SayHelloResponse>(_SayHelloResponse_QNAME, SayHelloResponse.class, null, value);}}
package com.programb.webservice.client;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlType;@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name="sayHello", propOrder={"userName"})publicclassSayHello{protected String userName;public StringgetUserName(){return userName;}publicvoidsetUserName(String value){this.userName= value;}}
package com.programb.webservice.client;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlType;@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name="sayHello", propOrder={"userName"})publicclassSayHello{protected String userName;public StringgetUserName(){return userName;}publicvoidsetUserName(String value){this.userName= value;}}
package com.programb.webservice.client;import javax.xml.bind.annotation.XmlAccessType;import javax.xml.bind.annotation.XmlAccessorType;import javax.xml.bind.annotation.XmlType;@XmlAccessorType(XmlAccessType.FIELD)@XmlType(name="user", propOrder={"age","id","name"})publicclassUser{protected Integer age;protected Long id;protected String name;public IntegergetAge(){return age;}publicvoidsetAge(Integer value){this.age= value;}public LonggetId(){return id;}publicvoidsetId(Long value){this.id= value;}public StringgetName(){return name;}publicvoidsetName(String value){this.name= value;}}
package com.programb.webservice.config;import javax.xml.ws.Endpoint;import org.apache.cxf.Bus;import org.apache.cxf.jaxws.EndpointImpl;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import com.programb.webservice.service.ICommonService;@ConfigurationpublicclassCxfConfig{@Autowiredprivate Bus bus;@Autowired
    ICommonService commonService;@Beanpublic Endpointendpoint(){
        EndpointImpl endpoint=newEndpointImpl(bus, commonService);
        endpoint.publish("/CommonService");return endpoint;}}
package com.programb.webservice.model;publicclassUser{private Long id;private String name;private Integer age;publicUser(){}publicUser(Long id, String name, Integer age){this.id= id;this.name= name;this.age= age;}public LonggetId(){return id;}publicvoidsetId(Long id){this.id= id;}public StringgetName(){return name;}publicvoidsetName(String name){this.name= name;}public IntegergetAge(){return age;}publicvoidsetAge(Integer age){this.age= age;}}
package com.programb.webservice.service;import javax.jws.WebMethod;import javax.jws.WebParam;import javax.jws.WebService;import com.programb.webservice.model.User;@WebService(name="CommonService",// 暴露服务名称
        targetNamespace="http://model.webservice.programb.com/"// 命名空间,一般是接口的包名倒序)publicinterfaceICommonService{@WebMethod//    @WebResult(name = "String", targetNamespace = "")public StringsayHello(@WebParam(name="userName") String name);@WebMethod//    @WebResult(name = "String", targetNamespace = "")public UsergetUser(
  • 作者:咔啡
  • 原文链接:https://programb.blog.csdn.net/article/details/106226491
    更新时间:2022-06-20 12:05:56