Re: URL space handling with Camel Rest and Jetty APIs

2015-12-06 Thread Joakim Bjørnstad
Hello,

You can't. It's part of the HTTP specification to escape non US-ASCII
characters with % followed by two hex digits representing the octet
code.

You will have to manually replace the %20 with space. As far as I
know, the DSL does not have options to do this for you.

But IMO, change your API design instead.

On Sun, Dec 6, 2015 at 11:32 AM, Vero Kato  wrote:
> hi, in our Camel REST/Jetty service we can have spaces, for example:
>
> localhost:8080/rest/ourSerivce/Curren Time/
>
> when we get "/Current Time/" string, it has %20 weird URL characters and we
> want to have spaces instead.
>
> we get it like this
>
> rest("/rest/ourSerivce/")
>  .produces("application/json")
>  .get("/{Parameter1}").outType(OurOutput.class)
>  .to("ourSerivce?method=getSomething(${Parameter1}");
>
> how we can nicely get ${Parameter1} converted to normal string with spaces
> with Camel Rest/Camel Jetty?
>
> thanks,
> Vero



-- 
Kind regards
Joakim Bjørnstad


Re: Exception handling with Apache Camel

2015-12-06 Thread Joakim Bjørnstad
Hello,

Set up your own logger, for example with slf4j and logback loggers/appenders.

private static final Logger LOGGER = LoggerFactory.getLogger(MyRoute.class);

onException(Exception.class)
  .handled(true)
  .setBody(constant("Parsing Error, please check your input"))
  .log(LoggingLevel.ERROR, LOGGER, "error sent back to client");

To log exception message, use the simple language:

