I'd like to create osgi bundle which listen for soap messages and route them to remote ejb. I have servicemix 4.x as a bundle environment, glassfish 4 as a ejb container and camel as routing engine. Is it possible to connect to each other?
Yes, there cxf and ejb components and you should be able to define your route like this:
from("cxf:...")
// ...
.to(ejb:...")
;
Please refer to: Apache Camel Components - CXF and EJB.
Related
My application has been using
org.apache.camel.component.cxf.common.header.CxfHeaderFilterStrategy
org.apache.camel.spi.HeaderFilterStrategy.Direction
org.apache.camel.component.cxf.CxfOperationException
defined by camel-cxf. But my build fails when using Camel 3.18.0. What dependencies changes do I need for these classes in 3.18.0?
Copying from the Camel 3.18 upgrade guide:
https://camel.apache.org/manual/camel-3x-upgrade-guide-3_18.html#_camel_cxf
The camel-cxf JAR has been split up into SOAP vs REST and Spring and non Spring JARs.
camel-cxf-soap
camel-cxf-spring-soap
camel-cxf-rest
camel-cxf-spring-rest
camel-cxf-transport
camel-cxf-spring-transport
When using Spring Boot then you need to migrate from camel-cxf-starter to use SOAP or REST:
camel-cxf-soap-starter
camel-cxf-rest-starter
For http4 component code check below.
rules.getRules().forEach(x->{
from("jetty:http://0.0.0.0:"+rules.getPort()+"/"+x.getFrom()+"??matchOnUriPrefix=true")
.to("http4://"+x.getTo()+"?bridgeEndpoint=true&throwExceptionOnFailure=false");
System.out.println(“Ieration Route: ”+x);});
Please check the sample routing below(X value)
Ieration Route: {"RouteRule":{ "from":"posts", "to":"jsonplaceholder.typicode.com/posts/?"}}
Ieration Route: {"RouteRule":{ "from":"users", "to":"reqres.in/api/users"}}
Ieration Route: {"RouteRule":{ "from":"countries", "to":"restcountries.eu/rest/v2/"}}
Application.yml file
routes:
port: 8088
route:
-
from: posts
to: jsonplaceholder.typicode.com/posts/?
-
from: users
to: reqres.in/api/users
-
from: countries
to: restcountries.eu/rest/v2/
Where we can add multiple servers in above scenario? in yml file configuration if yes how we can add that.
Appreciated your help.
Thanks
As per the camel doc The Load Balancer Pattern allows you to delegate to one of a number of endpoints using a variety of different load balancing policies
The camel-urlrewrite component will allow you to plugin url rewrite mechanism.
This failover load balancer can be configured in following fashion :
from("jetty:http://{host}:{{port}}/{context_1}?matchOnUriPrefix=true")
.loadBalance().failover(Exception.class)
.to("jetty:http://{host}:{{port2}}/context_2?bridgeEndpoint=true&urlRewrite=#myRewrite")
.to("jetty:http://{host}:{{port2}}/{other_context}?bridgeEndpoint=true&urlRewrite=#myRewrite");
The detailed code can be found here : https://github.com/apache/camel/tree/master/components/camel-urlrewrite/src/test/java/org/apache/camel/component/urlrewrite
*This component requires that your Camel routes starts from a servlet based endpoint such as Jetty etc. which your code already have.
Related Camel Doc # http://camel.apache.org/load-balancer.html
I'm using the camel 2.16.2 and I need to use the one CamelContext across multiple jars as I need to have all the Camel Routers in to one CamelContext. So my war will have all those jars as maven artifacts.
Please let me know how do I handle above scenario?
Edit
Just to elaborate more on above question.
In my war myApp.war, I have initialized the CamelContext. There are three jars myApp1.jar, myApp2.jar and myApp3.jar. Each jar has it own routers defined separately.
How do I start the routers in each jar ?
Can I use the same CamelContext injected to each routers?
If I cannot handle through jars, is it possible to implement with multiple war (myApp1.war, myApp2.war and myApp3.war) and each war having different camelContext and communicate to those routers from the main war (myApp.war) ?
As other guys said, you can't use the same CamelContext across different Jars. Could you explain a little what you want to do?
IMHO what you want to do is use routes defined in different Jars. So for that you can define a Camel Context and add all the routes from different Jars. Of course your Camel-Context-JAR has to have access to all those jars.
<camel:camelContext id="camel5">
<camel:package>org.apache.camel.spring.example</camel:package>
</camel:camelContext>
Or class by class
<camelContext id="camel5" xmlns="http://camel.apache.org/schema/spring">
<routeBuilder ref="myBuilder" />
</camelContext>
<bean id="myBuilder" class="org.apache.camel.spring.example.test1.MyRouteBuilder"/>
Or if you are using CDI you can follow this great article https://dzone.com/articles/using-camel-routes-in-java-ee-components
Reference: http://camel.apache.org/spring.html
After doing some research found a way to implement this. Infact we can use the same CamelContext across different jars as all jars are in the same war (Web Container).
We can implement easily with Apache Camel 2.16.2 with camel CDI. If you're using wildfly to deploy your war then you may need to add the camel patch. Download the the wildfly 9.0.2 pach
Steps are Given Below.
In your war create a servlet or restService and Inject the camelContext.
#Inject
#ContextName("cdi-context")
private CamelContext camelctx;
Create a router in the jar with below annotation.
#Startup
#ApplicationScoped
public class MyJRouteBuilder extends RouteBuilder {
In Configure method add
#Override
public void configure() throws Exception {
from("direct:startTwo").routeId("MyJRouteBuilder")
.bean(new SomeBeanThree());
}
Create a BootStrap Class in your jar and add the Router
#Singleton
#Startup
public class BootStrap {
private CamelContext camelctx;
#PostConstruct
public void init() throws Exception {
camelctx.addRoutes(new MyJRouteBuilder());
}
Add your jar as a artifact in the war pom.xml. Once you deploy the war you can see MyJRouteBuilder is Registred in the cdi-context CamelContext. So now you can access your Router anywhere you want.
Hope this would useful anyone who has the same issue what I had.
My goal is to get Camel running under IBM Liberty application server using OSGi and be able to describe the DSL (Domain Specific Language) routes in Blueprint. I am making progress and now have a Liberty environment with Camel installed and configured as OSGi bundles. When I write a Java DSL Camel app as an OSGi bundle, all works exactly as I might hope.
My last step is to be able to describe my camel routes in Blueprint. To that end I create a new OSGi bundle and defined a blueprint.xml that looks as follows:
<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:camelBlueprint="http://camel.apache.org/schema/blueprint"
xsi:schemaLocation="http://camel.apache.org/schema/blueprint http://camel.apache.org/schema/blueprint/camel-blueprint-2.14.1.xsd">
<camelBlueprint:camelContext>
<camelBlueprint:route>
<camelBlueprint:from uri="file:c:/temp/in"/>
<camelBlueprint:to uri="file:c:/temp/out"/>
</camelBlueprint:route>
</camelBlueprint:camelContext>
</blueprint>
When I attempt to deploy this OSGi bundle, the IBM Liberty OSGi framework fails to deploy the application with the following errors:
[3/2/15 0:42:38:796 CST] 00000035 com.ibm.ws.app.manager.esa.internal.DeploySubsystemAction
A CWWKZ0403E: A management exception was generated when trying to install the application Camel1 into an OSGi framework. The error text from the OSGi framework is:
Resource does not exist: org.apache.aries.subsystem.core.archive.SubsystemContentRequirement:
namespace=osgi.identity, attributes={}, directives={filter=(&(osgi.identity=OSGITest1)(type=osgi.bundle)(version>=1.0.0))}, resource=org.apache.aries.subsystem.core.internal.SubsystemResource#7bc2d3bc
Unfortunately this is where I am now stumped and stuck. I believe that IBM Liberty uses Equinox as the OSGi platform and not Karaf but reading the Camel Blueprint docs I seem to understand that Apache Aries is required (which Liberty supplies and uses) and that Karaf isn't a dependency.
My MANIFEST.MF for my test bundle is:
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OSGITest1
Bundle-SymbolicName: OSGITest1
Bundle-Version: 1.0.0.qualifier
Bundle-Blueprint: OSGI-INF/blueprint/*.xml
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: kolban.osgitest
Import-Package: org.apache.camel;version="2.14.1",
org.apache.camel.blueprint;version="2.14.1"
this message can occur if the resolver can't see the bundle, or there's something wrong with the bundle (typically with the Blueprint). If the bundle resolves ok when you remove the blueprint, then you need to look at what might be wrong in the blueprint. If this is the case, I would suspect you don't have the Camel blueprint namespace handler enabled in the runtime.
I hope this helps.
Regards, Graham.
I am using Servicemix 4.2 for my osgi based webservice application.
My webservice application is exposed using the CXF stack provided with the Servicemix.
Now we have to integrate the application with a separately developed Authentication api. The third party api is using JAAS as the mean to authenticate.
I embedded the third party jars in my application bundle. I exported the LoginModule implementation class using export-package instruction.
When I tried to use the third party provided jaas module, it gave error
Cannot create Login Context.No LoginModules configured for LoginModule
The third party jaas provider finds the location of jaas.config file using the system property
java.security.auth.login.config
The content of jaas.config file is as follows
LoginModule {
com.altair.aaservice.windowsauthn.hwec.WindowsAuthentication required;
};
After doing googling, I found that servicemix out of box provides two System bundles for jaas
Apache Felix Karaf :: JAAS Modules (1.4.0)
Apache Felix Karaf :: JAAS Config (1.4.0)
And you need to modify etc/users.properties file and some other things to implement jaas. But as we need to integrate with a third party jaas provider, i can not look into these ways. Also most of the documentation provided with servicemix insist you to use the servicemix way to implement jaas hence I did not get much success in finding any solution.
I manually uninstalled the two system bundles, after that I got following error
javax.security.auth.login.LoginException: unable to find LoginModule class: com.altair.aaservice.windowsauthn.hwec.WindowsAuthentication not found from bundle [org.apache.cxf.bundle]
As my webservice is CXF based, it may be looking in this bundle.
Is there any convenient way to integrate servicemix with custom jaas implementation. Please tell if there is any.
There is an example of writing a custom JAAS LoginModule here.