camel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Bevenius <daniel.beven...@gmail.com>
Subject Re: Issue with Camel-Smooks integration in Servicemix
Date Fri, 27 Aug 2010 08:22:22 GMT
Hey Sorin,

so I've been thinking about this and I think you should now be able to skip
the convertBodyTo call since we now have the converter from the Smooks
specific class org.milyn.payload.StringResult. So in your example you could
remove the convertBodyTo element.

We might need to add more converters but this is very easy in Camel and you
can also do this yourself. You could for example create your own set of
converter that convert to your domain objects, or in the case you have now
you could have added your own custom converter to get around this issue with
us not yet having one for the type in question.

To add a converter you can take the following steps.
1. Create a class and annotate it with @Converter:
package my.customer.converters;

@Converter
public class CustomConverter
{
    private CustomConverter()
    {
    }

    @Converter
    public static StreamSource toStreamSource(StringResult stringResult)
    {
        String result = stringResult.getResult();
        if (result != null)
        {
            StringReader stringReader = new StringReader(result);
            return new StreamSource(stringReader);
        }

        return null;
    }
}
2. Add a file named
META-INF/services/org/apache/camel/component/TypeConverter with the
following content:
my.customer.converters

3. Package your converter and put it in Camels classpath so that Camel can
find it.

4. Now when Camel needs to convert between types your custom type converter
will be considered and used if they types match. You can also explicitly
call convert using camelContext.getTypeConverter.convertTo(type, value).

So if we supply a fair number of converter for the types we know about and
also make sure that we document how users of Smooks can add their own I
think this would be a reasonable solution. What do you think?

Regards,

/Daniel


2010/8/26 Daniel Bevenius <daniel.bevenius@gmail.com>

