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

x33g5p2x  于2022-01-29 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(233)

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

Request.getClientInfo介绍

[英]Returns the client-specific information. Creates a new instance if no one has been set.
[中]返回特定于客户端的信息。如果未设置任何实例,则创建新实例。

代码示例

代码示例来源:origin: internetarchive/heritrix3

/**
 * If client can accept text/html, always prefer it. WebKit-based browsers
 * claim to want application/xml, but we don't want to give it to them. See
 * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a>
 */
public Variant getPreferredVariant() {
  boolean addExplicitTextHtmlPreference = false;
  for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) {
    if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) {
      mediaTypePreference.setQuality(Float.MAX_VALUE);
      addExplicitTextHtmlPreference = false;
      break;
    } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) {
      addExplicitTextHtmlPreference = true;
    }
  }
  
  if (addExplicitTextHtmlPreference) {
    List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes();
    acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE));
    getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes);
  }
  
  
  return super.getPreferredVariant();
}

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

/**
 * Returns the client-specific information.
 * 
 * @return The client-specific information.
 */
@Override
public ClientInfo getClientInfo() {
  return getWrappedRequest().getClientInfo();
}

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

/**
 * A beforeHandle will simply embed in request attributes a Nexus interface implemntor, depending on key used to
 * name it.
 */
protected int beforeHandle( Request request, Response response )
{
  String agentInfo = request.getClientInfo().getAgent() != null ? request
    .getClientInfo().getAgent().toLowerCase() : "unknown";
  // This solution was the only that came on my mind :)
  // should work only if client specified more then one "alternatives"
  if ( StringUtils.indexOfAny( agentInfo, new String[] { "mozilla", "firefox", "msie", "opera", "safari" } ) > -1
    && request.getClientInfo().getAcceptedMediaTypes().size() > 1 )
  {
    // overriding client preferences, since it is a browser to TEXT/HTML
    // doing this by adding text/html as firxt to accepted media types with quality 1
    request
      .getClientInfo().getAcceptedMediaTypes().add( 0, new Preference<MediaType>( MediaType.TEXT_HTML, 1 ) );
  }
  
  return CONTINUE;
}

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

List<String> clientAddresses = request.getClientInfo().getAddresses();
return request.getClientInfo().getAddress();

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

public static String findIP( Request request )
{
  Form form = (Form) request.getAttributes().get( "org.restlet.http.headers" );
  String forwardedIP = getFirstForwardedIp( form.getFirstValue( FORWARD_HEADER ) );
  if ( forwardedIP != null )
  {
    return forwardedIP;
  }
  List<String> ipAddresses = request.getClientInfo().getAddresses();
  return resolveIp( ipAddresses );
}

代码示例来源:origin: org.sonatype.nexus/nexus-rest-client-java

+ ( ( request != null ) ? request.getClientInfo().getAddress() : "?" ) );

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

@Override
 public ClientInfo getCurrentThreadClientInfo() {
  final Subject subject = SecurityUtils.getSubject();
  if (subject != null && subject.getPrincipal() != null) {
   final String userId = subject.getPrincipal().toString();

   final Request current = Request.getCurrent();
   if (current != null) {
    final String currentIp = RemoteIPFinder.findIP(current);
    final String currentUa = current.getClientInfo().getAgent();
    return new ClientInfo(userId, currentIp, currentUa);
   }
   else {
    // this is not HTTP processing thread at all
    return null;
   }
  }
  // we have no Shiro subject or "anonymous" user (from Shiro perspective, null principals
  return null;
 }
}

代码示例来源:origin: uk.org.mygrid.remotetaverna/taverna-rest-client

private Request makeRequest(Reference uri, MediaType accepts) {
  Request request = new Request();
  logger.debug("Making new request for " + uri + " -- " + uri.getTargetRef());
  request.setResourceRef(uri.getTargetRef());
  if (accepts != null) {
    request.getClientInfo().getAcceptedMediaTypes().add(
      new Preference<MediaType>(accepts));
  }
  if (baseURI.isParent(uri) && username != null) {
    logger.debug("Authenticating as " + username);
    ChallengeResponse challengeResponse =
      new ChallengeResponse(ChallengeScheme.HTTP_BASIC, username,
        password);
    request.setChallengeResponse(challengeResponse);
  } else {
    logger.warn("Not supplying credentials for out-of-site URI " + uri);
  }
  return request;
}

