Reputation: 1135
i am trying to fetch the request parameters from my url request for a REST Web Service. @Path is able to map the method. But QueryParam is unable to fetch the values from query parameters.
My Request Url is
192.168.20.147:8080/NestRestApi/rest/hello/ScripInfo/MACLEAN1-11365/nse_cm/531335
package Rest;
import com.omnesys.nest.classes.CNestQuotes;
import com.omnesys.nest.constants.NESTerror;
import java.io.IOException;
import java.util.Vector;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author maclean
*/
@Path("/hello")
public class ScripInfo {
/**
*
* @param AccountId
* @param Exch
* @param Symbol
* @return
* @throws ServletException
* @throws IOException
*/
@GET
@Path("/ScripInfo/{AccountId}/{exch}/{sym}")
@Produces(MediaType.APPLICATION_ATOM_XML)
public String getScripInfo(@QueryParam("AccountId") String AccountId,@QueryParam("exch") String Exch, @QueryParam("sym") String Symbol) throws ServletException, IOException
{
CNestQuotes oNestQuote = new CNestQuotes();
oNestQuote.sExchSeg=Exch;
oNestQuote.sLoginId=AccountId;
oNestQuote.sSymbol=Symbol;
HttpServletRequest request = null;
HttpServletResponse response = null;
request.setAttribute("QuoteStruct", oNestQuote);
RequestDispatcher dispatch =request.getServletContext().getRequestDispatcher("/NESTGetOMScripInfo") ;
dispatch.include(request, response);
Vector oResult = (Vector) request.getAttribute("NESToutObject");
if (oResult == null || oResult.size() == 0 || oResult.contains(NESTerror.BAD_INPUT) || oResult.contains(NESTerror.NO_DATA) || oResult.contains(NESTerror.MSG_FAILURE)) {
} else {
oNestQuote = (CNestQuotes) oResult.firstElement();
}
return null;
}
}
Upvotes: 0
Views: 345
Reputation: 1690
Instead of using QueryParam for AccountId, exch and sym you should use @PathParam.
In JAX-RS, you can use @PathParem to inject the value of URI parameter that defined in @Path expression, into Java method.
/users/Query?name=Nasruddin In above URI pattern, query parameter is "nanme=Nasruddin", and you can get the url value with @QueryParam("url")
Upvotes: 2
Reputation: 2528
The AccountId
, exch
and sym
are not query parameters but path parameters so instead of @QueryParam
use @PathParam
.
Upvotes: 4