Using Jersey 2.5 on Websphere 8.X - web-services

I am using the following configurations for my Rest-WS application and it deploys/works well on WAS 7.x.
But when i deploy the same on WAS8.0, i get the following exception:
(java.lang.NoSuchMethodError:
javax/ws/rs/core/Application.getProperties()Ljava/util/Map)
I understand that WAS 8.X has a JAX-RS-1.0 runtime and since the 1.0 api interface does not have the Application::getProperties(), i get the exception above.
So how do i get my project to work on WAS 8.X. Any pointers would be much appreciated..
My current application configuration as below -
JAX-RS-2.0/JSR339
JERSEY 2.5
JACKSON 2.3
WEB.XML
<servlet>
<servlet-name>jersey-serlvet</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.packagename.resources.MyAppResourceConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
MyAppResourceConfig.java
public class MyAppResourceConfig extends ResourceConfig {
public MonitoringResourceConfig() {
// Registers JAX-RS Components
register(RequestContextFilter.class);
register(MyRestResource.class);
packages( "com.packagename");
}
}
MyRestResource.java contains #path definitions.
P.S - I tried setting the JVM property DisableIBMJAXRSEngine in WAS, but it doesn't help.

I'm having the same trouble with Jersey 2.6 and WAS 8.0.0.3. I tried changing the class loading policy to parent last (on both, web module and application) and putting the Jersey jars into the application. It solved that problem, but is too restricted for my context.

Related

unable to add additional APIs endpoint classes to GCP endpoints v2

