2016-12-19 15 views
0

ジャージー・フィルターを使用しています。
マイコードロジックAuthenticationFilter.javaに、承認ヘッダーが空の場合は、アクセス拒否エラーメッセージを返します。私は、エラーメッセージと、ステータス401を取得し、ヘッダジャージー・フィルター・サーバー・エラー

http://localhost:8080/JerseyDemos2/rest/pocservice 

を装着せずにURLを使用して、残りのクライアントツールを介してアプリケーションを打っています
初めて
「あなたはこのリソースにアクセスすることはできません」。これは正しいです。

私は2度目のtryugh rest clientツールをヒットしようとし、サーバは例外メッセージを返します。

私たちは二度目を打つとき、それはエラーを与えるのはなぜのTomcat 7.xのの両方でWindowsとLinux

を自分のアプリケーションを導入しました。 この

@Provider 
public class AuthenticationFilter implements javax.ws.rs.container.ContainerRequestFilter { 

@Context 
private ResourceInfo resourceInfo; 

private static final String AUTHORIZATION_PROPERTY = "Authorization"; 
private static final Response ACCESS_DENIED = Response.status(Response.Status.UNAUTHORIZED).entity("You cannot access this resource").build(); 

@Override 
public void filter(ContainerRequestContext requestContext) {  

     // Get request headers 
     final MultivaluedMap<String, String> headers = requestContext.getHeaders(); 

     // Fetch authorization header 
     final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY); 

     // If no authorization information present; block access 
     if (authorization == null || authorization.isEmpty()) { 
      requestContext.abortWith(ACCESS_DENIED); 
      return; 
     } 
    } 
} } 

エラーメッセージを解決する方法:

Dec 19, 2016 6:26:18 PM org.glassfish.jersey.server.ServerRuntime$Responder writeResponse 
SEVERE: An I/O error has occurred while writing a response message entity to the container output stream. 
java.lang.IllegalStateException: The output stream has already been closed. 
at org.glassfish.jersey.message.internal.CommittingOutputStream.setStreamProvider(CommittingOutputStream.java:147) 
at org.glassfish.jersey.message.internal.OutboundMessageContext.setStreamProvider(OutboundMessageContext.java:803) 
...... 

は私に事前に 感謝を助けてください。

+0

あなたのフィルタはリクエストを許可し、リクエストを 'rest/pocservice'に転送しています。 bussinessメソッドのコードを含めて、何が起こっているのかを確認してください – pedrofb

答えて

0

あなたは以前に書かれた回答を書き込もうとしています。完全なログは、どこで起こっているのかを示します。 httpresponseが使用/変更されたログとコードをアップロードします。

0

は、私は静的変数

private static final Response ACCESS_DENIED = Response.status(Response.Status.UNAUTHORIZED).entity("You cannot access this resource").build(); 

を削除し、私はローカル変数を宣言しました。今は正常に動作します。

@Provider 
public class AuthenticationFilter implements javax.ws.rs.container.ContainerRequestFilter { 

@Context 
private ResourceInfo resourceInfo; 

private static final String AUTHORIZATION_PROPERTY = "Authorization"; 

@Override 
public void filter(ContainerRequestContext requestContext) { 
Response ACCESS_DENIED = Response.status(Response.Status.UNAUTHORIZED).entity("You cannot access this resource").build(); 

    // Get request headers 
    final MultivaluedMap<String, String> headers = requestContext.getHeaders(); 

    // Fetch authorization header 
    final List<String> authorization = headers.get(AUTHORIZATION_PROPERTY); 

    // If no authorization information present; block access 
    if (authorization == null || authorization.isEmpty()) { 
     requestContext.abortWith(ACCESS_DENIED); 
     return; 
    } 
} 
} } 
関連する問題