Jersey 1.9 RESTful服务资源库重新定义

时间:2017-05-11 14:44:01

标签: java web-services rest jersey weblogic11g

我们在WebLogic Server 11g(10.3.6.0)群集上部署了一个REST服务作为Web Archive。 以下屏幕截图显示了URL:

Settings for RESTServices 访问WADL(http://172.29.0.21:16200/cwe-rest/jersey/application.wadl)应将资源库显示为 http://172.29.0.21:16200/cwe-rest/jersey/但显示为http://wcpinternal.uk:80/cwe-rest/jersey/

在Web Archive中没有Java类扩展javax.ws.rs.core.Application,可以指定@ApplicationPath("override/the/base/uri")

完成WADL

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<application xmlns="http://wadl.dev.java.net/2009/02">
    <doc xmlns:jersey="http://jersey.java.net/" jersey:generatedBy="Jersey: 1.9 09/02/2011 11:17 AM"/>
    <grammars/>
    <resources base="http://wcpinternal.uk:80/cwe-rest/jersey/">
        <resource path="checkin">
            <resource path="/test">
                <method id="test" name="GET">
                    <response>
                        <representation mediaType="*/*"/>
                    </response>
                </method>
            </resource>
            <resource path="/doCheckinFilter">
                <method id="doCheckinFilter" name="POST">
                    <request>
                        <representation mediaType="application/json"/>
                    </request>
                    <response>
                        <representation mediaType="application/json"/>
                    </response>
                </method>
            </resource>
        </resource>
    </resources>
</application>

完整的web.xml

<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
  <filter>
    <filter-name>JpsFilter</filter-name>
    <filter-class>oracle.security.jps.ee.http.JpsFilter</filter-class>
    <init-param>
      <param-name>enable.anonymous</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>JpsFilter</filter-name>
    <url-pattern>/*</url-pattern>
    <dispatcher>FORWARD</dispatcher>
    <dispatcher>REQUEST</dispatcher>
    <dispatcher>INCLUDE</dispatcher>
  </filter-mapping>
  <servlet>
    <servlet-name>jersey</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>jersey</servlet-name>
    <url-pattern>/jersey/*</url-pattern>
  </servlet-mapping>
</web-app>

完成weblogic.xml

<?xml version = '1.0' encoding = 'windows-1252'?>
<weblogic-web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/weblogic-web-app http://www.bea.com/ns/weblogic/weblogic-web-app/1.0/weblogic-web-app.xsd" xmlns="http://www.bea.com/ns/weblogic/weblogic-web-app">
   <context-root>cwe-rest</context-root>
   <library-ref>
        <library-name>jax-rs</library-name>
        <specification-version>1.1</specification-version>
        <implementation-version>1.9</implementation-version>
        <exact-match>false</exact-match>
    </library-ref>
</weblogic-web-app>

这是如何实现的?任何见解都会有所帮助。

1 个答案:

答案 0 :(得分:0)

配置了web.xml中的url模式。

 <servlet-mapping>
    <servlet-name>jersey</servlet-name>
    <url-pattern>/jersey/*</url-pattern>
  </servlet-mapping>

从第一个请求的基本URL中提取wadl资源元素值。 例如。我有一个基于泽西的网络应用程序部署到localhost:7001。如果你试图访问wadl 然后基本网址是localhost:7001

1.重新部署您的应用,尝试使用您的计算机名称访问:端口,然后基本网址是计算机名称:端口。 希望它对你有所帮助。