users@grizzly.java.net

Re: [Jersey] Re: Better example

From: Paul Sandoz <Paul.Sandoz_at_oracle.com>
Date: Thu, 26 Aug 2010 12:37:14 +0200

Thanks for sharing, including Grizzly list.

Paul.

On Aug 26, 2010, at 12:02 PM, lio wrote:

>
> Hello,
> I have solve partially your issue for my own need
> In fact i have not found an implementation of static server
> but i have write a base one very simple
>
>
> all detaisl are available on my page
> http://gadille.free.fr/doc/java/jersey/jersey.php
> http://gadille.free.fr/doc/java/jersey/jersey.php
> and code on my source forge
>
>
> ServletAdapter sa;
>
> GrizzlyWebServer ws = new GrizzlyWebServer(8080, contextPath);
>
> sa = new ServletAdapter();
> sa.addInitParameter("com.sun.jersey.config.property.packages",
> "com.gadille.services");
> sa.setContextPath("/jersey"); // obligatoir sinnon sert du 200 vide
> sa.setServletInstance(new ServletContainer());
> ws.addGrizzlyAdapter(sa, new String[] { "/jersey" });
>
> ws.addGrizzlyAdapter(new GrizzlyAdapter() {
> @SuppressWarnings("unchecked")
> @Override
> public void service(GrizzlyRequest request, GrizzlyResponse
> response) {
> try {
> String uri = request.getRequestURI();
> String urlContext = contextPath + uri;
> File file = new File(urlContext);
> if (file.isDirectory()) {
> file = new File(urlContext + "/index.html");
> }
> if (file.exists()) {
> FileReader fr = new FileReader(file);
> response.getWriter().println("Impleme bitdon de http");
> response.setContentType(MediaType.TEXT_HTML);
> BufferedReader br = new BufferedReader(fr);
> while (br.ready()) {
> response.getWriter().println(br.readLine());
> }
> } else {
> response.getWriter().println("404 connard");
> }
>
> } catch (IOException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> }
>
> }
> }, new String[] { "/" });
>
> ws.start();
>
> System.out.println("Grizzly start on port 8080 by jersey2");
> System.out.println("Attention grizzly ne sert pas du html mais que des
> servlette");
> System.out.println("use url: http://localhost:8080/Jersey1/WS/helloworld
> to
> get hello");
> System.out.println("hit enter to stop");
>
> Scanner sc = new Scanner(System.in);
> sc.nextLine();
>
> System.out.println("Grizzly stop");
> ws.stop();
>
>
> gadille.free.fr lionel
> --
> View this message in context: http://jersey.576304.n2.nabble.com/Better-example-tp5325966p5465002.html
> Sent from the Jersey mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>