Re: Proper way to initialize Transaction management for Camel in an Application Server
Hi You can use SimpleCamelServletContextListener which then does not use the JndiRegistry but the simple instead, which should be able to do the lookups. See the docs at http://camel.apache.org/servletlistener-component.html On Thu, Sep 19, 2013 at 4:50 PM, kraythe wrote: > So am I to understand that there is no way possible right now to do this in a > ServletListener component? Can I create a simple registry without blowing up > the construction of the context or do something else? I would really like to > enable this type of ACID transactions. > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Proper-way-to-initialize-Transaction-management-for-Camel-in-an-Application-Server-tp5739760p5739827.html > Sent from the Camel - Users mailing list archive at Nabble.com. -- Claus Ibsen - Red Hat, Inc. Email: cib...@redhat.com Twitter: davsclaus Blog: http://davsclaus.com Author of Camel in Action: http://www.manning.com/ibsen
tokenize + group + aggregator strategy?
Hi Is it possible to do something like this: int myGroupSize = 100; .split(body().tokenize("\n", myGroupSize), new myAggStrategy()) ? The above doesn't work because the tokenize methods on the ValueBuilder don't take groups. The following compiles but is it the best way/can someone see if it obviously won't work? TokenizeLanguage language = new TokenizeLanguage(); language.setToken("\n"); language.setGroup(myGroupSize); language.setIncludeTokens(true); .split(new ValueBuilder(language.createExpression(null)), new myAggStrategy()).. Cheers, Tom
Re: tokenize + group + aggregator strategy?
Could you put an example of what have you tested? and which is the next step inside and after the splitter -- View this message in context: http://camel.465427.n5.nabble.com/tokenize-group-aggregator-strategy-tp5739864p5739869.html Sent from the Camel - Users mailing list archive at Nabble.com.
[ConsumerTemplate] CamelLocks deleted before file is completely processed
Hi, I'm using the consumer template for reading files, and I'm experiencing something that makes me think that I'm not using it correctly. What happens to me is: 1. I have a dir with multiple files 2. The consumer template reads one of those files, creating a camelLock file for the file that is going to be processed 3. The consumer template reads another file (same route, different thread) and, since the camelLock of the previous file still exists, deletes it and creates the camelLock for the file that is going to be processed now (the previous file haven´t ended its processing and haven´t been "finished" using the doneUnitOfWork) 4. The same for each file that is read (the camelLocks are removed and a WARNING appears in the log " Deleting orphaned lock file: .../.. .camelLock") I think that maybe this is because I'm creating a new consumerTemplate each time I have to read something (could it be?), because I have seen that it has a ConsumerCache. The problem is that I use some "rules" to use it (one of them creating the CT each time), because of some problems I have had in the past: - Don´t use the disconnect option for FTPs (Nullpointer, at least in Camel 2.9.0 that leaves threads alive, Camel post in [1]) - Create a new Consumer template each time I read a file (same reasons as previous sentence) and stop it after use - I synchronize the method that consumes an endpoint because otherwise, when reading files in parallel instead of reading two files, the consumer reads one twice In case it can helps, I put my code here: ConsumerTemplate cTemplate = camelContext.createConsumerTemplate(); Exchange dataExchange = null; if(timeoutInMilis == 0){ dataExchange = cTemplate.receiveNoWait(endpoint2Consume); } else{ dataExchange = cTemplate.receive(endpoint2Consume, timeoutInMilis); } try { cTemplate.stop(); } catch (Exception e) { log ... } Thanks in advance Camel Version: 2.10.4 [1] http://camel.465427.n5.nabble.com/FTP-ConsumerTemplate-Threads-remaining-alive-td5548338.html#a5723551 -- View this message in context: http://camel.465427.n5.nabble.com/ConsumerTemplate-CamelLocks-deleted-before-file-is-completely-processed-tp5739870.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: OGNL property syntax in documentation does not work
The last 2 rows of the variables table shows ways that are supposed to get properties by name, but I tried to use it and it throws an exception. The RootObject passed to OGNL has getProperty methods, but OGNL will not match up property(...) to getProperty() method. OGNL 4 can match property[name] to getProperty, but that is not released yet and is square brackets instead of parens. You could make property(...) methods but that would only work for reading the property, not setting the property. As it stands now the syntax that works is: properties -- Gets map of all properties properties[name] -- specific property, can be used to get or set getProperty(name) -- Get specific property getProperty(name, type) -- Get specific property as type I just realized that RootObject is missing any setter methods, e.g. setProperty. The only way to set a property from within OGNL is using: properties['name'[ = value But then again you have the DSL support for setting properties. On Sep 20, 2013 1:57 AM, "Claus Ibsen" wrote: > Can you post the link to where you found this "mistake". I cannot see > a problem at > http://camel.apache.org/ognl > > On Fri, Sep 20, 2013 at 12:57 AM, Dale King wrote: > > In the documentation for the Camel OGNL component it shows the following > > syntax: > > > > property(name) Object the property by the given name property(name, > type) the > > property by the given name as the given type > > This syntax does not actually work in camel and I do not see any tests > that > > tried to test that it worked. > > > > If you change those to getProperty they work. properties[name] also > works. > > > > In OGNL 4, which has not been released yet, property[name] should work. > > -- > > Dale King > > > > -- > Claus Ibsen > - > Red Hat, Inc. > Email: cib...@redhat.com > Twitter: davsclaus > Blog: http://davsclaus.com > Author of Camel in Action: http://www.manning.com/ibsen >
Creating a Camel Project with customized POM
Hi all, I created a camel project with "camel-archetype-spring" archetype to deploy in ServiceMix 4.4.2. But the versions of all the dependencies in POM are above that of ServiceMix. Example - ServiceMix camel-core version is 2.8.5 whereas the camel-core version in POM is 2.12.0. So I want to build a camel project that is compatible with ServiceMix 4.4.2. How can I achieve this. Please Help Thank you !!! -- View this message in context: http://camel.465427.n5.nabble.com/Creating-a-Camel-Project-with-customized-POM-tp5739872.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Using HTTP and HTTPS proxies with Camel HTTP Component
On 15 September 2013 05:36, Christian Posta wrote: > Alex, > > As Christian M. points out, use the camel config on the endpoint, not the > way you're doing in your OP. > > Cheers > > > On Wed, Sep 11, 2013 at 6:03 AM, Alex Anderson wrote: > >> On 10 September 2013 22:49, Christian Müller >> wrote: >> > Did you tried setting the proxy host/port as we described here [1]? >> >> Hi Christian, >> >> Thanks for the suggestion. Do you mean something other than what I >> referred to in my original post? >> >> >camelContext.properties['http.proxyHost'] = >> System.properties['http.proxyHost'] >> >camelContext.properties['http.proxyPort'] = >> System.properties['http.proxyPort'] >> >> Alex >> > > > > -- > *Christian Posta* > http://www.christianposta.com/blog > twitter: @christianposta Thanks for the pointers - will probably give this a go next week. As I'm using this to mock 3rd party services for a camel-based system under test, changing endpoint URLs is not convenient, but it's very helpful to know that other methods do not work.
Re: cast of property value for blueprint osgi implementation
Hi Claus, Yes, sorry, I ommitted that my message. I have this: and /etc/com.tradestonesoftware.aiextractor.cfg However, even without that in place, I would have thought that the type of the variable would have been converted to a boolean, and would have come in as false since the String value was not "true". I think I can get this to work by changing my setter methods to always take String, but was hoping this was not necessary, as it works fine using Spring DSL. Thanks, Carl -- View this message in context: http://camel.465427.n5.nabble.com/cast-of-property-value-for-blueprint-osgi-implementation-tp5739834p5739874.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: OGNL property syntax in documentation does not work
To be a little more concrete, according to the documentation you linked to, the following route should log "def" every second: from("timer:foo") .setProperty("foo").constant("abcdef") .setBody().ognl("property('foo').substring(3)") .log("${body}"); Instead it throws an exception every: [java.lang.NoSuchMethodException: org.apache.camel.language.ognl.RootObject.property(java.lang.String)] If I change property('foo') to properties['foo'] or to getProperty('foo') then it works None of the camel-ognl unit tests cover this use case. On Fri, Sep 20, 2013 at 8:24 AM, Dale King wrote: > The last 2 rows of the variables table shows ways that are supposed to get > properties by name, but I tried to use it and it throws an exception. The > RootObject passed to OGNL has getProperty methods, but OGNL will not match > up property(...) to getProperty() method. OGNL 4 can match property[name] > to getProperty, but that is not released yet and is square brackets instead > of parens. > > You could make property(...) methods but that would only work for reading > the property, not setting the property. > > As it stands now the syntax that works is: > > properties -- Gets map of all properties > properties[name] -- specific property, can be used to get or set > getProperty(name) -- Get specific property > getProperty(name, type) -- Get specific property as type > > I just realized that RootObject is missing any setter methods, e.g. > setProperty. The only way to set a property from within OGNL is using: > > properties['name'[ = value > > But then again you have the DSL support for setting properties. > On Sep 20, 2013 1:57 AM, "Claus Ibsen" wrote: > >> Can you post the link to where you found this "mistake". I cannot see >> a problem at >> http://camel.apache.org/ognl >> >> On Fri, Sep 20, 2013 at 12:57 AM, Dale King wrote: >> > In the documentation for the Camel OGNL component it shows the following >> > syntax: >> > >> > property(name) Object the property by the given name property(name, >> type) the >> > property by the given name as the given type >> > This syntax does not actually work in camel and I do not see any tests >> that >> > tried to test that it worked. >> > >> > If you change those to getProperty they work. properties[name] also >> works. >> > >> > In OGNL 4, which has not been released yet, property[name] should work. >> > -- >> > Dale King >> >> >> >> -- >> Claus Ibsen >> - >> Red Hat, Inc. >> Email: cib...@redhat.com >> Twitter: davsclaus >> Blog: http://davsclaus.com >> Author of Camel in Action: http://www.manning.com/ibsen >> > -- Dale King
Re: OGNL property syntax in documentation does not work
FYI, probably a better syntax to use for accessing properties that does work is properties.foo. Might want to put that in the documentation for OGNL. Similarly, request.headers.foo would work for request headers. On Fri, Sep 20, 2013 at 9:49 AM, Dale King wrote: > To be a little more concrete, according to the documentation you linked > to, the following route should log "def" every second: > > from("timer:foo") > .setProperty("foo").constant("abcdef") > .setBody().ognl("property('foo').substring(3)") > .log("${body}"); > > Instead it throws an exception every: > > [java.lang.NoSuchMethodException: > org.apache.camel.language.ognl.RootObject.property(java.lang.String)] > > If I change property('foo') to properties['foo'] or to getProperty('foo') > then it works > > None of the camel-ognl unit tests cover this use case. > > > On Fri, Sep 20, 2013 at 8:24 AM, Dale King wrote: > >> The last 2 rows of the variables table shows ways that are supposed to >> get properties by name, but I tried to use it and it throws an exception. >> The RootObject passed to OGNL has getProperty methods, but OGNL will not >> match up property(...) to getProperty() method. OGNL 4 can match >> property[name] to getProperty, but that is not released yet and is square >> brackets instead of parens. >> >> You could make property(...) methods but that would only work for reading >> the property, not setting the property. >> >> As it stands now the syntax that works is: >> >> properties -- Gets map of all properties >> properties[name] -- specific property, can be used to get or set >> getProperty(name) -- Get specific property >> getProperty(name, type) -- Get specific property as type >> >> I just realized that RootObject is missing any setter methods, e.g. >> setProperty. The only way to set a property from within OGNL is using: >> >> properties['name'[ = value >> >> But then again you have the DSL support for setting properties. >> On Sep 20, 2013 1:57 AM, "Claus Ibsen" wrote: >> >>> Can you post the link to where you found this "mistake". I cannot see >>> a problem at >>> http://camel.apache.org/ognl >>> >>> On Fri, Sep 20, 2013 at 12:57 AM, Dale King wrote: >>> > In the documentation for the Camel OGNL component it shows the >>> following >>> > syntax: >>> > >>> > property(name) Object the property by the given name property(name, >>> type) the >>> > property by the given name as the given type >>> > This syntax does not actually work in camel and I do not see any tests >>> that >>> > tried to test that it worked. >>> > >>> > If you change those to getProperty they work. properties[name] also >>> works. >>> > >>> > In OGNL 4, which has not been released yet, property[name] should work. >>> > -- >>> > Dale King >>> >>> >>> >>> -- >>> Claus Ibsen >>> - >>> Red Hat, Inc. >>> Email: cib...@redhat.com >>> Twitter: davsclaus >>> Blog: http://davsclaus.com >>> Author of Camel in Action: http://www.manning.com/ibsen >>> >> > > > -- > Dale King > -- Dale King
Bindy infinite loop
I have a route that looks like this if the route has to process a file that contains an empty line at the end (I suppose that if I have an empty line in the middle of the file, the problem will be the same) then the process restarts from the beginning of the file and so on ... infinite loop. The problem is only happening on Linux, I could not reproduce it on windows. Is it due to the token separator \n ? What could be done to put safe guards and avoid that something like this happen even if have empty lines in my file ? -- View this message in context: http://camel.465427.n5.nabble.com/Bindy-infinite-loop-tp5739879.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: AW: How to set a header in custom DataFormat?
Jan, I really appreciate the help, unfortunately your test case does not even reproduce the issue I am having. I think I may not have been clear in my original message. The issue is in a custom DataFormat, if a set a *new* header, that header will be gone from the Exchange, for the rest of the route, down-stream from the unmarshal (or marshal) call. So the issue is just setting a header and checking it it's still there. So the best way to recreate the problem is to create the most simplest DataFormat because marshal/unmarshal is not the issue - the issue is setting a new header *inside* the custom marshal/unmarshal methods. So I created a test case whose custom DataFormat does the bare minimum - no file I/O, no serialization - just string manipulation. Maybe you and/or other can have a look and explain why there's the issue. Thanks, Chris (the code formatting will be wrecked by the mailing list line length limit) import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.spi.DataFormat; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class SetHeaderDemo extends CamelTestSupport { @Test public void setHeaderInDataFormatProblem() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBodyAndHeader("direct:start", "one\ntwo\nthree\n", "DEMO_HEADER", "Hello..."); // This passes assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DEMO_HEADER}", "Hello..."); // This FAILS... WHY??? * assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DISAPPEARING_DEMO_HEADER}", "Will it be set?"); assertMockEndpointsSatisfied(); } @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() { from("direct:start") .unmarshal("customFmt") // <== will try to add a new header to Exchange IN msg .to("log://dataformat.demo?showAll=true&multiline=true&level=INFO") // <== not there .to("mock:result"); } }; } @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); CustomDataFormat fmt = new CustomDataFormat(); registry.bind("customFmt", fmt); return registry; } } /** * Simplest, contrived DataFormat impl to demonstrate that it's impossible * to set a new header in the DataFormat's implementation methods and * see the newly added header down-stream from the marshal/unmarshal * call(s). * */ class CustomDataFormat implements DataFormat { /** * Expects the body to be a newline-delimited list of strings, * which will be unmarshalled to a string array, whose elements * are the "lines" in the "document". * * Obviously the marshal/unmarshal process is not important - the * issue is that if a new header is added in the DataFormat marshal or * unmarshal - it will be GONE after returning. */ @Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { List result = new ArrayList(); BufferedReader in = new BufferedReader(new InputStreamReader(stream)); String line = null; while((line = in.readLine()) != null) { result.add(line); } exchange.getIn().setHeader("DISAPPEARING_DEMO_HEADER", "Will it be set?"); return result; } @Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { throw new UnsupportedOperationException("Not implemented."); } } On 9/19/2013 4:13 AM, Jan Matèrne (jhm) wrote: I tried building my own DF and that works (for me) Jan package org.apache.camel.dataformat; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.Map; import javax.activation.DataHandler; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.Processor; import org.apache.camel.builder.ExchangeBuilder; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultMessage; import org.apache.camel.spi.DataForm
Re: Is it possible to include XPath expression in simple expression?
Hi Christian, I think it would be useful if we have such "composite" expression. What do you think? -- View this message in context: http://camel.465427.n5.nabble.com/Is-it-possible-to-include-XPath-expression-in-simple-expression-tp5739830p5739882.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: AW: How to set a header in custom DataFormat?
Ok, I solved the issue. After reading the source code of org.apache.camel.processor.UnmarshalProcessor, I saw this little piece of code: } else if (result instanceof Message) { // the dataformat has probably set headers, attachments, etc. so let's use it as the outbound payload exchange.setOut((Message) result); Which means if a DataFormat implementation wants to set headers and/or attachments, the unmarshal implementation cannot directly return the results - it must create a new Message and set the results to body of the new Message and return this new Message instead. I have to say, I never saw this documented anywhere nor any example in the book. Of course I understand that there are a lot of higher priority items to do, so I'm not complaining ;) Well here's the revised sample DataFormat where you *can* successfully set new headers in the unmarshal implementation: Regards, Chris class CustomDataFormat2 implements DataFormat { @Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { // To be able to set new headers and/or attachments, etc. // we need to wrap the result in a new Message and return // the new Message instead... who knew? Message msg = exchange.getIn().copy(); List result = new ArrayList(); BufferedReader in = new BufferedReader(new InputStreamReader(stream)); String line = null; while((line = in.readLine()) != null) { result.add(line); } msg.setBody(result); // now it works! msg.setHeader("DISAPPEARING_DEMO_HEADER", "Will it be set?"); return msg; } @Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { throw new UnsupportedOperationException("Not implemented."); } } On 9/20/2013 10:55 AM, Chris wrote: Jan, I really appreciate the help, unfortunately your test case does not even reproduce the issue I am having. I think I may not have been clear in my original message. The issue is in a custom DataFormat, if a set a *new* header, that header will be gone from the Exchange, for the rest of the route, down-stream from the unmarshal (or marshal) call. So the issue is just setting a header and checking it it's still there. So the best way to recreate the problem is to create the most simplest DataFormat because marshal/unmarshal is not the issue - the issue is setting a new header *inside* the custom marshal/unmarshal methods. So I created a test case whose custom DataFormat does the bare minimum - no file I/O, no serialization - just string manipulation. Maybe you and/or other can have a look and explain why there's the issue. Thanks, Chris (the code formatting will be wrecked by the mailing list line length limit) import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.spi.DataFormat; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class SetHeaderDemo extends CamelTestSupport { @Test public void setHeaderInDataFormatProblem() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBodyAndHeader("direct:start", "one\ntwo\nthree\n", "DEMO_HEADER", "Hello..."); // This passes assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DEMO_HEADER}", "Hello..."); // This FAILS... WHY??? * assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DISAPPEARING_DEMO_HEADER}", "Will it be set?"); assertMockEndpointsSatisfied(); } @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() { from("direct:start") .unmarshal("customFmt") // <== will try to add a new header to Exchange IN msg .to("log://dataformat.demo?showAll=true&multiline=true&level=INFO") // <== not there .to("mock:result"); } }; } @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); CustomDataFormat fmt = new CustomDataFormat(); registry.bind("customFmt", fmt); return registry; } } /** * Simplest, contrived DataFormat impl to demonstrate that it's impossible * to set a new header in the DataFor
Re: Is it possible to include XPath expression in simple expression?
Perhaps adding language prefixes so that things like ${xpath:...} or ${ognl:...} and similar would work. On Fri, Sep 20, 2013 at 11:17 AM, bonnahu wrote: > Hi Christian, > I think it would be useful if we have such "composite" expression. What do > you think? > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Is-it-possible-to-include-XPath-expression-in-simple-expression-tp5739830p5739882.html > Sent from the Camel - Users mailing list archive at Nabble.com. > -- Dale King
Re: AW: How to set a header in custom DataFormat?
I spoke too soon... It works for unmarshalling, but not for marshalling - it's impossible to set new headers, attachments, etc. from a DataFormat's marshal method. On 9/20/2013 11:57 AM, Chris wrote: Ok, I solved the issue. After reading the source code of org.apache.camel.processor.UnmarshalProcessor, I saw this little piece of code: } else if (result instanceof Message) { // the dataformat has probably set headers, attachments, etc. so let's use it as the outbound payload exchange.setOut((Message) result); Which means if a DataFormat implementation wants to set headers and/or attachments, the unmarshal implementation cannot directly return the results - it must create a new Message and set the results to body of the new Message and return this new Message instead. I have to say, I never saw this documented anywhere nor any example in the book. Of course I understand that there are a lot of higher priority items to do, so I'm not complaining ;) Well here's the revised sample DataFormat where you *can* successfully set new headers in the unmarshal implementation: Regards, Chris class CustomDataFormat2 implements DataFormat { @Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { // To be able to set new headers and/or attachments, etc. // we need to wrap the result in a new Message and return // the new Message instead... who knew? Message msg = exchange.getIn().copy(); List result = new ArrayList(); BufferedReader in = new BufferedReader(new InputStreamReader(stream)); String line = null; while((line = in.readLine()) != null) { result.add(line); } msg.setBody(result); // now it works! msg.setHeader("DISAPPEARING_DEMO_HEADER", "Will it be set?"); return msg; } @Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { throw new UnsupportedOperationException("Not implemented."); } } On 9/20/2013 10:55 AM, Chris wrote: Jan, I really appreciate the help, unfortunately your test case does not even reproduce the issue I am having. I think I may not have been clear in my original message. The issue is in a custom DataFormat, if a set a *new* header, that header will be gone from the Exchange, for the rest of the route, down-stream from the unmarshal (or marshal) call. So the issue is just setting a header and checking it it's still there. So the best way to recreate the problem is to create the most simplest DataFormat because marshal/unmarshal is not the issue - the issue is setting a new header *inside* the custom marshal/unmarshal methods. So I created a test case whose custom DataFormat does the bare minimum - no file I/O, no serialization - just string manipulation. Maybe you and/or other can have a look and explain why there's the issue. Thanks, Chris (the code formatting will be wrecked by the mailing list line length limit) import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.spi.DataFormat; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class SetHeaderDemo extends CamelTestSupport { @Test public void setHeaderInDataFormatProblem() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBodyAndHeader("direct:start", "one\ntwo\nthree\n", "DEMO_HEADER", "Hello..."); // This passes assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DEMO_HEADER}", "Hello..."); // This FAILS... WHY??? * assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DISAPPEARING_DEMO_HEADER}", "Will it be set?"); assertMockEndpointsSatisfied(); } @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() { from("direct:start") .unmarshal("customFmt") // <== will try to add a new header to Exchange IN msg .to("log://dataformat.demo?showAll=true&multiline=true&level=INFO") // <== not there .to("mock:result"); } }; } @Override protected JndiRegistry createRegistry() throws Exception { JndiRegistry registry = super.createRegistry(); CustomDataFormat fmt = new
Re: AW: How to set a header in custom DataFormat?
On Fri, Sep 20, 2013 at 11:57 AM, Chris wrote: > I have to say, I never saw this documented anywhere nor any example in the > book. Of course I understand that there are a lot of higher priority items > to do, so I'm not complaining ;) > Well, it was in the code, isn't that documentation enough? ;-) -- Dale King
Re: Creating a Camel Project with customized POM
Please don't post the same question to multiple forums without to mention it. If you use camel-archetype-spring version 2.12.0, change all camel version numbers in the pom to 2.8.5. You could also use the camel-archetype-spring version 2.8.5 (if it's available) which does this by default ;-) Best, Christian - Software Integration Specialist Apache Camel committer: https://camel.apache.org/team V.P. Apache Camel: https://www.apache.org/foundation/ Apache Member: https://www.apache.org/foundation/members.html https://www.linkedin.com/pub/christian-mueller/11/551/642 On Fri, Sep 20, 2013 at 2:55 PM, madusanka wrote: > Hi all, > > I created a camel project with "camel-archetype-spring" archetype to deploy > in ServiceMix 4.4.2. But the versions of all the dependencies in POM are > above that of ServiceMix. > > Example - ServiceMix camel-core version is 2.8.5 whereas the camel-core > version in POM is 2.12.0. > > So I want to build a camel project that is compatible with ServiceMix > 4.4.2. > How can I achieve this. Please Help > > Thank you !!! > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Creating-a-Camel-Project-with-customized-POM-tp5739872.html > Sent from the Camel - Users mailing list archive at Nabble.com. >
Re: AW: How to set a header in custom DataFormat?
Ok, for *marshaling* the workaround is a bit different then *unmarshalling*. For *marshalling*, the solution is to set new headers (or attachments, etc.) on the "out" Message. That wasn't documented or in the code comments... but, again - not complaining, just glad I got it to work. On 9/20/2013 12:38 PM, Chris wrote: I spoke too soon... It works for unmarshalling, but not for marshalling - it's impossible to set new headers, attachments, etc. from a DataFormat's marshal method. On 9/20/2013 11:57 AM, Chris wrote: Ok, I solved the issue. After reading the source code of org.apache.camel.processor.UnmarshalProcessor, I saw this little piece of code: } else if (result instanceof Message) { // the dataformat has probably set headers, attachments, etc. so let's use it as the outbound payload exchange.setOut((Message) result); Which means if a DataFormat implementation wants to set headers and/or attachments, the unmarshal implementation cannot directly return the results - it must create a new Message and set the results to body of the new Message and return this new Message instead. I have to say, I never saw this documented anywhere nor any example in the book. Of course I understand that there are a lot of higher priority items to do, so I'm not complaining ;) Well here's the revised sample DataFormat where you *can* successfully set new headers in the unmarshal implementation: Regards, Chris class CustomDataFormat2 implements DataFormat { @Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { // To be able to set new headers and/or attachments, etc. // we need to wrap the result in a new Message and return // the new Message instead... who knew? Message msg = exchange.getIn().copy(); List result = new ArrayList(); BufferedReader in = new BufferedReader(new InputStreamReader(stream)); String line = null; while((line = in.readLine()) != null) { result.add(line); } msg.setBody(result); // now it works! msg.setHeader("DISAPPEARING_DEMO_HEADER", "Will it be set?"); return msg; } @Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { throw new UnsupportedOperationException("Not implemented."); } } On 9/20/2013 10:55 AM, Chris wrote: Jan, I really appreciate the help, unfortunately your test case does not even reproduce the issue I am having. I think I may not have been clear in my original message. The issue is in a custom DataFormat, if a set a *new* header, that header will be gone from the Exchange, for the rest of the route, down-stream from the unmarshal (or marshal) call. So the issue is just setting a header and checking it it's still there. So the best way to recreate the problem is to create the most simplest DataFormat because marshal/unmarshal is not the issue - the issue is setting a new header *inside* the custom marshal/unmarshal methods. So I created a test case whose custom DataFormat does the bare minimum - no file I/O, no serialization - just string manipulation. Maybe you and/or other can have a look and explain why there's the issue. Thanks, Chris (the code formatting will be wrecked by the mailing list line length limit) import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.spi.DataFormat; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class SetHeaderDemo extends CamelTestSupport { @Test public void setHeaderInDataFormatProblem() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBodyAndHeader("direct:start", "one\ntwo\nthree\n", "DEMO_HEADER", "Hello..."); // This passes assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DEMO_HEADER}", "Hello..."); // This FAILS... WHY??? * assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DISAPPEARING_DEMO_HEADER}", "Will it be set?"); assertMockEndpointsSatisfied(); } @Override protected RouteBuilder createRouteBuilder() throws Exception { return new RouteBuilder() { @Override public void configure() { from("direct:start") .unmarshal("customFmt") // <== will try to add a new header to Exchange IN msg .to("
Re: AW: How to set a header in custom DataFormat?
Actually you can just set the new headers on the *out* message for *both* marshalling/unmarshalling. I.e. Regardless of what the code comment in UnmarshalingProcessor says, you don't need to create a new Message and wrap the result. On 9/20/2013 1:19 PM, Chris wrote: Ok, for *marshaling* the workaround is a bit different then *unmarshalling*. For *marshalling*, the solution is to set new headers (or attachments, etc.) on the "out" Message. That wasn't documented or in the code comments... but, again - not complaining, just glad I got it to work. On 9/20/2013 12:38 PM, Chris wrote: I spoke too soon... It works for unmarshalling, but not for marshalling - it's impossible to set new headers, attachments, etc. from a DataFormat's marshal method. On 9/20/2013 11:57 AM, Chris wrote: Ok, I solved the issue. After reading the source code of org.apache.camel.processor.UnmarshalProcessor, I saw this little piece of code: } else if (result instanceof Message) { // the dataformat has probably set headers, attachments, etc. so let's use it as the outbound payload exchange.setOut((Message) result); Which means if a DataFormat implementation wants to set headers and/or attachments, the unmarshal implementation cannot directly return the results - it must create a new Message and set the results to body of the new Message and return this new Message instead. I have to say, I never saw this documented anywhere nor any example in the book. Of course I understand that there are a lot of higher priority items to do, so I'm not complaining ;) Well here's the revised sample DataFormat where you *can* successfully set new headers in the unmarshal implementation: Regards, Chris class CustomDataFormat2 implements DataFormat { @Override public Object unmarshal(Exchange exchange, InputStream stream) throws Exception { // To be able to set new headers and/or attachments, etc. // we need to wrap the result in a new Message and return // the new Message instead... who knew? Message msg = exchange.getIn().copy(); List result = new ArrayList(); BufferedReader in = new BufferedReader(new InputStreamReader(stream)); String line = null; while((line = in.readLine()) != null) { result.add(line); } msg.setBody(result); // now it works! msg.setHeader("DISAPPEARING_DEMO_HEADER", "Will it be set?"); return msg; } @Override public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception { throw new UnsupportedOperationException("Not implemented."); } } On 9/20/2013 10:55 AM, Chris wrote: Jan, I really appreciate the help, unfortunately your test case does not even reproduce the issue I am having. I think I may not have been clear in my original message. The issue is in a custom DataFormat, if a set a *new* header, that header will be gone from the Exchange, for the rest of the route, down-stream from the unmarshal (or marshal) call. So the issue is just setting a header and checking it it's still there. So the best way to recreate the problem is to create the most simplest DataFormat because marshal/unmarshal is not the issue - the issue is setting a new header *inside* the custom marshal/unmarshal methods. So I created a test case whose custom DataFormat does the bare minimum - no file I/O, no serialization - just string manipulation. Maybe you and/or other can have a look and explain why there's the issue. Thanks, Chris (the code formatting will be wrecked by the mailing list line length limit) import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.util.ArrayList; import java.util.List; import org.apache.camel.Exchange; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.component.mock.MockEndpoint; import org.apache.camel.impl.JndiRegistry; import org.apache.camel.spi.DataFormat; import org.apache.camel.test.junit4.CamelTestSupport; import org.junit.Test; public class SetHeaderDemo extends CamelTestSupport { @Test public void setHeaderInDataFormatProblem() throws Exception { MockEndpoint mock = getMockEndpoint("mock:result"); mock.expectedMessageCount(1); template.sendBodyAndHeader("direct:start", "one\ntwo\nthree\n", "DEMO_HEADER", "Hello..."); // This passes assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DEMO_HEADER}", "Hello..."); // This FAILS... WHY??? * assertExpression(mock.getReceivedExchanges().get(0), "simple", "${in.header.DISAPPEARING_DEMO_HEADER}", "Will it be set?"); assertMockEndpointsSatisfied(); } @Override protected RouteBuilder createRoute
Re: Simple way to do some elementary bean operations
On Fri, Sep 20, 2013 at 1:54 AM, Claus Ibsen wrote: > Hi > > You can use the language component, and set transform=false > http://camel.apache.org/language > That seems to do the trick, but having to add ?transform=false is a pain. I personally would argue that the default for transform should have been false since there are easier ways to do that in the DSL using the transform DSL element, but at this point don't think I would win that argument. > Though the idea of having a
Re: Creating a Camel Project with customized POM
Thanks!!! I'm sorry about posting the same question in multiple forums. I did so since it involved Camel, ServiceMix and Maven. Yes it worked. I added the "-DarchetypeVersion=2.10.5" argument to the maven command and it worked -- View this message in context: http://camel.465427.n5.nabble.com/Re-Creating-a-Camel-Project-with-customized-POM-tp5739892p5739902.html Sent from the Camel - Users mailing list archive at Nabble.com.
Possible Bug. Scala recipient list http turning %2B into plus
Hi all, So I'm trying to hit solr through camel and in the url there needs to be some pluses. Specifically to specify time facet gap "/HOUR+1HOUR". From googling I haven't seen any talk of this problem yet. I've tried java.util.URLEncoder and Decoder in numerous places inside and outside of the route to no avail. For example in the REPL: import org.apache.camel.impl.DefaultCamelContext import org.apache.camel.scala.dsl.builder.RouteBuilder val ctx = new DefaultCamelContext() val rs = new RouteBuilder { from("direct:thing") ==> { recipients(e => e.in[String]) to("log:debug?showAll=true") } } ctx.addRoutes(rs) ctx.start() ctx.createProducerTemplate().requestBody("direct:thing", "http://localhost:8080/solr/select?q=*:*&facet.range=datetime&f.datetime.facet.range.start=2010-01-01T00%3A00%3A00.000Z&f.datetime.facet.range.end=2010-01-10T00%3A00%3A00.000Z&f.datetime.facet.range.gap=%2FDAY%2B1DAY&facet=true&facet.limit=10&facet.mincount=1";) or really any address where you get a 400 error and can see in the message getting passed in is still %2B but then in the from the HTTPException that it has changed to a +. Caused by: org.apache.camel.component.http.HttpOperationFailedException: HTTP operation failed invoking http://localhost:8080/solr/select?f.datetime.facet.range.end=2010-01-10T00%3A00%3A00.000Z&f.datetime.facet.range.gap=%2FDAY+1DAY&f.datetime.facet.range.start=2010-01-01T00%3A00%3A00.000Z&facet=true&facet.limit=10&facet.mincount=1&facet.range=datetime&q=*%3A* with statusCode: 400 at org.apache.camel.component.http.HttpProducer.populateHttpOperationFailedException(HttpProducer.java:228) at org.apache.camel.component.http.HttpProducer.process(HttpProducer.java:156) at org.apache.camel.util.AsyncProcessorConverterHelper$ProcessorToAsyncProcessorBridge.process(AsyncProcessorConverterHelper.java:61) at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:73) Thanks for any help, Joseph Using scala 2.10.0 Camel 2.11.0 Java 7
Re: Bindy infinite loop
What version of camel does this affect? On Fri, Sep 20, 2013 at 7:16 AM, fclose wrote: > I have a route that looks like this > > > > > > > uri="bean:importLineHandler?method=handleImport"/> > > > > class="org.apache.camel.dataformat.bindy.csv.BindyCsvDataFormat"> > > > > > if the route has to process a file that contains an empty line at the end > (I suppose that if I have an empty line in the middle of the file, the > problem will be the same) then the process restarts from the beginning of > the file and so on ... infinite loop. > > The problem is only happening on Linux, I could not reproduce it on > windows. > > Is it due to the token separator \n ? > What could be done to put safe guards and avoid that something like this > happen even if have empty lines in my file ? > > > > > -- > View this message in context: > http://camel.465427.n5.nabble.com/Bindy-infinite-loop-tp5739879.html > Sent from the Camel - Users mailing list archive at Nabble.com. > -- *Christian Posta* http://www.christianposta.com/blog twitter: @christianposta
Re: Is it possible to include XPath expression in simple expression?
yah i like that. can you open a jira? On Fri, Sep 20, 2013 at 9:36 AM, Dale King wrote: > Perhaps adding language prefixes so that things like ${xpath:...} or > ${ognl:...} and similar would work. > > > On Fri, Sep 20, 2013 at 11:17 AM, bonnahu wrote: > > > Hi Christian, > > I think it would be useful if we have such "composite" expression. What > do > > you think? > > > > > > > > -- > > View this message in context: > > > http://camel.465427.n5.nabble.com/Is-it-possible-to-include-XPath-expression-in-simple-expression-tp5739830p5739882.html > > Sent from the Camel - Users mailing list archive at Nabble.com. > > > > > > -- > Dale King > -- *Christian Posta* http://www.christianposta.com/blog twitter: @christianposta
Re: missing output on route definition
I am using 2.11.0. I can try the newly released 2.12.0 if you think that would fix it. I removed the transacted statement and yes, the broker then showed up in the route definition. Maybe there is a bug in how routes with transacted are advised? -- View this message in context: http://camel.465427.n5.nabble.com/missing-output-on-route-definition-tp5739784p5739914.html Sent from the Camel - Users mailing list archive at Nabble.com.
Re: AW: How to set a header in custom DataFormat?
On 9/20/2013 12:40 PM, Dale King wrote: On Fri, Sep 20, 2013 at 11:57 AM, Chris wrote: I have to say, I never saw this documented anywhere nor any example in the book. Of course I understand that there are a lot of higher priority items to do, so I'm not complaining ;) Well, it was in the code, isn't that documentation enough? ;-) Better then nothing, true. Except my last message where I said it was impossible to set a new header from a "marshal" implementation - I just found a workaround for that too, and that wasn't commented...
Re: Proper way to initialize Transaction management for Camel in an Application Server
The question would be what functionality do I loose in doing that? Will I have to set up components like ActiveMQ manually instead of just getting it out of jboss jndi? Sent from my iPad > On Sep 20, 2013, at 2:01 AM, Claus Ibsen wrote: > > Hi > > You can use SimpleCamelServletContextListener which then does not use > the JndiRegistry but the simple instead, which should be able to do > the lookups. > > See the docs at > http://camel.apache.org/servletlistener-component.html > >> On Thu, Sep 19, 2013 at 4:50 PM, kraythe wrote: >> So am I to understand that there is no way possible right now to do this in a >> ServletListener component? Can I create a simple registry without blowing up >> the construction of the context or do something else? I would really like to >> enable this type of ACID transactions. >> >> >> >> -- >> View this message in context: >> http://camel.465427.n5.nabble.com/Proper-way-to-initialize-Transaction-management-for-Camel-in-an-Application-Server-tp5739760p5739827.html >> Sent from the Camel - Users mailing list archive at Nabble.com. > > > > -- > Claus Ibsen > - > Red Hat, Inc. > Email: cib...@redhat.com > Twitter: davsclaus > Blog: http://davsclaus.com > Author of Camel in Action: http://www.manning.com/ibsen
Re: Is there a Method to Determine if Mock Endpoints are Real?
Wouldn't it make sense to check that in the getMockEndpoint method and perhaps throw an assertion failure with a good message if the mock does exist? -- View this message in context: http://camel.465427.n5.nabble.com/Is-there-a-Method-to-Determine-if-Mock-Endpoints-are-Real-tp5739601p5739920.html Sent from the Camel - Users mailing list archive at Nabble.com.