> Hey Sorin,
>
> >Isn't this something that Camel or Servicemix has to handle ?
> I think this my fault and this should be handled by the Smooks/Camel
> integration which I need to make more intuitive. Let me think about this and
> see if I can improve this.
>
> Regards,
>
> /Daniel
>
>
> 2010/8/26 Sorin Silaghi <sorin7486@gmail.com>
>
> Hey Daniel,
>>
>>
>>      Yes I'm using the same example. What I did in order to test this
>> out was I changed the SmooksDataFormat class to return StreamSource
>> instead of StringResult. It's not a permanent solution but right now
>> I'm just trying to learn about these things.
>>
>>      Now the converter example will probably work. I wasn't able to
>> test it because I'm having some trouble with my machine right now. I
>> wasn't able to look deeper into the string conversion either. But the
>> question is should users really have to do one of these conversions ?
>> Isn't this something that Camel or Servicemix has to handle ? I mean
>> it doesn't seem exactly intuitive that these conversions are required.
>>
>>
>> thanks for all the help,
>> Sorin.
>>
>>
>> On Wed, Aug 25, 2010 at 9:19 PM, Daniel Bevenius
>> <daniel.bevenius@gmail.com> wrote:
>> > Hey Sorin,
>> >
>> > that looks correct to me and this should work as we provide a converter
>> from
>> > StringResult to String.
>> >  We've also added a converter now that can convert directly from
>> > StringResult to a StreamSource which you could try but since the String
>> did
>> > not work I don't expect that will.
>> > Could you add a log element that logs the result of the formatter too:
>> > <log message="After SmooksDataFormat: ${body}"/>
>> >
>> > Are you using the same example that you posted previously to the Smooks
>> user
>> > list? If not, could you send me an updated version and I'll try this out
>> > tomorrow.
>> >
>> > Regards,
>> >
>> > /Daniel
>> >
>> > Can you try adding a log element to the route make sure the Smooks
>> >
>> > 2010/8/25 Sorin Silaghi <sorin7486@gmail.com>
>> >
>> >> Pardon my ignorance but do you mean like this:
>> >>
>> >>            <route>
>> >>              <from
>> >> uri="jbi:endpoint:
>> >> http://servicemix.apache.org/samples/bridge/marshaled/edi-endpoint"/>
>> >>              <unmarshal ref="myEdifact"/>
>> >>               <convertBodyTo type="java.lang.String"/>
>> >>               <to
>> >> uri="nmr:{http://servicemix.apache.org/samples/bridge}ftp:sender<http://servicemix.apache.org/samples/bridge%7Dftp:sender>
>> "/>
>> >>            </route>
>> >>
>> >> because that doesn't work.
>> >>
>> >>
>> >>
>> >> On Wed, Aug 25, 2010 at 5:47 PM, Claus Ibsen <claus.ibsen@gmail.com>
>> >> wrote:
>> >> > You can most likely just convert to String before sending to NMR
>> >> >     <convertBodyTo type="String"/>
>> >> >
>> >> >
>> >> >
>> >> >
>> >> > On Wed, Aug 25, 2010 at 4:22 PM, Sorin Silaghi <sorin7486@gmail.com>
>> >> wrote:
>> >> >> Hello,
>> >> >>
>> >> >>
>> >> >>       I've been trying out the camel-integration component that
>> >> >> Daniel Bevenius started from the Smooks project. If you don't know
>> >> >> about it here's where you can find it:
>> >> >>
>> https://svn.codehaus.org/milyn/workspaces/tfennelly/camel-integration
>> >> >>
>> >> >>       The problem I had is it didn't work in Servicemix with the
ftp
>> >> >> endpoint. It seems that the problem was with the object type that
>> was
>> >> >> returned by the unmarshal method in SmooksDataFormat. What Smooks
>> >> >> normally returns is an implementation of javax.xml.transform.Result
>> >> >> and what was needed is javax.xml.transform.stream.StreamSource.
>> >> >>
>> >> >>       So my question is where should this type conversion take
place
>> >> >> exactly? I'm not that familiar with Camel or Servicemix. I thought
>> I'd
>> >> >> send this to the Camel mailing list because the problem is related
>> to
>> >> >> this camel-integration component but let me know if I have to move
>> >> >> this to the Servicemix mailing list.
>> >> >>
>> >> >>       Bellow is the content of my camel-context.xml file:
>> >> >>
>> >> >>        <bean id="myEdifact"
>> >> >> class="org.milyn.smooks.camel.dataformat.SmooksDataFormat2">
>> >> >>
>> >>
>>  <constructor-arg><value>file:/home/sorin/work/EDIGrid/apache-servicemix-4.2.0/etc/smooks-config.xml</value></constructor-arg>
>> >> >>
>> >>
>>  <constructor-arg><value>org.milyn.payload.StringResult</value></constructor-arg>
>> >> >>          <constructor-arg><value>result</value></constructor-arg>
>> >> >>        </bean>
>> >> >>
>> >> >>        <camelContext xmlns="http://camel.apache.org/schema/spring">
>> >> >>          <route>
>> >> >>              <from
>> >> >> uri="jbi:endpoint:
>> >> http://servicemix.apache.org/samples/bridge/marshaled/edi-endpoint"/>
>> >> >>              <unmarshal ref="myEdifact"/>
>> >> >>              <to
>> >> >> uri="nmr:{http://servicemix.apache.org/samples/bridge}ftp:sender<http://servicemix.apache.org/samples/bridge%7Dftp:sender>
>> "/>
>> >> >>          </route>
>> >> >>        </camelContext>
>> >> >>
>> >> >>
>> >> >> thank you,
>> >> >>                Sorin.
>> >> >>
>> >> >
>> >> >
>> >> >
>> >> > --
>> >> > Claus Ibsen
>> >> > Apache Camel Committer
>> >> >
>> >> > Author of Camel in Action: http://www.manning.com/ibsen/
>> >> > Open Source Integration: http://fusesource.com
>> >> > Blog: http://davsclaus.blogspot.com/
>> >> > Twitter: http://twitter.com/davsclaus
>> >> >
>> >>
>> >
>>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message