简体   繁体   中英

Apache-CXF JAX-RS implementation not respecting proper @Path ordering

I have a JAX-RS webservice that looks like this:

@Path("/service")
public interface Service {
    @GET
    @Path("/{serviceId}")
    public Response getService(@PathParam("serviceId") String serviceId);

    @GET
    @Path("/{serviceId}/private")
    public Response getPrivateService(@PathParam("serviceId") String serviceId);

    @GET
    @Path("/other-thing")
    public Response getOtherThing(@CookieParam("cookieName") String cookieValue);
}

For some reason, GET /other-thing always invokes the first method with @Path("/{serviceId}") . Invoking GET /abc/private returns a 404 claiming there is no matching route. According to the spec, the path with the most matching literal characters should be selected, but it seems as if my routes are being completely ignored. How can I debug this?

Here is the log message from CXF:

No operation matching request path "/service/abc/private" is found, Relative Path: /abc/private, HTTP Method: GET, ContentType: */*, Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,. Please enable FINE/TRACE log level for more details.

I discovered the problem.

I have recently switch from Eclipse to IntelliJ. Eclipse's default behavior is to ignore any annotations when auto-generating interface method implementations. IntelliJ, on the other hand, keeps the annotations. Here is the different:

// In Eclipse
public class ServiceImplementation implements Service {
    public Response getService(String serviceId) {
        return null;
    }
}

// In IntelliJ
public class ServiceImplementation implements Service {
    // Note the @PathParam
    public Response getService(@PathParam("serviceId") String serviceId) {
        return null;
    }
}

The additional annotations in the implementation of the service causes path resolution to fail. Since I had implemented getService in Eclipse, it worked correctly, but the new methods implemented IntelliJ did not work until I removed the parameter annotation in the service implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM