2016-06-22 9 views
2

1回目のリクエストでJSON応答を取得します。以降次の要求から私はServerResourceが正常に配線ルートの表現Restlet 200の代わりにHTTPステータスコード204を取得

org.restlet.engine.adapter.ServerAdapter commit 
WARNING: A response with an unavailable and potentially non empty entity was returned. Ignoring the entity for resource http://localhost:8888/xyz?abc=def 

Applicationクラス

@Override 
public Restlet createInboundRoot() { 
    router = new Router(getContext()); 
    CorsService corsService = new CorsService();   
    corsService.setAllowedOrigins(new HashSet<String>(Arrays.asList("http://example.com"))); 
    corsService.setAllowedCredentials(true); 
    getServices().add(corsService); 
    router.attach("/xyz", XYZ.class); 
} 

処理し、リターンサーバーリソースを返しているにもかかわらず、このログとHTTPステータスコード204を取得を開始しますJSON表現

public class XYZ extends ServerResource { 

    private static final Logger logger = Logger.getLogger("API:XyZ"); 

    @Get(":json") 
    public Representation handleGetRequest() { 
     .. 
     return API_RESPONSE_JSON_REPRESENTATION_SUCCESS; 
    } 
} 

答えて

0

応答を解放した後、表示状態availableをfに設定されていますその他。したがって、ServerResourceへのその後の呼び出しは、getResponseEntity().isAvailable()falseを返すので、handle()メソッドでは204に設定されていますが、表現を返します。 ServerResourceから

@Override 
public Representation handle() { 
     ... 
     } finally { 
      if (Status.CLIENT_ERROR_METHOD_NOT_ALLOWED.equals(getStatus())) { 
       updateAllowedMethods(); 
      } else if (Status.SUCCESS_OK.equals(getStatus()) 
        && (getResponseEntity() == null || !getResponseEntity() 
          .isAvailable())) { 
       getLogger() 
         .fine("A response with a 200 (Ok) status should have an entity. " 
           + "Changing the status to 204 (No content)."); 
       setStatus(Status.SUCCESS_NO_CONTENT); 
      } 
     } 
    } 
    return result; 
} 

SOLUTION

どちらの表現

を返す前に真に新しい表現を毎回またはsetAvailableを返します
関連する問題