【发布时间】:2019-10-11 02:22:32
【问题描述】:
我有一个如下定义的 JAX-RS 服务,使用 Jersey,并部署在 WebLogic 12.2.1 上。它工作正常。
@Path("/Profile")
public class ProfileServices {
@POST
@Consumes(APPLICATION_JSON)
@Produces(APPLICATION_JSON)
@Path("{ServiceName}")
public Response service(@PathParam("ServiceName") String serviceName, String message) {
...
}
}
但是,当使用 HTTP OPTIONS 调用服务时,Jersey 返回了一个 WADL 以及响应标头 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>
如何防止 Jersey 退回此 WADL?我不想向用户透露泽西版本。我对响应状态和标题没问题,但我不想返回内容。如果不可以,可以不退球衣信息吗?
我正在使用 javax.ws.rs.core.Application 并且不需要 web.xml 来指定 servlet。
编辑
事实上,我在 Application 中重写了以下方法:
@Override
public Map<String, Object> getProperties() {
Map<String, Object> props = new HashMap<>();
props.put("jersey.config.server.wadl.disableWadl", true);
return props;
}
但是当我重新部署时,我得到了以下异常:
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)
...
【问题讨论】:
-
将属性
ServerProperties.WADL_FEATURE_DISABLE设置为true。在您的 Application 类中,覆盖public Map<String, Object> getProperties()并将属性放入地图中。如果您没有使用任何 Jersey 特定代码,请使用字符串jersey.config.server.wadl.disableWadl作为键而不是常量 -
嗨,保罗,我之前已经按照你的建议做了(见我上面的编辑),但我遇到了例外。
-
这个错误什么时候出现?
-
应用程序启动时。
标签: jersey jax-rs weblogic12c