如何启用jax-rs 2 mvc

时间:2014-10-13 21:53:22

标签: tomcat7 jax-rs jersey-2.0

我正在为Jersey MVC苦苦挣扎但是在Tomcat 7中我的任何东西都不起作用。我在谷歌搜索但是我找不到任何对我有用的东西。我的jsp页面放在WEB-INF / protected /目录中,那个是我的代码:

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
     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">
<session-config>
    <session-timeout>
        5
    </session-timeout>
</session-config>
<filter>
    <filter-name>REST Service</filter-name>
    <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.onlinebook.servey.services.resources</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.provider.scanning.recursive</param-name>
        <param-value>false</param-value>
    </init-param>
    <init-param>
        <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.mvc.templateBasePath.jsp</param-name>
        <param-value>/WEB-INF/protected/</param-value>
    </init-param>
    <init-param>
        <param-name>jersey.config.server.provider.classnames</param-name>
        <param-value>org.glassfish.jersey.server.mvc.jsp.JspMvcFeature</param-value>
    </init-param>
    <init-param>
    <param-name>jersey.config.server.tracing</param-name>
    <param-value>ALL</param-value>
</init-param>
<init-param>
    <param-name>jersey.config.servlet.filter.staticContentRegex</param-name>
    <param-value>(/index.jsp)|(/(content|(WEB-INF/jsp))/.*)</param-value>
</init-param>
</filter>
<filter-mapping>
    <filter-name>REST Service</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<listener>
    <listener-class>org.jboss.weld.environment.servlet.Listener</listener-class>
</listener>

<resource-ref>
    <description>DB Connection</description>
    <res-ref-name>jdbc/onlineBookDS</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
    <res-auth>Container</res-auth>
</resource-ref>

<security-constraint>
    <display-name>Admin</display-name>
    <web-resource-collection>
        <web-resource-name>tomcat datasourcerealm administration</web-resource-name>
        <description/>
        <url-pattern>/protected/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>admin</role-name>
    </auth-constraint>
    <!--        <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>-->
</security-constraint>

<security-constraint>
    <display-name>User</display-name>
    <web-resource-collection>
        <web-resource-name>Online Book administration</web-resource-name>
        <description/>
        <url-pattern>/protected/*</url-pattern>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <description/>
        <role-name>user</role-name>
    </auth-constraint>
    <!--        <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>-->
</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <realm-name>jdbc-realm</realm-name>
    <form-login-config>
        <form-login-page>/signin.jsp</form-login-page>
        <form-error-page>/error.jsp</form-error-page>
    </form-login-config>
</login-config>
<security-role>
    <description/>
    <role-name>admin</role-name>
</security-role>
<security-role>
    <description/>
    <role-name>user</role-name>
</security-role>
<error-page>
    <error-code>403</error-code>
    <location>/access_denied.jsp</location>
</error-page>
</web-app>

我的REST服务:

@Path("userdata")
public class UserDataRestService {

@Inject
private AccessCodeBean accessCodeBean;
@Inject
UserDataBean userDataBean;

public UserDataRestService() {
}

@GET
public Viewable redirectTo() throws ServletException, IOException {
    return new Viewable("accessCodeEntry");
}
}

0 个答案:

没有答案