当前位置: 首页>>代码示例>>Java>>正文


Java CacheDirective类代码示例

本文整理汇总了Java中org.restlet.data.CacheDirective的典型用法代码示例。如果您正苦于以下问题:Java CacheDirective类的具体用法?Java CacheDirective怎么用?Java CacheDirective使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CacheDirective类属于org.restlet.data包,在下文中一共展示了CacheDirective类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: configureRestForm

import org.restlet.data.CacheDirective; //导入依赖的package包/类
/**
 * Configures REST HTTP Request Forms.
 * 
 * @param message the HTTP message to setup
 * @return the message configured HTTP headers.
 */
@SuppressWarnings("unchecked")
public static Series<Header> configureRestForm(Message message) {
    ConcurrentMap<String, Object> attrs = message.getAttributes();
    Series<Header> headers = (Series<Header>) attrs.get(HEADERS_KEY);

    if (headers == null) {
        headers = new Series<Header>(Header.class);
        Series<Header> prev = (Series<Header>) attrs.putIfAbsent(HEADERS_KEY, headers);

        if (prev != null)
            headers = prev;
    }

    headers.add(ACCESS_CONTROL_ALLOW_ORIGIN, ALLOW_ALL_FROM_ORIGIN);
    message.getCacheDirectives().add(CacheDirective.noCache());
    return headers;
}
 
开发者ID:jpinho,项目名称:soaba,代码行数:24,代码来源:RestletServer.java

示例2: getPicture

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Get
public InputRepresentation getPicture() {
  if(authenticate() == false) return null;
  
  String userId = (String) getRequest().getAttributes().get("userId");
  if(userId == null) {
    throw new ActivitiException("No userId provided");
  }
  Picture picture = ActivitiUtil.getIdentityService().getUserPicture(userId);
  
  String contentType = picture.getMimeType();
  MediaType mediatType = MediaType.IMAGE_PNG;
  if(contentType != null) {
    if(contentType.contains(";")) {
      contentType = contentType.substring(0, contentType.indexOf(";"));
    }
    mediatType = MediaType.valueOf(contentType);
  }
  InputRepresentation output = new InputRepresentation(picture.getInputStream(), mediatType);
  getResponse().getCacheDirectives().add(CacheDirective.maxAge(28800));
  
  return output;
}
 
开发者ID:iotsap,项目名称:FiWare-Template-Handler,代码行数:24,代码来源:UserPictureResource.java

示例3: testServletWithCallback

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Test
public void testServletWithCallback() throws Exception {
    ContextResource contextResource = resource.getContextResource();
    BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes());
    OAuthCallbackState state = new OAuthCallbackState(crypter);
    resource.setStateCrypter(crypter);
    state.setRealCallbackUrl("http://www.example.com/callback");
    contextResource.getParameters().set("cs", state.getEncryptedState());
    contextResource.getRequest().setResourceRef("http://foo.com?cs=foo&bar=baz");
    replay();
    resource.doGet();
    verify();

    assertEquals(Status.REDIRECTION_FOUND, contextResource.getStatus());
    assertEquals(new Reference("http://www.example.com/callback?bar=baz"), contextResource.getResponse().getLocationRef());

    List<CacheDirective> cacheDirectives = contextResource.getResponse().getCacheDirectives();
    assertEquals(2, cacheDirectives.size());
    assertEquals("private", cacheDirectives.get(0).getName());
    assertEquals("max-age", cacheDirectives.get(1).getName());
    assertEquals("3600", cacheDirectives.get(1).getValue());

}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:24,代码来源:OAuthCallbackResourceTest.java

示例4: testServletWithCallback_noQueryParams

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Test
public void testServletWithCallback_noQueryParams() throws Exception {
    ContextResource contextResource = resource.getContextResource();
    BlobCrypter crypter = new BasicBlobCrypter("00000000000000000000".getBytes());
    OAuthCallbackState state = new OAuthCallbackState(crypter);
    resource.setStateCrypter(crypter);
    state.setRealCallbackUrl("http://www.example.com/callback");
    contextResource.getParameters().set("cs", state.getEncryptedState());
    contextResource.getRequest().setResourceRef("http://foo.com?cs=foo");
    replay();
    resource.doGet();
    verify();

    assertEquals(Status.REDIRECTION_FOUND, contextResource.getStatus());
    assertEquals(new Reference("http://www.example.com/callback"), contextResource.getResponse().getLocationRef());

    List<CacheDirective> cacheDirectives = contextResource.getResponse().getCacheDirectives();
    assertEquals(2, cacheDirectives.size());
    assertEquals("private", cacheDirectives.get(0).getName());
    assertEquals("max-age", cacheDirectives.get(1).getName());
    assertEquals("3600", cacheDirectives.get(1).getValue());
}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:23,代码来源:OAuthCallbackResourceTest.java

