Jersey servlet version issues [java.lang.NoSuchMethodError] jakarta httpservlet - java

I'm learning Java web technologies and I'm trying to deploy a trivial REST service using Jersey, when I try to access the resource I get greeted with the following error:
SEVERE: Servlet.service() for servlet [Jersey REST Service] in context with path [/mkstick] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: 'void jakarta.servlet.http.HttpServletResponse.setStatus(int, java.lang.String)'] with root cause
java.lang.NoSuchMethodError: 'void jakarta.servlet.http.HttpServletResponse.setStatus(int, java.lang.String)'
My java class resource:
package com.dbmw.mkstick;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;
#Path("/hello")
public class Resource {
#GET
#Produces(MediaType.TEXT_HTML)
public String getText() {
return "<html><head/><body>Hello world!</body></html>" ;
}
}
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" 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">
<servlet>
<servlet-name>Jersey REST Service</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.dbmw.mkstick</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
pom.xml
<?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.dbmw</groupId>
<artifactId>mkstick</artifactId>
<version>0.1</version>
<name>mkstick</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>11</maven.compiler.target>
<maven.compiler.source>11</maven.compiler.source>
</properties>
<dependencies>
<dependency>
<groupId>org.glassfish.jersey.bundles</groupId>
<artifactId>jaxrs-ri</artifactId>
<version>3.0.4</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
<finalName>mkstick</finalName>
</build>
<packaging>war</packaging>
</project>
From what I can grasp it seems to be an issue with versions and I've tried to get every dependency up to date but it has not helped at all.

As comment said, if you are deploying on Tomcat 10.1.x or greater you need to upgrade your jersey version to 3.1+ (it is out now).
To get a starting template use the maven build archetype for Jersey 3.1.1 as seen here.
This is a confusing error too because the updates from Tomcat 10.0.x to Tomcat 10.1.x entail an entire version jump in Servlet spec (version 5 to 6) see link. Usually there arent such big version changes within the same major version ie 10.x

Related

How to correctly deploy war file to jetty running in docker-compose?

I am trying to run a java servlet on jetty in docker-compose.
This is my docker-compose.yml:
version: "3.2"
services:
app:
image: jetty:9.4-jre8
ports:
- "8080:8080"
volumes:
- /target/example.war:/var/lib/jetty/webapps/root.war
If I docker exec into the container and change into /var/lib/jetty/webapps/ directory (as specified in the docker-compose) I can see the root.war file is present.
I use the following docker command to do that after starting with docker-compose up -d:
docker exec -it <CONTAINER> /bin/bash/
Then cd into the webapps directory and ls.
However on localhost:8080/ I get a 404 response.
This is the HelloServlet.java I am using:
package org.server;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloServlet extends HttpServlet
{
/**
*
*/
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().println("<h1>Hello Servlet</h1>");
response.getWriter().println("session=" + request.getSession(true).getId());
}
}
And this is the configuration in src/main/webapp/WEB-INF/web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" metadata-complete="false" version="3.1">
<servlet>
<servlet-name>Hello</servlet-name>
<servlet-class>retro.server.HelloServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Hello</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>
</web-app>
If I run jetty through the maven plugin I get the Servlet responding. Only run in docker-compose or also docker I get only 404.
This is the error I receive in browser:
404 jetty in docker-compose
Is there any additional configuration to be done?
Is there something obviously wrong with the setup?
What I am ultimately trying to achieve is run a GraphQl servlet on jetty in docker-compose!
This is the maven pom.xml:
<?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>org</groupId>
<artifactId>server</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>server Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jettyVersion>9.4.30.v20200611</jettyVersion>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>15.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.graphql-java/graphql-java-tools -->
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-tools</artifactId>
<version>4.3.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.graphql-java/graphql-java-servlet -->
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java-servlet</artifactId>
<version>4.7.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jettyVersion}</version>
</dependency>
</dependencies>
<build>
<finalName>example</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jettyVersion}</version>
</plugin>
<!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Finally I found out that a . was missing in the volumes section of the docker-compose.yml like so:
- ./target/example.war:/var/lib/jetty/webapps/root.war

Unable to run JaxRs web service using Wildfly web server

