IBMRestServlet vs ServletContainer - rest

What are the advantages that offer implement REST WS with IBMRestServlet over ServletContainer?
I noted that the servlets have different configuration on web.xml:
For ServletContainer:
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
And IBM implementation:
<servlet>
<servlet-name>JAXRS</servlet-name>
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.myapp.ServiceApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
I'm using a Websphere 7.
Thanks!

You have to deploy Jersey for the former to work, don't you? The latter is part of WebSphere and officially supported under WebSphere (meaning you can get IBM support if you have problems with it).
(A quick web search does show at least a few hits on quirks or difficulties with Jersey under some versions of WebSphere, some of them even right here on StackOverflow.)

Related

How to deploy JAX-RS Application in WAS 7.0.23?

I am using RAD and WAS 7.0.23, and try to deploy jax-rs in it. But I am getting below error in deployment descriptor(Web.xml).
Error 404: javax.servlet.UnavailableException: SRVE0200E: Servlet
[com.ibm.websphere.jaxrs.server.IBMRestServlet]: Could not find
required class - class java.lang.ClassNotFoundException:
com.ibm.websphere.jaxrs.server.IBMRestServlet
Servlet Mapping
<servlet>
<description>JAX-RS Tools Generated - Do not modify</description>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>APPLICATION CLASS</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
JAX-RS wasn't added to WAS until 8.0. If you want to use JAX-RS on that old a server (which I generally wouldn't recommend for the reason Andy mentioned above), you'll need to bring your own provider.
First, I agree that continuing to use the well-out-of-support 7.0 is unwise.
That said, it may just be that you need to add the jar to the RAD project's "Deployment Assembly", in addition to the "Java Build Path".

adding RichFaces breaks my JSF project

