I want to deploy war to tomcat8 but when I call url:
http://localhost:8080/SpringNew/tesget
get error:
HTTP Status [500] – [Internal Server Error]
javax.servlet.ServletException: Servlet.init() for servlet
[dispatchers] threw exception
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
before I deploy, I run the project with maven build usually, this url running. why not running after deploy?
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
<servlet>
<servlet-name>dispatchers</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>ncb.taspen.spring.config</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatchers</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file></welcome-file>
</welcome-file-list>
</web-app>
pom.xml
<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.project.spring</groupId>
<artifactId>TaspenNCBSpring</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>TaspenNCBSpring Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<java-version>1.8</java-version>
<jersey.version>1.8</jersey.version>
<org.springframework-version>4.3.7.RELEASE</org.springframework-version>
<jackson.version>2.7.5</jackson.version>
<jaxb-api.version>2.2.11</jaxb-api.version>
<hibernate.version>4.3.11.Final</hibernate.version>
<slf4j.version>1.7.21</slf4j.version>
<tomcat.version>9.0.0</tomcat.version>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<!-- Hibernate Validator -->
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- Servlet+JSP+JSTL -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<!-- JSON -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.7</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
</dependency>
<!-- Dependency untuk mysql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.9</version>
</dependency>
<!-- Hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4j.version}</version>
</dependency>
<!-- Swagger -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>4.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>4.2.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>4.2.2.RELEASE</version>
</dependency>
</dependencies>
<build>
<finalName>TaspenNCBSpring</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<port>8085</port>
<path>/TaspenNCBSpring</path>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
there issue with your web.xml configuration. you are using Spring Framework and you need to load ApplicationContext.xml. you can refer bellow configuration :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>demo</display-name>
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:ApplicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/api/*</url-pattern>
</servlet-mapping>
<filter>
<filter-name>encoding-filter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encoding-filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
</welcome-file-list>
<!-- <listener> -->
<!-- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> -->
<!-- </listener> -->
</web-app>
Related
I have been struggling with converting my servlet working under RestEasy and JBoss to include a Swagger description. I have tried making some dependencies of scope provided, tried making them of type pom, tried changing the context-param's in the web.xml, etc. I have considered [this post ][1] and [this post] (which seemed a great match) [2] but seem to be going backwards so please help me address:
SEVERE: Missing dependency for constructor public org.jboss.resteasy.plugins.providers.JaxrsServerFormUrlEncodedProvider(boolean) at parameter index 0
SEVERE: Missing dependency for constructor public org.jboss.resteasy.core.AsynchronousDispatcher(org.jboss.resteasy.spi.ResteasyProviderFactory) at parameter index 0
SEVERE: Conflicting URI templates. The URI template /api-docs for root resource class com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON and the URI template /api-docs transform to the same regular expression /api\-docs(/.*)?
The relevant part of my pom.xml seems to be (with irrelevant dependencies removed):
<properties>
... <jackson.version>2.10.0</jackson.version>
<version.org.slf4j>1.7.26</version.org.slf4j>
<swagger-version>1.3.0</swagger-version>
<jax-rs-version>1.1.1</jax-rs-version>
<json4s-jackson-version>3.2.4</json4s-jackson-version>
<json4s-core-version>3.0.0</json4s-core-version>
<fasterxml-json-version>2.2.2</fasterxml-json-version>
<reflections-version>0.9.9-RC1</reflections-version>
<javassist-version>3.16.1-GA</javassist-version>
<paranamer-version>2.5.2</paranamer-version>
<scannotation-version>1.0.3</scannotation-version>
<servlet-api-version>2.5</servlet-api-version>
</properties>
...
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.thetransactioncompany</groupId>
<artifactId>cors-filter</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-servlet_2.10</artifactId>
<version>1.3.0</version>
<exclusions>
<exclusion>
<artifactId>dom4j</artifactId>
<groupId>dom4j</groupId>
</exclusion>
</exclusions>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-jaxrs</artifactId>
<version>1.9.13</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>${jax-rs-version}</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-jackson_2.9.1-1</artifactId>
<version>${json4s-jackson-version}</version>
</dependency>
<dependency>
<groupId>org.json4s</groupId>
<artifactId>json4s-core_2.9.2</artifactId>
<version>${json4s-core-version}</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.paranamer</groupId>
<artifactId>paranamer</artifactId>
<version>${paranamer-version}</version>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.12.15</version>
</dependency>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>${reflections-version}</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>${servlet-api-version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>${javassist-version}</version>
</dependency>
<dependency>
<groupId>org.scannotation</groupId>
<artifactId>scannotation</artifactId>
<version>${scannotation-version}</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jersey-jaxrs_2.9.1</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-annotations_2.9.1</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-core_2.9.1</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.9.1</artifactId>
<version>${swagger-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs-all</artifactId>
<version>2.2.1.GA</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
...
The application is trivial:
#Path("pam")
#Provider
#Api(value="/pam", description = "Returns data")
public class PamQueryHandler extends Application {
public PamQueryHandler() {
}
#ApiOperation(value = "Perform the actual query.", response = Response.class)
#GET
#Path("/query")
#Produces(MediaType.APPLICATION_JSON)
public Response handleQuery(#ApiParam(value="messageType") #QueryParam("messageType") String message)
{
...
}
And a web.xml whose content is almost entirely to accommodate the Swagger description:
<web-app>
<display-name>RESTful Querying of DBs</display-name>
<context-param>
<param-name>resteasy.wider.request.matching</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.ws.rs.core.Application</param-name>
<param-value>com.goprecise.jbpm.rest.PamQueryHandler</param-value>
</context-param>
<context-param>
<param-name>resteasy.resources</param-name>
<param-value>com.wordnik.swagger.jaxrs.listing.ApiListingResourceJSON</param-value>
</context-param>
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>
com.wordnik.swagger.jaxrs.json.JacksonJsonProvider,
com.wordnik.swagger.jaxrs.listing.ApiDeclarationProvider,
com.wordnik.swagger.jaxrs.listing.ResourceListingProvider
</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/query/*</url-pattern>
<!--url-pattern>/api-docs/*</url-pattern-->
</servlet-mapping>
<servlet>
<servlet-name>DefaultJaxrsConfig</servlet-name>
<servlet-class>com.wordnik.swagger.jaxrs.config.DefaultJaxrsConfig</servlet-class>
<init-param>
<param-name>api.version</param-name>
<param-value>1.0.0</param-value>
</init-param>
<init-param>
<param-name>swagger.api.basepath</param-name>
<param-value>http://localhost:8090/PamQuery</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
</web-app>
[1]: https://stackoverflow.com/questions/8171342/why-wont-jboss-resteasy-maven-dependency-work
[2]: https://stackoverflow.com/questions/9378106/jboss-7-1-0-error-unable-to-find-a-public-constructor-for-class-org-jboss-rest
The following is my web.xml
<web-app>
<display-name>Kafka_APIs_LogManagement</display-name>
<servlet>
<servlet-name>myapplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.apis</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.scanning.recursive</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>jersey.config.server.provider.classnames</param-name>
<param-value>org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>myapplication</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<error-page>
<error-code>404</error-code>
<location>/Error_404.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/Error_500.jsp</location>
</error-page>
<welcome-file-list>
<welcome-file>Error_404.jsp</welcome-file>
<welcome-file>Error_500.jsp</welcome-file>
</welcome-file-list>
</web-app>
The following is my pom.xml
<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.apis</groupId>
<artifactId>my_APIs</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>my_APIs</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.10.68</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.2</version>
</dependency>
<!--JERSEY DEPENDENCIES -- >
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.containers</groupId>
<artifactId>jersey-container-servlet</artifactId>
<version>2.23.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.23.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-multipart</artifactId>
<version>2.23.2</version>
</dependency>
<!--JERSEY DEPENDENCIES -- >
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.4.2</version>
</dependency>
</dependencies>
<build>
<finalName>myAPIS</finalName>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
The following is my method signature :
#POST
#Path("/upload/{filename}/{type}")
#Produces("application/json")
#Consumes(MediaType.MULTIPART_FORM_DATA)
public Response kafkaBulkProducer(InputStream a_fileInputStream,
#PathParam("filename") String filename,
#PathParam("type") String type,
#Context ContainerRequestContext crc,
#FormDataParam("file") InputStream fileInputStream,
#FormDataParam("file") FormDataContentDisposition contentDispositionHeader) {
}
and I am facing the following error :
[[FATAL] No injection source found for a parameter of type public javax.ws.rs.core.Response
If I remove both the #FormDataParam , it compiles perfectly and runs as expected, but If I introduce these two lines to my codes I get the error.
I have gone through the following links, but I did not able to solve my problem.
Link
Thank you
I have a JSF Web application and since i'm using using an embedded databse, i wanted to use an embedded server, so i went with tomcat.
I found a main class with the code i need.
I executed the main class using eclipse and everything worked fine so i decided to build to the project to a jar to execute it from the command line, and this is where this exception came up
java.lang.IllegalStateException: Could not find backup for factory javax.faces.context.FacesContextFactory.
javax.faces.FactoryFinderInstance.getFactory(FactoryFinderInstance.java:555)
javax.faces.FactoryFinder.getFactory(FactoryFinder.java:283)
javax.faces.webapp.FacesServlet.init(FacesServlet.java:358)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:518)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1091)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:668)
org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1517)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1474)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)
This is the Main Class:
import java.io.File;
import java.util.logging.Logger;
import org.apache.catalina.Context;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;
public class Main {
private final static Logger LOGGER = Logger.getLogger(Main.class.getName());
private final static String mWorkingDir = System.getProperty("java.io.tmpdir");
private static Tomcat tomcat = null;
public static Tomcat getTomcat() {
if(tomcat == null)
tomcat = new Tomcat();
return tomcat;
}
public static void main(String[] args) {
tomcat = new Tomcat();
tomcat.setPort(9090);
tomcat.setBaseDir(mWorkingDir);
tomcat.getHost().setAppBase(mWorkingDir);
tomcat.getHost().setAutoDeploy(true);
tomcat.getHost().setDeployOnStartup(true);
try {
tomcat.start();
} catch (LifecycleException e) {
LOGGER.severe("Tomcat could not be started.");
e.printStackTrace();
}
LOGGER.info("Tomcat started on " + tomcat.getHost());
// Alternatively, you can specify a WAR file as last parameter in the following call e.g. "C:\\Users\\admin\\Desktop\\app.war"
Context appContext = tomcat.addWebapp(tomcat.getHost(), "/JsfWebProject", "A:\\JsfWebProject.war");
LOGGER.info("Deployed " + appContext.getBaseName() + " as " + appContext.getBaseName());
tomcat.getServer().await();
}
}
The Pom.xml
<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>webProject</groupId>
<artifactId>JsfWebProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
<layout>default</layout>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.sopra.util.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<!-- JSF libraries -->
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.2.13</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Hibernate libraries -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.2.7.Final</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<!-- Java Mail API -->
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
<version>1.5.2</version>
</dependency>
<!-- Log4j library -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<!-- H2Database library -->
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.179</version>
</dependency>
<!-- Primefaces libraries -->
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>5.3</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.primefaces.themes</groupId>
<artifactId>bootstrap</artifactId>
<version>1.0.10</version>
</dependency>
<dependency>
<groupId>net.bootsfaces</groupId>
<artifactId>bootsfaces</artifactId>
<version>0.8.0</version>
<scope>compile</scope>
</dependency>
<!-- Apache poi and Xml related libraries -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.10-FINAL</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.3.0</version>
</dependency>
<!-- ChartistJSF library -->
<dependency>
<groupId>org.chartistjsf</groupId>
<artifactId>ChartistJSF</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<!-- Primefaces Exporter Pluguin -->
<dependency>
<groupId>com.lapis.jsfexporter</groupId>
<artifactId>jsf-exporter-core</artifactId>
<version>1.0.3.Final</version>
</dependency>
<dependency>
<groupId>com.lapis.jsfexporter</groupId>
<artifactId>export-type-csv</artifactId>
<version>1.0.3.Final</version>
</dependency>
<dependency>
<groupId>com.lapis.jsfexporter</groupId>
<artifactId>export-type-excel</artifactId>
<version>1.0.3.Final</version>
</dependency>
<dependency>
<groupId>com.lapis.jsfexporter</groupId>
<artifactId>export-type-pdf</artifactId>
<version>1.0.3.Final</version>
</dependency>
<dependency>
<groupId>com.lapis.jsfexporter</groupId>
<artifactId>export-type-xml</artifactId>
<version>1.0.3.Final</version>
</dependency>
<dependency>
<groupId>com.lapis.jsfexporter</groupId>
<artifactId>export-source-primefaces</artifactId>
<version>1.0.3.Final</version>
</dependency>
<!-- Tomcat -->
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>8.0.21</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-util</artifactId>
<version>8.0.21</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>8.0.21</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<version>7.0.8</version>
</dependency>
</dependencies>
</project>
and The Web.cml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>JsfWebProject</display-name>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>pages/index.xhtml</welcome-file>
</welcome-file-list>
</web-app>
I am using REST ESay API and getting the below error when starting jetty server, when I add the method in my REST service code. The aim is to override the content type with custom Charset. Please help me to resolve this issue.The method is:
#Provider
#ServerInterceptor
public class ContentTypeSetterPreProcessorInterceptor implements
PreProcessInterceptor {
public ServerResponse preProcess(HttpRequest request,
ResourceMethod method) throws Failure, WebApplicationException
{
request.setAttribute(InputPart.DEFAULT_CONTENT_TYPE_PROPERTY,
"*/*; charset=UTF-8"); return null;
}
}
This is the stack trace:
03:11:08.232(02/06) INFO org.jboss.resteasy.plugins.server.servlet.ConfigurationBootstrap : Adding scanned #Provider: com.lexisnexis.csa.fwu.rest.service.FWUploadService$ContentTypeSetterPreProcessorInterceptor
03:11:08.233(02/06) INFO org.jboss.resteasy.plugins.server.servlet.ConfigurationBootstrap : Adding scanned resource: com.lexisnexis.csa.fwu.rest.service.FWUploadService
2015-02-06 03:11:08.796:WARN::Failed startup of context o.e.j.w.WebAppContext{/,file:/C:/Users/SHANMUK3/workspace/LN_CSA_FWU_SRVC_COMP/target/LN_CSA_FWU_SRVC_COMP/},C:\Users\SHANMUK3\workspace\LN_CSA_FWU_SRVC_COMP\target\LN_CSA_FWU_SRVC_COMP.war
java.lang.RuntimeException: Unable to find a public constructor for interceptor class com.lexisnexis.csa.fwu.rest.service.FWUploadService$ContentTypeSetterPreProcessorInterceptor
at org.jboss.resteasy.core.interception.InterceptorRegistry$PerMethodInterceptorFactory.<init>(InterceptorRegistry.java:109)
at org.jboss.resteasy.core.interception.InterceptorRegistry.register(InterceptorRegistry.java:234)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:792)
at org.jboss.resteasy.spi.ResteasyProviderFactory.registerProvider(ResteasyProviderFactory.java:743)
at org.jboss.resteasy.spi.ResteasyDeployment.registerProvider(ResteasyDeployment.java:505)
at org.jboss.resteasy.spi.ResteasyDeployment.registration(ResteasyDeployment.java:305)
at org.jboss.resteasy.spi.ResteasyDeployment.start(ResteasyDeployment.java:225)
at org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap.contextInitialized(ResteasyBootstrap.java:28)
at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:640)
at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:229)
at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1208)
at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:586)
at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:449)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(ContextHandlerCollection.java:164)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCollection.java:224)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:89)
at org.eclipse.jetty.server.Server.doStart(Server.java:258)
at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:58)
at com.lxnx.ols.rsf.http.server.HttpServer.start(HttpServer.java:205)
at com.lxnx.ols.rsf.http.server.AbstractRestServer.start(AbstractRestServer.java:250)
at com.lxnx.ols.rsf.http.server.AbstractRestServer.run(AbstractRestServer.java:193)
at com.lexisnexis.fwu.service.DrsFWUServer.main(DrsFWUServer.java:28)
2015-02-06 03:11:08.875:INFO::Started SelectChannelConnector#0.0.0.0:8088 STARTING
03:11:08.891(02/06) INFO RSF : [main] ******* DrsFWU running on RETDAYV-7610098:8088 *******
My web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>LN_CSA_FWU_SRVC_COMP</display-name>
<servlet>
<servlet-name>resteasy-servlet</servlet-name>
<servlet-class>
org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>resteasy-servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<listener>
<listener-class>
org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
</listener-class>
</listener>
</web-app>
pom.xml:
<dependencies>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>2.3.1.GA</version>
</dependency>
<dependency>
<groupId>net.sf.scannotation</groupId>
<artifactId>scannotation</artifactId>
<version>1.0.2</version>
</dependency>
<!-- JAXB provider -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>2.3.1.GA</version>
</dependency>
<!-- Multipart support -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>2.3.1.GA</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.2.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.2.4</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>fluent-hc</artifactId>
<version>4.2.5</version>
</dependency>
This:
com.lexisnexis.csa.fwu.rest.service.FWUploadService$ContentTypeSetterPreProcessorInterceptor
Indicates that ContentTypeSetterPreProcessorInterceptor is an inner class. Define the inner class as static or make it a top-level class.
A non-static inner class does not have an empty constructor.
I have a Java application and it uses maven, jersey, spring and other libraries for that.
I use this tutorial github.com/erkobridee/restful-bookmarks-jerseyspring/tree/master/src/main
as guide for my project.
pom.xml is as follows:
<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>deconFmV5</groupId>
<artifactId>deconFM_V5</artifactId>
<packaging>war</packaging>
<version>0.0.1</version>
<name>deconFM_V5 Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<encoding>UTF-8</encoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- Spring Components -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context-support</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<!-- Hibernate / Datenbank Components -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.12.1.GA</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
</dependency>
<!-- Jersey Components -->
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-json</artifactId>
<version>1.13</version>
</dependency>
<!-- Jersey - Spmring Integration -->
<dependency>
<groupId>com.sun.jersey.contribs</groupId>
<artifactId>jersey-spring</artifactId>
<version>1.13</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-aop</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Log Components -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
My web.xml
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Decon FM Version 5</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:META-INF/spring/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>decon-fm-5</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>de.decon.v5.core.controller; org.codehaus.jackson.jaxrs</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>decon-fm-5</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
And my applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:oxm="http://www.springframework.org/schema/oxm"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/oxm
http://www.springframework.org/schema/oxm/spring-oxm-3.1.xsd">
<context:annotation-config />
<context:component-scan base-package="de.decon.v5.core.controller" />
<!-- <import resource="module/db-context.xml" /> -->
</beans>
I can't post an image from my project structure. My index.html is in src/main/webapp/index.html
When i call the url http://localhost/decon-fm-5/index.html in my browser, than called an 404 status error.
Why? What is the problem?
I can call my ApplicationController action in my browser with url http://localhost/deconFM_V5/app/login
package de.decon.v5.core.controller;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/app")
public class ApplicationController
{
#GET
#Path("/login")
#Produces(MediaType.APPLICATION_JSON)
public String application()
{
String loginForm = "{\"form\" : {\"name\" : \"login\"}}";
return loginForm;
}
}
Thank much for yours help
you are mapping all reqeust to jersy spring servlet it will look for a mapping for index.html in your Rest Endpoint if not found it will give 404. Ideally you should map /api/** or something for your Rest Endpoint .
Eg:
http://localhost/decon-fm-5/api/v1/resourcename/id
make the following change
<servlet-mapping>
<servlet-name>decon-fm-5</servlet-name>
<url-pattern>/api</url-pattern>
</servlet-mapping>