Setting the parameter as Exchange properties or Message headers is the
right way.
The data format has access to these and can change the behavior based on
this.

Best,

Christian
-----------------

Software Integration Specialist

Apache Member
V.P. Apache Camel | Apache Camel PMC Member | Apache Camel committer
Apache Incubator PMC Member

https://www.linkedin.com/pub/christian-mueller/11/551/642


On Tue, Feb 11, 2014 at 9:58 AM, viral.patel69 <viral.pa...@algorhythm.co.in
> wrote:

> I am new to camel
>
> i have implemented custom dataformat
>
> *Now i want to use custom property in marshel or unmarshal method.*
>
> Is this possible to do this in camel?
>
> please give example if there is way.
>
> My custom dataformat code is as follows
>
>
> 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;
>         }
> }
>
>
> *my route configuration is*
>
> <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&amp;serviceName={http://service.application.atpl.com}TestService&amp;portName={http://service.application.atpl.com}TestServiceHttpPort&amp;dataFormat=MESSAGE
> "/>
>     </camel:route>
>
>
> I am just working on marshaling so ignore unmarshal code.
>
> i want to pass
> "http://localhost:8081/Myservice/services/TestService?wsdl","TestService";,
> "getApplication","TestServiceHttpBinding" values runtime that is changed on
> request to request basis.
>
> i found 1 work aroung by setting header values, but which is not proper
> solution
>
> please help me
>
> Thanks in advance.
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/how-to-pass-parameter-to-camel-custom-datafotmat-tp5747098.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>

Reply via email to