Example usage for org.springframework.http HttpHeaders USER_AGENT

List of usage examples for org.springframework.http HttpHeaders USER_AGENT

Introduction

In this page you can find the example usage for org.springframework.http HttpHeaders USER_AGENT.

Prototype

String USER_AGENT

To view the source code for org.springframework.http HttpHeaders USER_AGENT.

Click Source Link

Document

The HTTP User-Agent header field name.

Usage

From source file:com.google.cloud.servicebroker.awwvision.RedditScraper.java

@RequestMapping("/reddit")
String getRedditUrls(Model model, RestTemplate restTemplate) throws GeneralSecurityException {
    HttpHeaders headers = new HttpHeaders();
    headers.add(HttpHeaders.USER_AGENT, redditUserAgent);
    RedditResponse response = restTemplate
            .exchange(REDDIT_URL, HttpMethod.GET, new HttpEntity<String>(headers), RedditResponse.class)
            .getBody();/*w w w .j  a v  a2 s.co  m*/

    storeAndLabel(response);

    return "reddit";
}

From source file:io.spring.initializr.web.project.MainController.java

@RequestMapping(path = "/", produces = "text/plain")
public ResponseEntity<String> serviceCapabilitiesText(
        @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) String userAgent) {
    String appUrl = generateAppUrl();
    InitializrMetadata metadata = this.metadataProvider.get();

    BodyBuilder builder = ResponseEntity.ok().contentType(MediaType.TEXT_PLAIN);
    if (userAgent != null) {
        Agent agent = Agent.fromUserAgent(userAgent);
        if (agent != null) {
            if (AgentId.CURL.equals(agent.getId())) {
                String content = this.commandLineHelpGenerator.generateCurlCapabilities(metadata, appUrl);
                return builder.eTag(createUniqueId(content)).body(content);
            }/*ww  w  . j  a  v a2 s . c o  m*/
            if (AgentId.HTTPIE.equals(agent.getId())) {
                String content = this.commandLineHelpGenerator.generateHttpieCapabilities(metadata, appUrl);
                return builder.eTag(createUniqueId(content)).body(content);
            }
            if (AgentId.SPRING_BOOT_CLI.equals(agent.getId())) {
                String content = this.commandLineHelpGenerator.generateSpringBootCliCapabilities(metadata,
                        appUrl);
                return builder.eTag(createUniqueId(content)).body(content);
            }
        }
    }
    String content = this.commandLineHelpGenerator.generateGenericCapabilities(metadata, appUrl);
    return builder.eTag(createUniqueId(content)).body(content);
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Submit a new job./*from ww w  .j av a  2  s  .c  o m*/
 *
 * @param jobRequest         The job request information
 * @param clientHost         client host sending the request
 * @param userAgent          The user agent string
 * @param httpServletRequest The http servlet request
 * @return The submitted job
 * @throws GenieException For any error
 */
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public ResponseEntity<Void> submitJob(@Valid @RequestBody final JobRequest jobRequest,
        @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) final String clientHost,
        @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) final String userAgent,
        final HttpServletRequest httpServletRequest) throws GenieException {
    log.info("[submitJob] Called json method type to submit job: {}", jobRequest);
    this.submitJobWithoutAttachmentsRate.increment();
    return this.handleSubmitJob(jobRequest, null, clientHost, userAgent, httpServletRequest);
}

From source file:com.netflix.genie.web.controllers.JobRestController.java

/**
 * Submit a new job with attachments.//from  ww  w .  ja va 2s .  com
 *
 * @param jobRequest         The job request information
 * @param attachments        The attachments for the job
 * @param clientHost         client host sending the request
 * @param userAgent          The user agent string
 * @param httpServletRequest The http servlet request
 * @return The submitted job
 * @throws GenieException For any error
 */
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
@ResponseStatus(HttpStatus.ACCEPTED)
public ResponseEntity<Void> submitJob(@Valid @RequestPart("request") final JobRequest jobRequest,
        @RequestPart("attachment") final MultipartFile[] attachments,
        @RequestHeader(value = FORWARDED_FOR_HEADER, required = false) final String clientHost,
        @RequestHeader(value = HttpHeaders.USER_AGENT, required = false) final String userAgent,
        final HttpServletRequest httpServletRequest) throws GenieException {
    log.info("[submitJob] Called multipart method to submit job: {}", jobRequest);
    this.submitJobWithAttachmentsRate.increment();
    return this.handleSubmitJob(jobRequest, attachments, clientHost, userAgent, httpServletRequest);
}

From source file:de.appsolve.padelcampus.reporting.ErrorReporter.java

public void notify(Throwable ex) {
    boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString()
            .contains("jdwp");
    if (!isDebug) {
        if (ex != null && !IGNORED_EXCEPTION_CLASS_NAMES.contains(ex.getClass().getSimpleName())) {
            if (ex.getCause() == null
                    || !IGNORED_EXCEPTION_CLASS_NAMES.contains(ex.getCause().getClass().getSimpleName())) {
                try {
                    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder
                            .currentRequestAttributes();
                    //log all errors when we don't have a request context, e.g. for scheduled tasks etc
                    if (attr == null || attr.getRequest() == null) {
                        LOG.error(ex.getMessage(), ex);
                    } else {
                        //if we have a request context, ignore bot requests
                        String userAgent = attr.getRequest().getHeader(HttpHeaders.USER_AGENT);
                        if (!StringUtils.isEmpty(userAgent)
                                && !IGNORED_USER_AGENT_PATTERN.matcher(userAgent).matches()) {
                            bugsnag.notify(ex);
                        }//from   w ww  . j a  v  a2 s  .c o m
                    }
                } catch (IllegalStateException e) {
                    LOG.error(ex.getMessage(), ex);
                }

            }
        }
    }
}

From source file:org.apache.geode.management.internal.web.http.support.HttpRequester.java

void addHeaderValues(HttpHeaders headers) {
    // update the headers
    headers.add(HttpHeaders.USER_AGENT, USER_AGENT_HTTP_REQUEST_HEADER_VALUE);
    headers.setAccept(acceptableMediaTypes);

    if (this.securityProperties != null) {
        for (String key : securityProperties.stringPropertyNames()) {
            headers.add(key, securityProperties.getProperty(key));
        }//from   www.  ja  va 2 s. c om
    }
}

From source file:org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainer.java

private Predicate[] getCompressionPredicates(Compression compression) {
    List<Predicate> predicates = new ArrayList<Predicate>();
    predicates.add(Predicates.maxContentSize(compression.getMinResponseSize()));
    predicates.add(new CompressibleMimeTypePredicate(compression.getMimeTypes()));
    if (compression.getExcludedUserAgents() != null) {
        for (String agent : compression.getExcludedUserAgents()) {
            RequestHeaderAttribute agentHeader = new RequestHeaderAttribute(
                    new HttpString(HttpHeaders.USER_AGENT));
            predicates.add(Predicates.not(Predicates.regex(agentHeader, agent)));
        }//from w  w  w . j  a v  a2 s .  c o m
    }
    return predicates.toArray(new Predicate[predicates.size()]);
}