0

I have a JAX-RS service defined like the below, using Jersey, and is deployed on WebLogic 12.2.1. It works fine.

@Path("/Profile")
public class ProfileServices {

    @POST
    @Consumes(APPLICATION_JSON)
    @Produces(APPLICATION_JSON)
    @Path("{ServiceName}")
    public Response service(@PathParam("ServiceName") String serviceName, String message) {
        ...
    }
}

However, when calling the service with HTTP OPTIONS, Jersey returned a WADL along with response header Allow: POST,OPTIONS.

<ns0:application xmlns:ns0="http://wadl.dev.java.net/2009/02">
   <ns0:doc ns1:generatedBy="Jersey: 2.22.4 2016-11-30 13:33:53" xmlns:ns1="http://jersey.java.net/"/>
   <ns0:grammars/>
   <ns0:resources base="https://xxx.xxx.xxx.xxx:nnnn/">
      <ns0:resource path="XXXXX">
         <ns0:method id="service" name="POST">
            <ns0:request>
               <ns0:representation mediaType="application/json"/>
            </ns0:request>
            <ns0:response>
               <ns0:representation mediaType="application/json"/>
            </ns0:response>
         </ns0:method>
      </ns0:resource>
   </ns0:resources>
</ns0:application>

How do I prevent Jersey from returning this WADL? I don't want to disclose the Jersey version to the user. I'm ok with the response status and headers, but I don't want to return the content. If it is not possible, can the Jersey information not be returned?

I am using javax.ws.rs.core.Application and do not require web.xml to specify the servlet.

EDIT

I had in fact override the following method in Application:

@Override
public Map<String, Object> getProperties() {
    Map<String, Object> props = new HashMap<>();
    props.put("jersey.config.server.wadl.disableWadl", true);
    return props;
}

But when I re-deployed, I got the following exception:

org.glassfish.hk2.api.UnsatisfiedDependencyException: There was no object available for injection at SystemInjecteeImpl(requiredType=WadlApplicationContext,parent=JaxRsMonitoringListener,qualifiers={},position=-1,optional=false,self=false,unqualified=null,1838803099)
    at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(ThreeThirtyResolver.java:75)
    at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:1012)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:1008)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:986)
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:617)
    at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:184)
    at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:350)
    at org.glassfish.jersey.server.ApplicationHandler$3.call(ApplicationHandler.java:347)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:255)
    at org.glassfish.jersey.server.ApplicationHandler.<init>(ApplicationHandler.java:347)
    at org.glassfish.jersey.servlet.WebComponent.<init>(WebComponent.java:392)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:177)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:369)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    ...
user3573403
  • 1,780
  • 5
  • 38
  • 64

1 Answers1

0

What worked for me was disabling it in /src/main/webapp/WEB-INF/web.xml like this:

<servlet>
  <servlet-name>REST</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>org.glassfish.jersey.jackson.JacksonFeature;
            org.glassfish.jersey.media.multipart.MultiPartFeature;
        </param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.your.packagedir</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.wadl.disableWadl</param-name>
        <param-value>true</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>