示例5: normalResponse

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Test
public void normalResponse() throws Exception {
    ContextResource contextResource = resource.getContextResource();
    resource.setRenderer(renderer);
    expect(renderer.render(isA(GadgetContext.class))).andReturn(RenderingResults.ok("working"));
    control.replay();

    resource.doGet();

    assertEquals(Status.SUCCESS_OK, contextResource.getStatus());

    List<CacheDirective> cacheDirectives = contextResource.getResponse().getCacheDirectives();
    assertEquals(2, cacheDirectives.size());
    assertEquals("private", cacheDirectives.get(0).getName());
    assertEquals("max-age", cacheDirectives.get(1).getName());
    assertEquals(String.valueOf(GadgetRenderingResource.DEFAULT_CACHE_TTL), cacheDirectives.get(1).getValue());

    assertEquals("working", contextResource.getText());
}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:20,代码来源:GadgetRenderingResourceTest.java

示例6: errorsPassedThrough

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Test
public void errorsPassedThrough() throws Exception {
    ContextResource contextResource = resource.getContextResource();

    resource.setRenderer(renderer);
    expect(renderer.render(isA(GadgetContext.class))).andReturn(RenderingResults.error("busted", HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    control.replay();

    resource.doGet();

    assertEquals(Status.SERVER_ERROR_INTERNAL, contextResource.getStatus());

    //        assertNull("Cache-Control header passed where it should not be.",
    //                recorder.getHeader("Cache-Control"));
    List<CacheDirective> cacheDirectives = contextResource.getResponse().getCacheDirectives();
    assertEquals(0, cacheDirectives.size());

    assertEquals("busted", contextResource.getText());

}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:21,代码来源:GadgetRenderingResourceTest.java

示例7: refreshParameter_specified

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Test
public void refreshParameter_specified() throws Exception {
    ContextResource contextResource = resource.getContextResource();
    resource.setRenderer(renderer);
    contextResource.getParameters().set("refresh", "1000");
    expect(renderer.render(isA(GadgetContext.class))).andReturn(RenderingResults.ok("working"));
    control.replay();
    resource.doGet();

    List<CacheDirective> cacheDirectives = contextResource.getResponse().getCacheDirectives();
    assertEquals(2, cacheDirectives.size());
    assertEquals("private", cacheDirectives.get(0).getName());
    assertEquals("max-age", cacheDirectives.get(1).getName());
    assertEquals("1000", cacheDirectives.get(1).getValue());

}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:17,代码来源:GadgetRenderingResourceTest.java

示例8: getMaxAge

import org.restlet.data.CacheDirective; //导入依赖的package包/类
/**
 * The "max-age" cache control header.
 * 
 * @return The max age in seconds, or -1 if not set
 * @see #setMaxAge(int)
 */
public int getMaxAge()
{
	for( CacheDirective cacheDirective : getResource().getResponse().getCacheDirectives() )
		if( cacheDirective.getName().equals( HeaderConstants.CACHE_MAX_AGE ) )
			return Integer.parseInt( cacheDirective.getValue() );

	return -1;
}
 
开发者ID:tliron,项目名称:prudence,代码行数:15,代码来源:ExecutionResourceConversationService.java

示例9: setMaxAge

import org.restlet.data.CacheDirective; //导入依赖的package包/类
/**
 * @param maxAge
 *        The max age in seconds, or -1 to explicitly set a "no-cache" cache
 *        control header
 * @see #getMaxAge()
 */
public void setMaxAge( int maxAge )
{
	for( Iterator<CacheDirective> i = getResource().getResponse().getCacheDirectives().iterator(); i.hasNext(); )
		if( i.next().getName().equals( HeaderConstants.CACHE_MAX_AGE ) )
			i.remove();

	if( maxAge != -1 )
		getResource().getResponse().getCacheDirectives().add( CacheDirective.maxAge( maxAge ) );
	else
		getResource().getResponse().getCacheDirectives().add( CacheDirective.noCache() );
}
 
开发者ID:tliron,项目名称:prudence,代码行数:18,代码来源:ExecutionResourceConversationService.java

示例10: afterHandle

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Override
protected void afterHandle( Request request, Response response )
{
	if( response.isEntityAvailable() )
	{
		MediaType mediaType = response.getEntity().getMediaType();
		Number maxAgeNumber = null;
		for( Map.Entry<MediaType, Number> entry : maxAgeForMediaType.entrySet() )
		{
			if( entry.getKey().includes( mediaType ) )
			{
				maxAgeNumber = entry.getValue();
				break;
			}
		}

		if( maxAgeNumber == null )
			maxAgeNumber = defaultMaxAge;

		int maxAge = maxAgeNumber.intValue();

		// Do nothing when negative
		if( maxAge < 0 )
			return;

		List<CacheDirective> cacheDirectives = response.getCacheDirectives();
		cacheDirectives.clear();
		if( maxAge == 0 )
			cacheDirectives.add( CacheDirective.noCache() );
		else
			cacheDirectives.add( CacheDirective.maxAge( maxAge ) );

		// Set expiration date accordingly
		response.getEntity().setExpirationDate( new Date( System.currentTimeMillis() + 1000L * maxAge ) );
	}
}
 
开发者ID:tliron,项目名称:prudence,代码行数:37,代码来源:CacheControlFilter.java

示例11: afterHandle

import org.restlet.data.CacheDirective; //导入依赖的package包/类
/**
 * Sets the HTTP Headers if request was successful
 */
protected void afterHandle(Request request, Response response) {
	super.afterHandle(request, response);
	if (response != null && response.getEntity() != null) {
		if (response.getStatus().equals(Status.SUCCESS_OK)) {
			final Calendar calendar = Calendar.getInstance();
			calendar.add(Calendar.YEAR, 1);
			response.getEntity().setExpirationDate(calendar.getTime());
			response.setCacheDirectives(new ArrayList<CacheDirective>());
			response.getCacheDirectives().add(CacheDirective.maxAge(31536000));
		}
	}
}
 
开发者ID:TomDemeranville,项目名称:orcid-update-java,代码行数:16,代码来源:CacheFilter.java

示例12: getAttachment

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Get
public InputRepresentation getAttachment() {
  if(authenticate() == false) return null;
  
  String attachmentId = (String) getRequest().getAttributes().get("attachmentId");
  
  if(attachmentId == null) {
    throw new ActivitiException("No attachment id provided");
  }

  Attachment attachment = ActivitiUtil.getTaskService().getAttachment(attachmentId);
  if(attachment == null) {
    throw new ActivitiException("No attachment found for " + attachmentId);
  }
  
  String contentType = attachment.getType();
  MediaType mediatType = MediaType.IMAGE_PNG;
  if(contentType != null) {
    if(contentType.contains(";")) {
      contentType = contentType.substring(0, contentType.indexOf(";"));
    }
    mediatType = MediaType.valueOf(contentType);
  }
  InputStream resource = ActivitiUtil.getTaskService().getAttachmentContent(attachmentId);
  InputRepresentation output = new InputRepresentation(resource, mediatType);
  getResponse().getCacheDirectives().add(CacheDirective.maxAge(28800));
  return output;
}
 
开发者ID:iotsap,项目名称:FiWare-Template-Handler,代码行数:29,代码来源:TaskAttachmentResource.java

示例13: renderWithTtl

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Test
public void renderWithTtl() throws Exception {
    resource.setRenderer(renderer);
    expect(renderer.render(isA(GadgetContext.class))).andReturn(RenderingResults.ok("working"));
    ContextResource contextResource = resource.getContextResource();
    contextResource.getParameters().set(Param.REFRESH.getKey(), "120");
    control.replay();
    resource.doGet();
    List<CacheDirective> cacheDirectives = contextResource.getResponse().getCacheDirectives();
    assertEquals(2, cacheDirectives.size());
    assertEquals("private", cacheDirectives.get(0).getName());
    assertEquals("max-age", cacheDirectives.get(1).getName());
    assertEquals("120", cacheDirectives.get(1).getValue());
}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:15,代码来源:GadgetRenderingResourceTest.java

示例14: renderWithBadTtl

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Test
public void renderWithBadTtl() throws Exception {
    resource.setRenderer(renderer);
    expect(renderer.render(isA(GadgetContext.class))).andReturn(RenderingResults.ok("working"));

    ContextResource contextResource = resource.getContextResource();
    contextResource.getParameters().set(Param.REFRESH.getKey(), "");
    control.replay();
    resource.doGet();
    List<CacheDirective> cacheDirectives = contextResource.getResponse().getCacheDirectives();
    assertEquals(2, cacheDirectives.size());
    assertEquals("private", cacheDirectives.get(0).getName());
    assertEquals("max-age", cacheDirectives.get(1).getName());
    assertEquals("300", cacheDirectives.get(1).getValue());
}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:16,代码来源:GadgetRenderingResourceTest.java

示例15: refreshParameter_default

import org.restlet.data.CacheDirective; //导入依赖的package包/类
@Test
public void refreshParameter_default() throws Exception {
    ContextResource contextResource = resource.getContextResource();
    resource.setRenderer(renderer);
    expect(renderer.render(isA(GadgetContext.class))).andReturn(RenderingResults.ok("working"));
    control.replay();
    resource.doGet();

    List<CacheDirective> cacheDirectives = contextResource.getResponse().getCacheDirectives();
    assertEquals(2, cacheDirectives.size());
    assertEquals("private", cacheDirectives.get(0).getName());
    assertEquals("max-age", cacheDirectives.get(1).getName());
    assertEquals("300", cacheDirectives.get(1).getValue());
}
 
开发者ID:devacfr,项目名称:spring-restlet,代码行数:15,代码来源:GadgetRenderingResourceTest.java


注:本文中的org.restlet.data.CacheDirective类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。