I recently upgraded my jersey jars from version 1 to 2 . With jersey-1 my web.xml mappings were as follows
<servlet>
<servlet-name>Restful App</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Restful App</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
I have other applications talking to this application through rest calls. After upgrading to jersey 2 I have changed web.xml as follows
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
Normal REST calls within the application seems to work fine, but rest calls made by other applications are not hitting my application now. No error logs also.
PS: Also I am having elasticsearch configured to talk to this application, even that gives me this error elasticsearch error
Related
I have a problem with deploying a gwt application on Tomcat, when I call my RPC service with this way it works very well :
this.service=GWT.create(MyService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) this.service;
endpoint.setServiceEntryPoint("2_rpc_project/myserviceclass");
But what I want exactly is to call my RPC service using the localhost like this :
this.service=GWT.create(MyService.class);
ServiceDefTarget endpoint = (ServiceDefTarget) this.service;
endpoint.setServiceEntryPoint("http://127.0.0.1:8080/2_rpc_project/myserviceclass");
web.xml
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>
com.tominto.server.MyServiceImpl
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/2_rpc_project/myserviceclass</url-pattern>
</servlet-mapping>
On GAE it works but on Tomcat no.
Thanks in advance
I have a Jetty Server which serves up an Angular page but also has several Jersey endpoints coded up. My Angular project is in a resources directory, and after building and running, the target looks like this:
WEB-INF
classes
index.html
com/
web.xml
My web.xml looks like this:
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<display-name>Sandbox</display-name>
<servlet>
<servlet-name>Jersey</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- Adds JSON processing to map java classes to JSON text in both directions -->
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<!-- Tell the Jersey framework where to search for services. Also, JAX-RS is needed
for the JSON serialization -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.hb.apps.server;org.codehaus.jackson.jaxrs</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>json</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
With this set up, hitting localhost:8080/Sandbox serves up the single page angular app, however hitting localhost:8080/Sandbox/rest/* tells me that my endpoint cannot be found. The Angular app was introduced after the Jersey app, and prior to the Angular app my Jersey endpoints were working fine with this configuration (minus the welcome-file-list). Why would having an Angular app obscure my Jersey endpoints?
The answer was unrelated to the web.xml. One of my colleagues had assisted me with setting up the project to work with Angular and had removed this block from my pom file:
<resource>
<directory>src/main/webapp</directory>
</resource>
I have a Dynamic Web application, and because of the requirements, I am specifying two types of servlet mappings in the web.xml file; Faces Servlet & Jersey(JAX-RS implementation).
My problem is, that if I try to use '/' as the base url-pattern in the Jersey configuration, then the resources of Faces Servlets stop working, i.e., nothing happens if I make REST call to those resources, otherwise everything works fine if I place something like'/rest/' in the Jersey Configuration. My web.xml file looks like this:
<!-- Jersey -->
<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.saf.web.v2.beans</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey REST Service</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<!-- Faces Servlet -->
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>100</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
Is there a way to specify the Jersey mapping so there is nothing in the url-pattern but '/*' and Faces Servlet resources also work fine at the same time.
Thanks!
If you define that Jersey should serve all requests (this is what /* means) the Faces Servlet doesn't have a chance any more. So in general: There is no such way.
Maybe you could work around this be mapping Jersey to /rest and writing an own Servlet mapped to /* which dispatches to one of the other servlets. I would not recommend that.
I had the same problem but I fixed it by using
/rest/*
for jersey's servlet
and other part of application can have any other url-pattern, as in your case it is *.xhtml for JSF's servlet.
I have deployed a sample spring java application to weblogic server (11g, 10.3.6). I have index.html at the root and I set that as the welcome-file in web.xml. But when I try to access the application, I am getting 'Error 404 -- Not Found'. Also, I noticed same issue with js and css files.
index.jsp works fine at the same location.
Here is my web.xml.
<display-name>hello</display-name>
<welcome-file-list>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>appServlet</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>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
The reason for this is the root level mapping(/) for your Spring DispatcherServlet. All the requests are forward to Spring servlet:
<servlet-mapping>
<servlet-name>appServlet</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I workaround this situation by using *.do for my Spring controllers and update the servlet mapping as mentioned here:
<servlet-mapping>
<servlet-name>appServlet/servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
But this will require you to update the 'calls to your Spring controller' with a .do at the end of the URLs.
I am using google app engine to develop my software's backend using java along with Restlet framework. I have index.jsp under my war directory which I want to treat as default page when somebody goes to my website(e.g. example.com). So I have mentioned it under welcome-file-list section in web.xml.
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Also, I have my Restlet servlet mapped to "/*" in web.xml.
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
But the problem occurs here, because even the call to default page i.e. example.com, also goes to the restlet which obviously doesn't find the mapping in its router. So I decided to instead map restlet servlet to "/restlet/*".
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/restlet/*</url-pattern>
</servlet-mapping>
But with this I get the HTTP 404 error because somehow even though web.xml successfully routes the call to restlet, but restlet doesn't find the mapping in this case in its router object. I have obviously changed the mapping in the restlet router to match the new pattern "restlet/*".
router.attach("/restlet/doSomething",DoSomething.class);
It would be really great if someone can help me with this. Following is my complete web.xml:
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.mWallet.loyaltyCardCase.LoyaltyCardCaseWebService
</param-value>
</init-param>
</servlet>
<!-- Catch all requests -->
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/restlet/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Thanks!
Manas
You don't need to change the mapping in the restlet router to match the new pattern "restlet/*" because the restlet router will now be considering "example.com/restlet/" as the base url.
So, if you change the router to match "/restlet/doSomething", your actual url will be "example.com/restlet/restlet/doSomething", which obviously will not work.
So, change your restlet routing to:
router.attach("/doSomething",DoSomething.class);
I did it in my project and its working.
i think you forgot to write below code in web.xml
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
<init-param>
<param-name>org.restlet.application</param-name>
<param-value>com.wa.gwtamazon.server.RestApi</param-value>
</init-param>
<!-- Catch all requests -->
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
and i already answer in this link Restlet API example may will help you.