Harshit Bansal
Harshit Bansal

Reputation: 71

unable to test restful web service

I am creating a simple restful service and testing it using soapui. Everytime I am getting error : 500 : Internal server error. At server logs it shows class not found . Adding jars it starts conflicting. I think it is jar issue only but do not know exact jars.

web.xml :-

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>Service</display-name>
 <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>com.service</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>  
</web-app>

jars:-

com.springsource.org.objectweb.asm_2.2.3.jar
jersey-client.jar
jersey-core.jar
jersey-gf-server.jar

Java Code:-

package com.service;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

@Path("/cal/")
public class RestService {

    @GET
    @Path("/one/")
    @Produces("application/xml")
    public String sanction(){               
        return new Sanction().servesRequest();
    }
}

wadl path :- http://localhost:8090/Service/rest/application.wadl

I have tried changing jars, changing jersey servlet class name, eclipse, netbeans and many more but unable to get it on floor.

Upvotes: 1

Views: 123

Answers (1)

Harshit Bansal
Harshit Bansal

Reputation: 71

This was the jar issue. I was downloading jars from https://jersey.java.net/download.html which contains 3 folders namely api,ext,lib but I was not using all jars from these folders by mistake. I also had to change web.xml as these jars are for jersey2.19 so the new web.xml is like

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>Service</display-name>
 <servlet>
    <servlet-name>REST Web </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.service</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>REST Web </servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

</web-app>

Upvotes: 1

Related Questions