How to declare multiple packagesin web.xml, by REST (JAX-RS)? - java

I want to declare tow packages in the web.xml in a REST application using jax-rs.
this my code of web.xml for the first package
<?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>LampPostZ12</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>lamppost12</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>cuLampPost</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lamppost12</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
like that, everything is working well.
but when I add the declaration of the second package:
<servlet>
<servlet-name>lamppost12</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>cuLampPost</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lamppost12</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>radar12</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>radar</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>radar12</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
it appears as it:
Etat HTTP 404
thank's in advance

The problem is solved when I declare in the web.xml, like this:
<servlet>
<servlet-name>lamppost12</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>cuLampPost;radar</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>lamppost12</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

Related

IOException parsing XML document from ServletContext resource [/WEB-INF/spring-dispatcher-servlet.xml]

Receiving this error from console:
*org.springframework.beans.factory.BeanDefinitionStoreException:
IOException parsing XML document from ServletContext resource
[/WEB- INF/spring-dispatcher-servlet.xml]; nested exception is
java.io.FileNotFoundException: Could not open ServletContext resource
[/WEB-INF/spring-dispatcher-servlet.xml]*
That's the error I receive from:
<?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_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>fj21-tarefas</display-name>
<welcome-file-list>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
I doing
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</init-param>
to change the default context from springmvc, but it is not working. Already took some advice here to write a servlet-name tag to the file name-context.xml convention, same error.
You should try changing the servlet name. Expected Spring web-context metadata XML file name should servletname-servlet.xml, this was expected filename till Spring 4, not sure if it is changed in spring 5.
. As your servlet name is springmvc, filename should be springmvc-servlet.xml.
<servlet>
<servlet-name>springmvc</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/springmvc-servlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>/app-name/*</url-pattern>
</servlet-mapping>
Make your web.xml look like this, taken straight from the Spring documentation:
<web-app>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-context.xml</param-value>
</context-param>
<servlet>
<servlet-name>app</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>app</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>

Angular 4 war file not running on JBOSS

I am new in angular and build a project with angular 4 as front end and JAVA Rest API as backend. I created a war file to deploy it on JBOSS but when I am trying to run the angular 4 war file on JBOSS but it gives me 404. It seems like some base-href issue in index.html. I tried with below base-href but nothing works:
<base href="/">
<base href="./">
<base href="/PROJECT_NAME/">
Please help me out in this.
Below is WEB.Xml for the same :
<?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>LeadAdminBackEnd</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>Jersey RESTful Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.newgen.aproj2</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>
</servlet>
<servlet-mapping>
<servlet-name>Jersey RESTful Application</servlet-name>
<url-pattern>/restAPI/*</url-pattern>
</servlet-mapping>
<filter>
<!-- The CORS filter with parameters -->
<filter-name>CORS</filter-name>
<filter-class>com.thetransactioncompany.cors.CORSFilter</filter-class>
<!-- Note: All parameters are options, if omitted the CORS
Filter will fall back to the respective default values.
-->
<init-param>
<param-name>cors.allowGenericHttpRequests</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.allowOrigin</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.allowSubdomains</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>cors.supportedMethods</param-name>
<param-value>GET, HEAD, POST, OPTIONS</param-value>
</init-param>
<init-param>
<param-name>cors.supportedHeaders</param-name>
<param-value>*</param-value>
</init-param>
<init-param>
<param-name>cors.exposedHeaders</param-name>
<param-value>X-Test-1, X-Test-2,X-Requested-With</param-value>
</init-param>
<init-param>
<param-name>cors.supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>cors.maxAge</param-name>
<param-value>3600</param-value>
</init-param>
</filter>
<filter-mapping>
<!-- CORS Filter mapping -->
<filter-name>CORS</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

Dynamic Web Project HTTP ERROR:503

I am making a dynamic web project with mysql database connectivity in eclipse using dynamic web module 3.0,jdk 1.7
This is my project structure
Project structure
web.xml for it
<?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>Project</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>AdminLogin</servlet-name>
<servlet-class>com.servlets.AdminLogin</servlet-class>
</servlet>
<servlet>
<servlet-name>AddBook</servlet-name>
<servlet-class>com.servlets.AddBook</servlet-class>
</servlet>
<servlet>
<servlet-name>AddBookForm</servlet-name>
<servlet-class>com.servlets.AddBookForm</servlet-class>
</servlet>
<servlet>
<servlet-name>AddLibrarian</servlet-name>
<servlet-class>com.servlets.AddLibrarian</servlet-class>
</servlet>
<servlet>
<servlet-name>AddLibrarianForm</servlet-name>
<servlet-class>com.servlets.AddLibrarianForm</servlet-class>
</servlet>
<servlet>
<servlet-name>DeleteBook</servlet-name>
<servlet-class>com.servlets.DeleteBook</servlet-class>
</servlet>
<servlet>
<servlet-name>DeleteLibrarian</servlet-name>
<servlet-class>com.servlets.DeleteLibrarian</servlet-class>
</servlet>
<servlet>
<servlet-name>EditLibrarian</servlet-name>
<servlet-class>com.servlets.EditLibrarian</servlet-class>
</servlet>
<servlet>
<servlet-name>IssueBook</servlet-name>
<servlet-class>com.servlets.IssueBook</servlet-class>
</servlet>
<servlet>
<servlet-name>IssueBookForm</servlet-name>
<servlet-class>com.servlets.IssueBookForm</servlet-class>
</servlet>
<servlet>
<servlet-name>LibrarianLogin</servlet-name>
<servlet-class>com.servlets.LibrarianLogin</servlet-class>
</servlet>
<servlet>
<servlet-name>LogoutAdmin</servlet-name>
<servlet-class>com.servlets.LogoutAdmin</servlet-class>
</servlet>
<servlet>
<servlet-name>LogoutLibrarian</servlet-name>
<servlet-class>com.servlets.LogoutLibrarian</servlet-class>
</servlet>
<servlet>
<servlet-name>ReturnBook</servlet-name>
<servlet-class>com.servlets.ReturnBook</servlet-class>
</servlet>
<servlet>
<servlet-name>ViewBook</servlet-name>
<servlet-class>com.servlets.ViewBook</servlet-class>
</servlet>
<servlet>
<servlet-name>ViewIssuedBook</servlet-name>
<servlet-class>com.servlets.ViewIssuedBook</servlet-class>
</servlet>
<servlet>
<servlet-name>ViewLibrarian</servlet-name>
<servlet-class>com.servlets.ViewLibrarian</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminLogin</servlet-name>
<url-pattern>/AdminLogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddBook</servlet-name>
<url-pattern>/AddBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddBookForm</servlet-name>
<url-pattern>/AddBookForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddLibrarian</servlet-name>
<url-pattern>/AddLibrarian</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddLibrarianForm</servlet-name>
<url-pattern>/AddLibrarianForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DeleteBook</servlet-name>
<url-pattern>/DeleteBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DeleteLibrarian</servlet-name>
<url-pattern>/DeleteLibrarian</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>EditLibrarian</servlet-name>
<url-pattern>/EditLibrarian</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>EditLibrarianForm</servlet-name>
<url-pattern>/EditLibrarianForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>IssueBook</servlet-name>
<url-pattern>/IssueBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>IssueBookForm</servlet-name>
<url-pattern>/IssueBookForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LibrarianLogin</servlet-name>
<url-pattern>/LibrarianLogin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LogoutAdmin</servlet-name>
<url-pattern>/LogoutAdmin</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LogoutLibrarian</servlet-name>
<url-pattern>/LogoutLibrarian</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ReturnBook</servlet-name>
<url-pattern>/ReturnBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ReturnBookForm</servlet-name>
<url-pattern>/ReturnBookForm</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ViewBook</servlet-name>
<url-pattern>/ViewBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ViewIssuedBook</servlet-name>
<url-pattern>/ViewIssuedBook</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ViewLibrarian</servlet-name>
<url-pattern>/ViewLibrarian</url-pattern>
</servlet-mapping>
</web-app>
I have included mysql-connector.jar in java resources/lib only.
When i am running it it shows
HTTP ERROR: 503
Problem accessing /Project/AdminLogin. Reason:
Service Unavailable
Powered by Jetty://
But when I am using the web.xml as
<?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>Project</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>AdminLogin</servlet-name>
<servlet-class>com.servlets.AdminLogin</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AdminLogin</servlet-name>
<url-pattern>/AdminLogin</url-pattern>
</servlet-mapping>
</web-app>
it opens the AdminLogin page but after that when I open other servlets it shows error as
HTTP ERROR 404
Problem accessing /Project/AddLibrarianForm. Reason:
Not Found
Is the problem due to my web.xml file or something else?

JavaMelody mapping URL

I'm trying to install Javamelody in my Spring application. I configured on localhost and can access Javamelody with URL:
http://localhost:9080/myapp/stats
Server: webSphere 7.0 and my web.xml config is:
<?xml version="1.0" encoding="UTF-8"?>
<!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 id="myapp">
<display-name>myapp</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
classpath:net/bull/javamelody/monitoring-spring.xml
/WEB-INF/applicationContext.xml
</param-value>
</context-param>
<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
<init-param>
<param-name>monitoring-path</param-name>
<param-value>/stats</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>myapp.web.AppInit</listener-class>
</listener>
<listener>
<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
<servlet>
<servlet-name>javascript</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>page</servlet-name>
<display-name>page</display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>unificator</servlet-name>
<display-name>unificator</display-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>webservicesoap</servlet-name>
<display-name>webservicesoap</display-name>
<servlet-class>org.apache.axis.transport.http.AxisServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>QuartzInitializer</servlet-name>
<servlet-class>org.quartz.ee.servlet.QuartzInitializerServlet</servlet-class>
<init-param>
<param-name>shutdown-on-unload</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>start-scheduler-on-load</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javascript</servlet-name>
<url-pattern>/validation.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>page</servlet-name>
<url-pattern>/page/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>unificator</servlet-name>
<url-pattern>/home/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>unificator</servlet-name>
<url-pattern>/users/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>unificator</servlet-name>
<url-pattern>/contacts/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>0</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
However, this config in production environment is not working. If I go to
http://app.gtrwe.dev.corp/myapp/stats
I get 404 error. Also I have servlets in my web.xml
I am looking for help on how to set this up.
It seems that IBM WebSphere may encounter the ERROR 404 if no servlet is mapped to either /* or /monitoring, as mentioned here

How to integrate swagger with tomcat?

I am new to swagger, I am trying to swagger to my tomcat application, and below is 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>Restful Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:xxx/xxx/xxx/xml/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>xxx.xxx.xxx.resource</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet>
<servlet-name>JerseyJaxrsConfig</servlet-name>
<servlet-class>com.wordnik.swagger.jersey.config.JerseyJaxrsConfig</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:8088/sms</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>jersey-helloworld-serlvet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
And I added Swagger Ui to my WebContent/WEB-INF folder, and added
swagger-annotations_2.9.1
swagger-jersey-jaxrs_2.10
swagger-core_2.10 jars to my class path
I am getting the below error:
java.lang.NoClassDefFoundError: com/wordnik/swagger/config/ConfigFactory
Appreciate your help on this.

Categories