代码示例来源:origin: org.geowebcache/gwc-rest

void checkPosMediaType(Representation entity) throws GeoWebCacheException {
  String remoteAdr = getRequest().getClientInfo().getAddress();
  if (entity == null
      || ((!entity.getMediaType().includes(MediaType.APPLICATION_XML)) 
      &&  (!entity.getMediaType().includes(MediaType.APPLICATION_JSON)))) {
    String message = "Request from "+ remoteAdr + " did not specify MIME type"
        + " of the document posted. Please specify application/xml "
        + " or application/json";
    throw new GeoWebCacheException(message);
  } else {
    log.info("Received seed request from  " + remoteAdr);
  }
}

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

@Override
  public ClientInfo getCurrentThreadClientInfo()
  {
    final Subject subject = SecurityUtils.getSubject();
    if ( subject != null && subject.getPrincipal() != null )
    {
      final String userId = subject.getPrincipal().toString();

      final Request current = Request.getCurrent();
      if ( current != null )
      {
        final String currentIp = RemoteIPFinder.findIP( current );
        final String currentUa = current.getClientInfo().getAgent();
        return new ClientInfo( userId, currentIp, currentUa );
      }
      else
      {
        // this is not HTTP processing thread at all
        return null;
      }
    }
    // we have no Shiro subject or "anonymous" user (from Shiro perspective, null principals
    return null;
  }
}

代码示例来源:origin: org.archive.heritrix/heritrix-engine

/**
 * If client can accept text/html, always prefer it. WebKit-based browsers
 * claim to want application/xml, but we don't want to give it to them. See
 * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a>
 */
public Variant getPreferredVariant() {
  boolean addExplicitTextHtmlPreference = false;
  for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) {
    if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) {
      mediaTypePreference.setQuality(Float.MAX_VALUE);
      addExplicitTextHtmlPreference = false;
      break;
    } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) {
      addExplicitTextHtmlPreference = true;
    }
  }
  
  if (addExplicitTextHtmlPreference) {
    List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes();
    acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE));
    getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes);
  }
  
  
  return super.getPreferredVariant();
}

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

/**
 * Returns the preferred variant according to the client preferences
 * specified in the request.
 * 
 * @return The preferred variant.
 */
public Variant getPreferredVariant() {
  Variant result = null;
  final List<Variant> variants = getVariants();
  if ((variants != null) && (!variants.isEmpty())) {
    Language language = null;
    // Compute the preferred variant. Get the default language
    // preference from the Application (if any).
    final Application app = Application.getCurrent();
    if (app != null) {
      language = app.getMetadataService().getDefaultLanguage();
    }
    result = getRequest().getClientInfo().getPreferredVariant(variants,
        language);
  }
  return result;
}

代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-launcher

request.getClientInfo().getAcceptedMediaTypes().add(
  new Preference<MediaType>(representation.getMediaType()));

代码示例来源:origin: org.sonatype.nexus/nexus-test-utils

request.getClientInfo().getAcceptedMediaTypes().add(
  new Preference<MediaType>( representation.getMediaType() ) );

代码示例来源:origin: org.geoserver/rest

if ( df == null ) {
  accepts = getRequest().getClientInfo().getAcceptedMediaTypes();
  acceptsAll = accepts.isEmpty();
  for ( Iterator<Preference<MediaType>> i = accepts.iterator(); i.hasNext(); ) {

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

result.getRequestContext().put(AccessManager.REQUEST_USER, subject.getPrincipal().toString());
result.getRequestContext().put(AccessManager.REQUEST_AGENT, request.getClientInfo().getAgent());

代码示例来源:origin: org.sonatype.nexus/nexus-test-harness-base

request.getClientInfo().getAcceptedMediaTypes().
add(new Preference<MediaType>(representation.getMediaType()));

代码示例来源:origin: org.sonatype.nexus.plugins/nexus-restlet1x-plugin

result.getRequestContext().put(AccessManager.REQUEST_USER, subject.getPrincipal().toString());
result.getRequestContext().put(AccessManager.REQUEST_AGENT, request.getClientInfo().getAgent());

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

result.getRequestContext().put( AccessManager.REQUEST_AGENT, request.getClientInfo().getAgent() );

代码示例来源:origin: org.sonatype.nexus/nexus-rest-api

result.getRequestContext().put( AccessManager.REQUEST_AGENT, request.getClientInfo().getAgent() );

相关文章