天天看點

ooofrom xfire to cxf

有個SOA項目,原來是使用xfire,最近閑來無事于是想把它轉移到cxf上,入門級,查了很多别人寫的東西,在結合cxf的網站,E文一般,加上猜測的成分,剛才終于算是可以釋出到tomcat上了。記錄下正确的東西。主要是我原來的項目沒有用annotation,隻是有接口和實作類,也沒用spring架構。

        不過配置servlet調用cxf還是要用spring,不然可能需要寫一些别的代碼,還是把spring的包引用進來吧。

         web.xml内容如下

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5"

 xmlns="http://java.sun.com/xml/ns/javaee"

 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

 http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

   <context-param>

  <param-name>contextConfigLocation</param-name>

  <param-value>/WEB-INF/beans.xml</param-value>

 </context-param>

 <listener>

  <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

 </listener>

 <servlet>

  <servlet-name>CXFServlet</servlet-name>

  <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

  <load-on-startup>1</load-on-startup>

 </servlet>

 <servlet-mapping>

  <url-pattern>/services/*</url-pattern>

 </servlet-mapping>

</web-app>

beans.xml的内容如下:

<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:simple="http://cxf.apache.org/simple"

xmlns:soap="http://cxf.apache.org/bindings/soap"

xsi:schemaLocation="

  http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd

  http://cxf.apache.org/bindings/soap http://cxf.apache.org/schemas/configuration/soap.xsd

  http://cxf.apache.org/simple http://cxf.apache.org/schemas/simple.xsd">

 <import resource="classpath:META-INF/cxf/cxf.xml" />

 <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />

 <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

 <simple:server id="hw" serviceClass="demo.hw.server.HelloWorld" address="/hw">

  <simple:serviceBean>

   <bean class="demo.hw.server.HelloWorldImpl" />

  </simple:serviceBean>

  <simple:dataBinding>

        <bean class="org.apache.cxf.aegis.databinding.AegisDatabinding" />

     </simple:dataBinding>

 </simple:server>

</beans> 

   使用預設的綁定資料方式啟動tomcat的時候會報錯,是以使用aegis,這種方式不會,具體不知道為什麼,需要繼續研究。

- <wsdl:definitions name="

HelloWorld

" targetNamespace="

http://server.hw.demo/

" xmlns:ns1="

http://cxf.apache.org/bindings/xformat

" xmlns:soap="

http://schemas.xmlsoap.org/wsdl/soap/

" xmlns:tns="

" xmlns:wsdl="

http://schemas.xmlsoap.org/wsdl/

" xmlns:xsd="

http://www.w3.org/2001/XMLSchema

">

- <wsdl:types>

- <xsd:schema attributeFormDefault="

unqualified

" elementFormDefault="

qualified

  <xsd:element name="

sayHi

" type="

tns:sayHi

" />

- <xsd:complexType name="

- <xsd:sequence>

  <xsd:element minOccurs="

" name="

greeting xsd:string

  </xsd:sequence>

  </xsd:complexType>

sayHiResponse tns:sayHiResponse return

" nillable="

true getADocument tns:getADocument

  <xsd:sequence />

getADocumentResponse tns:getADocumentResponse xsd:anyType

  </xsd:schema>

  </wsdl:types>

- <wsdl:message name="

  <wsdl:part element="

parameters

  </wsdl:message>

- <wsdl:portType name="

HelloWorldPortType

- <wsdl:operation name="

  <wsdl:input message="

  <wsdl:output message="

  </wsdl:operation>

  </wsdl:portType>

- <wsdl:binding name="

HelloWorldSoapBinding tns:HelloWorldPortType

  <soap:binding style="

document

" transport="

http://schemas.xmlsoap.org/soap/http

  <soap:operation soapAction="" style="

- <wsdl:input name="

  <soap:body use="

literal

  </wsdl:input>

- <wsdl:output name="

  </wsdl:output>

  </wsdl:binding>

- <wsdl:service name="

- <wsdl:port binding="

tns:HelloWorldSoapBinding HelloWorldPort

  <soap:address location="

http://127.0.0.1:9006/ra/services/hw

  </wsdl:port>

  </wsdl:service>

  </wsdl:definitions>