- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 JAX-RS 2.0 提供并受 RESTeasy 3.0.5Final 支持的 ContainerRequestFilter 在我的 Web 服务器中实现安全措施。我使用 JBoss 7.1.1 作为我的平台。
我将以下类添加到我的项目中:
@Provider
@Priority(Priorities.AUTHENTICATION)
public class ServiceInterceptor implements ContainerRequestFilter, ContainerResponseFilter {
@Override
public void filter(ContainerRequestContext arg0) throws IOException {
System.out.println("request filter");
}
@Override
public void filter(ContainerRequestContext arg0, ContainerResponseContext arg1) throws IOException {
System.out.println("response filter");
}
}
但是,当我尝试访问 RESTful API 时,这两个方法都没有被调用,例如:
@Path("/users")
@RequestScoped
public class UserRESTService {
@Inject
private UserRepository userRepository;
@GET
@DenyAll
@Produces(MediaType.APPLICATION_JSON)
public List<User> getAll() {
return userRepository.getAll();
}
}
我尝试在 web.xml 文件中添加 @Provider:
<context-param>
<param-name>resteasy.providers</param-name>
<param-value>com.package.my.rest.ServiceInterceptor</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.providers</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>resteasy.scan.resources</param-name>
<param-value>true</param-value>
</context-param>
我的 pom.xml 看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<!-- JBoss, Home of Professional Open Source Copyright 2013, Red Hat, Inc.
and/or its affiliates, and individual contributors by the @authors tag. See
the copyright.txt in the distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tellyo.uam</groupId>
<artifactId>uam</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>uam</name>
<description>A starter Java EE 6 webapp project for use on JBoss AS 7 / EAP 6, generated from the jboss-javaee6-webapp archetype</description>
<url>http://jboss.org/jbossas</url>
<licenses>
<license>
<name>Apache License, Version 2.0</name>
<distribution>repo</distribution>
<url>http://www.apache.org/licenses/LICENSE-2.0.html</url>
</license>
</licenses>
<properties>
<!-- Explicitly declaring the source encoding eliminates the following
message: -->
<!-- [WARNING] Using platform encoding (UTF-8 actually) to copy filtered
resources, i.e. build is platform dependent! -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- JBoss dependency versions -->
<version.jboss.maven.plugin>7.4.Final</version.jboss.maven.plugin>
<!-- Define the version of the JBoss BOMs we want to import to specify
tested stacks. -->
<version.jboss.bom>1.0.7.Final</version.jboss.bom>
<!-- Alternatively, comment out the above line, and un-comment the line
below to use version 1.0.4.Final-redhat-4 which is a release certified to
work with JBoss EAP 6. It requires you have access to the JBoss EAP 6 maven
repository. -->
<!-- <version.jboss.bom>1.0.4.Final-redhat-4</version.jboss.bom>> -->
<!-- other plugin versions -->
<version.surefire.plugin>2.10</version.surefire.plugin>
<version.war.plugin>2.1.1</version.war.plugin>
<!-- maven-compiler-plugin -->
<maven.compiler.target>1.6</maven.compiler.target>
<maven.compiler.source>1.6</maven.compiler.source>
</properties>
<dependencyManagement>
<dependencies>
<!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill
of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection)
of artifacts. We use this here so that we always get the correct versions
of artifacts. Here we use the jboss-javaee-6.0-with-tools stack (you can
read this as the JBoss stack of the Java EE 6 APIs, with some extras tools
for your project, such as Arquillian for testing) and the jboss-javaee-6.0-with-hibernate
stack you can read this as the JBoss stack of the Java EE 6 APIs, with extras
from the Hibernate family of projects) -->
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-hibernate</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- First declare the APIs we depend on and need for compilation. All
of them are provided by JBoss AS 7 -->
<!-- Import the CDI API, we use provided scope as the API is included in
JBoss AS 7 -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the Common Annotations API (JSR-250), we use provided scope
as the API is included in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.annotation</groupId>
<artifactId>jboss-annotations-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the JPA API, we use provided scope as the API is included in
JBoss AS 7 -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<scope>provided</scope>
</dependency>
<!-- Import the EJB API, we use provided scope as the API is included in
JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- JSR-303 (Bean Validation) Implementation -->
<!-- Provides portable constraints such as @Email -->
<!-- Hibernate Validator is shipped in JBoss AS 7 -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>jaxrs-api</artifactId>
<version>3.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.5.Final</version>
<scope>provided</scope>
</dependency>
<!-- JAXB support -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.5.Final</version>
<scope>compile</scope>
</dependency>
<!-- multipart/form-data and multipart/mixed support -->
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
<version>3.0.5.Final</version>
<scope>compile</scope>
</dependency>
<!-- Import the JSF API, we use provided scope as the API is included in
JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.faces</groupId>
<artifactId>jboss-jsf-api_2.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<!-- Now we declare any tools needed -->
<!-- Annotation processor to generate the JPA 2.0 metamodel classes for
typesafe criteria queries -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<scope>provided</scope>
</dependency>
<!-- Annotation processor that raising compilation errors whenever constraint
annotations are incorrectly used. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<scope>provided</scope>
</dependency>
<!-- Needed for running tests (you may also use TestNG) -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<!-- Optional, but highly recommended -->
<!-- Arquillian allows you to test enterprise code such as EJBs and Transactional(JTA)
JPA from JUnit/TestNG -->
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.11</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<!-- Maven will append the version to the finalName (which is the name
given to the generated war, and hence the context root) -->
<finalName>${project.artifactId}</finalName>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<!-- Java EE 6 doesn't require web.xml, Maven needs to catch up! -->
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<!-- The JBoss AS plugin deploys your war to a local JBoss AS container -->
<!-- To use, run: mvn package jboss-as:deploy -->
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<version>${version.jboss.maven.plugin}</version>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- The default profile skips all tests, though you can tune it to run
just unit tests based on a custom pattern -->
<!-- Seperate profiles are provided for running all tests, including Arquillian
tests that execute in the specified container -->
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${version.surefire.plugin}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests in your
JBoss AS instance -->
<!-- This profile will start a new JBoss AS instance, and execute the
test, shutting it down when done -->
<!-- Run with: mvn clean test -Parq-jbossas-managed -->
<id>arq-jbossas-managed</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-managed</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- An optional Arquillian testing profile that executes tests in a remote
JBoss AS instance -->
<!-- Run with: mvn clean test -Parq-jbossas-remote -->
<id>arq-jbossas-remote</id>
<dependencies>
<dependency>
<groupId>org.jboss.as</groupId>
<artifactId>jboss-as-arquillian-container-remote</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
<profile>
<!-- When built in OpenShift the 'openshift' profile will be used when
invoking mvn. -->
<!-- Use this profile for any OpenShift specific customization your app
will need. -->
<!-- By default that is to put the resulting archive into the 'deployments'
folder. -->
<!-- http://maven.apache.org/guides/mini/guide-building-for-different-environments.html -->
<id>openshift</id>
<build>
<plugins>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>${version.war.plugin}</version>
<configuration>
<outputDirectory>deployments</outputDirectory>
<warName>ROOT</warName>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
我从中删除了以下条目:
<!-- Import the JAX-RS API, we use provided scope as the API is included
in JBoss AS 7 -->
<dependency>
<groupId>org.jboss.spec.javax.ws.rs</groupId>
<artifactId>jboss-jaxrs-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
因为我知道 RESTeasy 包中提供了 JAX-RS API,而我需要的是 JAX-RS 2.0,其中包括 ContainerRequestFilter 和 ContainerResponseFilter 类。
我还缺少什么?为什么不调用过滤器?
最佳答案
正如我所怀疑的,JBoss 很困惑并且仍在部分使用旧的 RESTeasy 版本。解决方案是在 JBoss 中升级 RESTeasy,根据 RESTeasy 文档:
3.1。在 JBoss AS 7 中升级 Resteasy
Resteasy 与 JBoss AS 7 捆绑在一起。您可能需要在 AS7 中升级 Resteasy。 Resteasy 发行版附带一个名为 Resteasy-jboss-modules-3.0.5.Final.zip 的 zip 文件。将该文件解压缩到 JBoss AS7 发行版的 module/目录中。这将覆盖那里的一些现有文件。
更新:这可能听起来很愚蠢,但 6 个月后我在尝试在 Wildfly 8 上部署 Web 应用程序时遇到了类似的问题。这一次,我忘记将 SecurityInterceptor 添加到 JaxRsActivator 类中:
@ApplicationPath("/rest")
public class JaxRsActivator extends Application {
/* class body intentionally left blank */
@Override
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(RESTTest.class, SecurityInterceptor.class));
}
}
关于maven - RESTeasy Jboss 7.1.1 最终 ContainerRequestFilter @Provider 未调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19744745/
正在复制的问题是,当sew呈现登录页面时,然后我们继续执行身份验证,现在将我们重定向到网站的仪表板,此时我们继续关闭会话,并且在之前的交互中生成的这些cookie没有被删除。这个问题是重复性的,并且一
我是 Flutter 的新手,目前正在研究 DI。 我正在使用 flutter_bloc 和 provider 包。 flutter_bloc 附带一个 RepositoryProvider,我现在问
我是 Flutter 的新手,目前正在研究 DI。 我正在使用 flutter_bloc 和 provider 包。 flutter_bloc 附带一个 RepositoryProvider,我现在问
我正在使用 Angular2 开发一个应用程序。 我正在尝试在我的应用程序中使用 Reactive Forms,但我遇到了一些错误: 第一个错误是关于 NgControl 的,如下所示: No pro
最近很多用户在使用电脑的时候发现了wmi provider host进程占用内存比较大,不知道这个进程到底是干什么的,能不能禁止,怎么禁止。下面来一起看看想想的介绍吧。 wmi provide
我的问题是: 当我在设计时不知道这些表达式的数量和类型时,如何将列表中的表达式拼接成一个引用? 在底部,我包含了类型提供程序的完整代码。 (我已经剥离了这个概念来证明这个问题。)我的问题出现在这些行:
我目前正在学习使用 Flutter 进行应用程序开发,并已开始学习 Provider 包。我遇到了一些困难并收到错误: “在此...小部件之上找不到正确的提供者” 我最终移动了 Provider 小部
我是 android 的新手,我正在学习如何使用 JavaMail API 发送电子邮件的教程,我已经正确添加了必要的 Jar,但我总是遇到无法解析 GmailSender 类上的符号提供程序,我尝试
我正在我的 Angular 应用程序中进行单元测试,我正在使用 TestBed 方法, 我正在测试组件,所以每个规范文件看起来像这样 import... describe('AppComponent'
enter image description here 代码:这是我的 index.js 文件 index.js import { Provider } from "react-redux"
Microsoft ASP.NET Universal Providers 1.1昨天与System.Web.Providers 1.2一起发布.在后面的 nuget 页面上声明:Legacy pac
在我的 Next js 项目中,我使用了 Next auth,其中 import {Provider} from 'next-auth/client' , 并包裹 在 _app.js 中。 但是,与此
当我在 View 模型中使用如下界面时 class MainViewModel @ViewModelInject constructor( private val trafficImagesR
更新 - 我实际上发现它是 Flutter Issue . 我有两个 Provider,一个是 EntriesProvider,另一个是 EntryProvider。我在创建条目时使用我的 Entry
function configure($provide, $injector) { $provide.provider("testservice", function () {
这真让我抓狂。我似乎无法弄清楚这有什么问题。 代码: public interface IMinutesCounter { void startTimer(); void stopTi
我在我的项目中玩 Dagger 2,然后我陷入了这个错误编译。-> Error:(18, 21) error: ....MyManager cannot be provided without an
我有一个 Resteasy 应用程序,它使用 Spring 并包含 ContainerRequestFilter 和 ContainerResponseFilter 实现,并用 @Provider 注
我正在尝试使用 Dagger2 设置一个新项目,我以前使用过 Dagger2,但现在我正在尝试自己从头开始设置它。我正在从我参与的 Kotlin 项目中获取示例,但无法像现在在 Kotlin 中一样为
我刚开始学习 dagger2,遇到了一个奇怪的问题,在我看来像是一个错误。这是模块: @Module public class SimpleModule { @Provides Coo
我是一名优秀的程序员,十分优秀!