我是骆驼新手
我已经实现了自定义数据格式
现在我想在marshel或unmarshal方法中使用自定义属性。
这可以在驼峰中完成吗?
如果有任何办法,请举例。
我的自定义数据格式代码如下
package com.camel.spring.test.dataFormat;
import groovy.xml.MarkupBuilder;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.StringWriter;
import java.util.HashMap;
import org.apache.camel.Exchange;
import org.apache.camel.spi.DataFormat;
import com.predic8.wsdl.Definitions;
import com.predic8.wsdl.WSDLParser;
import com.predic8.wstool.creator.RequestCreator;
import com.predic8.wstool.creator.SOARequestCreator;
public final class SOAPDataFormat implements DataFormat {
public void marshal(Exchange exchange, Object dataDefination, OutputStream stream) throws Exception {
WSDLParser parser = new WSDLParser();
Definitions wsdl = parser
.parse("http://localhost:8081/Myservice/services/TestService?wsdl");
StringWriter writer = new StringWriter();
HashMap<String, Object> formParams = new HashMap<String, Object>();
SOARequestCreator creator = new SOARequestCreator(wsdl,
new RequestCreator(), new MarkupBuilder(writer));
creator.setBuilder(new MarkupBuilder(writer));
creator.setDefinitions(wsdl);
creator.setFormParams(formParams);
creator.setCreator(new RequestCreator());
creator.createRequest("TestService", "getApplication","TestServiceHttpBinding");
stream.write(writer.toString().getBytes());
}
public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
return null;
}
}
我的路线配置是
<camel:route>
<from uri="file:d:/inbox/wsJson?noop=true" />
<marshal >
<custom ref="soapDataFormat" />
</marshal>
<to uri="cxf://http://localhost:8081/Myservice/services/TestService?wsdlURL=http://localhost:8081//Myservice/services/TestService?wsdl&serviceName={http://service.application.atpl.com}TestService&portName={http://service.application.atpl.com}TestServiceHttpPort&dataFormat=MESSAGE"/>
</camel:route>
我正在进行封送处理,因此请忽略解组代码。
我希望将"http://localhost:8081/Myservice/services/TestService?wsdl","TestService", "getApplication","TestServiceHttpBinding"
值运行时传递给请求基于请求更改。
我通过设置标题值找到了一个解决方法,但这不是正确的解决方案
请帮帮我
提前致谢。