I have started an Google cloud endpoints v2 project using the starter code provided by Google which exposes one API named "echo".
My aim is to add another exposed class (one class/api name per business module).
Once deployed, all calls to the new API are not generating a "NOT FOUND" error.
As a solution i have tried to look into the web.xml and did the below changes.
Initial WEB.XML version:
<!-- Route API method requests to the backend. -->
<servlet-mapping>
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/_ah/api/*</url-pattern>
</servlet-mapping>
I have added my new servlet and tried to add a new servlet mapping as below:
<servlet-mapping>
<servlet-name>EndpointsServlet</servlet-name>
<url-pattern>/_ah/api/echo/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UserEndpointsServlet</servlet-name>
<url-pattern>/_ah/api/user/*</url-pattern>
</servlet-mapping>
Now after adding the /echo/* to the initial servlet mapping, the ECHO working services stopped servicing, and the system still cannot invoke the new service.
Does anyone knows what i am doing wrong and what is the solution?
I don't think this feature is not supported by the endpoints v2 framework since it does seem a good design practice to do this separation.
You should use the same servlet, using an init-param with all of the Endpoint classes you need:
<init-param>
<param-name>services</param-name>
<param-value>com.example.echo.Echo,com.example.echo.Echo2</param-value>
</init-param>
You should not use /_ah/api/echo/* or /_ah/api/user/* in your web.xml. Instead, use #Api(name = "echo") or #Api(name = "user") and bind EndpointsServlet to /_ah/api/*.

RESTful web service with apache cxf

I've already developed a SOAP web service in Java with apache cxf and now I've to develop the same services in RESTful.
I have some troubles to deploy the web service on my tomcat. In fact, I don't know how should I configure my web.xml or any other XML file.
There are many examples online but everything I've tried so far doesn't work.
To build the project, I use an Ant build tool.
Anyone knows some good tips?
Here my service class used to test tutorials
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
#Path("/book")
public class BookService {
#GET
#Path("{id}")
#Produces({"application/xml","application/json"})
public Book getBookForId(#PathParam("id") int id) {
Book book = null
book = DB.getBookForId();
if(book == null){
return Response.status(Response.Status.BAD_REQUEST).build();
}else{
return Response.ok(book).build();
}
}
}
And my web.xml looks like this most of the time :
<?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"
version="3.0">
<display-name>REST</display-name>
<servlet>
<servlet-name>Jersey Web Application</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>Jersey Web Application</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
Apache CXF's example and other examples are "easy" to understand but the fast is that what i've done until now won't work.
My web service is deployed on my tomcat but everytime there is error like this :
Servlet.service() for servlet [Jersey Web Application] in context with path [/WebServices] threw exception [L''exécution de la servlet a lancé une exception] with root cause
java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri(Ljava/lang/String;)Ljavax/ws/rs/core/UriBuilder;
at javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:119)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:669)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
I know that this kind of error are stupid btu i don't get it Zzz.
I have to use jdk 1.6.0.45 so i can't try example which use jdk 1.7 and higher version. The fact is most of example tell to use Jersey 2.18...

PrimeFaces push with AWS

I am using PrimeFaces 5.0 and tomcat 7 and my application is in AWS.
I am trying to use PrimeFaces push. I have implemented a sample application and it is working with my local system. If i deploy the code to AWS it fails.
Xhtml code
<p:socket onMessage="jsFunctionToCall" channel="/service/push"/>
Web.xml
<filter>
<filter-name>shiroFilter</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
<init-param>
<param-name>targetFilterLifecycle</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>org.atmosphere.cpr.AtmosphereInterceptor</param-name>
<param-value>org.atmosphere.interceptor.ShiroInterceptor</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>shiroFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>Push Servlet</servlet-name>
<servlet-class>org.primefaces.push.PushServlet</servlet-class>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>Push Servlet</servlet-name>
<url-pattern>/primepush/*</url-pattern>
</servlet-mapping>
Java code
#PushEndpoint("/service/push")
public class ServicePushResource {
#OnMessage(encoders = {JSONEncoder.class})
public String onMessage(String count) {
return count;
}
}
Pushing message:
EventBus eventBus = EventBusFactory.getDefault().eventBus();
eventBus.publish("/service/push", String.valueOf("msg"));
I am getting the error message that
WebSocket connection to 'ws://example.com/primepush/service/push?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.4-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true' failed: Error during WebSocket handshake: Unexpected response code: 501
After this error there is another error message that
Websocket failed. Downgrading to Comet and resending push.js.xhtml?ln=primefaces&v=5.1:1
Failed to load resource: the server responded with a status of 501 (Not Implemented) http://example.com/primepush/service/push?X-Atmos…ng&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true&_=1422008343786
On inspecting both the error message, I found that the p:socket component is failing with transport as 'WebSocket' and it is trying with 'long-polling' which is not implemented. So my question is whether AWS support 'WebSocket' if not what is the workaround for that?
Currently WebSocket is not supported with AWS. The work aroud is to use AWS EB loadbalancer with TCP/SSL. I did this by changing the protocol from HTTP to TCP in loadbalancer configuration. But this won't work alone, need to tell beanstalk to communicate directly to tomcat in case of websocket. This can be done using a configuration file which can be added as specified in this post.
Documentation of Primefaces 5.0 says to use Atmosphere 2.1.3. I had had similar problem as you when I tried to use 2.2.x version. The current version I use is 2.1.4 and it works for me fine. Maybe you could try this also.
The other case is that firefox browser throws wss connection error (but primepush works anyway).
Please refer also to:
https://bugzilla.mozilla.org/show_bug.cgi?id=594502

Starting JAXWS servlet at root of the web context?

Is it possible to start JAXWS servlet at the roor of the web contex, so that the WSDL will be also accessible?
My context root, defined in application.xml is /myapp/webservice/v1 (the last part should be configurable in the deployment descriptor, and the web service should be available in web context root).
I've tried:
<servlet>
<display-name>WebService</display-name>
<servlet-name>WebService</servlet-name>
<servlet-class>my.package.WebServiceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>WebService</servlet-name>
<url-pattern></url-pattern>
</servlet-mapping>
The WebService answers under the address /myapp/webservice/v1, but when I type /myapp/webservice/v1?wsdl, it's converted into /myapp/webservice/v1/?wsdl, which doesn't return WSDL, but it tries to invoke the WebService itself, which answers: "Hello! This is an Axis2 Web Service!" (standard greeting when doing GET to WebService).
I've tried also with url pattern '.'. '' and '/' are not accepted (WebSphere).
When I use
<url-pattern>ws</url-pattern>
and
<welcome-file-list>
<welcome-file>ws</welcome-file>
</welcome-file-list>
the web service works, but the WSDL is available only on /myapp/webservice/v1/ws?wsdl, which makes the solution incompatibile with existing clients.
The reason behind is to create version as separate WARs, which can be then deployed independently or within EAR, and to make WebService address fully configurable, we need to make it accessible under the context root of the Web Module.
I don't know if the problems we are experiencing are WebSphere-specific or Axis-specific...

Spring with Apache Camel and Web services getting started

I am starting to try to figure out how to work with Apache Camel within a Spring framework. The first thing that I want to try to get a grasp on would be running simple web service calls over this but I have no idea where to start.
Right now all I have is a basic HelloWorld Spring project set up and am trying to figure out what needs to be configured Apache Camel wise and where to get started on creating a simple web service.
I have taken a look at the examples on the Apache site but I was hoping maybe someone here knew of a tutorial that was a basic start to finish of something like I am trying to do.
Thanks for any tips or help that you all have!
I really found this one useful once: http://camel.apache.org/spring-ws-example.html (and complete source code in the camel distribution).
There are multiple ways you can deal with web services with Camel. Either use the spring web services as in the example I mention, or use Apache CXF.
Spring Web services are really easy to get started with, compared to CXF. Although CXF is a more complete web service stack.
There are multiple Camel and CXF examples here:
http://camel.apache.org/examples.html
If you go with CXF, you may well benefit from actually learning a few "CXF only" examples before mixing with Camel.
There are essentially two ways to do web services, contract first start with a WSDL, then auto generate classes/interfaces. The other approach is code first - where the you start with java classes and then get an auto generated WSDL.
There are some rather good articles over here: http://cxf.apache.org/resources-and-articles.html
But to answer your question, I don't know of any good step-by-step tutorial on this matter. The examples in the links are really good though.
I had the same question, and I have found this article
Step by step introduction to Web services creation using CXF and Spring:
http://www.ibm.com/developerworks/webservices/library/ws-pojo-springcxf/index.html?ca=drs-
In short, there is four steps to create a web service
1 - Create a service endpoint interface (SEI) and define a method to
be exposed as a Web service.
package demo.order;
import javax.jws.WebService;
#WebService
public interface OrderProcess {
String processOrder(Order order);
}
2 - Create the implementation class and annotate it as a Web service.
package demo.order;
import javax.jws.WebService;
#WebService(endpointInterface = "demo.order.OrderProcess")
public class OrderProcessImpl implements OrderProcess {
public String processOrder(Order order) {
return order.validate();
}
}
3 - Create beans.xml and define the service class as a Spring bean
using a JAX-WS front end.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint
id="orderProcess"
implementor="demo.order.OrderProcessImpl"
address="/OrderProcess" />
</beans>
4 - Create web.xml to integrate Spring and CXF.
<web-app>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>WEB-INF/beans.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>CXFServlet</servlet-name>
<display-name>CXF Servlet</display-name>
<servlet-class>
org.apache.cxf.transport.servlet.CXFServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>CXFServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>