0

I am just trying out a sample rest service example. My rest service class is :

@Path("oauth")
public class OauthClass {

    private static Map<String, OauthBean> oAuthBeanMap = new HashMap<String, OauthBean>();

    static {

        OauthBean oAuthBean = new OauthBean();
        oAuthBean.setAccess_token(String.valueOf(Math.random()));
        oAuthBean.setToken_type("bearer");
        oAuthBean.setRefresh_token(String.valueOf(Math.random()));
        oAuthBean.setExpires_in("44517");
        oAuthBeanMap.put(oAuthBean.getToken_type(), oAuthBean);
    }

    @GET
    @Path("/token?client_id={clntID}")
    @Produces("application/json")
    public OauthBean getOAuthJSON(@PathParam("clntID") String clientID) {

        System.out.println(clientID + " Secret ");
        System.out.println("oAuthBeanMap.get(\"bearer\") :P " + oAuthBeanMap.get("bearer"));
        return oAuthBeanMap.get("bearer");
    }

}

Now when i trry to invoke this url :

http://localhost:7070/RESTfulWS/rest/oauth/token?client_id=clnt001

I get a 405 error.Method not allowed Below is my web.xml :

<?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" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
id="WebApp_ID" version="2.5">

 <display-name>RESTfulWS</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.eviac.blog.restws</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>

I am using jersey 1.18. What am i doing wrong? Looking forward tyo your solutions.

Roy
  • 1,187
  • 1
  • 20
  • 59
  • Reading through your code, I think you should write `@Path("/token")` instead of `@Path("/token?client_id={clntID}")`. But I'm not sure I would expect a 405 for that mistake. Later today I might be able to find some time to try it, in the meantime maybe you could try yourself. – lrnzcig Jan 19 '15 at 10:29
  • Thanks for the reply Irnzcig....Yes, I solved it, Used QueryParam instead of PathParam – Roy Jan 19 '15 at 11:14

1 Answers1

1

Reading through your code, I think you should write @Path("/token") instead of @Path("/token?client_id={clntID}").

Besides, as you yourself noted, you should use QueryParam instead of PathParam

lrnzcig
  • 3,374
  • 4
  • 33
  • 44