camel component 'velocity' not found - apache-camel

I implement *.vm template in my routing application (Servicemix)
but after deploying JAR archive I get this error
karaf#root> Exception in thread "SpringOsgiExtenderThread-38" org.apache.camel.RuntimeCamelException: org.apache.camel.FailedToCreateRouteException:
Failed to create route route14 at: >>> To[velocity:getPayments.vm] <<< in route: Route(route14)[[From[direct:start]] -> [To[velocity:getPayme...
because of Failed to resolve endpoint: velocity://getPayments.vm due to:
No component found with scheme: velocity
I followed this manual
http://camel.apache.org/tutorial-example-reportincident-part4.html
and pointed camel-velocity in pom.xml with same camel-core version
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-velocity</artifactId>
<version>2.13.1</version>
</dependency>
Does anybody know, what the matter is ?

As you are using Karaf you need to add the velocity feature:
feature:install camel-velocity
Or if using Karaf 4.x
feature:install camel-velocity

nothing changed even after ServiceMix restarting, but I found solution.
after init-ing of CamelContext I add camel components manually.
import org.apache.camel.component.velocity.*;
import org.apache.camel.component.spring.ws.*;
....
private CamelContext camel;
.....
camel = new DefaultCamelContext();
camel.addComponent("velocity", new VelocityComponent());
camel.addComponent("spring-ws",new SpringWebserviceComponent());

Related

spring authentication using react.js sends gibberish response

I have a application in react.js and it's server is in spring boot.
Now I want to implement OAuth2 for user authentication. If user is authenticated, then app can get response from the server.
In my application.properties I have added these:
spring.security.oauth2.client.registration.github.client-id=somekey
spring.security.oauth2.client.registration.github.client-secret=somekeyhere`
In pom.xml I have added these:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-oauth2-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-security-oauth2-jose</artifactId>
</dependency>
I have create WebSecurityConfiguration like this:
#Configuration
public class WebSecurityConfiguration extends WebSecurityConfigurerAdapter {
#Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.anyRequest().authenticated()
.and()
.oauth2Login();
}
}
When I try to get any requests like /user in browser it redirects me to login or to create account and everything works fine.
But the problem is I can't use the react.js application anymore, so how can I make the authentication in client portion?

Spring boot - image upload failed

Im working on uploading images with spring but I get error when I try save file in one of my projects folder.
Errors:
java.nio.file.NoSuchFileException: \resources\images\photo001.png
There was an unexpected error (type=Internal Server Error, status=500).
\resources\images\photo001.png
I have this path:
String path = "\\resources\\images\\";
String path2 = "c:\\temp\\";
Path2 works but I would like to save my files in project without passing whole path starting from C:...
What pass should I pass to save it in resources/images in my project?
My project looks like that:
https://i.imgur.com/Dn6wXAK.png
Try 'images/'
All files in src/main/resources are copied into classes/ so in your jar or war there is no folder /resources.
You also should not use the windows specific backslash '\' instead use the
Use /images/ instead this makes your build portable so it can run on Linux also.
Senio, if you are using Spring Boot then there is a project called Spring Content that will allow you to create an image store in very few lines of code.
All you would need to do is add the following Spring Content dependencies (assuming maven):-
<dependencies>
<!-- Standard Spring Boot -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.3</version>
</dependency>
<!-- Spring Content -->
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-fs-boot-starter</artifactId>
<version>0.0.10</version>
</dependency>
<dependency>
<groupId>com.github.paulcwarren</groupId>
<artifactId>spring-content-rest-boot-starter</artifactId>
<version>0.0.10</version>
</dependency>
</dependencies>
In your Spring Boot Application class, create an ImageStore interface. Annotate it as a REST resource. This causes Spring Content to inject an implementation (of this interface for the filesystem) as well as REST endpoints saving you from having to write any this code yourself:-
#SpringBootApplication
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
#StoreRestResource(path="images")
public interface ImageStore extends Store<String> {}
}
By default Spring Content FS will create a store under java.io.tmpdir. So you will also need to set the SPRING_CONTENT_FS_FILESYSTEM_ROOT environment variable to point to the root of your "store"; c:\temp\resources\images.
Start the application and you will be able to upload images by POSTing (or PUTting) to:-
/images/some/path/image-1.jpg
(This also supports GET (download) and DELETE.)
You'll find uploaded images under c:\temp\resources\images\some\path\image-1.jpg
HTH

Deploying Spring Boot WAR to Tomcat 8 - HTTP 404 when accessing resources

I'm new to Spring Boot and struggling to deploy a simple HTML web app (AngularJS) to Tomcat 8. This web app simply serves some HTML/CSS/JS content with no REST calls to a backend. It has been "compiled" using Webpack -- this produces JS/CSS bundles and a single index.html file that points to them via <script> / <link> tags -- and has been tested on ExpressJS and Spring Boot w/ Embedded tomcat and works as expected. But going down the path of a stand-alone WAR and deploying to Tomcat 8 does not seem to work properly.
For the Spring Boot project, I've included all the HTML/CSS/JS files in the src/main/resources/public folder (no subfolders) and have also configured the pom.xml as follows (basic config):
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.my-app</groupId>
<artifactId>my-app</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>my-app</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.0.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
"Main" class:
package com.example.my.app;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.web.SpringBootServletInitializer;
#SpringBootApplication
public class MyAppApplication extends SpringBootServletInitializer {
#Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MyAppApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(MyAppApplication.class, args);
}
}
Here are the steps I used to do the Tomcat deployment:
mvn clean package to generate the WAR
Copy the WAR to path/to/tomcat8/webapp
Start Tomcat
http://localhost:8080/my-app => auto-loads index.html
Unfortunately all I see are 404 errors because it couldn't find some JS/CSS file. Is there a config I'm missing?
Updated:
Here is the index.html file (auto-generated via Webpack):
<!doctype html>
<html>
<head>
<base href="/">
<meta charset="utf-8">
<title>My App</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width">
<link rel="icon" type="image/png" href="./assets/images/favicon.ico" />
<link href="/main-aa49893f83cc830596563d81f09a9611.css" rel="stylesheet"><link href="/main-5949f1f257a55a77e48bc4ab62fbc99a.css" rel="stylesheet"></head>
<body ng-app="myapp">
<ui-view></ui-view>
<script type="text/javascript" src="vendor-353ddb48f4ffe6546d59.js"></script><script type="text/javascript" src="app-353ddb48f4ffe6546d59.js"></script></body>
</html>
Here are the errors I'm seeing in Chrome Web Inspector when visiting localhost:8080/my-app/index.html:
http://localhost:8080/main-5949f1f257a55a77e48bc4ab62fbc99a.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/main-aa49893f83cc830596563d81f09a9611.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/vendor-4ba9083ed9802279c207.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/app-4ba9083ed9802279c207.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/vendor-4ba9083ed9802279c207.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/app-4ba9083ed9802279c207.js Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/main-aa49893f83cc830596563d81f09a9611.css Failed to load resource: the server responded with a status of 404 (Not Found)
http://localhost:8080/main-5949f1f257a55a77e48bc4ab62fbc99a.css Failed to load resource: the server responded with a status of 404 (Not Found)
One more thing I forgot to mention. When I generate the war using mvn clean package, all the files that are under src/main/resources/public are placed into the WEB-INF/classes/resource subfolder. According to research, these files are not publicly visible (i.e. if I try to access localhost:8080/my-app/foo.css, it'll give 404). Is this why the index.html file is unable to "see" the JS/CSS files it depends on?
I ended up figuring it out but not using Spring Boot to package the WAR file. There was another project lying around on my local that used plain old Maven + pom.xml + web.xml to create WARs, which I used as a reference to figure out why the current project was not working. There were multiple issues:
When you deploy onto Tomcat 8 using default config, it will append the name of the WAR file (what they refer to as Context) to its path. In this case, it was http://localhost:8080/my-app. The "compiled" AngularJS app's index.html had a <base href="/"> tag that needed to point to /my-app/ instead of /. This was the main reason why the JS/CSS files were not visible in Web Inspector > Sources.
<link> tag's src attribute was not supposed to contain a leading /
In the case of the Spring Boot App I posted above, it comes with an Embedded Tomcat and deploys the app at the Root Context so there's no need to change any paths in the index.html file.
Similar to Spring Boot, I also had no issues running the app in ExpressJS since a "sub-context" was not created. Again, there was no need to modify any files in this case.
There were other errors related to finding resources like .ttf files but at least the app was able to run.
Update:
Looks like its possible to serve the WAR file from the Tomcat 8 root by adding the following near the bottom of the server.xml file:
<Context path="" docBase="my-app" debug="0" reloadable="true"></Context>
This will prevent the need to modify the index.html file.
Awesome :)
The most common issue with the setup you have described, without more context, is that you are most likely using absolute URLs to point at your js / css files. As such when you put them into the servlet container under /my-app they no longer reference properly as they are trying to go to the root /. You need to use relative URLs when describing the location of the resource files on the path.
I had the same problem, and it is related to Webpack more than to Spring-boot.
In your webpack.common.js / webpack.prod.js you have to set :
metada.baseUrl = './';
and inject this in your <base> link in index.html
And you also have to set
output.publicPath: './'
With both variable set, this worked for me.
Uhmm i've tried some of this on my spring-boot project.
First i'd add a dependency on my project pom.xml
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
then i'd add an index.html on src/main/resources/templates
after that you should add a controller to point to that index
#Controller
public class AppController {
#RequestMapping("/")
String index() {
return "index";
}
}
For more information see this guide. Spring-boot and Thymeleaf

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.

Using blueprint as the Apache Camel DSL to describe routes in IBM Liberty

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.

Resources