如何在Camel中路由一系列消耗SOAP Web服务的端点?

时间:2015-12-14 13:46:33

标签: java web-services soap apache-camel

使用Camel并尝试创建一个我想要使用供应商实施了多个步骤的Web服务的路由 供应商希望任何客户端首先调用Login端点,然后在成功登录后,任何其他调用都将成功。

http://edw.morningstar.com/webservice/edw.asmx?wsdl

我一直尝试了几种方法,但总是以返回字符串结束:

<StatusCode>1003</StatusCode><StatusMessage>You need call Login() or LoginAndGetClientId() first</StatusMessage>

我想做的是从目录中获取文件,然后将其作为二进制文件(base64)发送到Web服务。

编辑:格式错误的示例,修复了示例... 这是我的代码的一个版本:

        final ModelCamelContext camCtx = getContext();
        camCtx.setTracing(true);
        final CxfComponent cxf = new CxfComponent(getContext());
        final CxfEndpoint endLogin = new CxfEndpoint(
                "http://edw.morningstar.com/webservice/edw.asmx?Login&email=<nnn>&password=<nnn>&clientid=<nnn>",
                cxf);
        endLogin.setServiceClass(EDWSoap.class);
        endLogin.setDataFormat(org.apache.camel.component.cxf.DataFormat.CXF_MESSAGE);
        endLogin.setWsdlURL("http://edw.morningstar.com/webservice/edw.asmx?wsdl");

        final CxfEndpoint endGetUploadList = new CxfEndpoint(
                "http://edw.morningstar.com/webservice/edw.asmx?UploadPrivateList&ClientId=<nnn>&flag=ISIN&filename=filename.txt&fs=",
                cxf);
        endGetUploadList.setServiceClass(EDWSoap.class);
        endGetUploadList.setDataFormat(org.apache.camel.component.cxf.DataFormat.CXF_MESSAGE);
        endGetUploadList.setWsdlURL("http://edw.morningstar.com/webservice/edw.asmx?wsdl");

        from("file:data/inbox").marshal().base64().to(endLogin).to(endGetUploadList).log("MyLogg: ${body}").stop();

这里有追踪:

2015-12-14 14:38:24:463 o.a.camel.spring.SpringCamelContext INFO  - Route: route2 started and consuming from: Endpoint[file://data/inbox]
2015-12-14 14:38:25:513 o.a.c.processor.interceptor.Tracer INFO  - ID-Grevens-MBP-local-50361-1450100301592-0-2 >>> (route2) from(file://data/inbox) --> marshal[org.apache.camel.dataformat.base64.Base64DataFormat@2b289ac9] <<< Pattern:InOnly, Headers:{breadcrumbId=ID-Grevens-MBP-local-50361-1450100301592-0-1, CamelFileAbsolute=false, CamelFileAbsolutePath=/Users/mgr/git/FundDecomposition/FundDecomposition/data/inbox/kaka.txt, CamelFileContentType=null, CamelFileLastModified=1449815386000, CamelFileLength=5, CamelFileName=kaka.txt, CamelFileNameConsumed=kaka.txt, CamelFileNameOnly=kaka.txt, CamelFileParent=data/inbox, CamelFilePath=data/inbox/kaka.txt, CamelFileRelativePath=kaka.txt}, BodyType:org.apache.camel.component.file.GenericFile, Body:[Body is file based: GenericFile[kaka.txt]]
2015-12-14 14:38:25:523 o.a.c.processor.interceptor.Tracer INFO  - ID-Grevens-MBP-local-50361-1450100301592-0-2 >>> (route2) marshal[org.apache.camel.dataformat.base64.Base64DataFormat@2b289ac9] --> http://edw.morningstar.com/webservice/edw.asmx?UploadPrivateList&ClientId=<nnn>&flag=ISIN&filename=gegga.txt&fs= <<< Pattern:InOnly, Headers:{breadcrumbId=ID-Grevens-MBP-local-50361-1450100301592-0-1, CamelFileAbsolute=false, CamelFileAbsolutePath=/Users/mgr/git/FundDecomposition/FundDecomposition/data/inbox/kaka.txt, CamelFileContentType=null, CamelFileLastModified=1449815386000, CamelFileLength=5, CamelFileName=kaka.txt, CamelFileNameConsumed=kaka.txt, CamelFileNameOnly=kaka.txt, CamelFileParent=data/inbox, CamelFilePath=data/inbox/kaka.txt, CamelFileRelativePath=kaka.txt}, BodyType:byte[], Body:Z2VnZ2E=
2015-12-14 14:38:25:805 route2 INFO  - MyLogg: <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope"/><soap:Body><GetUniverseXMLResponse xmlns="http://tempuri.org/"><GetUniverseXMLResult><XOIException xmlns=""><StatusCode>1003</StatusCode><StatusMessage>You need call Login() or LoginAndGetClientId() first</StatusMessage></XOIException></GetUniverseXMLResult></GetUniverseXMLResponse></soap:Body></soap:Envelope>

1 个答案:

答案 0 :(得分:0)

如果@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); try { callback = (Callback) getParentFragment(); } catch (ClassCastException e) { throw new ClassCastException("Calling fragment must implement Callback interface"); } } endGetUploadList按预期工作,我会尝试这样的事情:

endLogin

(ProducerTemplate会在调用main webservice之前调用mock方法)