使用 Camel 并尝试创建一条路线,我想在其中使用供应商已实现多个步骤的 Web 服务。
供应商希望任何客户端首先调用登录端点,然后在成功登录后任何其他调用都会成功。
http://edw.morningstar.com/webservice/edw.asmx?wsdl
我尝试了多种方法,但总是以返回字符串结束:
<StatusCode>1003</StatusCode><StatusMessage>You need call Login() or LoginAndGetClientId() first</StatusMessage>
我想做的是从目录中获取文件,然后将其作为二进制(base64)发送到网络服务。
编辑:格式错误的示例,修复了示例...这是我的代码的一个版本:
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>
如果endGetUploadList
和endLogin
按预期工作,我会尝试这样的事情:
from("file:data/inbox")
.process(new Processor() {
@Override
public void process(Exchange exchange) throws Exception {
ProducerTemplate producer=exchange.getContext().createProducerTemplate();
producer.requestBody("direct:mock", new Object());
}
})
.marshal()
.base64()
.to(endGetUploadList)
.log("MyLogg: ${body}")
.stop();
(ProducerTemplate 将在调用主 Web 服务之前调用您的模拟路由)
我是一名优秀的程序员,十分优秀!