Hi I am trying to build a Simple JaxRs web service on JBoss developer studio and Wildfly 11 as application server but i am getting following error while i am trying to deploy my maven project :
Failed to start service
jboss.undertow.deployment.default-server.default-host."/JaxRsTest-0.0.1-SNAPSHOT":
org.jboss.msc.service.StartException in service
jboss.undertow.deployment.default-server.default-host."/JaxRsTest-0.0.1-SNAPSHOT":
java.lang.NoSuchMethodError:
org.apache.tomcat.util.descriptor.DigesterFactory.newDigester(ZZLorg/apache/tomcat/util/digester/RuleSet;Z)Lorg/apache/tomcat/util/digester/Digester;
Also i want to inform you that the project is working fine when i use apache tomcat 9 However it throws above mentioned error when I switch to wildfly 11. I am new to java and Specially web service and just started working for a company which uses Jboss eap server which is quite same as wildfly and unfortunately i am receiving same error there as well while working on a web service assignment.
For more reference below is my pom.xml file :
<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>JaxRsServiceTest</groupId>
<artifactId>JaxRsServiceTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.19</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.19</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
and my web.xml file content is :
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
<display-name>JaxRsServiceTest</display-name>
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.test.jaxrs.service</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
and my java class within package com.test.jaxrs.service is
package com.test.jaxrs.service;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
#Path("/test")
public class JaxRsTest {
#GET
#Path("/hello/{msg}")
#Produces(MediaType.TEXT_PLAIN)
public String processRequest(#PathParam(value="msg")String message)
{
return "Hello : " + message;
}
}
Please let me know where i am going wrong with the wildfly.... and Thanks in advance
Wildfly and EAP are a full JEE servers - there is no need to include Jersey dependencies in your pom.xml. Tomcat required that because it is primarily a servlet/JSP engine. Your service looks good but your pom.xml and web.xml are the result using Tomcat. Additionally, you do not need a web.xml any longer if you don't want and you certainly don't need to use Jersey to map it.
You'll want one more file - the Application class that gets things started. It looks something like:
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
/**
* Used to bootstrap JAX-RS. Otherwise this class is
* not directly used.
*/
#ApplicationPath("/rest")
public class RestApplicationConfig extends Application {
// intentionally empty
}
It can go anywhere in your source tree. Note that it takes over the /rest path which is similar to what you had in your web.xml.
The pom.xml below will create a .war file that you can deploy to Wildfly. This is about as simple as it gets and again, remove your web.xml for now.
pom.xml
<?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>JaxRsServiceTest</groupId>
<artifactId>JaxRsServiceTest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties>
<dependencies>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>3.0.12.Final</version>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

Maven Web-app deployment file not found

Hi there I an issue trying to deploy my Maven jsp college project to a bluemix server. Every thing work fines locally on my tomcat server. I use cloud foundry to push to the server which is okay. the index page works fine but I can not access the pages i get for example.
Error 404: java.io.FileNotFoundException: SRVE0190E: File not found: /handler
Which is a Java class using annotation instead of setting routes in web xml like so.
#WebServlet("/handler")
My pom.xml looks like so.
<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>ie.cit.ooss</groupId>
<artifactId>BarSurvey</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>assignment2 Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>BarSurvey</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<warSourceDirectory>src</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</project>
And my project structure looks like so.
You can see my project here .
https://github.com/yawlhead91/ChocolateBarsSurvey/tree/master/BarSurvey
If any one has some help would be great.
Thanks
I made some changes after cloning your git project:
in index.jsp file
change <form action="/BarSurvey/handler" method="POST">
to <form action="/handler" method="POST">
in Handler.java file
change response.sendRedirect("/BarSurvey/results.jsp");
to `response.sendRedirect("/results.jsp");
in results.jsp file
change Return
to Return
Push your application using the java_buildpack
cf push appname -p target/BarSurvey.war -b java_buildpack
Check your web.xml - you are currently using:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
When you should be using:
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
See this post : servlet 3.0 #WebServlet use..what will be in web.xml?

JAVA HTTP Status 500 - Authenticator.invoke() failed

In my Java app, I'm getting the following error for all Rest service calls like:
https://example.com/secselfservice/rest/ping
which returns: HTTP Status 500 - Authenticator.invoke() failed
Log of the error:
javax.servlet.ServletException: Authenticator.invoke() failed at
com.sap.core.jpaas.security.auth.service.lib.AbstractAuthenticator.invoke(AbstractAuthenticator.java:174)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:956)
at
com.sap.core.tenant.valve.TenantValidationValve.invokeNextValve(TenantValidationValve.java:168)
at
com.sap.core.tenant.valve.TenantValidationValve.invoke(TenantValidationValve.java:94)
at
com.sap.js.statistics.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:38)
at
com.sap.core.js.monitoring.tomcat.valve.RequestTracingValve.invoke(RequestTracingValve.java:27)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:442)
at
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1083)
at
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:640)
at
org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:807) Caused by:
java.lang.NullPointerException: while trying to invoke the method
java.lang.String.length() of a null object loaded from local variable
'name' at
org.eclipse.osgi.internal.loader.BundleLoader.loadClass(BundleLoader.java:338)
at
org.eclipse.osgi.framework.internal.core.BundleHost.loadClass(BundleHost.java:229)
at
org.eclipse.osgi.framework.internal.core.AbstractBundle.loadClass(AbstractBundle.java:1212)
at
org.eclipse.gemini.web.tomcat.internal.loading.BundleDelegatingClassLoader.findClass(BundleDelegatingClassLoader.java:91)
at
org.eclipse.gemini.web.tomcat.internal.loading.BundleDelegatingClassLoader.loadClass(BundleDelegatingClassLoader.java:139)
at java.lang.ClassLoader.loadClass(ClassLoader.java:427) at
org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.doLoadClass(ChainedClassLoader.java:174)
at
org.eclipse.gemini.web.tomcat.internal.loading.ChainedClassLoader.loadClass(ChainedClassLoader.java:164)
at
org.eclipse.gemini.web.tomcat.internal.loading.BundleWebappClassLoader.loadClass(BundleWebappClassLoader.java:298)
at java.lang.ClassLoader.loadClass(ClassLoader.java:427) at
org.apache.catalina.core.StandardWrapper.servletSecurityAnnotationScan(StandardWrapper.java:1211)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:494)
at
com.sap.core.jpaas.security.auth.service.lib.AbstractAuthenticator.invoke(AbstractAuthenticator.java:170)
... 16 common frames omitted
Here is the code of 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" 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>secselfservice</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>com.sap.coe.securityselfservice.rest.SecSelfServApplication</servlet-name>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>com.sap.coe.securityselfservice.rest.SecSelfServApplication</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<resource-ref>
<res-ref-name>user/Provider</res-ref-name>
<res-type>com.sap.security.um.user.UserProvider</res-type>
</resource-ref>
<resource-ref>
<res-ref-name>mail/SAPInternalNWCloudSession</res-ref-name>
<res-type>javax.mail.Session</res-type>
</resource-ref>
<login-config>
<auth-method>FORM</auth-method>
</login-config>
<security-role>
<description>All SAP HANA Cloud Platform users</description>
<role-name>EVERYONE</role-name>
</security-role>
<security-role>
<description>Members of security team</description>
<role-name>Approver</role-name>
</security-role>
<security-role>
<description>Read only access to admin view</description>
<role-name>Viewer</role-name>
</security-role>
<security-role>
<description>Superadmin</description>
<role-name>Tester</role-name>
</security-role>
<security-constraint>
<web-resource-collection>
<web-resource-name>all</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>Approver</role-name>
<role-name>Viewer</role-name>
<role-name>Tester</role-name>
<role-name>EVERYONE</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<ejb-local-ref>
<ejb-ref-name>ejb/CustomDataEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Customization</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/MailTemplateEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.MailTemplates</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/QuestionEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Questions</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/UsrVariantEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.UsrVariants</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ProjectEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Projects</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ProjectRequestEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.ProjectRequests</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/UserEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Users</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ResourcesEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.Resources</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ProjectAnswerObserverEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.observer.ProjectAnswerObserver</local>
</ejb-local-ref>
<ejb-local-ref>
<ejb-ref-name>ejb/ProjectDataObserverEJB</ejb-ref-name>
<local>com.sap.coe.securityselfservice.ejb.observer.ProjectDataObserver</local>
</ejb-local-ref>
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>com.sap.coe.securityselfservice.rest.exception.WebServiceExceptionHandler</param-value>
</context-param>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
</web-app>
The code of the servlet SecSelfServApplication:
/**
* Application
*/
package com.sap.coe.securityselfservice.rest;
import java.util.HashSet;
import java.util.Set;
import javax.ws.rs.core.Application;
/**
* JAX-RS Application
*/
public class SecSelfServApplication extends Application {
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(InitService.class);
s.add(MailTemplateService.class);
s.add(PingService.class);
s.add(ProjectRequestService.class);
s.add(ProjectService.class);
s.add(QuestionService.class);
s.add(ResourceService.class);
s.add(UserService.class);
s.add(UsrVariantService.class);
return s;
}
}
And for PingService.java:
package com.sap.coe.securityselfservice.rest;
import javax.servlet.ServletException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
//import com.qmino.miredot.annotations.ReturnType;
import com.sap.coe.securityselfservice.rest.bean.WebServiceException;
import com.wordnik.swagger.annotations.ApiOperation;
/**
* Rest Service - Ping
*
* #author C5178621
* #servicetag Ping
*/
#Path("/ping")
public class PingService {
/**
* Ping the rest service application and check if it is alive
*
* #summary Test Application Alive
* #return "pong" if application is up and running
* #throws WebServiceException
*/
#GET
#Path("/")
#Produces(MediaType.TEXT_PLAIN)
#ApiOperation(value = "ping", notes = "ping", response = String.class)
public Response ping() throws ServletException {
return Response.ok().entity("pong").build();
}
}
Also 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<!--<?xml version="1.0" encoding="UTF-8"?>-->
<parent>
<groupId>com.sap.it.mobile</groupId>
<artifactId>hcp-parent-pom</artifactId>
<version>2.3.3</version>
</parent>
<groupId>com.sap.coe</groupId>
<artifactId>SecSelfService</artifactId>
<version>1.1.14-SNAPSHOT</version>
<packaging>war</packaging>
<licenses>
<license>
<name>SAP DEVELOPER LICENSE AGREEMENT</name>
<url>https://tools.hana.ondemand.com/developer-license-3.1.txt</url>
</license>
</licenses>
<scm>
<url>git#github.example.corp:SRCOffice/SelfService_Backend.git</url>
<connection>scm:git:git#github.example.corp:SRCOffice/SelfService_Backend.git</connection>
<developerConnection>scm:git:git#github.example.corp:SRCOffice/SelfService_Backend.git</developerConnection>
<tag>HEAD</tag>
</scm>
<properties>
<java-version>1.7</java-version>
<war.name>secselfservice</war.name>
<sap.cloud.application>secselfservice</sap.cloud.application>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<!-- Project plugin versions -->
<version.eclipse-plugin>2.6</version.eclipse-plugin>
<version.shade-plugin>2.2</version.shade-plugin>
</properties>
<!--Use Java EE6-->
<profiles>
<profile>
<id>neo-javaee6-wp</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.13</version>
<exclusions>
<exclusion>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
</dependency>
<dependency>
<groupId>com.sap.it.mobile</groupId>
<artifactId>hcp-java-util</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>${java-version}</source>
<target>${java-version}</target>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName>secselfservice</warName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>${version.eclipse-plugin}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${version.shade-plugin}</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
</plugins>
</pluginManagement>
</build>
</project>
Anyone has an idea how to solve this?
Thank you
Hmm, obviously classloading problems with no very useful hint from the eclipse (osgi) framework...
I've seen from time to time failing apps when they bring their own versions of libraries which collide with some libs that are already part of the provided platform.
Consider this HCP maven blog: there they reference one artifact and most imporantly they use <scope>provided</scope> to tell maven to NOT include the libs into your app's war file (as some jars are already provided by the platform).
My best bet is that at least org.eclipse.persistence is already provided by the platform (and maybe other libs you want as well).
I faced the same error (my Q&A you can find here) and found a solution in this SAP discussion.
For me the error did no longer occur as soon as I added jersey manually and removed the <servlet-class> tag from the web.xml In the end the configuration within the web.xml wasn't necessary at all for my simple rest service (see this answer).
So It seems that this is a Hana cloud platform specific problem.

Maven - Could not resolve dependencies for project X

I'm trying to make a webservice and pack this into a .war file.
Everything worked fine, untill i made some edits to the pom. After a few CTRL+Z's i can't get it back the way is was..
My current (not working pom) gives the following error:
Failed to collect dependencies at com.sun.jersey:jersey-client:jar:1.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.gis</groupId>
<artifactId>com.gis</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src.com.gis</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-client</artifactId>
<version>1.8</version>
</dependency>
</dependencies>
My web.xml:
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>Restful Web Application</display-name>
<servlet>
<servlet-name>jersey-servlet</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.gis</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I have added the following jars to my Build Path:
java-json.jar
javax.ws.rs-api-2.0.1.jar
jersey-bundle-1.8.jar
jersey-server.jar
Can anyone give me a hint to make this work properly again?
EDIT: Removing .jars and closing proxy did the trick.
Unfortunatly, the next error is coming in:
SEVERE: Servlet [jersey-servlet] in web application [/com.gis] threw load() exception java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer
Any hints anyone?
Updated:Add jersey-server dependency
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.8</version>
</dependency>
Try: Rightclick on project > Build with dependencies

Categories