org.restlet.Request.getCookies()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(159)

本文整理了Java中org.restlet.Request.getCookies方法的一些代码示例,展示了Request.getCookies的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Request.getCookies方法的具体详情如下:
包路径:org.restlet.Request
类名称:Request
方法名:getCookies

Request.getCookies介绍

[英]Returns the modifiable series of cookies provided by the client. Creates a new instance if no one has been set.

Note that when used with HTTP connectors, this property maps to the "Cookie" header.
[中]返回客户端提供的可修改cookie系列。如果未设置任何实例,则创建新实例。
请注意,当与HTTP连接器一起使用时,此属性映射到“Cookie”头。

代码示例

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Sets the modifiable series of cookies provided by the client. Note that
 * when used with HTTP connectors, this property maps to the "Cookie"
 * header. This method clears the current series and adds all entries in the
 * parameter series.
 * 
 * @param cookies
 *            A series of cookies provided by the client.
 */
public void setCookies(Series<Cookie> cookies) {
  synchronized (getCookies()) {
    if (cookies != getCookies()) {
      if (getCookies() != null) {
        getCookies().clear();
      }
      if (cookies != null) {
        getCookies().addAll(cookies);
      }
    }
  }
}

代码示例来源:origin: DeviceConnect/DeviceConnect-Android

/**
 * Sets the modifiable series of cookies provided by the client. Note that
 * when used with HTTP connectors, this property maps to the "Cookie"
 * header. This method clears the current series and adds all entries in the
 * parameter series.
 * 
 * @param cookies
 *            A series of cookies provided by the client.
 */
