6) Trying to generate the input with jaxb:
I used this tutorial:
http://camel.apache.org/tutorial-business-partners.html
6a) in the camel pom.xml, I add:
<dependency>
<artifactId>camel-jaxb</artifactId>
<groupId>org.apache.camel</groupId>
<version>1.4.0</version>
</dependency>
and
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
</plugin>
that respectively import the jaxb library and automatically generates java
classes.
And then I save the following xsd into src/main/xsd/messageHello.xsd:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema elementFormDefault="qualified" version="1.0"
targetNamespace="http://servicemix.apache.org/test3"
xmlns:tns="http://servicemix.apache.org/test3"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="message" type="xs:string">
</xs:element>
</xs:schema>
Run mvn install: the libraries are downloaded if not present and the build
is OK.
New auto generated classes are in target/generated-sources/jaxb
7) Trying to generate the output with java2wsdl:
in the camel pom.xml, i add :
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>2.2.2</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/target/generated-sources/wsdl</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/helloWorld.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
Run mvn install: the libraries are downloaded if not present and the build
is OK.
New auto generated classes are in target/generated-sources/wsdl
8) I create a new java class to test those two interfaces:
public static void main(String[] args) {
// read an xml input
String jaxbContext1 = "org.apache.servicemix.test3";
String input = "<message
xmlns=\"http://servicemix.apache.org/test3\">Hello</message>";
String inputWS = null;
try {
JAXBContext jc = JAXBContext.newInstance(jaxbContext1);
Unmarshaller u = jc.createUnmarshaller();
Object appDefaults = u.unmarshal(new
ByteArrayInputStream(input.getBytes()));
inputWS = ((JAXBElement<String>)appDefaults).getValue();
System.out.println(inputWS);
} catch (Exception e) {
e.printStackTrace();
}
// generate the SOAP output
HelloWorld hw = new HelloWorld();
HelloWorldPortType client = hw.getHelloWorldSOAP11PortHttp();
String output = client.hello(inputWS);
System.out.println(output);
}
prints:
Hello
Hello World
The aim is now to convert the input XML message to a SOAP message:
8a)
<message xmlns="http://servicemix.apache.org/test3">Hello</message>
---->
<ns0:hello xmlns:ns0="http://ode/bpel/unit-test.wsdl">
<TestPart>Held</TestPart>
</ns0:hello>
and to convert back SOAP response to XML:
8b)
<helloResponse xmlns:odens="http://ode/bpel/unit-test.wsdl">
<TestPart xmlns:q0="http://ode/bpel/unit-test.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Hello World</TestPart>
</helloResponse>
---->
<response xmlns="http://servicemix.apache.org/test3">Hello
World</response>
Using the org.apache.cxf, I don't know how to create a SOAP message instead
of call the WS.
Does something has to be done differently?
Does someone know how to match the pieces I have?
Fly13DW wrote:
>
> Thank you for your answer.
> I try to add the following properties to my xbean :useJBIWrapper="false"
> and useSOAPEnvelope="false"
> I get the following error:
> InvalidPropertyException: Invalid property 'useSOAPEnvelope' of bean class
> [org.apache.servicemix.cxfbc.CxfBcProvider]: No property 'useSOAPEnvelope'
> found
> So, I looked on the Internet and found that my cxf-bc was not up to date.
> Going on:
> http://people.apache.org/repo/m2-snapshot-repository/org/apache/servicemix/servicemix-cxf-bc/2009.02-SNAPSHOT/
> to downoload the installer and try again...
> And then, deployment is fine :)
> Testing the application.
> I send:
> <ns0:hello xmlns:ns0="http://ode/bpel/unit-test.wsdl">
> <TestPart>Hello</TestPart>
> </ns0:hello>
> and then I receive:
> STATUS: 200
> <?xml version='1.0' encoding='UTF-8'?>
> <odens:helloResponse xmlns:odens="http://ode/bpel/unit-test.wsdl">
> <TestPart xmlns:ns0="http://ode/bpel/unit-test.wsdl"
> xmlns:soap="http://www.w3.org/2003/05/soap-envelope">Held World</TestPart>
> </odens:helloResponse>
>
> So my SU system is working
>
> ------------------------------------------------------------
>
> I just need to do the transformation into the java class using the camel
> component.
>
> Here is the api: http://camel.apache.org/maven/camel-core/apidocs/
>
> My first question is about camel. I just try using the process method in
> the RouteBuilder as follow:
>
> public void configure() {
>
> from("jbi:service:http://www.servicemix.org/example/my-service-camel")
> .process(new XMLProcessor())
> .to("jbi:service:http://ode/bpel/unit-test.wsdl/helloWorld")
> .process(new SOAPProcessor());
> }
>
> private class XMLProcessor implements Processor {
>
> public void process(Exchange exch) throws Exception {
> // Message inMessage = exch.getIn();
> // Message outMessage = exch.getOut();
> // exch.setIn(inMessage);
> // exch.setOut(outMessage);
> }
> }
>
> private class SOAPProcessor implements Processor {
>
> public void process(Exchange exch) throws Exception {
>
> }
> }
>
> The commented code generates an error in ServiceMix:
> STATUS: 500
> <?xml version='1.0'
> encoding='UTF-8'?><error><![CDATA[java.lang.NullPointerException
> at
> org.apache.xalan.transformer.TransformerIdentityImpl.transform(TransformerIdentityImpl.java:418)
> at
> org.apache.servicemix.cxfbc.CxfBcProvider.convertMessageToInputStream(CxfBcProvider.java:691)
> at
> org.apache.servicemix.cxfbc.CxfBcProvider.process(CxfBcProvider.java:232)
> at
> org.apache.servicemix.common.AsyncBaseLifeCycle.doProcess(AsyncBaseLifeCycle.java:600)
> at
> org.apache.servicemix.common.AsyncBaseLifeCycle.processExchange(AsyncBaseLifeCycle.java:554)
> at
> org.apache.servicemix.common.AsyncBaseLifeCycle.onMessageExchange(AsyncBaseLifeCycle.java:510)
> at
> org.apache.servicemix.common.SyncLifeCycleWrapper.onMessageExchange(SyncLifeCycleWrapper.java:60)
> at
> org.apache.servicemix.jbi.messaging.DeliveryChannelImpl.processInBound(DeliveryChannelImpl.java:620)
> at
> org.apache.servicemix.jbi.nmr.flow.AbstractFlow.doRouting(AbstractFlow.java:172)
> at
> org.apache.servicemix.jbi.nmr.flow.seda.SedaFlow.doRouting(SedaFlow.java:168)
> at
> org.apache.servicemix.jbi.nmr.flow.seda.SedaQueue$1.run(SedaQueue.java:134)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
> at
> java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
> at java.lang.Thread.run(Thread.java:619)
> ]]></error>
>
> I'm asking myself:
> 5a) why this piece of code doesn't work when uncommented? (I thought I
> changed nothing...)
> 5b) Is there a simpler way to transform message using java (without xslt).
>
> I thought of this solution:
> - generate classes with jaxb for input xml post (based on the xsd)
> - generate classes with java2wsdl for output soap message.
> - link the input and the output with java code for incoming messages (in
> the XMLProcessor) and for responses (in the SOAPProcessor)
>
> 5c) Is this conception should not be used?
> 5d) do you think of a better way to do this?
>
>
> Gert Vanthienen wrote:
>>
>> L.S.,
>>
>> The CXF provider endpoint can receive the message in three different
>> formats. The default (that you are using now) is the JBI wrapper
>> format, which is a special JBI specific way to wrap a SOAP message.
>> You can disable this by adding useJBIWrapper="false" to your endpoint
>> definition. In that case, the endpoint expects the plain SOAP
>> envelope message. From the information in your previous mail, this
>> seems to be the configuration you need to use.
>>
>> And finally, if you specify both useJBIWrapper="false" and
>> useSOAPEnvelope="false, you tell the endpoint that you are going to
>> send only the actual message to be sent, without any wrappers. For
>> your use case, this would allow you to send the plain <ns0:hello
>> xmlns:ns0="http://ode/bpel/unit-test.wsdl">...</ns0:hello> message.
>>
>> Hope this helps your get over the final hurdle,
>>
>> Gert Vanthienen
>> ------------------------
>> Open Source SOA: http://fusesource.com
>> Blog: http://gertvanthienen.blogspot.com/
>>
>>
>>
>> 2009/5/29 Fly13DW <[email protected]>:
>>>
>>> Hello,
>>>
>>> I just wanted to remember what I am trying to do:
>>>
>>> -------------- ---------------
>>> -------------
>>> XML Message >>>>>> | BC : HTTP SU | >>>>>> | SE : CAMEL SU | >>>>>> | BC
>>> :
>>> CXF SU | >>>>>> WebService
>>> -------------- ---------------
>>> -------------
>>> http://localhost:8192/example my-service-camel helloWorld
>>> http://localhost:8080/ode/processes/helloWorld
>>> (copy/paste in notepad for a better view)
>>>
>>
>
>
--
View this message in context:
http://www.nabble.com/components-to-use-for-an-XML-to-SOAP-request-tp23745527p23834630.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.