.log(LoggingLevel.ERROR, LOGGER, "error sent back to client.
originalExceptionMessage=${exception.message}");

If you want to do custom processing on the exception object. It can be
found in exchangeProperty(Exchange.EXCEPTION_CAUGHT)

Please also see: http://camel.apache.org/logeip.html

On Sun, Dec 6, 2015 at 11:05 AM, Vero Kato  wrote:
> hi, I use Camel Rest and currently when I need to suppress exception in my
> code and show on a screen nice message, I do like this:
>
> onException(Exception.class).handled(true).setBody(constant("Parsing Error,
> please check your input")).log("error sent back to client");
>
> The only problem is that "error sent back to client" is not logged in our
> log file, how to wire up my own logger into this? I also want to log
> original exception message, how to reference original exception object
> instance in this code?
>
> Thanks,
> Vero



-- 
Kind regards
Joakim Bjørnstad


Re: Camel and Activemq setup with Spring Boot

2015-12-04 Thread Joakim Bjørnstad
Hello,

I'd check out the source of JmsAutoConfiguration and
ActiveMQAutoConfiguration to see what Spring Boot autoconfigures.
Essentially everything under the
org.springframework.boot.autoconfigure package.

For example ActiveMQ can be configured by supplying ActiveMQProperties
through Spring Boot externalized configuration.
spring.activemq.brokerUrl
spring.activemq.inMemory
spring.activemq.pooled
spring.activemq.user
spring.activemq.password

So you can probably cut a bean or two if you go that way. Also IMO not
necessary to explicitly add components to the camel context. Register
a Component bean in Spring and you can refer to it by methodname in
the camel URI. It gets automatically registered.

e.g.:

@Bean
@Inject
public JmsComponent myjms(ConnectionFactory myConnectionFactory) {
  JmsComponent jmsComponent = new JmsComponent();
  jmsComponent.setConnectionFactory(myConnectionFactory);
  return jmsComponent;
}

The component should automatically be available in Camel (same should
go for ActiveMQComponent): myjms:MY_QUEUE?concurrentConsumers=10

But what is the issue really, just clean up Spring config or is there
something not working with your config ?


On Fri, Dec 4, 2015 at 5:12 AM, zpyoung  wrote:
> Any help on this?
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Camel-and-Activemq-setup-with-Spring-Boot-tp5774544p5774651.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad


Re: Am I using headers right?

2015-11-25 Thread Joakim Bjørnstad
Yes, you typically use them for route internal metadata.

But they are not lost when they enter and return from an endpoint,
unless you or the component creates a fresh new exchange.

Please also see this SO:
http://stackoverflow.com/questions/10330998/passing-values-between-processors-in-apache-camel


On Wed, Nov 25, 2015 at 4:00 PM, Matt Sicker  wrote:
> Properties get lost even more often than headers, though. They're only
> copied when the entire Exchange is used instead of the message body or the
> Message object. I use them for temporary metadata between Processors,
> beans, etc.
>
> On 25 November 2015 at 06:54, Joakim Bjørnstad  wrote:
>
>> Hello,
>>
>> If you need metadata or a value on multiple endpoints, or to be used
>> internally in your routes, it is better to put them in the
>> exchangeProperties. Then copy them out to headers, when needed. Since
>> headers are meant to be used at the protocol/component in/out, there
>> is no guarantee they persist or be unchanged when the message returns.
>> Also reduces unwanted metadata leaking out of your routes, for example
>> to JMS, HTTP/SOAP as you mentioned.
>>
>>
>>
>> On Wed, Nov 25, 2015 at 12:52 AM, Matt Sicker  wrote:
>> > I filter out what headers to send when making REST calls through http4
>> for
>> > instance, so that's not an issue. When I make internal calls to networked
>> > services (e.g., Kafka, Hazelcast, or pretty much anything other than the
>> > message brokering components), I lose all my headers until the response
>> > message is handled (and only some components save those headers).
>> >
>> > On 24 November 2015 at 16:36, ychawla 
>> wrote:
>> >
>> >> That sounds sensible to me.  The headers are for message and exchange
>> >> metadata.  Just be careful to not send them over the wire when you call
>> an
>> >> external component.
>> >>
>> >>
>> >>
>> >> --
>> >> View this message in context:
>> >>
>> http://camel.465427.n5.nabble.com/Am-I-using-headers-right-tp5774363p5774365.html
>> >> Sent from the Camel - Users mailing list archive at Nabble.com.
>> >>
>> >
>> >
>> >
>> > --
>> > Matt Sicker 
>>
>>
>>
>> --
>> Kind regards
>> Joakim Bjørnstad
>>
>
>
>
> --
> Matt Sicker 



-- 
Kind regards
Joakim Bjørnstad


Re: Am I using headers right?

2015-11-25 Thread Joakim Bjørnstad
Hello,

If you need metadata or a value on multiple endpoints, or to be used
internally in your routes, it is better to put them in the
exchangeProperties. Then copy them out to headers, when needed. Since
headers are meant to be used at the protocol/component in/out, there
is no guarantee they persist or be unchanged when the message returns.
Also reduces unwanted metadata leaking out of your routes, for example
to JMS, HTTP/SOAP as you mentioned.



On Wed, Nov 25, 2015 at 12:52 AM, Matt Sicker  wrote:
> I filter out what headers to send when making REST calls through http4 for
> instance, so that's not an issue. When I make internal calls to networked
> services (e.g., Kafka, Hazelcast, or pretty much anything other than the
> message brokering components), I lose all my headers until the response
> message is handled (and only some components save those headers).
>
> On 24 November 2015 at 16:36, ychawla  wrote:
>
>> That sounds sensible to me.  The headers are for message and exchange
>> metadata.  Just be careful to not send them over the wire when you call an
>> external component.
>>
>>
>>
>> --
>> View this message in context:
>> http://camel.465427.n5.nabble.com/Am-I-using-headers-right-tp5774363p5774365.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> Matt Sicker 



-- 
Kind regards
Joakim Bjørnstad


Re: Camel + SpringBoot + Endpoint Mocking

2015-11-16 Thread Joakim Bjørnstad
Hello,

Please see this thread:
http://camel.465427.n5.nabble.com/spring-boot-test-mocks-td5773902.html

In summary, @MockEndpoints and @MockEndpointsAndSkip are not supported
in Camel thus far (2.16.0).

On Fri, Nov 13, 2015 at 2:08 PM, Kai Broszat  wrote:
> Hi,
> I want to test a complex route that involves sending messages to ActiveMQ and 
> calling webservices with SpringWs.
> The route itself is working fine using spring-boot (1.2.7.RELEASE) and the 
> camel-spring-boot plugin (2.16.0).
>
> Here are the important parts of the code:
>
> @Component
> public class MyRoute extends SpringRouteBuilder {
> @Override
> public void configure() throws Exception {
> from(direct:responseQueue)
> .transacted()
> .split(...)
> .to(activemq:individual_persist_queue)
> .end()
> .to("spring-ws:http://localhost:8088/acknowledge_webservice";)
> .log("DONE");
> }
> }
>
> Now I want to test this route by mocking the activemq and spring-ws endpoints 
> so the test can be run without any dependency on the broker or the webserver.
> My basic requirement is to verify that the right amount of messages are sent 
> to each endpoint.
>
> In my current scenario, the original message is split into three parts which 
> should be sent to ActiveMQ, followed by a single acknowledge message to the 
> WebService.
> The transaction is there to roll-back the JMS deliveries in case the 
> web-service call fails. None of that should be important for this test 
> however.
>
> My test looks as follows:
>
> @RunWith(CamelSpringJUnit4ClassRunner.class)
> @BootstrapWith(CamelTestContextBootstrapper.class)
> @SpringApplicationConfiguration(classes = MyConfig.class)
> @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD)
> @MockEndpointsAndSkip
> public class CamelSpringBootTest {
>
> @Produce(uri = "direct:responseQueue ")
> protected ProducerTemplate template;
>
> @EndpointInject(uri = "mock: 
> spring-ws:http://localhost:8088/acknowledge_webservice";)
> MockEndpoint webserviceMock;
>
> @EndpointInject(uri = "mock:activemq:individual_persist_queue ")
> MockEndpoint activemqMock;
>
>
> @Test
> public void test() throws Exception {
> activemqMock.expectedMessageCount(3);
> webserviceMock.expectedMessageCount(1);
>
> template.sendBody(someXML);
>
> MockEndpoint.assertIsSatisfied(10L, TimeUnit.SECONDS, toKcxMock);
> }
> }
>
> When I run the test with the webservice and ActiveMQ available then 
> everything works as expected.
> The assertions fail however as the mock endpoints don't register any messages.
>
> If I disable the ActiveMQ broker, then I get 'Connection refused' exceptions 
> from the ActiveMQ component.
> As far as I understand Camel shouldn't have tried to send the messages to 
> ActiveMQ though because of the @MockEndpointsAndSkip annotation.
>
> What am I missing?
>
> Thanks for any suggestion,
> Kai
>
> IMPORTANT NOTICE: This email is intended solely for the use of the individual 
> to whom it is addressed and may contain information that is privileged, 
> confidential or otherwise exempt from disclosure under applicable law. If the 
> reader of this email is not the intended recipient or the employee or agent 
> responsible for delivering the message to the intended recipient, you are 
> hereby notified that any dissemination, distribution, or copying of this 
> communication is strictly prohibited. If you have received this communication 
> in error, please immediately return the original message to the sender at the 
> listed email address. In accordance with Kewill policy, emails sent and 
> received may be monitored. Although Kewill takes reasonable precautions to 
> minimize the risk, Kewill accepts no responsibility for any loss or damage 
> should this email contain any virus, or similar destructive or mischievous 
> code.



-- 
Kind regards
Joakim Bjørnstad


Re: spring boot test mocks

2015-11-16 Thread Joakim Bjørnstad
Hello Minh,

Yeah it is a little bit awkward. At the moment I make microservice
style apps with Spring Boot and Camel and the time from prototype to
production goes a lot faster with all the free Spring Boot stuffs.

The way we test these Camel routes are two-fold:

Unit tests per SpringRouteBuilder implementation. Tested with
CamelTestSupport. No Spring involved. All To, Enrich, etc endpoints
mocked out (both subroutes and external endpoints).

Unit integration tests for the full pipelines. Here we use the Spring
Boot test harness.
To mock camel endpoints we use propertyplaceholders supplied by the
Spring Environment abstraction and @EndpointInject (mentioned earlier
in the thread):

@EndpointInject(uri = "{{DOCUMENTREGISTER_METADATA_URL}}")
private MockEndpoint documentRegisterMock;

Whereas the property/environment variable is:
DOCUMENTREGISTER_METADATA_URL=mock:documentregister

For the endpoints that we can't or won't mock using placeholders, we
use the NotifyBuilder:

http://camel.apache.org/notifybuilder.html

Then use @ActiveProfiles("testenv") or -spring.profiles.active=testenv
to configure the placeholder endpoints (mock or test environment)

IMO it's not a total dealbreaker, we can still test camel route
functional behaviour for production with almost zero modification.

For me, going back to re-implementing EIP, Nope :)

On Mon, Nov 16, 2015 at 12:48 PM, Claus Ibsen  wrote:
> Hi
>
> You can help by logging a JIRA ticket
> http://camel.apache.org/support.html
>
> For sure camel-spring-boot is getting a lot more attraction with the
> popularity of spring-boot and hence we and Camel users will continue
> to make it better.
>
>
>
>
> On Mon, Nov 16, 2015 at 12:32 PM, Minh Tran  wrote:
>> Hi
>>
>> I think the workaround has some disadvantages.
>> - It makes the routes more difficult to read. It took me a while to decipher 
>> what {{target:jms:queue}} actually meant. You might get away with it if 
>> you’re only going to mock a few endpoints but I generally mock every 
>> endpoint in my routes. I would need a placeholder for every single endpoint 
>> which is way too much work.
>> - The endpoint isn’t actually running whereas @MockEndpoints actually 
>> executes the endpoint and if I wanted to skip it, I simply switch to 
>> @MockEndpointAndSkip
>>
>> Without these features, it makes it very difficult to unit test and IMO is 
>> one of the biggest reasons why Camel rocks. It allows you to test your 
>> production routes with zero modification. I have to say this is a deal 
>> breaker and I will probably go back to plain Spring which is a shame since 
>> Spring Boot does have other lovely features.
>>
>> I fully appreciate you are putting your own time into this and am very 
>> grateful so don’t get me wrong. I hope this is constructive criticism, I 
>> apologise in advance if it isn’t. I’ll also look at how I can contribute. 
>> Thanks again.
>>
>>> On 16 Nov 2015, at 9:16 PM, Henryk Konsek  wrote:
>>>
>>> Hi,
>>>
>>> Yes, @MockEndpoints annotation is not supported at the moment. This is a
>>> feature that has to be coded and added to our Spring Boot module.
>>>
>>> As a workaround you can define your mocked endpoint like:
>>>
>>>  from("from...").to("{{target:jms:queue}}");
>>>
>>> And then set the target=direct:queue for the tests using the Spring Boot
>>> @IntegrationTest("target=direct:queue") annotation.
>>>
>>> Also you are more than welcome to contribute @MockEndpoints support. It is
>>> on my TODO list, but not with high priority.
>>>
>>> Cheers!
>>>
>>> pon., 16.11.2015 o 09:32 użytkownik Joakim Bjørnstad 
>>> napisał:
>>>
>>>> Hello,
>>>>
>>>> Doesn't seem like there is any support for @MockEndpoints and
>>>> @MockEndpointsAndSkip with Spring Boot and Camel at the moment.
>>>>
>>>> The reason for this is that the CamelSpringTestContextLoader is never
>>>> loaded. Typically you use:
>>>>
>>>> @RunWith(CamelSpringJUnit4ClassRunner.class)
>>>> @BootstrapWith(CamelTestContextBootstrapper.class)
>>>>
>>>> Together with @SpringApplicationConfiguration, it goes directly to the
>>>> SpringApplicationContextLoader and thus Camel test annotations are not
>>>> loaded.
>>>>
>>>> Please see https://issues.apache.org/jira/browse/CAMEL-7963
>>>>
>>>> On Mon, Nov 16, 2015 at 2:40 AM, Minh Tran 
>>>> wrote:
>>&g

Re: spring boot test mocks

2015-11-16 Thread Joakim Bjørnstad
Hello,

Doesn't seem like there is any support for @MockEndpoints and
@MockEndpointsAndSkip with Spring Boot and Camel at the moment.

The reason for this is that the CamelSpringTestContextLoader is never
loaded. Typically you use:

@RunWith(CamelSpringJUnit4ClassRunner.class)
@BootstrapWith(CamelTestContextBootstrapper.class)

Together with @SpringApplicationConfiguration, it goes directly to the
SpringApplicationContextLoader and thus Camel test annotations are not
loaded.

Please see https://issues.apache.org/jira/browse/CAMEL-7963

On Mon, Nov 16, 2015 at 2:40 AM, Minh Tran  wrote:
> Hi
>
> I’m trying to write unit tests in camel 2.16.0 and spring boot.
>
> My route looks like
>
> from(“direct:start”).to(“direct:end”)
>
> My unit test looks like
>
> @RunWith(SpringJUnit4ClassRunner.class)
> @SpringApplicationConfiguration(classes = Config.class)
> @MockEndpoints
> public class MyUnitTest {
>
>   @Produce(uri=“direct:start”)
>   private ProducerTemplate producer;
>
>   @EndpointInject(uri=“mock:direct:end”)
>   private MockEndpoint end;
>
> @Test
> public void testMock() throws InterruptedException {
> end.expectedBodiesReceived("blah");
> producerTemplate.sendBody("blah");
> end.assertIsSatisfied();
> }
>
> }
>
> It looks like the direct:end bit is never mocked so the assertion fails. It’s 
> like @MockEndpoints is completely ignored.
>
> Is this the correct way to mock existing components when using spring boot? 
> Thanks.



-- 
Kind regards
Joakim Bjørnstad


Re: SimpleBuilder usage in camel

2015-11-12 Thread Joakim Bjørnstad
Hello,

In your example, ${body} is still of type Object[]. So it seems the
SimpleBuilder evaluates it to null since getFirstName() is not a
method on the Object[] in body.

Try:

System.out.println(SimpleBuilder.simple("Hello
${body[0].getFirstName()}").evaluate(exchng, String.class));

On Thu, Nov 12, 2015 at 1:11 PM, Kasim Sert (Ibtech-Software
Infrastructure)  wrote:
> Hi,
>
> I have following processor, when I run it from my route I get the following 
> error.  I know exchange body is not null and you can see it in logs below. 
> What is wrong with my usage of SimpleBuilder here ?
>
> public class UpdateCustomerProcessor implements Processor {
> public static final Logger log = 
> LoggerFactory.getLogger(UpdateCustomerProcessor.class);
>
> public void process(Exchange exchng) throws Exception {
> Customer c = (Customer) exchng.getIn().getBody(Object[].class)[0];
> System.out.println("Updating customer " + c.getFirstName() + " " + 
> c.getLastName());
> System.out.println(SimpleBuilder.simple("Hello 
> ${body.getFirstName()}").evaluate(exchng, String.class));
> exchng.getOut().setBody(new Object[] {});
> }
>
> }
>
> Updating customer kasim sert
> org.apache.cxf.interceptor.Fault: Failed to invoke method: .getFirstName() on 
> null due to: org.apache.camel.language.bean.RuntimeBeanExpressionException: 
> Failed to invoke method: getFirstName() on null
>
>
>
> [Facebook]<http://www.facebook.com/Finansbank>  [Twitter] 
> <http://twitter.com/finansbank>
>
> [https://www.finansbank.com.tr/Disclaimer/BannerImages.aspx?date=12.11.201514:1100]<https://www.finansbank.com.tr/Disclaimer/Bannerlink.aspx?date=12.11.201514:1100>
>
>
> Bu e-posta'n?n i?erdi?i bilgiler (ekleri dahil olmak ?zere) gizlidir. 
> Onay?m?z olmaks?z?n ???nc? ki?ilere a?iklanamaz. Bu mesaj?n g?nderilmek 
> istendi?i ki?i de?ilseniz, l?tfen mesaj? sisteminizden derhal siliniz. IBTech 
> A.?. bu mesaj?n i?erdi?i bilgilerin do?rulu?u veya eksiksiz oldu?u konusunda 
> bir garanti vermemektedir. Bu nedenle bilgilerin ne ?ekilde olursa olsun 
> i?eri?inden, iletilmesinden, al?nmas?ndan, saklanmas?ndan sorumlu de?ildir. 
> Bu mesaj?n i?eri?i yazar?na ait olup, IBTech A.?.'nin g?r??lerini 
> i?ermeyebilir.
>
> The information contained in this e-mail (including any attachments)is 
> confidential. It must not be disclosed to any person without our authority. 
> If you are not the intended recipient, please delete it from your system 
> immediately. IBTech A.S. makes no warranty as to the accuracy or completeness 
> of any information contained in this message and hereby excludes any 
> liability of any kind for the information contained therein or for the 
> information transmission, reception, storage or use of such in any way 
> whatsoever. Any opinions expressed in this message are those of the author 
> and may not necessarily reflect the opinions of IBTech A.S.



-- 
Kind regards
Joakim Bjørnstad


Re: Spring to Plain Vanilla Camel

2015-10-15 Thread Joakim Bjørnstad
Hello,

On Thu, Oct 15, 2015 at 5:27 AM, contactreji  wrote:
> Hello guys
>
> We are considering groovy dsl using plain vanilla camel coding. All beans
> would probably go in as @Autowired into RouteBuilder classes. I just need
> some inputs on how following CXF Endpoint config can be written in a Java
> class representation.
>
> We were kind of used to Spring XML before. Now we are exploring more on pure
> java / groovy style.
>
> *
>  address="${CXF_Endpoint}"
> xmlns:c="http://mySoapServiceWSDL";
> endpointName="c:EnterpriseIntegrationSOAP11port_http"
> serviceName="c:EnterpriseIntegrationService"
> wsdlURL="Artifacts/wsdl/BSSApi/ServiceDefinition.wsdl">
> 
> 
>  value-ref="passwordCallback" />
> 
> 
> 
> 
> 
> 
> 
> 
> 
> 
> *
>


I think this would be pretty close. Please note that I think you
possibly might have to configure the receiveTimeout and
connectionTimeout on the client HttpConduit, not entirely sure on how
to do this on the top of my head.

You could then refer to this in your route as
.to("cxf:bean:enterpriseIntegrationService") or maybe just
.to(enterpriseIntegrationService) assuming it is @Autowired in to the
RouteBuilder.

@Autowired
private GZIPInInterceptor gzipInInterceptor;
@Autowired
private PasswordCallback_bss passwordCallback_bss;
@Autowired
private BssapiWss4jOutInterceptor bssapiWss4jOutInterceptor;
@Autowired
private PasswordCallback passwordCallback;

@Bean
public CxfEndpoint enterpriseIntegrationService() {
CxfEndpoint cxfEndpoint = new CxfEndpoint();
cxfEndpoint.setAddress("${CXF_Endpoint}");
cxfEndpoint.setWsdlURL("Artifacts/wsdl/BSSApi/ServiceDefinition.wsdl");
cxfEndpoint.setEndpointName(new QName("http://mySoapServiceWSDL";,
"EnterpriseIntegrationSOAP11port_http"));
cxfEndpoint.setServiceName(new QName("http://mySoapServiceWSDL";,
"EnterpriseIntegrationService"));
cxfEndpoint.setDataFormat(DataFormat.PAYLOAD);
cxfEndpoint.setProperties(cxfProperties());
cxfEndpoint.getInInterceptors().add(gzipInInterceptor);
cxfEndpoint.getOutInterceptors().add(passwordCallback_bss);
cxfEndpoint.getOutInterceptors().add(bssapiWss4jOutInterceptor);
return cxfEndpoint;
}

private Map cxfProperties() {
Map properties = new HashMap<>();
properties.put("ws-security.callback-handler", passwordCallback);
properties.put("receiveTimeout", "15000");
properties.put("connectionTimeout", "2000");
return properties;
}

>
>
> -
> Reji Mathews
> Sr. Developer - Middleware Integration / SOA ( Open Source - Apache Camel & 
> Jboss Fuse ESB | Mule ESB )
> LinkedIn - http://in.linkedin.com/pub/reji-mathews/31/9a2/40a
> Twitter - reji_mathews
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Spring-to-Plain-Vanilla-Camel-tp5772667.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad


Re: Output of exec used for exception handling to enable message redelivery

2015-10-14 Thread Joakim Bjørnstad
Hello,

On Wed, Oct 14, 2015 at 3:13 PM, jamesburn  wrote:
> Hi
>
> I'm using exec to call a BASH script to do some stuff. The output of exec is
> returned as the body of my processed message, so I'm able, with , to
> pick out whether the script succeeded:
>
> ...
> 
> exec:PDFInvoicesCurl.sh?args=${file:name} {{InputFolder}}
> {{SendURL}}
> 
> 
> 
> 
> ${body} not contains 'HTTP/1.1 200 OK'
>  loggingLevel="WARN"/>
> 
> 
> ...
>
> This is great, but I'd like to try the BASH script again a couple of times
> if the exec fails. The way to do this seems to use onException:
>
> http://camel.apache.org/how-do-i-retry-processing-a-message-from-a-certain-point-back-or-an-entire-route.html
> <http://camel.apache.org/how-do-i-retry-processing-a-message-from-a-certain-point-back-or-an-entire-route.html>
>
> Is there a way to get the output of the exec (body) into the exception so I
> can do a redelivery. Or can I setup a redelivery attempt based on my
>  above?
>

Yes you can do this by seperating your litte snippet in a subroute,
disable errorhandling in the subroute like the docs you linked say,
throw an exception with the body in the message in your .

Note that when using redeliverypolicy, the body of the failed exchange
will be caught by onException when redelivery has been exhausted. So
you can get the body in both exchange body and exception message if
you want.

Your exception will be found in the property "CamelExceptionCaught"
after exhausted redelivery.

Of course other things can fail seperately and you need to handle that
as well, either in onException or with the errorhandler.

Something like this?


  
  
org.example.PdfInvoiceException


  
  
  exec:PDFInvoicesCurl.sh?args=${file:name}
{{InputFolder}}  {{SendURL}}
  
  
  
  
  ${body} not contains 'HTTP/1.1 200 OK'
  
  
  


Please note I don't usually use XML route declarations. Also not sure
if  allows simple language in message in 2.13.x

> Using Camel 2.13.2
>
> Thanks
>
> James
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Output-of-exec-used-for-exception-handling-to-enable-message-redelivery-tp5772641.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad


Re: Camel-Metrics component -- is it safe to use in Production?

2015-10-14 Thread Joakim Bjørnstad
Hello,

Camel 2.16.0 uses metrics 3.1.2 but as far as I know, there is still
an issue with this in metrics.
Related metrics issue: https://github.com/dropwizard/metrics/issues/742

The github issue explains some of the circumstances. Problems with
ThreadLocals not being garbage collected when deploying/undeploying to
certain servlet containers, Tomcat is mentioned.

We use camel-metrics in production. No issues on Jboss EAP 6.1 thus
far. In my current project I have used camel standalone and no issues
thus far either.

Alternatives, not as a camel component as far as I know. Camel does
gather its own statistics for exchanges though, exposed as JMX.
But with metrics it is very easy to expose a REST endpoint that just
dumps the metrics registry as json. Like 6 lines of code to put it on
the edge.


On Wed, Oct 14, 2015 at 7:34 AM, xlogger  wrote:
> In the documentation http://camel.apache.org/metrics-component.html, it
> mentioned that
>
> MetricRegistry uses internal thread(s) for reporting. There is no public API
> in version 3.0.1 for users to clean up on exit. Thus using Camel Metrics
> Component leads to Java classloader leak and my cause OutOfMemoryErrors in
> some cases.
>
> May I know what were the cases that might leads to the OOM issue? Was it
> still the case in the latest Camel 2.16.0 version or the issue has been
> fixed and safe to use in Production environment?
>
> Is there any alternatives that could achieve the same functionality?
>
>
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Camel-Metrics-component-is-it-safe-to-use-in-Production-tp5772630.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad


Re: When original exchange "isDone" - with aggregator?

2015-10-12 Thread Joakim Bjørnstad
Hello,

On Mon, Oct 12, 2015 at 4:40 PM, dermoritz  wrote:
> My route looks like this
>
> from( trigger )
> .routePolicy( new FinishNotifier( onFinsh ) )
> .to( in ).split().body()
> .streaming()
> .process( aggregationHeaderProcessor )
> .aggregate( header( AggregationHeaderProcessor.ORDER_ID_HEADER
> ), packAggregator )
> .completionSize( header(
> AggregationHeaderProcessor.PACK_COUNT_HEADER ) )
> .executorService( Executors.newFixedThreadPool(
> validationThreads ) )
> .log( LoggingLevel.TRACE, "Processing order #
> ${property.CamelSplitSize}" )
> .process( validationProcessor )
> .process( statusCounterProcessor )
> .process( statisticsProcessor )
> .process( validationResultProcessor )
> .to( out )
> .routeId( ROUTE_ID );
>
> FinishNotifier only implements "onExchangeDone". My problem is that this is
> called right after aggregation has completed. But i want that complete route
> has finished when exchange is done. The route worked fine without the 3
> lines for aggregation (process(), aggregate(), completionSize). So i suspect
> the aggregator to mark the exchange as done.
> So is there a way to unmark or prevent the too early call of
> onExchangeIsDone ?
>

I don't know any way of doing that. But instead, have you tried using
onCompletion instead of the RoutePolicy?

http://camel.apache.org/oncompletion.html

from("direct:start")
  .onCompletion()
  .process(exchange -> {
 // do something
  })
  .end()
  .to(in).split() ... etc

>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/When-original-exchange-isDone-with-aggregator-tp5772577.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad


Re: Missing handle(boolean) in Camel 2.16.0

2015-10-12 Thread Joakim Bjørnstad
On Mon, Oct 12, 2015 at 11:46 AM, Henrik Brautaset Aronsen
 wrote:
> On Mon, Oct 12, 2015 at 10:44 AM, Joakim Bjørnstad 
> wrote:
>
>> onException(NullPointerException.class)
>>   .wireTap("someUri").end()
>>   .handled(true)
>>   .bean("someBean");
>>
>> Allows you to return to the OnExceptionDefinition.
>>
>> Seems there was a change in 2.16.0 that makes newExchange and some
>> other fluent builders to not return to the previous type in the DSL.
>>
>
> Thanks!  But where do I put my .newExchange(someProcessor) now?

Well right now it doesn't seem possible in that order, which is unfortunate.

Maybe you can consider changing the order in your exception handling?
Since you want to mark the failed exchange handled anyways.
Wiretap new exchange fire and forget to other endpoint. Then call
someBean with the handled exchange?

onException(NullPointerException.class)
  .handled(true)
  .wireTap("someUri")
  .newExchange(exchange -> {

  })
  .end()
  .bean("someBean");

If this isn't functionally equivalent, I'd suggest logging a ticket on
the Camel JIRA.

>
> Henrik



-- 
Kind regards
Joakim Bjørnstad


Re: Missing handle(boolean) in Camel 2.16.0

2015-10-12 Thread Joakim Bjørnstad
Hello,

onException(NullPointerException.class)
  .wireTap("someUri").end()
  .handled(true)
  .bean("someBean");

Allows you to return to the OnExceptionDefinition.

Seems there was a change in 2.16.0 that makes newExchange and some
other fluent builders to not return to the previous type in the DSL.

On Mon, Oct 12, 2015 at 10:09 AM, Henrik Brautaset Aronsen
 wrote:
> On Mon, Oct 12, 2015 at 10:06 AM, Henrik Brautaset Aronsen 
> wrote:
>
>> But in 2.16.0 it seems like .handle(..) isn't available anymore.  Any
>> suggestions on how to mark this as handled now?
>>
>
> Sorry, typo.  Obviously I mean .handled(boolean).
>
> Henrik



-- 
Kind regards
Joakim Bjørnstad


Re: Query

2015-10-08 Thread Joakim Bjørnstad
Hello,

Recipient list allows dynamic endpoints:

http://camel.apache.org/recipient-list.html



On Thu, Oct 8, 2015 at 1:38 PM, ram kumar  wrote:
> Hi,
> i would like to set the hdfs path to the current time (in millisecond),
> but CamelContext takes from conf once, is it possible to change it
>
> .to("hdfs://"+ System.currentTimeMillis() + "/")
>
> Thanks



-- 
Kind regards
Joakim Bjørnstad


Re: Dynamic datasource with Camel 2.15.x

2015-10-06 Thread Joakim Bjørnstad
Well now this isn't a Camel question but rather a Spring one.

Anyways, I suggest checking out Spring @Value annotation and
PropertyPlaceholderConfigurer. With this you can leverage Camel's
BridgePropertyPlaceholderConfigurer to configure your routes as well.

http://camel.apache.org/using-propertyplaceholder.html

Spring Boot has some nice documentation on how to do externalized
config: 
http://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html

And no, you should not do it like the latter.

On Tue, Oct 6, 2015 at 11:38 AM, burner
 wrote:
> Hello Joakim,
>
> yes, I am use Spring.
>
> your Idea look good. But how can I use parameters in your solution?
>
> @Configuration
> public class InfrastructureConfig {
>
> String username = "";
> String password = "";
> String url = "";
>
> @Bean
> public DataSource dataSource() {
> String url = this.url;
> BasicDataSource ds = new BasicDataSource();
> ds.setDriverClassName("com.jdbc.DBDriver");
> ds.setUsername(this.username);
> ds.setPassword(this.password);
> ds.setUrl(url);
> return ds;
> }
>
> // getter and setter 
>
> }
>
> I don't think this is possibile like this, or?
>
> ApplicationContextRegistry registry =
> getContext().getRegistry(ApplicationContextRegistry.class);
> DataSource dataSource = registry.lookup("dataSource", DataSource.class);
> dataSource.setUrl("XYZ");
> dataSource.setUsername("XYZ");
> dataSource.setUPassword("XYZ");
>
> ?dataSource=#myDataSource
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Dynamic-datasource-with-Camel-2-15-x-tp5772178p5772328.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad


Re: custom Registry in CamelTestSupport

2015-10-02 Thread Joakim Bjørnstad
Hello,

To do this, you need to override creation of the CamelContext.

Then you can test with whatever Registry implementation that you want.

public class CustomRegistryTest extends CamelTestSupport {

@Test
public void shouldTest() throws Exception {

}

@Override
protected CamelContext createCamelContext() throws Exception {
return new DefaultCamelContext(createCustomRegistry());
}

private Registry createCustomRegistry() {
return new SimpleRegistry();
}
}

On Wed, Sep 30, 2015 at 7:43 PM, bprager  wrote:
> I am trying to unit test a custom registry.
> The createRegistry() method which I try to override exist only for
> JndiRegistry.
> How do I use a custom registry?
>
> Thank you.
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/custom-Registry-in-CamelTestSupport-tp5772135.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad


Re: Dynamic datasource with Camel 2.15.x

2015-10-02 Thread Joakim Bjørnstad
Hello,

First of all, it seems you use Spring with Camel. The
PropertyPlaceholderDelegateRegistry delegates to the Spring
ApplicationContextRegistry and not any JndiRegistry.

Using this, I don't think you can go this route, since the
ApplicationContextRegistry only allows lookup. And it does this in the
Spring ApplicationContext.

Instead, use Spring mechanics. Create a Configuration, register a
Bean. Use external configuration properties through standard Spring
means.

@Configuration
public class InfrastructureConfig {

@Bean
public DataSource dataSource() {
String url = "jdbc:PROT://localhost:PORT/NS";
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName("com.jdbc.DBDriver");
ds.setUsername("USER");
ds.setPassword("PASS");
ds.setUrl(url);
return ds;
}
}

To look it up in your route configuration:

ApplicationContextRegistry registry =
getContext().getRegistry(ApplicationContextRegistry.class);
DataSource dataSource = registry.lookup("dataSource", DataSource.class);

Preferrably this is injected into the beans that need a DataSource. Or
configured using the uri of a component by referring to it
?dataSource=#myDataSource


On Fri, Oct 2, 2015 at 11:35 AM, burner
 wrote:
> Hello Together,
>
> i want to create dynamic datasources on runtime. I found some examples to do
> this. But this code:
>
> PropertyPlaceholderDelegateRegistry registry =
> (PropertyPlaceholderDelegateRegistry) getContext().getRegistry();
> JndiRegistry jndiRegistry = (JndiRegistry ) registry.getRegistry();
> jndiRegistry.bind("myDS", ds);
>
> don't work in Camel 2.15 anymore. I get a
> java.lang.ClassCastException:
> org.apache.camel.spring.spi.ApplicationContextRegistry cannot be cast to
> org.apache.camel.impl.JndiRegistry
>
> Have any of you an idea how I can solve it?
>
> I'm in a RouteBuilder:
>
> RouteBuilder builder = new RouteBuilder() {
> public void configure() {
> CamelContext context = getContext();
>
> // I create the Datasource
> String url = "jdbc:PROT://localhost:PORT/NS";
> BasicDataSource ds = new BasicDataSource();
> ds.setDriverClassName("com.jdbc.DBDriver");
> ds.setUsername("USER");
> ds.setPassword("PASS");
> ds.setUrl(url);
>
> // Here I must register the DS, but how? This don't work:
> PropertyPlaceholderDelegateRegistry registry =
> (PropertyPlaceholderDelegateRegistry) getContext().getRegistry();
> JndiRegistry jndiRegistry = (JndiRegistry ) 
> registry.getRegistry();
> jndiRegistry.bind("myDataSource", ds);
>
> // Here I build my route
> from("direct:xyz")
> .to("jdbc:myDataSource")
> }
> }
>
> Thank you for help
>
>
>
> --
> View this message in context: 
> http://camel.465427.n5.nabble.com/Dynamic-datasource-with-Camel-2-15-x-tp5772178.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Kind regards
Joakim Bjørnstad


Re: HTTP Basic Authentication

2015-10-01 Thread Joakim Bjørnstad
Hello,

Are you using the http component?

http://camel.apache.org/http.html

There is a section on authentication there.

Example:

from("http://examples.com/rest/hello?";
+ "authMethod=Basic"
+ "&authUsername=User"
+ "&authPassword=Password")
.to("mock:answer");


On Thu, Oct 1, 2015 at 1:29 PM, zied123456  wrote:

> Hello,
> I try to send request to a webservice with camel and i dont found how to
> set
> httplogin and httppass with
> POJO i can do this:
>
> final String s =  my_httpLogin+":"+my_httpPwd;
> final byte[] authBytes = s.getBytes(StandardCharsets.UTF_8);
> final String encoded = Base64.getEncoder().encodeToString(authBytes);
>
> and i set it in the header like this:
>
> con.setRequestProperty("Authorization", "Basic " + encoded);
>
> How can i do this with Camel Route ?
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/HTTP-Basic-Authentication-tp5742229p5772150.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Kind regards
Joakim Bjørnstad


Re: How to generate Javadoc?

2015-09-22 Thread Joakim Bjørnstad
Hello,

Do you compile on JDK8? If so, try to turn off Javadoc linting.

Please check this:
http://stackoverflow.com/questions/15886209/maven-is-not-working-in-java-8-when-javadoc-tags-are-incomplete
And this:
http://blog.joda.org/2014/02/turning-off-doclint-in-jdk-8-javadoc.html

On Wed, Sep 23, 2015 at 7:34 AM, Frizz  wrote:

> Hi there,
>
> I just downloaded Camel 2.15.3 source and tried to generate the javadocs
> for the project by running "mvn javadoc:javadoc" in the project root
> directory - but it failed:
>
> [ERROR] Failed to execute goal
> org.apache.maven.plugins:maven-javadoc-plugin:2.9.1:javadoc (default-cli)
> on project spi-annotations: An error has occurred in JavaDocs report genera
> tion:
> [ERROR] Exit code: 1 -
>
> D:\Projects\Apache\apache-camel-2.15.3\tooling\spi-annotations\src\main\java\org\apache\camel\spi\Metadata.java:27:
> error: self-closing element not allowed
> [ERROR] * 
> [ERROR] ^
> [ERROR]
>
> D:\Projects\Apache\apache-camel-2.15.3\tooling\spi-annotations\src\main\java\org\apache\camel\spi\Metadata.java:45:
> warning: no @return
> [ERROR] String defaultValue() default "";
> [ERROR] ^
> [ERROR]
>
> D:\Projects\Apache\apache-camel-2.15.3\tooling\spi-annotations\src\main\java\org\apache\camel\spi\Metadata.java:37:
> error: self-closing element not allowed
> [ERROR] * 
> [ERROR] ^
> [ERROR]
>
> D:\Projects\Apache\apache-camel-2.15.3\tooling\spi-annotations\src\main\java\org\apache\camel\spi\Metadata.java:40:
> warning: no @return
> [ERROR] String label() default "";
> [ERROR] ^
> ...
>
> How do I fix this?
>
> cheers,
> F.
>



-- 
Med vennlig hilsen
Joakim Bjørnstad