将Web应用程序Http Request Web.xml与RESTful Web.xml相结合

时间:2017-01-03 11:20:03

标签: java web-services rest http google-app-engine

我正在构建一个GAE应用程序,我的规范要求我能够使用普通的http请求和RESTful来访问我的数据存储区。

所以正常的请求是

webURl/getSomething?format=json

的RESTful

webURL/Something/json

(非常简短的例子)

我使用Jersey进行RESTful实现。

我的问题是如何组合两个Web.xml以确保两个请求都有效?

标准web.xml -

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">

    <servlet>
        <servlet-name>GetSomething</servlet-name>
        <servlet-class>Servlets.GetSomething</servlet-class>
    </servlet>


    <servlet-mapping>
        <servlet-name>GetSomething</servlet-name>
        <url-pattern>/GetSomething</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>index.html</welcome-file>
    </welcome-file-list>
</web-app>

RESTful Jersey web.xml -

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>jersey.first</display-name>
 <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
     <!-- Register resources and providers under com.vogella.jersey.first package. -->
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>jersey.first</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

0 个答案:

没有答案