public void setCookies(Series<Cookie> cookies) {
  synchronized (getCookies()) {
    if (cookies != getCookies()) {
      if (getCookies() != null) {
        getCookies().clear();
      }
      if (cookies != null) {
        getCookies().addAll(cookies);
      }
    }
  }
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Returns the cookies provided by the client.
 * 
 * @return The cookies provided by the client.
 */
@Override
public Series<Cookie> getCookies() {
  return getWrappedRequest().getCookies();
}

代码示例来源:origin: org.nuxeo/nuxeo-http-client

protected void setupCookies(Request request) {
  if (cookies != null) {
    request.getCookies().clear();
    for (Cookie cookie : cookies) {
      request.getCookies().add(cookie);
    }
  }
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs

/**
 * Get any cookies that accompanied the request.
 * 
 * @return a map of cookie name (String) to Cookie.
 * @see HttpHeaders#getCookies()
 */
public Map<String, Cookie> getCookies() {
  if (this.cookies == null) {
    final Map<String, Cookie> cookies = new HashMap<String, Cookie>();
    for (final org.restlet.data.Cookie rc : this.request.getCookies()) {
      final Cookie cookie = Converter.toJaxRsCookie(rc);
      cookies.put(cookie.getName(), cookie);
    }
    this.cookies = Collections.unmodifiableMap(cookies);
  }
  return this.cookies;
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Returns the modifiable series of cookies provided by the client. Creates
 * a new instance if no one has been set.
 * 
 * @return The cookies provided by the client.
 * @see Request#getCookies()
 */
public Series<Cookie> getCookies() {
  return getRequest() == null ? null : getRequest().getCookies();
}

代码示例来源:origin: DeviceConnect/DeviceConnect-Android

/**
 * Returns the modifiable series of cookies provided by the client. Creates
 * a new instance if no one has been set.
 * 
 * @return The cookies provided by the client.
 * @see Request#getCookies()
 */
public static Series<Cookie> getResourceCookies() {
  return getRequest() == null ? null : getRequest().getCookies();
}

代码示例来源:origin: org.restlet.osgi/org.restlet.ext.oauth

private void validateState(Request request, Form params) throws Exception {
  String sessionId = request.getCookies().getFirstValue("_state");
  String state = (String) getContext().getAttributes().get(sessionId);
  if (state != null && state.equals(params.getFirstValue(STATE))) {
    return;
  }
  // CSRF detected
  throw new Exception("The state does not match.");
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs

private void addCookieParam(Request request, String representationAsText,
    Annotation annotation) {
  Series<Cookie> cookies = request.getCookies();
  if (cookies == null) {
    cookies = new Series<Cookie>(Cookie.class);
  }
  cookies.add(new Cookie(((CookieParam) annotation).value(),
      representationAsText));
  request.setCookies(cookies);
}

代码示例来源:origin: org.restlet.osgi/org.restlet

/**
 * Returns the cookies provided by the client.
 * 
 * @return The cookies provided by the client.
 */
@Override
public Series<Cookie> getCookies() {
  Series<Cookie> result = super.getCookies();
  if (!this.cookiesAdded) {
    String cookieValues = getHttpCall().getRequestHeaders().getValues(
        HeaderConstants.HEADER_COOKIE);
    if (cookieValues != null) {
      new CookieReader(cookieValues).addValues(result);
    }
    this.cookiesAdded = true;
  }
  return result;
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

public static void main(String[] args) throws Exception {
  ClientResource mailClient = new ClientResource(
      "http://localhost:8111/accounts/chunkylover53/mails/123");
  mailClient.getRequest().getCookies()
      .add(new Cookie("Credentials", "chunkylover53=pwd"));
  Form form = new Form();
  form.add("subject", "Message to Jérôme");
  form.add("content", "Doh!\n\nAllo?");
  System.out.println(form.getWebRepresentation());
  mailClient.put(form).write(System.out);
}

代码示例来源:origin: com.github.ansell.restlet-utils/restlet-utils

/**
 * Restores credentials from the cookie named {@link #getCookieName()} if available. The usual
 * processing is the followed.
 */
@Override
protected boolean authenticate(final Request request, final Response response)
{
  // Restore credentials from the cookie
  final Cookie credentialsCookie = request.getCookies().getFirst(this.getCookieName());
  
  if(credentialsCookie != null)
  {
    ChallengeResponse credentials = this.parseCredentials(credentialsCookie.getValue());
    if(credentials == null)
    {
      response.getCookieSettings().removeAll(this.getCookieName());
    }
    else
    {
      request.setChallengeResponse(credentials);
    }
  }
  
  this.log.debug("Calling super.authenticate");
  return super.authenticate(request, response);
}

代码示例来源:origin: org.restlet.jee/org.restlet.ext.jaxrs

String cookieName = this.cookieParam.value();
Series<org.restlet.data.Cookie> cookies;
cookies = this.tlContext.get().getRequest().getCookies();

代码示例来源:origin: org.restlet.jse/org.restlet.example

mailClient.getRequest().getCookies()
    .add(new Cookie("Credentials", "scott=tiger"));

代码示例来源:origin: org.opencadc/cadc-auth-restlet

Series<Cookie> cookies = getRequest().getCookies();
log.debug("cookie count: " + cookies.size());
log.debug("principal count: " + principals.size());

代码示例来源:origin: org.restlet.osgi/org.restlet

Series<Cookie> cookies = request.getCookies();

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
protected void afterHandle(Request request, Response response) {
  super.afterHandle(request, response);
  Cookie cookie = request.getCookies().getFirst("Credentials");
  if (request.getClientInfo().isAuthenticated() && (cookie == null)) {
    String identifier = request.getChallengeResponse().getIdentifier();
    String secret = new String(request.getChallengeResponse()
        .getSecret());
    CookieSetting cookieSetting = new CookieSetting("Credentials",
        identifier + "=" + secret);
    cookieSetting.setAccessRestricted(true);
    cookieSetting.setPath("/");
    cookieSetting.setComment("Unsecured cookie based authentication");
    cookieSetting.setMaxAge(30);
    response.getCookieSettings().add(cookieSetting);
  }
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
protected void afterHandle(Request request, Response response) {
  super.afterHandle(request, response);
  Cookie cookie = request.getCookies().getFirst("Credentials");
  if (request.getClientInfo().isAuthenticated() && (cookie == null)) {
    String identifier = request.getChallengeResponse().getIdentifier();
    String secret = new String(request.getChallengeResponse()
        .getSecret());
    CookieSetting cookieSetting = new CookieSetting("Credentials",
        identifier + "=" + secret);
    cookieSetting.setAccessRestricted(true);
    cookieSetting.setPath("/");
    cookieSetting.setComment("Unsecured cookie based authentication");
    cookieSetting.setMaxAge(30);
    response.getCookieSettings().add(cookieSetting);
  }
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
protected int beforeHandle(Request request, Response response) {
  Cookie cookie = request.getCookies().getFirst("Credentials");
  if (cookie != null) {
    // Extract the challenge response from the cookie
    String[] credentials = cookie.getValue().split("=");
    if (credentials.length == 2) {
      String identifier = credentials[0];
      String secret = credentials[1];
      request.setChallengeResponse(new ChallengeResponse(
          ChallengeScheme.HTTP_COOKIE, identifier, secret));
    }
  } else if (Method.POST.equals(request.getMethod())
      && request.getResourceRef().getQueryAsForm().getFirst("login") != null) {
    // Intercepting a login form
    Form credentials = new Form(request.getEntity());
    String identifier = credentials.getFirstValue("identifier");
    String secret = credentials.getFirstValue("secret");
    request.setChallengeResponse(new ChallengeResponse(
        ChallengeScheme.HTTP_COOKIE, identifier, secret));
    // Continue call processing to return the target representation if
    // authentication is successful or a new login page
    request.setMethod(Method.GET);
  }
  return super.beforeHandle(request, response);
}

代码示例来源:origin: org.restlet.jse/org.restlet.example

@Override
protected int beforeHandle(Request request, Response response) {
  Cookie cookie = request.getCookies().getFirst("Credentials");
  if (cookie != null) {
    // Extract the challenge response from the cookie
    String[] credentials = cookie.getValue().split("=");
    if (credentials.length == 2) {
      String identifier = credentials[0];
      String secret = credentials[1];
      request.setChallengeResponse(new ChallengeResponse(
          ChallengeScheme.HTTP_COOKIE, identifier, secret));
    }
  } else if (Method.POST.equals(request.getMethod())
      && request.getResourceRef().getQueryAsForm().getFirst("login") != null) {
    // Intercepting a login form
    Form credentials = new Form(request.getEntity());
    String identifier = credentials.getFirstValue("identifier");
    String secret = credentials.getFirstValue("secret");
    request.setChallengeResponse(new ChallengeResponse(
        ChallengeScheme.HTTP_COOKIE, identifier, secret));
    // Continue call processing to return the target representation if
    // authentication is successful or a new login page
    request.setMethod(Method.GET);
  }
  return super.beforeHandle(request, response);
}

相关文章