コード例 #1
0
ファイル: VaryTest.java プロジェクト: tootedom/httpcache4j
 @Test
 public void acceptWithManyPreferencesShouldMatch() {
   HashMap<String, String> map = new HashMap<String, String>();
   map.put("Accept", "application/xml, application/json");
   vary = new Vary(map);
   Assert.assertFalse("Header names added", vary.isEmpty());
   Assert.assertEquals("Header names added", 1, vary.size());
   HTTPRequest request = new HTTPRequest(URI.create("no.uri"));
   request = request.addHeader("Accept", "application/xml");
   request = request.headers(new Headers());
   request =
       request.preferences(
           new Preferences()
               .addMIMEType(MIMEType.valueOf("application/xml"))
               .addMIMEType(MIMEType.valueOf("application/json")));
   Assert.assertTrue("request did not specify application/xml", vary.matches(request));
 }
コード例 #2
0
    public CacheItemHolder mapRow(ResultSet rs, Connection connection) throws SQLException {
      URI uri = URI.create(rs.getString("uri"));
      Vary vary = convertToVary(rs.getString("vary"));
      Blob blob = rs.getBlob("payload");

      Payload payload = null;
      if (blob != null && !rs.wasNull()) {
        payload =
            new InputStreamPayload(
                new ResultSetInputStream(rs, connection, blob.getBinaryStream()),
                MIMEType.valueOf(rs.getString("mimetype")));
      }
      Status status = Status.valueOf(rs.getInt("status"));
      Headers headers = convertToHeaders(rs.getString("headers"));
      DateTime cacheTime = new DateTime(rs.getTimestamp("cachetime").getTime());
      HTTPResponse response = new HTTPResponse(payload, status, headers);
      return new CacheItemHolder(uri, vary, new CacheItem(rewriteResponse(response), cacheTime));
    }