package/packagescan tag in Apache camel - apache-camel

Trying to load the routes from .xml file.Instead of using import resource,or "route context ref".
So i wrote a Routebuilder class with following code
InputStream is = getClass().getResourceAsStream("barRoute.xml");
RoutesDefinition routes = context.loadRoutesDefinition(is);
context.addRouteDefinitions(routes.getRoutes());
and loaded the routes at the time of camelcontext loading.
using
com.***.Loadroutes
I am able to load routes from xml file in standalone.
But when i deploy the bundle to fuse container,routes are not loading from xml file.
How to use package/packagescan in blurprint/spring to run inside fuse
note :made project as osgi specific bundle and normal bundle(mvn camel:run).

Related

Cannot access pages with direct url after building project for deployment Spring and React

When running my spring app from my IDE and running the React app from within VSCode, everything worked perfectly. I used the build script to build my React project, and then put the output into my /static folder of Spring. Then I used mvn clean install to build the .jar file. After running the entire app from the .jar file, I can access my homepage with localhost:5000. I can also use my navbar links to access different parts of the website, like the Home page and the About page... But if I try to manually enter the url localhost:5000/about I get a 404 Not found error.. What am I doing wrong?
My guess is that your Spring (webmvc?) application is not configured to listen to different URLs other than /. And while it may seem as if the navbar successfully redirects to http://localhost:5000/about, in reality the single page application uses JavaScript client-side routing to change the URL in the browser, unload the currently rendered page, and load another page.
If you are indeed using Spring MVC, you could (among other options) modify your Spring static resource configuration, modify your #RequestMapping to listen to multiple endpoints, or use a ViewControllerRegistry.

React SPA dynamic environment configuration

I'm building React SPA application from ground up using create-react-app and setting up uri address for API server of my SPA. According to official documentation suggested way is to create environment .env files for such kind of needs. I'm using a continuous delivery as part of development workflow. After deployment React SPA application goes in one Docker container and API goes to another. Those containers are deployed in separate servers and I do not know exactly what uri for API will be, so there is no way to create separate .env file for each deployment. Is there any "right way" to provide dynamic configuration for my SPA application so I can easily change environment parameters
API URI examples in SPA
// api.config.js
export const uriToApi1 = process.env.REACT_APP_API1_URI;
export const uriToApi2 = process.env.REACT_APP_API2_URI;
// in App.js
import { uriToApi1, uriToApi2 } from '../components/config/api.config.js';
/* More code */
<DataForm apiDataUri={`${uriToApi1}/BasicService/GetData`} />
/* More code */
<DataForm apiDataUri={`${uriToApi2}/ComplexService/UpdateData`} />
Let's imagine that you build your frontend code in some dist folder that will be packed by Docker in the image. You need to create config folder in your project that also will be added in dist folder (and obvious, will be packed in Docker image). In this folder, you will store some config files with some server-specific data. And you need to load these files when your react application starts.
The flow will be like that:
User opens your app.
Your App shows some loader and fetches config file (e.g. ./config/api-config.json)
Then your app reads this config and continues its work.
You need to setup Docker Volumes in your Docker config file and connect config folder in Docker container with some config folder on your server. Then you will be able to substitute config files in a docker container by files on your server. This will help you to override config on each server.

Issues with loading beans from other bundles in Camel BLueprint DSL in Karaf OSGi

I am trying to use Camel(2.18.2) + karaf(4.0.8)+blueprint(Aries) for my migration as suggested by experts.
I have separated files as Routes XML files and Beans XML files.
RouteXml-> it has only Camel Routes
BeanXml-> it has only beans defines
Structure::
Bundle-Conf/OSGI-INF/blueprint/rootCamelContext.xml
Bundle-A/OSGI-INF/blueprint/RouteContextA.xml
/OSGI-INF/blueprint/BeansA2.xml
Bundle-B/OSGI-INF/blueprint/RouteContextB.xml
/OSGI-INF/blueprint/BeansB2.xml
karaf/Config/Routes/RoutesA1.xml
karaf/Config/Routes/RoutesB1.xml
rootCamelContext.xml -> it has CamelContext and Has some routes and beans defined .
RouteContextA.xml-> it has <RouteContex> with some routes
RoutesA1.xml-> it has <Routes> with some routes
BeansA2.xml-> it has <Blueprint> with some beans
RouteContextB.xml-> it has <RouteContex> with some routes
RoutesB1.xml-> it has <Routes> with some routes
BeansB2.xml-> it has <Blueprint> with some beans
Now rootCamelContext.xml is loading fine.
But other bundle A and B routes are not loading.
Questions:
1. How to load Routes and Beans from Bundle A and Bundle B ?
2. How to attach bundle A and B routes to rootCamelContext ?
Please help me on how to load beans from other bundles.
I did export all packages from other bundles.
Update
I am now getting
Caused by: org.apache.camel.NoSuchBeanException: No bean could be found in the registry for: customBeanProcessor of type: org.apache.camel.Processor
Even though I exposed this above bean in Bundle-B and its state is Active.
karaf-root()>ls |grep -i custom
[org.apache.camel.Processor, com.rnd.model.impl.CustomServiceProcessorBase, com.rnd.generic.CustomServiceProcessor]
osgi.service.blueprint.compname = customBeanProcessor
Thanks,

Loading properties file while running camel blueprint test

I am using property-placeholder tag to load a properties as follows:
<cm:property-placeholder id="myblueprint.test" persistent-id="camel.blueprint"/>
While deploying my project on JBOSS Fuse, it will load camel.blueprint.cfg from /etc/ directory of FUSE, and when I deploy project on a fabric profile, it will read from properties file created in profile.
But, when I run camel blueprint test, how can I configure it to load properties file from a particular location?
After browsing the documentation for property-placeholder, I got the solution. We can set the location for properties file in test case file as follows:
#Override
protected String[] loadConfigAdminConfigurationFile() {
// String[0] = tell Camel the path of the .cfg file to use for OSGi ConfigAdmin in the blueprint XML file
// String[1] = tell Camel the persistence-id of the cm:property-placeholder in the blueprint XML file
return new String[]{"src/test/resources/etc/stuff.cfg", "stuff"};
}
Please ensure that, property file is having extension .cfg. otherwise it will be ignored.

How to use same CamelContext in multiple jar on the same war

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.

Resources