Apache Camel REST - not connecting - rest

I'm trying to get Apache Camel's REST DSL working but it's not connecting for me.
I've got a RouteBuilder that's being called:
#Override
public void configure() {
restConfiguration().component("servlet")
.contextPath("/")
.enableCORS(true)
.dataFormatProperty("prettyPrint", "true")
.apiContextPath("/api-doc")
.apiProperty("api.version", buildVersion)
.apiProperty("cors", "true")
.bindingMode(RestBindingMode.json);
rest("/say/hello")
.get().route().transform().constant("Hello World");
}
but then the routes don't actually work.
This is inside a Spring Boot app that has other REST endpoints defined via JAX-RS but this is an integration package that I want to be able to keep separate. The weird thing is that this WAS working a few months ago before I had to work on other things, but now, coming back to it, I can't even get this simple endpoint working.
I've got Camel in my Maven pom.xml and everything seems to be starting correctly, but nothing happens when I hit http:://localhost:9071/say/hello, I just get the standard Tomcat 404 page.
Any thoughts on what I'm missing?

According to this: http://www.baeldung.com/apache-camel-spring-boot
As of Camel’s version 2.19, this configuration has been dropped as the
CamelServlet is by default set to “/camel”.
so /camel/say/hello is the correct URL and it works for me. Still looking at how to customize this.
EDIT:
Here's how to customize this under Spring Boot. You add a property to application.properties like this:
camel.component.servlet.mapping.contextPath=/*

Related

camel route for opc-ua milo project

I am working on creating a Camel, Spring boot application that implements the OPC-UA connection. Till now, I was successfully able to run the examples obtained from Eclipse milo github repository.
Now, my task is to create a camel route that will connect to the opc-ua server that is running on a different machine, read data from there and store in a jms queue.
Till now, I am able to run the BrowseNodeExample and ReadNodeExample where I am connecting to a server simulator (Top Server V6). In the example code, when connecting to the server, the endpoint of the server is given as - "opc.tcp://127.0.0.1:49384/SWToolbox.TOPServer.V6"
Now in the camel routing piece of code, in the .configure() part, what shall I write in the .from() part. The piece of code is as -
#Override
public void configure() throws Exception {
from("opc.tcp://127.0.0.1:49384/SWToolbox.TOPServer.V6")
.process(opcConnection)
.split(body().tokenize(";"))
.to(opcBean.getKarafQueue());
}
While searching for the solution I came across one option: milo-server:tcp://127.0.0.1:49384/SWToolbox.TOPServer.V6/nodeId=2&namespaceUri=http://examples.freeopcua.github.io. I tried that but it didn't work. In both the cases I get the below error:
ResolveEndpointFailedException: Failed to resolve endpoint: (endpoint
given) due to: No component found with scheme: milo-server (or
opc.tcp)
You might want to add the camel-opc component to your project.
I've found one on Github
and also milo version on maven central for the OPC-UA connection.
Hope that helps :-)
The ResolveEndpointFailedException is quite clear, Camel cannot find the component. That means that the auto-discovery failed to load the definition in the META-INF directory.
Have you checked that the camel-milo jar is contained in your fat-jar/war?
As a workaround you can add the component manualy via
CamelContext context = new DefaultCamelContext();
context.addComponent("foo", new FooComponent(context));
http://camel.apache.org/how-do-i-add-a-component.html
or in your case
#Override
public void configure() throws Exception {
getContext().addComponent("milo-server", new org.apache.camel.component.milo.server.MiloServerComponent());
from("milo-server:tcp://127.0.0.1:49384/SWToolbox.TOPServer.V6/nodeId=2&namespaceUri=http://examples.freeopcua.github.io")
...
}
Furthermore be aware that milo-server starts an OPC UA server. As I understood your question you want to connect to an OPC UA server. Therefore you need the milo-client component.
camel-milo client at github

SpringBoot RestController returns 405 for path 'services/*'

We recently updated a project to spring boot version '1.5.6.RELEASE' and noticed that several REST-services did not work anymore. We found out that it has to do with the RequestMapping - when a Rest-URL starts with 'services/', the Request always returns a HTTP 405 (Method not allowd). Changing that path a bit, it works again. Our API uses this 'services/...' paths. This only seems to occur when I also use soap services.
Has anyone a hint to solve this?
Here is a simple working example:
https://github.com/gemdat/rest_demo/tree/master
We finally found the problem - due to a spring servlet refactoring we had to adjust the 'webservice path' in the application.properties...
spring.data.rest.base-path=/services/rest
spring.webservices.path=/services/soap

camunda-webapp and JAAS-authentication

In a Wildfly 8.1.0.Final we deploy:
our own CRM-webapp (Seam2/JSF1.2)
camunda-webapp 7.3.0
camunda-engine 7.3.0 as a module (shared engine)
custom engine-plugin to enable camunda-engine to use the user/group-store of our CRM
We display camunda tasklist in an iframe inside our CRM.
This setup runs fine so far, but we have to login twice.
So we need SSO, but cannot establish AD/LDAP, like in camunda-sso-jboss example.
I thought of Wildfly's JAAS and SSO capabilities, but i'am not sure, if camunda-webapp supports JAAS-authentication.
I think the security-domain configuration in jboss-web.xml is just generated by a maven archetype and has no effect on the camunda-webapp, is that right? I changed that configuration and it had no effect at all.
Can someone give me a hint, where i should hook into camunda-webapp or if it is possible at all?
Ok, i have a first success.
I changed org.camunda.bpm.webapp.impl.security.auth.Authentications.getFromSession to accept HttpServletRequest as parameter instead of HttpSession (called from AuthenticationFilter.doFilter). If the session contains no Authentications, i try to pull the Principle from the request and if one exists, i log em in silently (copied most from UserAuthenticationResource.doLogin).
Then i have a very simple webapp ("testA") with only one JSP and Basic Authentication. Both camunda-webapp and testA have the same security-domain configured, and the host in the undertow-subsystem has the "single-sign-on"-setting.
Now i can login into /testA, then call /camunda in another tab without further authentication.
The code has to be improved a lot. If everythink works fine, i'll post the details.
If someone thinks this is a wrong approach, please let me know ;-)

Does Feign retry require some sort of configuration?

I just tried to do a attempted a seamless upgrade of a service in a test setup. The service is being accessed by a Feign client. And naively I was under the impression that with multiple instances available of the service, the client would retry another instance if it failed to connect to one.
That, however, did not happen. But I cannot find any mention of how Feign in Spring Cloud is supposed to be configured to do this? Although I have seen mentions of it supporting it (as opposed to using RestTemplate where you would use something like Spring Retry?)
If you are using ribbon you can set properties similar to the following (substituting "localapp" for your serviceid):
localapp.ribbon.MaxAutoRetries=5
localapp.ribbon.MaxAutoRetriesNextServer=5
localapp.ribbon.OkToRetryOnAllOperations=true
ps underneath Feign has a Retryer interface, which was made to support things like Ribbon.
https://github.com/Netflix/feign/blob/master/core/src/main/java/feign/Retryer.java
see if property works - OkToRetryOnAllOperations: true
You can refer application ->
https://github.com/spencergibb/spring-cloud-sandbox/blob/master/spring-cloud-sandbox-sample-frontend/src/main/resources/application.yml
Spencer was quick...was late by few minutes :-)

How to do integration test on MongoDB Connection in play framework using Java

I want to do an integration test on my project which store some data into MongoDB in test mode. I am using org.Mongo .
I have some testing unit class in /test folder. However when I run the unit class from eclipse, there is no data found at all from Mongo DB, nor can I get any collection instance from it.
Here is the test code like:
#Test
public void test(){
running(testServer(3333, fakeApplication(conf.asMap())), HTMLUNIT, new Callback<TestBrowser>() {
public void invoke(TestBrowser browser) {
String body = "\"name:\": \"abc\"";
MongoStore.store(body);
}
});
}
Conf is different config file other than application.conf, which I use to provide staging config. MongoStore is just a wrapper to store data in mongoDB.
I can never store the date into Mongo ( I am pretty sure the rest of mongo connection is good to use ), Nor can I get an instance of DBCollection.
Anyone know how to connect the play to mongo db when running in test unit?
I figured it out finally.
In the original code , I write a plugin to connect to mongoDB. It seems that when in test mode, play do not automatically load that plugin. So I need to add it as an additionalPlugin as a parameter of fakeApplication().
Everything works fine after that .
Inspired by a question in stackoverflow mentioning that plugins are not enabled automatically in test mode, forget the link thought( What a shame !)
other links :
name of the plugins should be the same as ones in conf/play.plugins
How to load different plugins in Play framework unit tests?
Play 2.0 FakeApplication setup with test configuration
This answer might be too late and irrelevant now, but I am adding just in case someone find it useful. I wrote an opinionated approach to integration/unit testing play application that uses mongodb here. The repository uses reactivemongo as the driver, and scalatest as the testing framework.