I have a simple JSF project which works just fine; after adding RichFaces to it, it stops working properly
Environment: Eclipse IDE, JSF 2.1 (Apache MyFaces 2.1.5), Tomcat v7.0 Server (Location: workspace metadata, Server Locations: Use Tomcat installation); http://localhost:8181/ gives me the admin console, so the server is running ok
The application: a Dynamic Web Project (version 3.0) named jsf1;
under WebContent, i have a page named main.xhtml (For brevity, i won't paste the content, because things work well so far; Its a simple hello world page);
the faces-config.xml is left unchanged;
the web.xml contains:
<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>/faces/*</url-pattern>
</servlet-mapping>
In Project Explorer, i right click on the project > Run As > Run on Server, and the application is accessible in a web browser at the url http://localhost:8181/jsf1/faces/main.xhtml
Adding RichFaces: i followed the instructions given at https://docs.jboss.org/richfaces/latest_3_3_X/en/devguide/html/GettingStarted.html
under WEB-INF/lib i have added all the required jars
i have appended to web.xml the following content:
<!-- Plugging the "Blue Sky" skin into the project -->
<context-param>
<param-name>org.richfaces.SKIN</param-name>
<param-value>blueSky</param-value>
</context-param>
<!-- Making the RichFaces skin spread to standard HTML controls -->
<context-param>
<param-name>org.richfaces.CONTROL_SKINNING</param-name>
<param-value>enable</param-value>
</context-param>
<!-- Defining and mapping the RichFaces filter -->
<filter>
<display-name>RichFaces Filter</display-name>
<filter-name>richfaces</filter-name>
<filter-class>org.ajax4jsf.Filter</filter-class>
</filter>
<filter-mapping>
<filter-name>richfaces</filter-name>
<servlet-name>Faces Servlet</servlet-name>
<dispatcher>REQUEST</dispatcher>
<dispatcher>FORWARD</dispatcher>
<dispatcher>INCLUDE</dispatcher>
</filter-mapping>
Now, when i run the project on server, in the console i get:
SEVERE: Exception starting filter richfaces
java.lang.ClassNotFoundException: org.ajax4jsf.Filter
I added the richfaces-impl-3.3.3.Final.jar, which contains the org.ajax4jsf.Filter class.
Now, when i run the project on server,the console contains no errors, however, the link http://localhost:8181/jsf1/faces/main.xhtml displays a blank page.
How is it possible to create a functional RichFaces application?

HTTP Status 404 when running simple RESTful web service in Java using Jersey

I am getting HTTP Status 404 when running simple RESTful web service in Java using Jersey. I am following the tutorial REST with Java (JAX-RS) using Jersey. I have copied all the jars that I downloaded from Jersey download site to WEB-INF/lib folder of my project(please see the screenshot for jars).
When I run the application from eclipse development environment Eclipse Console shows that Tomcat was started successfully. My web-app is deployed and I can see index.html coming up. But hitting http://localhost:8080/com.kj.rest.jersey.first/ gives Http Status 404.
My Environment:
Spring Tool Suite as my eclipse dev environment
Jersey 2.22.2 jars
Apache Tomcat v8.0
Please note I am not using Maven in my project and I also looked at other similar questions here but none of them solved my issue.
What am I missing, where should I look for the issue, which logs?
<servlet>
<servlet-name>Jersey REST Service</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<!-- Register resources and providers under com.vogella.jersey.first package. -->
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.*******</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>
The mistake that I was making was to not specify the service name(specified by #Path annotation) in the URL. After doing that it worked.
So essentially the URL to hit should be http://localhost:8080/com.kj.rest.jersey.first/rest/path_from_rest_class and I missed the path_from_rest_class earlier.

java.lang.IllegalArgumentException: The main resource set specified [...] is not valid

I'm having trouble starting my Tomcat server, it used to work, but I did something wrong and now it throws me this exception:
Caused by: java.lang.IllegalArgumentException: The main resource set specified [E:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps\workspace\j2eeapplication\target\j2eeapplication-0.0.1-SNAPSHOT] is not valid
at org.apache.catalina.webresources.StandardRoot.startInternal(StandardRoot.java:643)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
... 9 more
And this is my 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"
version="3.1">
<display-name>J2EE Application Example</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>Resources Servlet</servlet-name>
<servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Resources Servlet</servlet-name>
<url-pattern>/resources/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>Spring MVC Dispatcher Servlet</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>Spring MVC Dispatcher Servlet</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
<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>*.jsf</url-pattern>
</servlet-mapping>
<filter>
<filter-name>charEncodingFilter</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>charEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
I looked at different solutions over the forums, but nothing worked. Final option will be uninstalling tomcat and fresh installation, cause I read that might work. Thanks for the help in advance.
Seems like you have an outdated web application referenced in your Tomcat embeded server (You are using Tomcat As within Eclipse right?).
First checkout the deployed application within you server, and check the artifact name j2eeapplication-0.0.1-SNAPSHOT and version. You may need to remove it and clean your working directory the redeploy it and you should be safe.
For me, this was caused by a file permission issue. We use a different deployment strategy where I work (not something I can change) which means the webapp exists in a completely different directory to the normal Tomcat directory structure. The above exception occurred when the Tomcat runtime didn't have permission to access that directory.
I had this error when I was starting an application that was designed for Tomcat 8 using Tomcat 7.
A maven update did the trick for me.
Right click on your maven project:
Maven > Update Project...
Select All
Check "Force Update of Snapshots/Releases"
Click Ok
Now, right click on your server:
Clean...
Just in case this might help anyone who come later, I managed to start my tomcat8 server after close and reopen the front project in:
The main resource set specified [project-to-be-reopened]
In my case, it's maven dependency that's causing me this issue, updating maven-dependency will also help.
I had a similar issue. Just if someone else runs into this problem:
For me it was caused because I had an old project deployed, then closed that project. For several weeks, everything was fine, until I used the "Clean..." command of eclipse on that tomcat server. From that point on the famous The main resource set specified [...path to deployment location of this project...] is not valid was raised every time I tried to start Tomcat.
What solved this problem for me was just removing that old project from tomcat (Right click on that entry under Tomcat Server and choose "Remove").
I had a similar issue with one of the projects. I tried all the solutions to this question. None worked for me. I then double-clicked the Tomcat server to see the actual config. In there, under the tab "Modules", there is a list of projects currently associated with the Tomcat server. I could see that the "trouble-causing project" was listed there. I clicked on that and hit remove.
Then everything started to work just fine.
In my case with Tomcat 9 and using Eclipse under Windows, I somehow removed the application from the webapp directory under the Tomcat true server and could no longer start the standalone Tomcat server service. Got the same root cause text as the initial posted question. My solution was to copy the Eclipse version of the application (from the workspace's .metadata.plugins\org.eclipse.wst.server.core\tmp1\wtpwebapps tree) to the C:\Program Files\Apache Software Foundation\Tomcat 9.0\webapps directory.
Note that I am not using Maven in my workspace, and it was just a standard Java Web project.
For me, the cause was another:
In .metadata.plugins\org.eclipse.wst.server.core\servers.xml the "server" element had no "list" element.
I added the "list" element:
<server auto-publish-setting="1" auto-publish-time="1" configuration-id="/Servers/Tomcat v9.0 Server 9091 ASM-config" deployDir="wtpwebapps" hostname="localhost" id="Tomcat v9.0 Server 9091 ASM" jrebel.old-auto-publish-setting="2" name="Tomcat v9.0 Server 9091 ASM" runtime-id="Apache Tomcat v9.0" server-type="org.eclipse.jst.server.tomcat.90" server-type-id="org.eclipse.jst.server.tomcat.90" start-timeout="9000" stop-timeout="30" testEnvironment="true" timestamp="4">
<list key="modules" value0="adsuite-market::org.eclipse.jst.j2ee.server:adsuite-market::jst.web::2.4"/>
and restarted Eclipse. Then it worked as normal again.

what's the "correct" practive for designing the interface for this REST web service?

I'm building a REST web service to manage customers and customer orders.
I'm using Eclipse 3.4 with JAX-RS (Apache Wink 1.0) on WebSphere 7.
I have a web project defined in web.xml like so ...
<servlet>
<servlet-name>JAX-RS Servlet</servlet-name>
<servlet-class>org.apache....RestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.mydomain.ws.CustomerWS</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>JAX-RS Servlet</servlet-name>
<url-pattern>/ws/*</url-pattern>
</servlet-mapping>
/***/
</servlet>
... which gives me a URL like http://.../ws/customers that returns all customers.
Now what I need to do is have something like http://.../ws/orders that returns all orders.
My questions are,
I want to add a second web service -- what do I add to the web.xml so that new web service is visible? or am I supposed to create a totally new web project for my second "orders" web service?
or any other ideas? Not sure how to design this "correctly".
Thanks, Rob
I'm not familiar with Wink, but assuming it's JAX-RS-compatible, you should not need any web.xml changes.
If your container is JAX-RS aware,
then annotating your 2nd class with #Path should automatically deploy it
else you can add that new resource class to your REST Application, e.g. based on the example you linked and speculating on your resource class names:
#Override
public Set<Class<?>> getClasses() {
Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(CustomersResource.class);
classes.add(OrdersResource.class);
return classes;
}