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

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

本文整理了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

  1. /**
  2. * If client can accept text/html, always prefer it. WebKit-based browsers
  3. * claim to want application/xml, but we don't want to give it to them. See
  4. * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a>
  5. */
  6. public Variant getPreferredVariant() {
  7. boolean addExplicitTextHtmlPreference = false;
  8. for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) {
  9. if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) {
  10. mediaTypePreference.setQuality(Float.MAX_VALUE);
  11. addExplicitTextHtmlPreference = false;
  12. break;
  13. } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) {
  14. addExplicitTextHtmlPreference = true;
  15. }
  16. }
  17. if (addExplicitTextHtmlPreference) {
  18. List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes();
  19. acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE));
  20. getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes);
  21. }
  22. return super.getPreferredVariant();
  23. }

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

  1. /**
  2. * Returns the client-specific information.
  3. *
  4. * @return The client-specific information.
  5. */
  6. @Override
  7. public ClientInfo getClientInfo() {
  8. return getWrappedRequest().getClientInfo();
  9. }

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

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

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

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

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

  1. public static String findIP( Request request )
  2. {
  3. Form form = (Form) request.getAttributes().get( "org.restlet.http.headers" );
  4. String forwardedIP = getFirstForwardedIp( form.getFirstValue( FORWARD_HEADER ) );
  5. if ( forwardedIP != null )
  6. {
  7. return forwardedIP;
  8. }
  9. List<String> ipAddresses = request.getClientInfo().getAddresses();
  10. return resolveIp( ipAddresses );
  11. }

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

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

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

  1. @Override
  2. public ClientInfo getCurrentThreadClientInfo() {
  3. final Subject subject = SecurityUtils.getSubject();
  4. if (subject != null && subject.getPrincipal() != null) {
  5. final String userId = subject.getPrincipal().toString();
  6. final Request current = Request.getCurrent();
  7. if (current != null) {
  8. final String currentIp = RemoteIPFinder.findIP(current);
  9. final String currentUa = current.getClientInfo().getAgent();
  10. return new ClientInfo(userId, currentIp, currentUa);
  11. }
  12. else {
  13. // this is not HTTP processing thread at all
  14. return null;
  15. }
  16. }
  17. // we have no Shiro subject or "anonymous" user (from Shiro perspective, null principals
  18. return null;
  19. }
  20. }

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

  1. private Request makeRequest(Reference uri, MediaType accepts) {
  2. Request request = new Request();
  3. logger.debug("Making new request for " + uri + " -- " + uri.getTargetRef());
  4. request.setResourceRef(uri.getTargetRef());
  5. if (accepts != null) {
  6. request.getClientInfo().getAcceptedMediaTypes().add(
  7. new Preference<MediaType>(accepts));
  8. }
  9. if (baseURI.isParent(uri) && username != null) {
  10. logger.debug("Authenticating as " + username);
  11. ChallengeResponse challengeResponse =
  12. new ChallengeResponse(ChallengeScheme.HTTP_BASIC, username,
  13. password);
  14. request.setChallengeResponse(challengeResponse);
  15. } else {
  16. logger.warn("Not supplying credentials for out-of-site URI " + uri);
  17. }
  18. return request;
  19. }

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

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

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

  1. @Override
  2. public ClientInfo getCurrentThreadClientInfo()
  3. {
  4. final Subject subject = SecurityUtils.getSubject();
  5. if ( subject != null && subject.getPrincipal() != null )
  6. {
  7. final String userId = subject.getPrincipal().toString();
  8. final Request current = Request.getCurrent();
  9. if ( current != null )
  10. {
  11. final String currentIp = RemoteIPFinder.findIP( current );
  12. final String currentUa = current.getClientInfo().getAgent();
  13. return new ClientInfo( userId, currentIp, currentUa );
  14. }
  15. else
  16. {
  17. // this is not HTTP processing thread at all
  18. return null;
  19. }
  20. }
  21. // we have no Shiro subject or "anonymous" user (from Shiro perspective, null principals
  22. return null;
  23. }
  24. }

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

  1. /**
  2. * If client can accept text/html, always prefer it. WebKit-based browsers
  3. * claim to want application/xml, but we don't want to give it to them. See
  4. * <a href="https://webarchive.jira.com/browse/HER-1603">https://webarchive.jira.com/browse/HER-1603</a>
  5. */
  6. public Variant getPreferredVariant() {
  7. boolean addExplicitTextHtmlPreference = false;
  8. for (Preference<MediaType> mediaTypePreference: getRequest().getClientInfo().getAcceptedMediaTypes()) {
  9. if (mediaTypePreference.getMetadata().equals(MediaType.TEXT_HTML)) {
  10. mediaTypePreference.setQuality(Float.MAX_VALUE);
  11. addExplicitTextHtmlPreference = false;
  12. break;
  13. } else if (mediaTypePreference.getMetadata().includes(MediaType.TEXT_HTML)) {
  14. addExplicitTextHtmlPreference = true;
  15. }
  16. }
  17. if (addExplicitTextHtmlPreference) {
  18. List<Preference<MediaType>> acceptedMediaTypes = getRequest().getClientInfo().getAcceptedMediaTypes();
  19. acceptedMediaTypes.add(new Preference<MediaType>(MediaType.TEXT_HTML, Float.MAX_VALUE));
  20. getRequest().getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes);
  21. }
  22. return super.getPreferredVariant();
  23. }

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

  1. /**
  2. * Returns the preferred variant according to the client preferences
  3. * specified in the request.
  4. *
  5. * @return The preferred variant.
  6. */
  7. public Variant getPreferredVariant() {
  8. Variant result = null;
  9. final List<Variant> variants = getVariants();
  10. if ((variants != null) && (!variants.isEmpty())) {
  11. Language language = null;
  12. // Compute the preferred variant. Get the default language
  13. // preference from the Application (if any).
  14. final Application app = Application.getCurrent();
  15. if (app != null) {
  16. language = app.getMetadataService().getDefaultLanguage();
  17. }
  18. result = getRequest().getClientInfo().getPreferredVariant(variants,
  19. language);
  20. }
  21. return result;
  22. }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

相关文章