Netty Http4 (client): Null body whereas content-length > 0

2017-02-05 Thread scoutant
Hello,

I'm developping a payment platform and I decided to use Camel EIP 2.18.0 as
my communication framework. In particular the Netty HTTP4 component. Note
that I'm new to Camel.

I have a problem using Netty HTTP4 while requesting a simple web service
published by the European Central Bank to get the last Euro <-> currency
exchange rates.
This service can be query with the following URL:
http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml which returns a
simple xml file.

The route is configured as follow in my RouteBuilder class (I have added
traces to see what's going on):

@Override public void configure() throws Exception { 

from("direct:ecb").wireTap("log:TRACE?showAll=true").process(new
Processor(){
@Override public void process(Exchange exchange) throws 
Exception {
Message message = exchange.getOut();
message.setHeader(Exchange.HTTP_METHOD, 
HTTP_METHOD_GET);
}}).to(ECB_WEB_SERVICE).process(new Processor(){
@Override public void process(Exchange 
exchange) throws Exception {
   String body = 
exchange.getIn().getBody(String.class);
   log (Level.DEBUG, "Body: " + body);
}
}).end();

}

And invoked like this (there is no body and no parameter for the requested
service, I did try with null and empty Object array):

ProducerTemplate producer = 
getContext().createProducerTemplate();
String responseBody = producer.requestBody("direct:ecb", new 
Object[0],
String.class);

When I run the service, I obtain this:

-
2017-02-05 13:42:52.578 INFO  - [ECB Eurofxref] Invokes
netty4-http:http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml?traceEnabled=true

2017-02-05 13:42:52.584 DEBUG - Starting producer: Producer[direct://ecb]
2017-02-05 13:42:52.584 DEBUG - Adding to producer cache with key:
direct://ecb for producer: Producer[direct://ecb]
2017-02-05 13:42:52.589 DEBUG -  direct://ecb Exchange[]
2017-02-05 13:42:52.597 INFO  - ID-SCO-ASUS-62929-1486298532114-0-2 >>>
(route12) from(direct://ecb) --> wireTap(log:TRACE?showAll=true) <<<
Pattern:InOut, Headers:{breadcrumbId=ID-SCO-ASUS-62929-1486298532114-0-1},
BodyType:Object[], Body:[Ljava.lang.Object;@16aeed18
2017-02-05 13:42:52.601 DEBUG -  (wiretap) log:TRACE?showAll=true
Exchange[]
2017-02-05 13:42:52.601 INFO  - ID-SCO-ASUS-62929-1486298532114-0-2 >>>
(route12) wireTap(log:TRACE?showAll=true) --> Processor@0x7cf7aee <<<
Pattern:InOut, Headers:{breadcrumbId=ID-SCO-ASUS-62929-1486298532114-0-1},
BodyType:Object[], Body:[Ljava.lang.Object;@16aeed18
2017-02-05 13:42:52.601 DEBUG - Using ComponentResolver:
org.apache.camel.impl.DefaultComponentResolver@1827a871 to resolve component
with name: log
2017-02-05 13:42:52.601 INFO  - ID-SCO-ASUS-62929-1486298532114-0-2 >>>
(route12) Processor@0x7cf7aee -->
http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml?traceEnabled=true
<<< Pattern:InOut, Headers:{CamelHttpMethod=GET}, BodyType:null, Body:[Body
is null]
2017-02-05 13:42:52.602 DEBUG - Lookup Component with name log in registry.
Found: null
2017-02-05 13:42:52.606 DEBUG - 
http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml?traceEnabled=true
Exchange[ID-SCO-ASUS-62929-1486298532114-0-2]
2017-02-05 13:42:52.607 DEBUG - Lookup Component with name log-component in
registry. Found: null
2017-02-05 13:42:52.609 DEBUG - Found component: log via type:
org.apache.camel.component.log.LogComponent via:
META-INF/services/org/apache/camel/component/log
2017-02-05 13:42:52.616 DEBUG - Registered MBean with ObjectName:
org.apache.camel:context=camel-1,type=components,name="log"
2017-02-05 13:42:52.617 DEBUG - Creating endpoint
uri=[log://TRACE?showAll=true], path=[TRACE]
2017-02-05 13:42:52.621 DEBUG - Configured property: showAll on bean:
org.apache.camel.processor.DefaultExchangeFormatter@727eece6 with value:
true
2017-02-05 13:42:52.621 DEBUG - log://TRACE?showAll=true converted to
endpoint: log://TRACE?showAll=true by component:
org.apache.camel.component.log.LogComponent@7e5c50c7
2017-02-05 13:42:52.623 DEBUG - Starting producer:
Producer[log://TRACE?showAll=true]
2017-02-05 13:42:52.624 DEBUG - Adding to producer cache with key:
log://TRACE?showAll=true for producer: Producer[log://TRACE?showAll=true]
2017-02-05 13:42:52.627 DEBUG -  log://TRACE?showAll=true
Exchange[ID-SCO-ASUS-62929-1486298532114-0-3]
2017-02-05 13:42:52.636 INFO  - Exchange[Id:
ID-SCO-ASUS-62929-1486298532114-0-3, ExchangePattern: InOnly, Properties:
{CamelCorrelationId=ID-SCO-ASUS-62929-1486298532114-0-2,
CamelCreatedTimestamp=Sun Feb 05 13:42:52 CET 2017,
CamelMessageHistory=[DefaultMessageHistory[routeId=route12, node=wireTap7]],
CamelToEndpoint=log://TRACE?showAll=true}, Headers:
{breadcru

Problem using mockEndpoint in Spring Boot test

2017-02-05 Thread Preben.Asmussen
It seems that using MockEndpoints in spring boot tests you can get
unpredictable results.

Unit tests annotated with ->

@RunWith(CamelSpringBootRunner.class)
@MockEndpoints

Seems to work when running them locally, but fails on CI servers properly
due to somewhat slower execution time.

The problem can be reproduced when running existing Camel tests 

https://github.com/apache/camel/blob/master/components/camel-spring-boot/src/test/java/org/apache/camel/spring/boot/mockendpoints/MockEndpointsTest.java

Running both tests in the package org/apache/camel/spring/boot/mockendpoints
at the same time, will result in the last to fail.

 



/Preben




--
View this message in context: 
http://camel.465427.n5.nabble.com/Problem-using-mockEndpoint-in-Spring-Boot-test-tp5793492.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Netty Http4 (client): Null body whereas content-length > 0

2017-02-05 Thread Claus Ibsen
Hi

netty is streaming based, and you also do a wire tap, so the body is
only readable once. You need to turn on stream caching


See this FAQ and its links for more details
http://camel.apache.org/why-is-my-message-body-empty.html

On Sun, Feb 5, 2017 at 2:33 PM, scoutant  wrote:
> Hello,
>
> I'm developping a payment platform and I decided to use Camel EIP 2.18.0 as
> my communication framework. In particular the Netty HTTP4 component. Note
> that I'm new to Camel.
>
> I have a problem using Netty HTTP4 while requesting a simple web service
> published by the European Central Bank to get the last Euro <-> currency
> exchange rates.
> This service can be query with the following URL:
> http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml which returns a
> simple xml file.
>
> The route is configured as follow in my RouteBuilder class (I have added
> traces to see what's going on):
>
> @Override public void configure() throws Exception {
>
> 
> from("direct:ecb").wireTap("log:TRACE?showAll=true").process(new
> Processor(){
> @Override public void process(Exchange exchange) 
> throws Exception {
> Message message = exchange.getOut();
> message.setHeader(Exchange.HTTP_METHOD, 
> HTTP_METHOD_GET);
> }}).to(ECB_WEB_SERVICE).process(new Processor(){
> @Override public void process(Exchange 
> exchange) throws Exception {
>String body = 
> exchange.getIn().getBody(String.class);
>log (Level.DEBUG, "Body: " + body);
> }
> }).end();
>
> }
>
> And invoked like this (there is no body and no parameter for the requested
> service, I did try with null and empty Object array):
>
> ProducerTemplate producer = 
> getContext().createProducerTemplate();
> String responseBody = producer.requestBody("direct:ecb", new 
> Object[0],
> String.class);
>
> When I run the service, I obtain this:
>
> -
> 2017-02-05 13:42:52.578 INFO  - [ECB Eurofxref] Invokes
> netty4-http:http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml?traceEnabled=true
>
> 2017-02-05 13:42:52.584 DEBUG - Starting producer: Producer[direct://ecb]
> 2017-02-05 13:42:52.584 DEBUG - Adding to producer cache with key:
> direct://ecb for producer: Producer[direct://ecb]
> 2017-02-05 13:42:52.589 DEBUG -  direct://ecb Exchange[]
> 2017-02-05 13:42:52.597 INFO  - ID-SCO-ASUS-62929-1486298532114-0-2 >>>
> (route12) from(direct://ecb) --> wireTap(log:TRACE?showAll=true) <<<
> Pattern:InOut, Headers:{breadcrumbId=ID-SCO-ASUS-62929-1486298532114-0-1},
> BodyType:Object[], Body:[Ljava.lang.Object;@16aeed18
> 2017-02-05 13:42:52.601 DEBUG -  (wiretap) log:TRACE?showAll=true
> Exchange[]
> 2017-02-05 13:42:52.601 INFO  - ID-SCO-ASUS-62929-1486298532114-0-2 >>>
> (route12) wireTap(log:TRACE?showAll=true) --> Processor@0x7cf7aee <<<
> Pattern:InOut, Headers:{breadcrumbId=ID-SCO-ASUS-62929-1486298532114-0-1},
> BodyType:Object[], Body:[Ljava.lang.Object;@16aeed18
> 2017-02-05 13:42:52.601 DEBUG - Using ComponentResolver:
> org.apache.camel.impl.DefaultComponentResolver@1827a871 to resolve component
> with name: log
> 2017-02-05 13:42:52.601 INFO  - ID-SCO-ASUS-62929-1486298532114-0-2 >>>
> (route12) Processor@0x7cf7aee -->
> http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml?traceEnabled=true
> <<< Pattern:InOut, Headers:{CamelHttpMethod=GET}, BodyType:null, Body:[Body
> is null]
> 2017-02-05 13:42:52.602 DEBUG - Lookup Component with name log in registry.
> Found: null
> 2017-02-05 13:42:52.606 DEBUG - 
> http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml?traceEnabled=true
> Exchange[ID-SCO-ASUS-62929-1486298532114-0-2]
> 2017-02-05 13:42:52.607 DEBUG - Lookup Component with name log-component in
> registry. Found: null
> 2017-02-05 13:42:52.609 DEBUG - Found component: log via type:
> org.apache.camel.component.log.LogComponent via:
> META-INF/services/org/apache/camel/component/log
> 2017-02-05 13:42:52.616 DEBUG - Registered MBean with ObjectName:
> org.apache.camel:context=camel-1,type=components,name="log"
> 2017-02-05 13:42:52.617 DEBUG - Creating endpoint
> uri=[log://TRACE?showAll=true], path=[TRACE]
> 2017-02-05 13:42:52.621 DEBUG - Configured property: showAll on bean:
> org.apache.camel.processor.DefaultExchangeFormatter@727eece6 with value:
> true
> 2017-02-05 13:42:52.621 DEBUG - log://TRACE?showAll=true converted to
> endpoint: log://TRACE?showAll=true by component:
> org.apache.camel.component.log.LogComponent@7e5c50c7
> 2017-02-05 13:42:52.623 DEBUG - Starting producer:
> Producer[log://TRACE?showAll=true]
> 2017-02-05 13:42:52.624 DEBUG - Adding to producer cache with key:
> log://TRACE?showAll=true for producer: Producer[log://TRACE?showAll=true]
> 2017-02-05 13:42:52.6

Re: Netty Http4 (client): Null body whereas content-length > 0

2017-02-05 Thread scoutant
Good evening Claus,

Thank you for your swift reply.

In fact, I have omitted to say that I already turned on the stream caching
(my fault, I work hard 7/7, please forgine me), by doing this:

getContext().setTracing(true);
getContext().setStreamCaching(true);
getContext().getStreamCachingStrategy().setSpoolDirectory("./");
getContext().getStreamCachingStrategy().setSpoolThreshold(64 * 
1024);
getContext().getStreamCachingStrategy().setBufferSize(130 * 
1024);

Following what I read from Netty4-HTTP component documentation.
Before setting this during my test sessions, I had same result (body null),
but no response header as well.

And to be honest, I have also omitted that I set netty configuration like
this:

NettyHttpConfiguration configuration = super.getConfiguration();

//configuration.setAllowDefaultCodec(true); Not supported by 
Netty
configuration.setAllowSerializedHeaders(false);
configuration.setConnectTimeout(CONNECT_TIMEOUT_IN_SECONDS);
configuration.setAutoAppendDelimiter(false);
configuration.setBroadcast(false);
configuration.setClientMode(true);
configuration.setDisconnectOnNoReply(true);
configuration.setKeepAlive(false);
configuration.setLazyChannelCreation(false);
configuration.setReconnect(false);
configuration.setSync(true);
configuration.setTcpNoDelay(true);
configuration.setSend503whenSuspended(true);
configuration.setThrowExceptionOnFailure(true);
configuration.setTransferException(false);


And I have created a JNDI Registry in camel context (I don't think it has an
impact, but).

This time, I promise there is no more hidden information!

By the way, I don't know if it can have an incidence, but the ECB server
returns a xml file (application/xml), but the content-type indicated is
"text".

Thanks again for your reply.
Kind regards,
Stéphane Coutant





--
View this message in context: 
http://camel.465427.n5.nabble.com/Netty-Http4-client-Null-body-whereas-content-length-0-tp5793490p5793494.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Netty Http4 (client): Null body whereas content-length > 0

2017-02-05 Thread Willem Jiang
Hi,

I went through the whole thread, but didn't find out how the
camel-netty4-http endpoint is used (from the camel route).
I guess that something is still missing.



Willem Jiang

Blog: http://willemjiang.blogspot.com (English)
  http://jnn.iteye.com  (Chinese)
Twitter: willemjiang
Weibo: 姜宁willem

On Mon, Feb 6, 2017 at 3:07 AM, scoutant  wrote:

> Good evening Claus,
>
> Thank you for your swift reply.
>
> In fact, I have omitted to say that I already turned on the stream caching
> (my fault, I work hard 7/7, please forgine me), by doing this:
>
> getContext().setTracing(true);
> getContext().setStreamCaching(true);
> getContext().getStreamCachingStrategy().
> setSpoolDirectory("./");
> getContext().getStreamCachingStrategy().setSpoolThreshold(64
> * 1024);
> getContext().getStreamCachingStrategy().setBufferSize(130
> * 1024);
>
> Following what I read from Netty4-HTTP component documentation.
> Before setting this during my test sessions, I had same result (body null),
> but no response header as well.
>
> And to be honest, I have also omitted that I set netty configuration like
> this:
>
> NettyHttpConfiguration configuration =
> super.getConfiguration();
>
> //configuration.setAllowDefaultCodec(true); Not supported
> by Netty
> configuration.setAllowSerializedHeaders(false);
> configuration.setConnectTimeout(CONNECT_
> TIMEOUT_IN_SECONDS);
> configuration.setAutoAppendDelimiter(false);
> configuration.setBroadcast(false);
> configuration.setClientMode(true);
> configuration.setDisconnectOnNoReply(true);
> configuration.setKeepAlive(false);
> configuration.setLazyChannelCreation(false);
> configuration.setReconnect(false);
> configuration.setSync(true);
> configuration.setTcpNoDelay(true);
> configuration.setSend503whenSuspended(true);
> configuration.setThrowExceptionOnFailure(true);
> configuration.setTransferException(false);
>
>
> And I have created a JNDI Registry in camel context (I don't think it has
> an
> impact, but).
>
> This time, I promise there is no more hidden information!
>
> By the way, I don't know if it can have an incidence, but the ECB server
> returns a xml file (application/xml), but the content-type indicated is
> "text".
>
> Thanks again for your reply.
> Kind regards,
> Stéphane Coutant
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.
> com/Netty-Http4-client-Null-body-whereas-content-length-0-
> tp5793490p5793494.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>


Re: Netty Http4 (client): Null body whereas content-length > 0

2017-02-05 Thread Taariq Levack
Hi Stephane,

I just took a quick stab and it works with the following route, note the
endpoint  is the url with netty4 prefixed.

@Override
protected RoutesBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {

from("direct:ecb").streamCaching().wireTap("log:TRACE?showAll=true")
.to("netty4-
http://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml";);
}
};
}

@Test
public void testNetty() {
String body = template.requestBody("direct:ecb", "", String.class);
assertNotNull(body);
assertTrue(body.contains("European Central Bank"));
}


Cheers

On Mon, Feb 6, 2017 at 2:25 AM, Willem Jiang  wrote:

> Hi,
>
> I went through the whole thread, but didn't find out how the
> camel-netty4-http endpoint is used (from the camel route).
> I guess that something is still missing.
>
>
>
> Willem Jiang
>
> Blog: http://willemjiang.blogspot.com (English)
>   http://jnn.iteye.com  (Chinese)
> Twitter: willemjiang
> Weibo: 姜宁willem
>
> On Mon, Feb 6, 2017 at 3:07 AM, scoutant  wrote:
>
> > Good evening Claus,
> >
> > Thank you for your swift reply.
> >
> > In fact, I have omitted to say that I already turned on the stream
> caching
> > (my fault, I work hard 7/7, please forgine me), by doing this:
> >
> > getContext().setTracing(true);
> > getContext().setStreamCaching(true);
> > getContext().getStreamCachingStrategy().
> > setSpoolDirectory("./");
> > getContext().getStreamCachingStrategy().
> setSpoolThreshold(64
> > * 1024);
> > getContext().getStreamCachingStrategy().
> setBufferSize(130
> > * 1024);
> >
> > Following what I read from Netty4-HTTP component documentation.
> > Before setting this during my test sessions, I had same result (body
> null),
> > but no response header as well.
> >
> > And to be honest, I have also omitted that I set netty configuration like
> > this:
> >
> > NettyHttpConfiguration configuration =
> > super.getConfiguration();
> >
> > //configuration.setAllowDefaultCodec(true); Not
> supported
> > by Netty
> > configuration.setAllowSerializedHeaders(false);
> > configuration.setConnectTimeout(CONNECT_
> > TIMEOUT_IN_SECONDS);
> > configuration.setAutoAppendDelimiter(false);
> > configuration.setBroadcast(false);
> > configuration.setClientMode(true);
> > configuration.setDisconnectOnNoReply(true);
> > configuration.setKeepAlive(false);
> > configuration.setLazyChannelCreation(false);
> > configuration.setReconnect(false);
> > configuration.setSync(true);
> > configuration.setTcpNoDelay(true);
> > configuration.setSend503whenSuspended(true);
> > configuration.setThrowExceptionOnFailure(true);
> > configuration.setTransferException(false);
> >
> >
> > And I have created a JNDI Registry in camel context (I don't think it has
> > an
> > impact, but).
> >
> > This time, I promise there is no more hidden information!
> >
> > By the way, I don't know if it can have an incidence, but the ECB server
> > returns a xml file (application/xml), but the content-type indicated is
> > "text".
> >
> > Thanks again for your reply.
> > Kind regards,
> > Stéphane Coutant
> >
> >
> >
> >
> >
> > --
> > View this message in context: http://camel.465427.n5.nabble.
> > com/Netty-Http4-client-Null-body-whereas-content-length-0-
> > tp5793490p5793494.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
>