J.H.Cha,

The only difference I see when I look at the code, it the message ExchangePattern. requestBodyAndHeader() explicitly sets the pattern to InOut, while the sendBodyAndHeader() just leaves the default (InOnly). Not sure why this causes a problem in your case though, I would even think that InOut would be a more correct representation...

I would guess that the InOut pattern causes the http: endpoint to wait on a reply from the jetty: endpoint, but I'm not sure why that doesn't happen. What version of Camel are you using? To determine what's going on here, could you try replacing your http/jetty endpoints with a direct:b or something?
Regards,

Gert


jhcha wrote:
When I tested two methods  requestBodyAndHeader and sendBodyAndHeader in my
test source,
I found the very curious result.
sendBodyAndHeader  returns ok, but requestBodyAndHeader does not return, and
hangs...

two methods have the same(?) input parameters and very similar comments.. (Is it different things, endpoint and endpointUri ? )
Object requestBodyAndHeader(String endpoint, Object body, String header,
Object headerValue)
          Send the body to an endpoint returning any result output body
Object sendBodyAndHeader(String endpointUri, Object body, String header,
Object headerValue)
          Sends the body to an endpoint with a specified header and header
value

Maybe I should not use requestBodyAndHeader with "direct" end point.

but I need to know the accurate reason for that. Would you explain me what is the difference of the two methods, and the correct usage case ?

Thank you.

J. H. Cha

the below source is my test code.
=============================
import org.apache.camel.CamelContext;
import org.apache.camel.CamelTemplate;
import org.apache.camel.Endpoint;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.impl.DefaultCamelContext;
import org.apache.camel.impl.DefaultExchange;
import org.apache.camel.util.ExchangeHelper;
import org.apache.log4j.Logger;

public class JettyRequestTest extends Thread {

        private static final Logger logger =
Logger.getLogger(JettyRequestTest.class);

        private static int threads = 1;

        
        public static void main(String[] args) throws Exception {

                for (int i = 0; i < threads; i++) {
                        JettyRequestTest client = new JettyRequestTest();
                        client.start();
                }
        }

        @Override
        public void run() {
                try {
                        testJettyConsumerEndpoint();
                } catch (Exception e) {
                        logger.fatal("testJmsSpeed fail", e);
                }
        }

        public void testJettyConsumerEndpoint() throws Exception {
                try {
                        CamelContext ctx = new DefaultCamelContext();

                        RouteBuilder builder = new ServerRoutes();
                        ctx.addRoutes(builder);

                        ctx.start();

                        CamelTemplate<DefaultExchange> template = new
CamelTemplate<DefaultExchange>(ctx);

                        String body = "<hello>world!</hello>";

                        Object result = 
template.sendBodyAndHeader("direct:start", body,
"Content-Type",  "application/xml");
                        Exchange exchange = new DefaultExchange(ctx);
                        String response = 
ExchangeHelper.convertToType(exchange, String.class,
result);
                        logger.info("response : [" + response + "]");
                                        
                        // the below line meet hang !!!!                        
                                        
                        template.requestBodyAndHeader("direct:start", body, 
"Content-Type",
"application/xml");


                        ctx.stop();
                } catch (Throwable e) {
                        if (logger.isEnabledFor(org.apache.log4j.Level.ERROR)) {
                                logger.error("testJettyConsumerEndpoint()", e);
                        }

                        e.printStackTrace();
                }
        }
}

class ServerRoutes extends RouteBuilder {
        @Override
        public void configure() throws Exception {
                Processor proc = new Processor() {
                        public void process(Exchange exchange) throws Exception 
{
                                String request = 
exchange.getIn().getBody(String.class);
                                exchange.getOut(true).setBody(request + " >> 
processed");
                        }
                };

                from("jetty:http://localhost:8080/hello";).process(proc);

                from("direct:start").to("http://localhost:8080/hello";);
        }
}

Reply via email to