I have the following camel route
<camel:route>
<camel:from uri="restlet:/foo/{bar}/model" />
<camel:process ref="dummyProcessor" />
</camel:route>
My problem is why do I have match for these requests (basically I can put anything after model)
GET /foo/hoi/modelbroken
GET /foo/hoi/modelwhyisthisamatch
I expect that these should return 404.
What am I doing wrong?
There is a Matching Mode configuration option in Restlet.
http://restlet.com/learn/guide/2.3/core/routing/
While guide says it should be MODE_EQUALS by default, looks like it's Template.MODE_STARTS_WITH if you check the code:
https://github.com/restlet/restlet-framework-java/blob/master/modules/org.restlet/src/org/restlet/engine/component/InternalRouter.java
Not sure if it's a bug in guide or source, but you can configure it for yourself.
I've encountered something similar, and update to Java 11 and camel solved this issue.
Related
I've the following dependency to 3.7.2:
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-dependencies</artifactId>
<version>3.7.2</version>
I've this in the code:
fluentProducerTemplate.to("direct:myenpoint");
fluentProducerTemplate.send();
This code was working until the upgrade, but now it throws:
java.lang.IllegalArgumentException: No endpoint configured on FluentProducerTemplate. You can configure an endpoint with to(uri)`
Now I'm not able to figure why it's complaining about configuring endpoint as endpoint is clearly set in to(endpoint) call. I couldn't find anything in their documentation.
It's a fluent builder, so you should use it in a style like this:
template.to("xxx").send()
I found that endpoint has to be set at fluentProducerTemplate.setDefaultEndpoint(startingEndpoint);
The error message was misleading. And, I am not sure why to (endpoint) is still there.
i have jsut upgraded my camel version and some functionality that was working before version 2.16.0 is now broken, I used to be able to get the URI for a toDefinition that replaced a placeholder, having just upgraded, this now doesnt replace the placeholder.
Code example is as follows:
<propertyPlaceholder id="properties" location="config.properties" />
<route>
<from uri="direct:input" />
<to uri="mq:queue:{{MY_PLACEHOLDER}}" />
</route>
config.properties
MY_PLACEHOLDER=FOO
Camel version 2.15.5
toDefinition.getUri() // equals mq:queue:FOO
Camel version 2.16.0
toDefinition.getUri() // equals mq:queue:{{MY_PLACEHOLDER}}
Any ideas?
Yes that is how its intended to be. The model is the model as it was designed (in this case with placeholder value).
The resolved uri is when Camel startup and runs the routes. So you can take that uri, and ask Camel to resolve, there is an API on CamelContext for that resolvePropertyPlaceholders
http://static.javadoc.io/org.apache.camel/camel-core/2.18.2/org/apache/camel/CamelContext.html#resolvePropertyPlaceholders-java.lang.String-
I am using camel-blueprint with aries blueprint in osgi container. My configuration is as follows
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:c="http://camel.apache.org/schema/blueprint">
<c:camelContext>
<c:proxy id="myProxySender" serviceInterface="com.cmt.gabs.camel.test.MyInterface" serviceUrl="direct:a" />
<c:route>
<c:from uri="direct:a" />
<c:transform>
<c:simple>Hello ${body}</c:simple>
</c:transform>
<c:to uri="log:org.apache.camel.example?level=ERROR" />
</c:route>
</c:camelContext>
When i start the bundle it does not give any error, but the proxy is also not created as a service. Please tell me if i am doing any wrong.
I Want to use Camel Proxy for endpoint direct:a
edit
Camel version 2.11
OSGI container equinox 3.8
I had found the answer long ago but forgot to respond to it.
The answer is simple i just had to export it as a service.
This is the example that is bundled with apache camel binaries
<route>
<!-- incoming requests from the servlet is routed -->
<from uri="servlet:///hello"/>
<choice>
<when>
<!-- is there a header with the key name? -->
<header>name</header>
<!-- yes so return back a message to the user -->
<transform>
<simple>Hello ${header.name} how are you?</simple>
</transform>
</when>
<otherwise>
<!-- if no name parameter then output a syntax to the user -->
<transform>
<constant>Add a name parameter to uri, eg ?name=foo</constant>
</transform>
</otherwise>
</choice>
</route>
How to translate this to Java
Am a beginner in camel, and some how came up to this
CamelContext context = new DefaultCamelContext();
context.addRoutes(new RouteBuilder(){
public void configure(){
from("servlet://hello").transform().....
}
});
But dont know how to proceed further...
If you want to port it over to java without any XML (spring that is) you can't (easily) use the servlet component.
Just porting the route will be like:
from("servlet:///hello")
.choice()
.when()
.header("name")
.transform(simple("Hello ${header.name} how are you?"))
.otherwise()
.transform(constant("Add a name parameter to uri, eg ?name=foo"));
It should work in the spring example (or any spring web app), just replacing the <route> in the <CamelContext> with <routeBuilder ref="demoRoute"> given you have defined your route as a spring bean (<bean id="demoRoute" class="org.example.demo.DemoRoute">).
However, I guess you want to do this in plain java (no spring, no xml, no webapp). You could go with the Jetty component. The difference being that Camel then will start the servlet container, instead of the servlet container starting Camel. No difference for this simple example though.
I suggest you start out with a Maven archetype to get the skeleton up
e.g. mvn archetype:generate then choose org.apache.camel.archetypes:camel-archetype-java (Creates a new Camel project using Java DSL.)
Well, you don't need the maven archetype if you have your own java application and have the thread keep running. Then you should do fine with your approach. The maven archetype is however very good for training purposes.
You then need to add a dependency to Jetty (camel-jetty.jar) (read more here).
The actual route would be exactly the same except the first row: from("jetty:http://localhost:8080/camel/hello")
Nice and easy.
Try this one:
from("servlet://hello")
.choice()
.when(header("name").isNotNull()).transform(simple("Hello ${header.name} how are you?"))
.otherwise().transform(constant("Add a name parameter to uri, eg ?name=foo"));
I am running servicemix 4.4.1. I am trying to make a http call to a website by using camel-http4. No matter which website I try to invoke, I keep getting this error:
org.apache.camel.RuntimeCamelException: org.apache.camel.component.http.HttpOperationFailedException: HTTP operation failed invoking http://servicemix.apache.org/downloads/servicemix-4.4.0.html with statusCode: 405
Here is my code snippet:
<camelContext xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="activemq://events1"/>
<setHeader headerName="CamelHttpMethod">
<constant>POST</constant>
</setHeader>
<to uri="http://servicemix.apache.org/downloads/servicemix-4.4.0.html"/>
<to uri="log:events"/>
</route>
</camelContext>
I have tried a number of sites and tried using different http methods (post vs get), and I keep getting the same error. Any idea? Thanks in advance.
The website you specified is no target of a form. So most likely it will only allow GET requests not POST. So try to set the CamelHttpMethod to GET.
Btw. what do you want to achieve with your route? If you want to send the activeMQ message to the website then POST is ok but you have to use a website that accepts POST.
You could achieve that by defining your own route to receive the request.
Then you can send to that url in the first route.
I checked this;
problem solved by set option 'bridgeEndpoint';
You are setting the http endpoint to be bridgeEndpoint which means the request url will be updated with request URI.
<route>
<from uri="-------"/>
<to uri="jetty://http://localhost:9090/my.html?bridgeEndpoint=true"/
<to uri="log:events"/>
</route>