mule發佈調用webservice

                                                               mule發佈webservice
java

        使用mule esb消息總線發佈和調用webservice都很是精簡,mule包裝了全部操做,你只須要拖控件配置就能夠,下面講解mule發佈:
web

                1.下面是flow,http監聽接口,CXF發佈webservice,java用來引用webservice的方法。
json

                image.png

                2.xml代碼以下:
api

    <flow name="webService">
    	<http:listener config-ref="HTTP_Listener_Configuration" path="hello" doc:name="HTTP"/>
    	<cxf:jaxws-service serviceClass="com.test.HelloWorld" doc:name="CXF"/>
    	<component class="com.test.HelloWorldImpl" doc:name="Java"/>
    </flow>

                 3.java代碼以下:app

                    ①Impl實現類ide

package com.test;

import javax.jws.WebService;

@WebService(endpointInterface = "com.test.HelloWorld",  
serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld{

	@Override
	public String sayHi(String text) {
		// TODO Auto-generated method stub
		return "Hello " + text;  
	}

}

                      ②Impl實現類工具

package com.test;

import javax.jws.WebService;

@WebService(endpointInterface = "com.test.HelloWorld",  
serviceName = "HelloWorld")
public class HelloWorldImpl implements HelloWorld{

	@Override
	public String sayHi(String text) {
		// TODO Auto-generated method stub
		return "Hello " + text;  
	}

}

                4.Java控件引用Class Name: com.test.HelloWorldImpl。
component


啓用mule服務,訪問http://localhost:8080/api/hello?wsdl 結果以下:orm

image.png

    至此,發佈成功。
xml


                                                         mule請求webservice

            使用mule esb請求webservice很是簡單,只須要使用Web Service Consumer控件就能夠,下面講解請求webservice:

                1.下面是flow,http請求監聽接口,Web Service Consumer調用接口,Set Payload傳遞參數。

                    image.png

                 2.請求webservice須要使用一個工具來拼裝請求的body:SoapUI-5.2.1.exe,下載連接在附件,使用方法以下:

                        image.png

                    咱們只須要<soap:Body>裏面的參數,須要把xmlns:web="http://Mozi.com/Webservices/"  粘貼到<web:PostPatientRequest> 請求裏,以下:

                    <web:PostPatientRequest xmlns:web="http://Mozi.com/Webservices/">

                         <!--Optional:?裏面是你的參數-->

                         <web:requestContent>?</web:requestContent>

                   </web:PostPatientRequest>

                 3.xml代碼以下:

  <http:listener-config name="HTTP_Listener_Configuration8081" host="localhost" port="8081" doc:name="HTTP Listener Configuration"/>
    <ws:consumer-config name="Web_Service_Consumer" wsdlLocation="http://localhost:8080/api/hello?wsdl" service="HelloWorldService" port="HelloWorldPort" serviceAddress="http://localhost:8080/api/hello" doc:name="Web Service Consumer"/>
    <flow name="customerFlow">
        <http:listener config-ref="HTTP_Listener_Configuration8081" path="/webService" doc:name="HTTP"/>
        <set-payload value="      &lt;web:PostPatientRequest  xmlns:web=&quot;http://Mozi.com/Webservices/&quot;&gt;
         &lt;web:requestContent&gt;#[json:]&lt;/web:requestContent&gt;
      &lt;/web:PostPatientRequest&gt;" doc:name="Set Payload" encoding="UTF-8" mimeType="application/xml"/>
        <ws:consumer config-ref="Web_Service_Consumer" operation="sayHi" doc:name="Web Service Consumer"/>
        <json:xml-to-json-transformer doc:name="XML to JSON"/>
    </flow>

                 至此,請求webservice發佈成功!   

相關文章
相關標籤/搜索