Error running local camel context - apache-camel

I am trying to execute the examples in Camel in action.
When I try to execute the "Spring DSL->Run As Local Camel Context" I am getting below error in JBoss Developer IDE:
Source locator does not exist: org.fusesource.ide.server.karaf.core.server.sourceLocator
Can any one help me?

I'm unaware of the build system of the project, but if it is Maven you may add following plugin to the pom.xml:
<plugin>
<groupId>org.apache.camel</groupId>
<artifactId>camel-maven-plugin</artifactId>
<version>2.12.0</version>
<configuration>
<!--
the spring context file must be separate from the OSGi bundle, so we provide one here
-->
<fileApplicationContextUri>
src/main/resources/META-INF/spring/camel-context.xml
</fileApplicationContextUri>
</configuration>
</plugin>
where you can put the path to the camel-context.xml, and then you can run
mvn camel:run
to test the routes.
Hope I've helped you.

I had updated the plugin for fuse integration in Jboss IDE and it is working fine now.
Thanks a lot for your response.

Related

What's the correct class to run Apache Camel 3.14.0 from command line?

I set the following pom.xml to use Camel 3.14.0:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.apps</groupId>
<artifactId>MyApp</artifactId>
<version>1.0.0</version>
<name>MyApp Camel component</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bom</artifactId>
<version>3.14.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-csv</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-sql</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
</dependency>
<!-- DB dependencies -->
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.6.1</version>
<scope>system</scope>
<systemPath>D:\Drivers\hsqldb-2.6.1-jdk8.jar</systemPath>
</dependency>
</dependencies>
</project>
Then I have this command line in Windows to collect dependencies:
C:\Users\Public\apache-maven-3.2.5\bin\mvn -f pom.xml dependency:copy-dependencies
When I run it I get all jars in the destination folder (../build/target/dependency).
And then I get other run.bat file with following:
set CLASSPATH=../build/target/dependency/*;../config/
java -classpath "%CLASSPATH%" org.apache.camel.spring.Main
But when I run it, I get an error saying it can't find Main class. That class is the one used in previous use cases (Camel 2.10.6) and it worked fine. Would you please advise on what's the right class to reference here?
EDIT 1: I found in documentation that Main is now in org.apache.camel.main, so I configured that in run.bat and it's seems to be running. But now it shows the following and the odd thing about this is that it ceased picking the file from the path configured in context.xml. Any ideas?
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
EDIT 2: I looked on the error and found I needed to include dependency
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
It still seems to work (message regarding slf4 is gone) but still won't pick file from path.
Now, reason I decided to move to last LTS version was because I needed to use a component property only available in newer version of Camel than the one I've been using. So I decided to give a shot to latest version, but now I'm stuck with error saying it can't find the class.
I've somewhat used Camel in the past but only based on examples provided by someone else, never from scratch so I'm no expert at all and unfortunately I need to solve this in a hurry. I guess the easiest would be to use a java bean but I'm no java developer so I thought it might be ok using Spring XML DSL. I'm using java 1.8.0_92.
Camel documentation doesn't seem to provide so many details as per spring xml, so any help will be greatly appreciated.
Frameworks and documentation
First and foremost its good to understand that Apache Camel is integration framework, Spring is application framework with probably its most notable feature being dependency injection. Due to this the documentation kinda expects the developer to be familiar with spring-framework and able juggle between camel and spring documentation.
Camel main
Camel-main in the other hand is tool you can use to run camel applications without any framework so it has no knowledge about spring framework. There's camel-spring-main but more on that later.
Spring-boot
When it comes to spring it might be easier to just use spring-boot which you can think of as collection of maven dependencies you can use to auto-configure your spring application with default configurations.
I recommend that you create a new project using camel maven archetype camel-archetype-spring-boot. This should provide you with good starting point and example on how to get started with camel and spring.
To use spring-xml files with camel-spring-boot you can add annotation #ImportResource(classpath:META-INF/spring/camel-context.xml) over your SpringBootApplication class (class annotated with #SpringBootApplication, named MySpringBootApplication when using the template).
Change the path to match the location and name of your xml-file and delete or comment the example RouteBuilder class from the project to prevent it from interrupting with anything.
# You can run spring-boot application using maven
mvn spring-boot:run
# Alternatively you should be able to run it from jar using
java -jar application.jar
Downside for spring-boot is that it'll flood our project with bunch of extra dependencies. For example to just keep the application running the template project uses spring-boot-start-web, spring-boot-starter-undertow and spring-boot-starter-actuator dependencies.
Camel Spring Main
There's also archetype camel-archetype-spring you can use to create camel spring application without spring-boot. It uses the camel-spring-main I mentioned above and can be run using maven with command mvn camel:run.
However I find this archetype a bit lacking. First it lacks visible main class which is inconsistent if you compare it to some camel-archetype-main. Secondly there seems to be problems with its packaging configurations as I didn't find an easy way to run it from jar. Most attempts I tried resulted in ClassNotFoundException for org/apache/camel/spring/Main even tough I had all maven dependencies in place. It runs fine from IDE however.
Convert your project to JAVA-DSL and use camel main
Since your route doesn't seem all that complex you could probably convert it to Java-DSL from XML in minutes and just run it with camel-main without any application framework. There's archetype for this as well called camel-archetype-main.

Spring boot web main/ressources/static not reloading if changed outside STS

I'm working on a AngularJS project with Spring Boot and the HTML/JS/CSS are placed inside src/main/ressources/static.
The problem is that if I change these files outside Eclipse and refresh the browser the changes are not reflected. Previously I worked on a project where the HTML/JS/CSS files where placed in src/main/webapp folder and I didn't have this kind problem.
I'm required to keep the files in ressources/static and I also can't use a live reload server to serve the files. I have tried to enable "Refresh using native hooks or polling" in Eclipse, but still sometimes the files take awhile to refresh.
Is there a way to have the same behavior that using src/main/webapp folder gives?
Thanks in advance.
I end up using an workaround which was adding the config below to the pom.xml and runninng the app with mvn spring-boot:run instead of Eclipse's "Run as Spring Boot Application"
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<addResources>true</addResources>
</configuration>
</plugin>
If I understood your question correctly. You want to be able to change files outside of Eclipse and have those changes in server also?
If you change HTML/JS/CSS files outside of Eclipse you can sync files to {source_directory}\target\classes\static for instance update.
It worked for me when I was using the development server. Hope it works for you as well.

How to use Apache httpclient-win in a Camel route within an OSGi container?

I'm trying to use Apache httpclient-win to get at IIS-hosted Web resources secured by Windows Authentication. I've managed to use the Camel HTTP4 component without authentication. I've also managed to use httpclient-win with authentication successfully from straight Java code. But now, I'm having a hard time figuring out how to use httpclient-win in a Camel route hosted in an OSGi container (ServiceMix).
I managed to create an OSGi bundle that embeds the dependencies required by httpclient-win by adding this section to my POM file:
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<version>2.3.7</version>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>BundleName</Bundle-SymbolicName>
<Embed-Dependency>httpclient|httpcore|httpclient-win|jna|jna-platform;scope=compile|runtime|provided</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>
I haven't done the security part but deployed http, netty4 and restlet to Apache Karaf which is an OSGI container.
What exactly do you have problem with?

Get validation to work with Maven and Requestfactory on Eclipse

I have a project setup with Maven and using RequestFactory. However I cannot get the validation to work through maven settings. This is how my maven setup looks like:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${target.jdk}</source>
<target>${target.jdk}</target>
<encoding>${project.build.sourceEncoding}</encoding>
<proc>none</proc>
</configuration>
<dependencies>
<dependency>
<groupId>com.google.web.bindery</groupId>
<artifactId>requestfactory-apt</artifactId>
<version>${gwt.version}</version>
</dependency>
</dependencies>
</plugin>
I have also added Hibernate validator.
On the Eclipse side, I have tried various things, among which the most correct one looks like this:
I also have installed the m2e-apt plugin.
However I still can't get the validation tool to run. I don't get validation errors if I make mistakes on purpose and of course, when I run my application I get the infamous
SEVERE: Unexpected error
java.lang.RuntimeException: The RequestFactory ValidationTool must be run for the ...
Anyone has any idea of what I am missing? Should I simply resign myself to configure Eclipse manually?
You explicitly disabled annotation processing in the maven-compiler-plugin's configuration:
<proc>none</proc>
Remove that line and it should run annotation processors.
Note that there's a regression with maven-compiler-plugin 3.x where the plugin dependencies no longer are taken into account when compiling (it probably never was thought as a feature) so your requestfactory-apt would not be seen by JavaC with recent maven-compiler-plugin versions and you'd still have the same problem then.
The only way to reliably use annotation processors with Maven is to declare them as project dependencies with either <scope>provided</scope> or <optional>true</optional>, or to use the maven-processor-plugin. There's an open feature request for better support in Maven proper through the maven-compiler-plugin: http://jira.codehaus.org/browse/MCOMPILER-203

Using the google appengine maven plugin to deploy a Jax-RS war

I'm trying to make a simple base project to deploy a service I make using Jax-RS librarys to my Google app engine cloud space. The problem is that I don't know how to configure the plugin properly to not keep looking to a webapp directory under the target folder. The structure of the Jax-rs project puts the web.xml and all other WEB-INF files under the resources directory instead of a webapp directory. Is there a way to configure the maven plugin to deploy my already built and zipped up war file?
This is the error I see
[INFO] Updating Google App Engine Application Unable to find the
webapp directory C:\dev\gameTrunk\server\target\HOMMTG-server-1.0
usage: AppCfg [options] [] []
Action must be one of: help: Print help for a specific action.
download_app: Download a previously uploaded app version.
request_logs: Write request logs in Apache common log format.
rollback: Rollback an in-progress update. start: Start the specified
server version.
and it goes on with all the appengine plugin targets...
This s my pom
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<version>2.5.1</version>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<archiveClasses>true</archiveClasses>
<webResources>
<!-- in order to interpolate version from pom into appengine-web.xml -->
<resource>
<directory>${basedir}/src/main/resources/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
</plugin>
</plugins>
Thats just the plugins part but its almost exactly the same as the guestbook example project except for the path for the WEB-INF directory
Currently there is no way to configure the appengine-maven-plugin to use a different directory for the war contents. It would be best though to probably create a multimodule build where one submodule just used the maven-ant-plugin to assemble the war directory and then run the plugin on that instead. I don't think we want to make that configurable in the plugin, since it doesn't really align with the maven-war-plugin, and configuring that would make it difficult to setup your project to use the maven-war-plugin seamlessly in the future.
The configuration you currently have for the war-plugin in your pom isn't necessary unless you want interpolation of the version number into the appengine-web.xml. I'm happy to help with setting up your pom so that the official Google App Engine Maven plugin works correctly for you.
(The instructions below apply to maven-gae-plugin, not appengine-maven-plugin.
Have I told you how much Google sucks in Open Source today?)
I think you must add in your maven-gae-plugin a property called appDir pointing to your webapp directory, like this:
<plugin>
<groupId>net.kindleit</groupId>
<artifactId>maven-gae-plugin</artifactId>
<configuration>
<appDir>PATH-TO-YOUR-BUILT-EXPLODED-WAR-PATH</appDir>
</configuration>
</plugin>
However, I must stress that changing the path in Maven produces undesirable results (you're mixing source and object code, your .ignore files will get messed up, and other weird things)
Note you STILL NEED your unpacked war somewhere. One way to achieve that is to create another .war project and use dependencies-unpack into it. See http://maven.apache.org/plugins/maven-dependency-plugin/unpack-dependencies-mojo.html
(reference: https://github.com/maven-gae-plugin/maven-gae-plugin/blob/master/maven-gae-plugin/src/main/java/net/kindleit/gae/EngineGoalBase.java)
(just in case, there is a JAX-RS based project for GAE I've wrote a while ago, and its open. See https://github.com/ipeirotis/ReadabilityMetrics/ for an overview)

Resources