users@jersey.java.net

[Jersey] Re: Grizzly Jersey REST and static HTML

From: kevinb <kbrisso_at_gmail.com>
Date: Tue, 13 Dec 2011 09:14:35 -0800 (PST)

This worked, here is the full code I'm using. Hope I'm replying correct.
Thanks for everyone's help!


package com.frk.jerseyrestgrizzly;
import com.sun.jersey.api.container.grizzly2.GrizzlyWebContainerFactory;
import org.glassfish.grizzly.http.server.HttpServer;

import javax.ws.rs.core.UriBuilder;
import java.io.IOException;
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import org.glassfish.grizzly.http.server.StaticHttpHandler;


/**
 * Hello world!
 *
 */
public class App
{
    /**
     * @param args the command line arguments
     */
    private static URI getBaseURI() {
        return UriBuilder.fromUri("http://localhost/").port(8080).build();
    }

    public static final URI BASE_URI = getBaseURI();

    protected static HttpServer startServer() throws IOException {

        final Map<String, String> initParams = new HashMap<String,
String>();

        initParams.put("com.sun.jersey.config.property.packages",
                "com.test.jerseyrestgrizzly");

        System.out.println("Starting grizzly...");

        return GrizzlyWebContainerFactory.create(BASE_URI, initParams);

    }

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

        HttpServer httpServer = startServer();

        httpServer.getServerConfiguration().addHttpHandler(new
StaticHttpHandler("C:\\Projects\\JerseyRESTGrizzly\\test\\"),"/test");


        System.out.println(String.format("Jersey app started with WADL
available at "
                + "%sapplication.wadl\nTry out %shelloworld\nHit enter to
stop it...",
                BASE_URI, BASE_URI));
        System.in.read();

        httpServer.stop();

    }
}





On Mon, Dec 12, 2011 at 6:12 AM, Oleksiy Stashok-2 [via Jersey] <
ml-node+s576304n7086200h21_at_n2.nabble.com> wrote:

> Hi Kevin,
>
> pls. try something like this:
>
> httpServer.getServerConfiguration().addHttpHandler(new
> StaticHttpHandler(docRootFolder), path);
>
> where
> docRootFolder is a path in your local filesystem to the folder with
> static resources,
> path is context root the StaticHandler will be registered to.
>
>
> Hope this will help.
>
> WBR,
> Alexey.
>
> On 12/12/2011 10:56 AM, Pavel Bucek wrote:
>
> > Hi Kevin,
> >
> > please use [hidden email]<http://user/SendEmail.jtp?type=node&node=7086200&i=0>for grizzly related questions.
> >
> > (cc'd, you don't need to repost)
> >
> > Thanks,
> > Pavel
> >
> > On 12/9/11 11:02 PM, kevinb wrote:
> >> Hi All-
> >> I have this sample project running that uses Grizzly and Jersey. The
> >> project
> >> works and serves up a REST request. I was wondering how I can also
> >> serve up
> >> static HTML from this. I have done some searching on GOOGLE but have
> >> found
> >> very little.
> >>
> >> Here is a snippet of my code below
> >>
> >> public class App
> >> {
> >> /**
> >> * @param args the command line arguments
> >> */
> >> private static URI getBaseURI() {
> >> return
> >> UriBuilder.fromUri("http://localhost/").port(8080).build();
> >> }
> >>
> >> public static final URI BASE_URI = getBaseURI();
> >>
> >> protected static HttpServer startServer() throws IOException {
> >>
> >> final Map<String, String> initParams = new
> HashMap<String,
> >> String>();
> >>
> >> initParams.put("com.sun.jersey.config.property.packages",
> >> "com.mycompany.jerseyrestgrizzly");
> >>
> >> System.out.println("Starting grizzly...");
> >>
> >>
> >> return GrizzlyWebContainerFactory.create(BASE_URI,
> >> initParams);
> >>
> >> }
> >>
> >> public static void main(String[] args) throws IOException {
> >> HttpServer httpServer = startServer();
> >> System.out.println(String.format("Jersey app started
> >> with WADL
> >> available at "
> >> + "%sapplication.wadl\nTry out %shelloworld\nHit
> >> enter
> >> to stop it...",
> >> BASE_URI, BASE_URI));
> >> System.in.read();
> >> httpServer.stop();
> >> }
> >> }
> >>
> >> Thanks
> >> Kevin
> >>
> >>
> >>
> >>
> >> --
> >> View this message in context:
> >>
> http://jersey.576304.n2.nabble.com/Grizzly-Jersey-REST-and-static-HTML-tp7079979p7079979.html
> >> Sent from the Jersey mailing list archive at Nabble.com.
> >>
> >
>
>
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
> http://jersey.576304.n2.nabble.com/Grizzly-Jersey-REST-and-static-HTML-tp7079979p7086200.html
> To unsubscribe from Grizzly Jersey REST and static HTML, click here<http://jersey.576304.n2.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=7079979&code=a2JyaXNzb0BnbWFpbC5jb218NzA3OTk3OXwxNDUxMzY0MTcw>
> .
> NAML<http://jersey.576304.n2.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.InstantMailNamespace&breadcrumbs=instant+emails%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>


--
View this message in context: http://jersey.576304.n2.nabble.com/Grizzly-Jersey-REST-and-static-HTML-tp7079979p7090701.html
Sent from the Jersey mailing list archive at Nabble.com.