目的:用Talend將獲取的數據用webservice的形式發布接口
實現:
1、在Services下增加我們的Webservice,里面定義要實現的方法以及輸入輸出等。
我們也可以通過Source來直接編輯WSDL文件,附demo代碼:
<?xml version="1.0" encoding="UTF-8"?> <wsdl:definitions name="MyFirstService" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://www.talend.org/service/" targetNamespace="http://www.talend.org/service/"> <wsdl:types> <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.talend.org/service/"> <xsd:element name="InputMessage"> <xsd:complexType> <xsd:sequence> <xsd:element name="Get_BWPM_Users"> <xsd:complexType> <xsd:sequence> <xsd:element name="UserName" type="xsd:string" /> <xsd:element name="LastLoginYM" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> <xsd:element name="OutputMessage"> <xsd:complexType> <xsd:sequence> <xsd:element name="BWPM_User" minOccurs="0" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="UserName" type="xsd:string" /> <xsd:element name="LastLoginDate" type="xsd:string" /> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element> </xsd:schema> </wsdl:types> <wsdl:message name="getDataRequest"> <wsdl:part name="parameters" element="tns:InputMessage"></wsdl:part> </wsdl:message> <wsdl:message name="getDataResponse"> <wsdl:part name="parameters" element="tns:OutputMessage"></wsdl:part> </wsdl:message> <wsdl:message name="getQABWPMUsersRequest"> <wsdl:part name="parameters" element="tns:getQABWPMUsers"></wsdl:part> </wsdl:message> <wsdl:message name="getQABWPMUsersResponse"> <wsdl:part name="parameters" element="tns:getQABWPMUsersResponse"></wsdl:part> </wsdl:message> <wsdl:portType name="MyFirstServicePortType"> <wsdl:operation name="getData"> <wsdl:input message="tns:getDataRequest"></wsdl:input> <wsdl:output message="tns:getDataResponse"></wsdl:output> </wsdl:operation> </wsdl:portType> <wsdl:binding name="MyFirstServiceBinding" type="tns:MyFirstServicePortType"> <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" /> <wsdl:operation name="getData"> <soap:operation soapAction="http://www.talend.org/service/getData" /> <wsdl:input> <soap:body use="literal" /> </wsdl:input> <wsdl:output> <soap:body use="literal" /> </wsdl:output> </wsdl:operation> </wsdl:binding> <wsdl:service name="MyFirstService"> <wsdl:port name="MyFirstServicePort" binding="tns:MyFirstServiceBinding"> <soap:address location="http://localhost:8090/services/MyFirstService" /> </wsdl:port> </wsdl:service> </wsdl:definitions>
2、實現方法調用的Job
注:這個Job需要以tESBProviderRequest開頭,以tESBProviderResponse結尾
另外當tMSSqlInput取數為空時,就不會執行后面的tESBProviderResponse,導致調用返回錯誤信息,所以在tMSSqlInput處加了一個Run if(判斷條件為:(Integer)globalMap.get("tMSSqlInput_1_NB_LINE") == 0),讓查詢數據為空時走另外的流程來返回tESBProviderResponse,這樣查詢沒有結果就不會返回錯誤信息了!
3、Service加入Job
這樣Webservice基本完成!