我的TomEE Plume 7.0.2存在问题。
我已经创建了一个过滤器:
package com.gfp.rest.providers;
import java.io.IOException;
import javax.annotation.Priority;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.ext.Provider;
@PreMatching
@Provider
@Priority(value = 1)
public class AuthenticationFilter implements ContainerRequestFilter
{
public AuthenticationFilter()
{
System.out.println("AuthenticationFilter.AuthenticationFilter()");
}
@Override
public void filter(ContainerRequestContext requestContext) throws IOException
{
System.out.println("AuthenticationFilter.filter()");
String token = requestContext.getHeaderString("token");
ResponseBuilder responseBuilder = null;
Response response = null;
// check if token is empty
if (token.isEmpty()) {
responseBuilder = Response.serverError();
response = responseBuilder.status(Status.UNAUTHORIZED).build();
requestContext.abortWith(response);
}
}
}
这是我的Rest Application:
package com.gfp.rest;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
@ApplicationPath("api/v1")
public class RestApplication extends Application
{
}
问题是:过滤器似乎没有被调用。我已阅读了大量文档和许多其他帖子,我找不到任何解决方案。有什么特别的东西我错过了吗?
非常感谢!
答案 0 :(得分:0)
试试这个
<table id="mytable" class="table table-hover">
<thead>
<tr style="font-weight: bold">
<td>Item number
</td>
<td>Price EUR
</td>
</tr>
</thead>
<tbody>
<tr class="person">
<td>
<input type="text" name="fixed_name[0]" id="fixed_name_0" class="form-control emptythis" autocomplete="off" />
</td>
<td>
<input type="number" name="fixed_price[0]" id="fixed_price_0" class="form-control emptythis" autocomplete="off" />
</td>
</tr>
</tbody>
</table>
<div class="row">
<div class="col-md-3">
<button type="button" class="btn btn-success btn-block btn-lg" id="add">Add line
</button>
</div>
<div class="col-md-9">
<button type="submit" class="btn btn-primary btn-block btn-lg" id="searchinternal">Update
</button>
</div>
</div>
</form>
另外,您可能需要使用org.glassfish.jersey.servlet.ServletContainer作为web.xml中的servlet容器,用于Jersey 2.x.
答案 1 :(得分:0)
它取决于您的配置(我认为是openejb-jar.xml和系统属性),因为它应该开箱即用(https://github.com/apache/tomee/blob/41cb392c6e3dc63d6792eae88e90c33743255212/server/openejb-cxf-rs/src/test/java/org/apache/openejb/server/cxf/rs/CDIProviderContainerRequestFilterTest.java不再做任何事情)
另一种方法是在Rahul的回答中注册过滤器(但请不要做任何球衣相关的事情,因为TomEE没有使用球衣它会失败而且只是添加一团糟)或者只是在openejb-jar.xml中配置它。