Question

Glassfish 4, very simple application. I'm using Kepler, created a dynamic Web service project using Glassfish 4 as the server, allowed Eclipse to generate web.xml and glassfish-web.xml. The context names is /calls.

Application

package com.deltacontractservices.calls.service;

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;

@ApplicationPath("/rest/*")
public class CallsApplication extends Application
{
    @Override
    public Set<Class<?>> getClasses()
    {
        final Set<Class<?>> classes = new HashSet<Class<?>>();

        classes.add(Controller.class);

        return classes;
    }
}

Resource

package com.deltacontractservices.calls.service;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

/**
 * This class implements a JAX-RS service controller for the Calls API
 */
@ApplicationScoped
@Path("/rest")
public class Controller
{

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String base()
    {
        return "Calls application default.";
    }

    @GET
    @Path("ping")
    @Produces(MediaType.TEXT_PLAIN)
    public String ping()
    {
        return "Calls application ping.";
    }
}

http: //localhost:8080/calls/rest produces "Calls application default". Good.

http: //localhost:8080/calls/rest/ produces 404.

http: //localhost:8080/calls/rest/ping produces 404.

I must be missing something obvious. Help please...

Was it helpful?

Solution

Well. I needed to do something like .../calls/rest/rest/ping. I duplicated "/rest" in the application and the resource. Changing the resource class to @Path("") responds correctly to /calls/rest/ and /calls/rest/ping but not /calls/rest (no trailing /) Also, changing the application @ApplicationPath("/rest") didn't seem to affect anything.

OTHER TIPS

Try to put in controller class first @path like this @Path"/". I am newbie in this staff. Bath you can try! Then the answer might be first method ind this class(in rest client type .../calls/rest). If you type request in rest client ../calls/rest/ping the answer could be produced from second method in the controller class. Bath I am not sure! Only try to help!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top