This discussion is archived
0 Replies Latest reply: Sep 4, 2012 5:20 PM by 959962 RSS

Grizzly+Jersey Get Init or Context parameters from @Context ServletContext

959962 Newbie
Currently Being Moderated
Hi, I have also post the same question on StackOverflow but without answer.

I am new to Grizzly + Jersey and currently it works well. But I found I can not get the Init or Context parameters from @Context ServletContext. Below is my code.

public static void main( String[] args ) throws IOException
{

GrizzlyWebServer ws = new GrizzlyWebServer(9998);
ServletAdapter jAdapter = new ServletAdapter();
jAdapter.setContextPath("/api");
jAdapter.setServletInstance(new ServletContainer());
jAdapter.addInitParameter("com.sun.jersey.config.property.packages", "test.ui.controller");
jAdapter.addInitParameter("test1","test1");
jAdapter.addContextParameter("test2","test2");
ws.addGrizzlyAdapter(jAdapter, null);

ws.start();
System.out.println("Running... please press enter to stop the server.");

System.in.read();
ws.stop();

}

And I try to get the parameters from @Context like follow.

@Path("/home")
public class LoginController {
@GET
@Produces("text/html")
public String getIt(@Context HttpServletRequest req,@Context ServletContext context) {                     
System.out.println(context.getAttribute("test1"));
System.out.println(context.getAttribute("test2"));
System.out.println(context.getInitParameter("test1"));
System.out.println(context.getInitParameter("test2"));

return "hello";
}
}


But all my tries are failed. The outputs are null, null, null, null....
I am using Grizzly 1.9.51 and Jesery 1.13
Any help will be appreciated. Thanks at advance.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points