0

I am trying to write a REST service using Jetty WebAppcontext, I have below code but I'm getting 503. Not sure what I'm missing.

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

        Server server = new Server(8081);

        HandlerCollection handlers=new HandlerCollection();

        String resourceBase = WebServer.class.getClassLoader().getResource(".").toString()+"../../src/main/webapp";
        WebAppContext webAppContext = new WebAppContext(resourceBase,"/");
        System.out.println(" resourceBase "+resourceBase);
        handlers.addHandler(webAppContext);
        server.setHandler(handlers);
        server.start();
        System.out.println("Started");
        server.join();

    }

Web.xml

<servlet>
        <servlet-name>Jersey</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.app.server.WebApplication</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Jersey</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>

WebApplication code

public class WebApplication extends ResourceConfig {

    public WebApplication(){

        System.out.println("initialized");
        register(JacksonJaxbJsonProvider.class);
        packages("com.app.rest.services");
    }

}

and the Service is

@Path("/get")
public class Get {

    private static final Logger logger = LogManager.getLogger(Get.class);
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String get() {

        return "Yes";
    }
}

When I make the call as http://localhost:8081/rest/get, I get 503. I have tried a lot but I still get the same error. Please let me know what I'm missing.

Thanks

Raj
  • 401
  • 6
  • 20
  • I tried accessing http://localhost:8081/index.html even this is not working – Raj Dec 18 '18 at 15:34
  • Hi All, I resolved this issue sharing answer here to help others. I added the Jetty logs as described here [https://stackoverflow.com/questions/9235809/how-to-enable-debug-level-logging-with-jetty-embedded] and then found the issue and fixed it as shown here [https://stackoverflow.com/questions/44088493/jersey-stopped-working-with-injectionmanagerfactory-not-found]. Now everything works fine. – Raj Dec 19 '18 at 15:16

0 Answers0