0

Hello all i am new to this ibm web sphere and i have written an simple java code and exposed it as a restful.

Application class

public class WorkflowResourceApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
    Set<Class<?>> classes = new HashSet<Class<?>>();
    classes.add(LibraryServiceImpl.class);
    return classes;
}

}

Service

@Path("/books")
@Produces( MediaType.APPLICATION_JSON)
@Consumes( MediaType.APPLICATION_JSON)
public class LibraryServiceImpl implements LibraryService {

private LibraryDAO libDao = new LibraryImpl();

@Path("/getbooks")
@GET
public Response getBooks(@QueryParam("format") String format) throws SQLException {
    return Response.status(Status.OK).entity(new GenericEntity<List<Book>>(libDao.getAllBooks()) {
    }).status(Status.OK).build();

}

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<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">
<display-name>Library</display-name>
<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>com.library.nag.restful.application.WorkflowResourceApplication</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>JAX-RS Servlet</servlet-name>
    <url-pattern>/*</url-pattern>
</servlet-mapping>

Using apache wink as it is provided by default.No compilation errors.When i see the response in postman it error code 415 i.e unsupported mediatype.

Below is error in my IBM Business Integrator

00000121 RequestProces I org.apache.wink.server.internal.RequestProcessor logException The following error occurred during the invocation of the handlers chain: WebApplicationException (415 - Unsupported Media Type) with message 'null' while processing GET request

But the same project worked it in tomcat when i have deployed but not with websphere v8.5.5.On my research i found that following dependency should be added to my server.xml

 <application location="C:\myproject\target\myapp.war" type="war">
<classloader apiTypeVisibility="spec,ibm-api,api,third-party"/>

When i tried to add it to server.xml found at

${PROFILE_HOME}/config/cells/${CELL}/nodes/${NODE}/servers/${SERVER}/server.xml

My server dont even start.Where am i doing wrong.Please help me out

Thank you.

mark
  • 47
  • 9

2 Answers2

0

On the client side, do you make the call with an HTTP header "Accept=application/json" ?

titou10
  • 2,814
  • 1
  • 19
  • 42
0

You have to specifically use Content-Type: application/json, not just Accept.