I am getting an exception while using Camel Bean Validator. The exception is No component found with scheme: bean-validator
And i have these dependencies in my POM
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bean-validator</artifactId>
<version>2.13.2</version>
<scope>provided</scope>
</dependency>
And i am using Bean Validator component as below
from("direct:XXX").process(new Processor() {
#Override
public void process(Exchange exchange) throws Exception {
Car car = new Car();
//car.setVehicleId(1);
car.setName("Swift");
car.setCompany("Maruti");
exchange.getIn().setBody(car);
}
}).to("bean-validator://x").process(new Processor() {
#Override
public void process(Exchange arg0) throws Exception {
LOG.debug("Bean Validation is Success");
}
});
But when i am deploying the generated war into the Wildfly, am getting the exception No component found with scheme: bean-validator. To my surprise the code is working fine in standalone application.
Your help is greatly appreciated.
The issue is that you define the scope as provided, which means the JAR is supposely already part of the server. You most often only use provided scope for API JARs such as the servlet api, etc.
So change this
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bean-validator</artifactId>
<version>2.13.2</version>
<scope>provided</scope>
</dependency>
To
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-bean-validator</artifactId>
<version>2.13.2</version>
</dependency>
Related
I try to apply thymeleaf template engine in Spring Boot application. Template exists in: src/main/resources/templates/user/new.html
#GetMapping("/new")
public ModelAndView newUser() {
ModelAndView mav = new ModelAndView("user/new");
return mav;
}
When I test with String response, it works well, no problem with the route.
Here're my dependencies:
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>3.0.11.RELEASE</version>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
Than I decided to add starter as told in the tutorials:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
But than, when I run application I get the following error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'viewResolver' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration$WebMvcAutoConfigurationAdapter.class]: Error creating bean with name 'thymeleafViewResolver' defined in class path resource
What I am missing?
I found my mistake. When I only added starter dependency, it all worked well. Than I added layout-dialect and layout also worked like a charm.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>nz.net.ultraq.thymeleaf</groupId>
<artifactId>thymeleaf-layout-dialect</artifactId>
</dependency>
I'm trying to integrate Swagger into my Jersey application following the guide they provide: https://github.com/swagger-api/swagger-core/wiki/Swagger-Core-Jersey-1.X-Project-Setup-1.5
I'm using Jersy v1.17 and I'm using a custom application rather than web.xml
The following is everything I have in my simple test project which is failing!
public class ResConfig extends DefaultResourceConfig { // custom app
public ResConfig() {
super();
BeanConfig beanConfig = new BeanConfig();
beanConfig.setVersion("1.0.2");
beanConfig.setSchemes(new String[] { "http" });
beanConfig.setHost("localhost:9998");
beanConfig.setBasePath("/api");
beanConfig.setResourcePackage("test.resources"); // the package containing my resource
beanConfig.setScan(true);
}
}
The simple resource I have
#Path("hello")
#Produces("application/json")
public class Res {
public Res() {
}
#GET
public Response getHello() {
Result result = new Result(); // Result is annotated with XmlRootElement and contains one field String str;
result.setStr("hello");
return Response.status(Status.OK).entity(result).build();
}
}
The main:
public static void main(String[] args) throws Exception {
ResConfig resConfig = new ResConfig();
resConfig.getClasses().add(Res.class);
resConfig.getClasses().add(io.swagger.jaxrs.listing.ApiListingResource.class);
resConfig.getClasses().add(io.swagger.jaxrs.listing.SwaggerSerializers.class);
GrizzlyServerFactory.createHttpServer("http://localhost:9998/", resConfig);
System.in.read();
}
the POM contains the following:
<dependencies>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-jersey-jaxrs</artifactId>
<version>1.5.9</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-core</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-multipart</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2</artifactId>
<version>${jersey-version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
The Jersey Grizzly server fails on start by throwing exception:
SEVERE: The following errors and warnings have been detected with resource and/or provider classes:
SEVERE: Missing dependency for method public javax.ws.rs.core.Response io.swagger.jaxrs.listing.ApiListingResource.getListing(javax.ws.rs.core.Application,javax.servlet.ServletConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo,java.lang.String) at parameter at index 1
SEVERE: Method, public javax.ws.rs.core.Response io.swagger.jaxrs.listing.ApiListingResource.getListing(javax.ws.rs.core.Application,javax.servlet.ServletConfig,javax.ws.rs.core.HttpHeaders,javax.ws.rs.core.UriInfo,java.lang.String), annotated with GET of resource, class io.swagger.jaxrs.listing.ApiListingResource, is not recognized as valid resource method.
SEVERE: Missing dependency for field: javax.servlet.ServletContext io.swagger.jaxrs.listing.ApiListingResource.context
Exception in thread "main" com.sun.jersey.spi.inject.Errors$ErrorMessagesException
at com.sun.jersey.spi.inject.Errors.processErrorMessages(Errors.java:170)
at com.sun.jersey.spi.inject.Errors.postProcess(Errors.java:136)
at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:199)
at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795)
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:172)
at com.sun.jersey.api.container.ContainerFactory.createContainer(ContainerFactory.java:134)
at com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpServer(GrizzlyServerFactory.java:243)
at com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.createHttpServer(GrizzlyServerFactory.java:137)
I searched the first 2 pages of Google for an answer but nothing helped!
Swagger uses Servlet APIs, so the application MUST run in a servlet environment. The way you are configuring Grizzly does not set up a servlet container. It is only an HTTP server.
You want to use the jersey-grizzly2-servlet dependency instead, and use the GrizzlyWebContainerFactory to bootstrap the application. This will set up a servlet container.
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-grizzly2-servlet</artifactId>
<version>1.19.1</version>
</dependency>
Map<String, String> initParams = new HashMap<>();
initParams.put("javax.ws.rs.Application", "com.package.ResConfig");
GrizzlyWebContainerFactory.create(uri, initParams);
I am trying to integration Spring 4.2.3 with hibernate validator v.5.2.2.Final to validate input JSON data expose with REST Controller.
I don't see any compile time or running time exception but at the same time it does not validate input data.
Pom.xml
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.2.3.RELEASE</version>
<scope>compile</scope>
</dependency>
<!-- jsr303 validation dependencies -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.2.Final</version>
</dependency>
<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-cdi</artifactId>
<version>5.2.2.Final</version>
</dependency>
Pojo java class:
public class RequestVO {
#NotEmpty
private String testValidation;
#NotNull
private String testNull;
#NotBlank
private String testBlank;
.... getters and setters .....
}
#Controller
#RequestMapping("/login")
public class LoginController {
#RequestMapping(method=RequestMethod.POST, value="/user")
public #ResponseBody ResponseVO getLoginResponse(#Valid #RequestBody RequestVO request, Errors error) {
ResponseVO response = new ResponseVO ();
if (error.hasErrors()) {
System.err.println("Success");
}
return response;
}
}
In your dependency list there's a comment saying ...jsr303 validation dependencies.... Note the bean validation has an updated specification (JSR-349), and this can very well be your issue.
You should align your dependencies in the following manner
hibernate-validator-5.x.x
validation-api-1.1.x
which implement JSR-349
OR
hibernate-validator-4.x.x
validation-api-1.0.x.
which implements JSR-303
If you mix the dependencies, the validation will simply not kick-in. As a solution suggestion, add
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
and make sure that you remove any dependency to validation-api-1.0 jar
I think is interest to take a look at this link
and if you to remove the validation just remove #Valid from method and you're ok.
I am attempting to run camel within spring. Below are the files i have..
POM xml file which have relevant dependencies.
<properties>
<spring.version>3.2.11.RELEASE</spring.version>
<camel.version>2.14.1</camel.version>
</properties>
<?xml version="1.0" encoding="UTF-8"?>
<dependencies>
<!-- camel core -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring</artifactId>
<version>${camel.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-metrics</artifactId>
<version>${camel-version}</version>
</dependency>
<!-- Spring 3 dependencies -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
Main context file (main-context.xml).
<camel:camelContext trace="false" id="mc-service-camel-context" threadNamePattern="Camel (#camelId#) thread ##counter# - #name#">
<camel:contextScan/>
</camel:camelContext>
A route that looks like this
#Component
public class MyRoute extends RouteBuilder {
#Override
public void configure() throws Exception {
from("timer://runOnce?repeatCount=1&delay=5000")
.log("Hello World!!")
.end();
}
}
And finally a main class that looks like this.
public static void main(String[] args) throws InterruptedException {
AbstractXmlApplicationContext appContext = new ClassPathXmlApplicationContext("main-context.xml");
Thread.sleep(100000);
}
Issue is i don't see the log "Hello World". Could someone give me some feedback on what i am missing..
I had to enable Component scanning.
<context:annotation-config/>
<context:component-scan base-package="com.mycompany.app*" />
I have written a program to send mail using gmail, its working fine if I execute it separately but When I integrating with google appengine its giving me the below error,
Exception in thread "main" com.google.apphosting.api.ApiProxy$CallNotFoundException: The API package 'mail' or call 'Send()' was not found.
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:104)
at com.google.apphosting.api.ApiProxy.makeSyncCall(ApiProxy.java:56)
at com.google.appengine.api.mail.MailServiceImpl.doSend(MailServiceImpl.java:98)
at com.google.appengine.api.mail.MailServiceImpl.send(MailServiceImpl.java:34)
at com.google.appengine.api.mail.stdimpl.GMTransport.sendMessage(GMTransport.java:231)
at javax.mail.Transport.send(Transport.java:95)
at javax.mail.Transport.send(Transport.java:48)
at in.javadomain.PostMail.postMailMethod(PostMail.java:49)
at in.javadomain.PostMail.main(PostMail.java:20)
I am sure that no integration error or mistakes. I have added javax.mail jar also already.
You need to setup the test environment properly, like this:
private final LocalServiceTestHelper helper =
new LocalServiceTestHelper(new LocalMailServiceTestConfig());
#Before
public void setUp() {
helper.setUp();
}
#After
public void tearDown() {
helper.tearDown();
}
GAE requires these dependencies:
<properties>
<gae.version>1.9.17</gae.version>
</properties>
...
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-labs</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-stubs</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-testing</artifactId>
<version>${gae.version}</version>
<scope>test</scope>
</dependency>