jeudi 31 octobre 2019

Unable to test restful service

I am very new to Restful Services and I followed some guidelines given be the boss to make it. When I am using the URL to test it via browser, it shows not found. Console is not showing any error or exception (However, I removed almost 100 errors to reach this point), but still the result is same.

This is my directory structure

This is my RDRresource.java (Includes the service I want to test)

package org.uclab.IMP.rs.rdr;

import java.util.ArrayList;
import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.uclab.IMP.*;
import com.google.gson.Gson;

import org.uclab.IMP.datamodel.*;
import org.uclab.IMP.datamodel.RDR.*;
import org.uclab.IMP.datamodel.RDR.dataadapter.*;



/**
 * Facade for the Restful Web service to handle the data curation functions 
 */
@Path("rdr")
public class RDRresource {

    @Context
    private UriInfo context;

    /**
     * Creates a new instance of DataCurationResource
     */
    public RDRresource() {
    }

    private static final Logger logger = LoggerFactory.getLogger(RDRresource.class);
    /**
     * This function is using to get user by ID 
     * @param UserID
     * @return a list of object Users with "Error", "No Error" and new added ID
     */
    @GET
    @Produces("application/json")
    @Consumes("application/json")
    @Path("RetriveRules")
    public List<Rules> RetriveRules() {
        Rules objOuterRules = new Rules();
        List<Rules> objListRules = new  ArrayList<Rules>();
        try
        {
            objOuterRules.setRuleID(Long.parseLong("RuleID"));
            DataAccessInterface objDAInterface = new RuleDataAdapter();
            AbstractDataBridge objADBridge = new DatabaseStorage(objDAInterface);
            objListRules = objADBridge.RetriveRules();
            logger.info("Get all rules successfully, rules Details="+objOuterRules);
        }
        catch(Exception ex)
        {
            logger.info("Error in getting user");
        }
        return objListRules;
    }    

This is my web.xml file

<web-app id="WebApp_ID" version="2.4"
    xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>Restful Web Application</display-name>

    <servlet>
        <servlet-name>jersey-serlvet</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>org.uclab.IMP.rs.rdr</param-value>
        </init-param>


        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>jersey-serlvet</servlet-name>
        <url-pattern>/webresources/*</url-pattern>
    </servlet-mapping>

</web-app>

URL I am trying and result is here

I will be thankful if someone can guide me through.




Aucun commentaire:

Enregistrer un commentaire