Et voila:

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.servicemix.MessageExchangeListener;
import org.apache.servicemix.components.http.HttpClientMarshaler;
import org.apache.servicemix.components.util.ComponentSupport;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.w3c.dom.Document;

import javax.jbi.JBIException;
import javax.jbi.messaging.*;
import javax.xml.namespace.QName;

public class HttpClientBC extends ComponentSupport implements
MessageExchangeListener {

  private SourceTransformer _transformer;
    protected HttpClientMarshaler marshaler = new HttpClientMarshaler();
    protected MultiThreadedHttpConnectionManager connectionManager = new
MultiThreadedHttpConnectionManager();
    protected HttpClient httpClient = new HttpClient(connectionManager);
    protected HostConfiguration hostConfiguration = new
HostConfiguration();
    protected String url;


    public void stop() throws JBIException {
        super.stop();
        connectionManager.shutdown();
    }


    public HttpClientBC() {
       
    }


    public void onMessageExchange(MessageExchange messageExchange)
throws MessagingException {
        InOut inOut = (InOut) messageExchange;
        if (inOut.getStatus() == ExchangeStatus.DONE) {
            return;
        } else if (inOut.getStatus() == ExchangeStatus.ERROR) {
            return;
        }
        try {

            NormalizedMessage inMsg = inOut.getInMessage();
            Document doc = (Document)
_transformer.toDOMNode(inMsg.getContent());

...  Do something with the message ?!

            boolean httpResponse = sendHttpReq();
..... Do something with the response?!

            NormalizedMessage answer = inOut.createMessage();
            answer.setContent(....);

            answer(inOut, answer);
        } catch (Exception e) {
            throw new MessagingException(e);
        }
    }

    private boolean sendHttpReq(String id) {
        PostMethod method = new PostMethod(url);
        try {
            method.addParameter("id", id);
            int response = httpClient.executeMethod(hostConfiguration,
method);

            if (response != HttpStatus.SC_OK && response !=
HttpStatus.SC_ACCEPTED) {
                return false;
            }
        }
        catch (Exception e) {
            return false;
        }
        finally {
            method.releaseConnection();
        }
        return true;
    }


    public String getUrl() {
        return url;
    }

    public void setUrl(String url) {
        this.url = url;
    }
} 

-----Original Message-----
From: jpuro [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, October 09, 2007 5:33 PM
To: [EMAIL PROTECTED]
Subject: Re: Basic TCP component


So, what to do about a TCP component?  :)

-jeff


gnodet wrote:
> 
> On 10/9/07, Andrea Zoppello <[EMAIL PROTECTED]> wrote:
>> Hi Guillaume,
>>
>> If you take a look at the document "How to cook your spagic" you 
>> could find all the information, on the patches, enhnacements that 
>> we've made on servicemix.
>>
>> Actually spagic is based on smx 3.1.1 codebase.
>>
>> By the way our approach is to keep the patches that we've done in 
>> spagic until they're taken bu smx codebase.
> 
> Most of the bug you are talking about have been already fixed afaik 
> (SM-781, SM-924, SM-879).  One is still pending in an unknown state 
> (SM-888).  You have raised another one recently about the split 
> aggregator which has been included too (not released yet).  But I 
> agree some have not been relesed yet :-(
> 
>>
>> In future versions of spagic the patches that we've update to JIRA 
>> will not be there anymore, because it will be included directly in 
>> smx :-)
> 
> Cool, I think that's the way to go too.  Hopefully we will be able to 
> have shorter release cycles now.
> 
>>
>> By the way have you seen my post about the needing for "Merge 
>> components" in front of a Drools or Content Based router??
>>
>>
>> Andrea Zoppello
>>
>> Guillaume Nodet ha scritto:
>> > Andrea, I've just downloaded the source zip of the components and 
>> > it seems that there is lots of components coming from ServiceMix: 
>> > are these differents in some sort ? Bug fixes, enhancements ?  If 
>> > so what about raising JIRAs and attaching your patches ? I know you

>> > have already done so and iirc i have applied them ...
>> >
>> > On 10/9/07, Andrea Zoppello <[EMAIL PROTECTED]> wrote:
>> >
>> >> Hi Bruce,
>> >>
>> >> You can take a look at:
>> >>
>> >> http://forge.objectweb.org/projects/spagic
>> >>
>> >> In the project site you could find the source code.
>> >>
>> >> By the way some information the spagic TCP component is based on
>> apache
>> >> mina.
>> >>
>> >>
>> >> Andrea Zoppello
>> >>
>> >>
>> >>
>> >>
>> >> Bruce Snyder ha scritto:
>> >>
>> >>> On 10/8/07, jpuro <[EMAIL PROTECTED]> wrote:
>> >>>
>> >>>
>> >>>> Yup, that makes sense.  But after looking at spagic it seems 
>> >>>> that
>> they
>> >>>> already use mina in a similar fashion and handle a lot of other
>> requirements
>> >>>> for tcp/ip etc.  Take a look at their source code and let me 
>> >>>> know
>> what you
>> >>>> think.  Otherwise I'll just implement my own version on apache 
>> >>>> mina
>> as I
>> >>>> have seen camel-mina do.
>> >>>>
>> >>>>
>> >>> Please provide a URL to the source of the code you're looking at.
>> >>>
>> >>> Bruce
>> >>>
>> >>>
>> >>
>> >
>> >
>> >
>>
>>
> 
> 
> --
> Cheers,
> Guillaume Nodet
> ------------------------
> Blog: http://gnodet.blogspot.com/
> 
> 

--
View this message in context:
http://www.nabble.com/Re%3A-Basic-TCP-component-tf4592566s12049.html#a13
117891
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.

Reply via email to