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


Java HttpRequest类代码示例

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


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

示例1: intercept

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
    ClientHttpRequestExecution execution) throws IOException {

  if (omegaContext.globalTxId() != null) {
    request.getHeaders().add(GLOBAL_TX_ID_KEY, omegaContext.globalTxId());
    request.getHeaders().add(LOCAL_TX_ID_KEY, omegaContext.localTxId());

    LOG.debug("Added {} {} and {} {} to request header",
        GLOBAL_TX_ID_KEY,
        omegaContext.globalTxId(),
        LOCAL_TX_ID_KEY,
        omegaContext.localTxId());
  }
  return execution.execute(request, body);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-saga,代码行数:17,代码来源:TransactionClientHttpRequestInterceptor.java

示例2: getTags

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Override
public Iterable<Tag> getTags(String urlTemplate, HttpRequest request, ClientHttpResponse response) 
{
	Tag uriTag = StringUtils.hasText(urlTemplate)? RestTemplateExchangeTags.uri(urlTemplate): RestTemplateExchangeTags.uri(request);
	
	
            
	return Arrays.asList(RestTemplateExchangeTags.method(request), uriTag,
			RestTemplateExchangeTags.status(response),
            RestTemplateExchangeTags.clientName(request),
            modelName(request),
            modelImage(request),
            modelVersion(request),
            projectName(),
            deploymentName(),
            deploymentVersion(),
            predictorName(),
            predictorVersion());
}
 
开发者ID:SeldonIO,项目名称:seldon-core,代码行数:20,代码来源:SeldonRestTemplateExchangeTagsProvider.java

示例3: EmptyBodyCheckingHttpInputMessage

import org.springframework.http.HttpRequest; //导入依赖的package包/类
public EmptyBodyCheckingHttpInputMessage(HttpInputMessage inputMessage) throws IOException {
	this.headers = inputMessage.getHeaders();
	InputStream inputStream = inputMessage.getBody();
	if (inputStream == null) {
		this.body = null;
	}
	else if (inputStream.markSupported()) {
		inputStream.mark(1);
		this.body = (inputStream.read() != -1 ? inputStream : null);
		inputStream.reset();
	}
	else {
		PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream);
		int b = pushbackInputStream.read();
		if (b == -1) {
			this.body = null;
		}
		else {
			this.body = pushbackInputStream;
			pushbackInputStream.unread(b);
		}
	}
	this.method = ((HttpRequest) inputMessage).getMethod();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:AbstractMessageConverterMethodArgumentResolver.java

示例4: fromHttpRequestResetsPortBeforeSettingIt

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Test
public void fromHttpRequestResetsPortBeforeSettingIt() throws Exception {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.addHeader("X-Forwarded-Proto", "https");
	request.addHeader("X-Forwarded-Host", "84.198.58.199");
	request.addHeader("X-Forwarded-Port", 443);
	request.setScheme("http");
	request.setServerName("example.com");
	request.setServerPort(80);
	request.setRequestURI("/rest/mobile/users/1");

	HttpRequest httpRequest = new ServletServerHttpRequest(request);
	UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();

	assertEquals("https", result.getScheme());
	assertEquals("84.198.58.199", result.getHost());
	assertEquals(-1, result.getPort());
	assertEquals("/rest/mobile/users/1", result.getPath());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:20,代码来源:UriComponentsBuilderTests.java

示例5: intercept

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
	throws IOException
{
	if (log.isDebugEnabled())
	{
		log.debug(String.format("Request: %s %s %s", request.getMethod(), request.getURI(),
			new String(body, getCharset(request))));
	}
	
	ClientHttpResponse response = execution.execute(request, body);
	
	if (log.isDebugEnabled())
	{
		log.debug(String.format("Response: %s %s", response.getStatusCode().value(),
			copyToString(response.getBody(), getCharset(response))));
	}
	
	return response;
}
 
开发者ID:markhobson,项目名称:spring-rest-template-logger,代码行数:21,代码来源:LoggingInterceptor.java

示例6: createSessionTemplate

import org.springframework.http.HttpRequest; //导入依赖的package包/类
private RestTemplate createSessionTemplate(VaultEndpoint endpoint,
                                           ClientHttpRequestFactory requestFactory) {

    RestTemplate restTemplate = UtilKt.createRestTemplate(endpoint, requestFactory);

    restTemplate.getInterceptors().add(new ClientHttpRequestInterceptor() {

        @Override
        public ClientHttpResponse intercept(HttpRequest request, byte[] body,
                                            ClientHttpRequestExecution execution) throws IOException {

            final VaultToken sessionToken = sessionManager.getSessionToken();
            if (sessionToken != null) {
                final String token = sessionToken.getToken();
                if (token != null) {
                    request.getHeaders().add(VaultHttpHeaders.VAULT_TOKEN, token);
                }
            }

            return execution.execute(request, body);
        }
    });

    return restTemplate;
}
 
开发者ID:JetBrains,项目名称:teamcity-hashicorp-vault-plugin,代码行数:26,代码来源:VaultTemplate.java

示例7: clientName

import org.springframework.http.HttpRequest; //导入依赖的package包/类
/**
 * Create a {@code clientName} {@code Tag} derived from the {@link URI#getHost host}
 * of the {@link HttpRequest#getURI() URI} of the given {@code request}.
 *
 * @param request the request
 * @return the clientName tag
 */
public static Tag clientName(HttpRequest request) {
    String host = request.getURI().getHost();
    if (host == null) {
        host = "none";
    }
    return Tag.of("clientName", host);
}
 
开发者ID:micrometer-metrics,项目名称:micrometer,代码行数:15,代码来源:RestTemplateExchangeTags.java

示例8: execute

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Override
public ClientHttpResponse execute(HttpRequest request, byte[] body) throws IOException {
	if (iterator.hasNext()) {
		ClientHttpRequestInterceptor nextInterceptor = iterator.next();
		return nextInterceptor.intercept(request, body, this);
	}
	else {
		ClientHttpRequest delegate = requestFactory.createRequest(request.getURI(), request.getMethod());

		delegate.getHeaders().putAll(request.getHeaders());

		if (body.length > 0) {
			StreamUtils.copy(body, delegate.getBody());
		}
		return delegate.execute();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:18,代码来源:InterceptingClientHttpRequest.java

示例9: setApiKey

import org.springframework.http.HttpRequest; //导入依赖的package包/类
/**
 * Sets the api key.
 *
 * @throws JsonParseException the json parse exception
 * @throws JsonMappingException the json mapping exception
 * @throws IOException Signals that an I/O exception has occurred.
 */
private void setApiKey() throws JsonParseException, JsonMappingException, IOException{
	ArrayList<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
	interceptors.add((HttpRequest request, byte[] body, ClientHttpRequestExecution execution) -> {
		if(body.length > 0) {
			body = addTokenInObject(body, new JsonNodeFormatter());
		}else{
			try {
				request = addTokenInURI(request);
			} catch (URISyntaxException e) {
				e.printStackTrace();
			}
		}
		return execution.execute(request, body);
	});
	this.restTemplate.setInterceptors(interceptors);
}
 
开发者ID:ac-silva,项目名称:desafio-pagarme,代码行数:24,代码来源:Client.java

示例10: shouldTransformHttpCallFromClientSideError

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Test
public void shouldTransformHttpCallFromClientSideError() throws Exception {
  String url = "https://ajax.googleapis.com/ajax/services/search/web?v=1.0";
  URI uri = create(url);
  String requestBody = "requestBody";
  HttpHeaders httpHeaders = new HttpHeaders();
  httpHeaders.put("Content-Type", Arrays.asList("application/json"));

  HttpRequest httpRequest = mock(HttpRequest.class);
  when(httpRequest.getMethod()).thenReturn(POST);
  when(httpRequest.getURI()).thenReturn(uri);
  when(httpRequest.getHeaders()).thenReturn(httpHeaders);

  IOException ioException = new UnknownHostException("Unable to connect");

  SpringHttpRequestTransformer transformer = new SpringHttpRequestTransformer();

  HttpCall httpCall = transformer.transform(httpRequest, toBytes(requestBody), ioException);

  assertThat(httpCall.getMethod(), is("POST"));
  assertThat(httpCall.getPayload(), is(requestBody));
  assertThat(httpCall.getUrl(), is(url));
  assertThat(httpCall.getRequestHeaders().size(), is(1));
  assertNotNull(httpCall.getRequestHeaders().get(CONTENT_TYPE));
  assertThat(httpCall.getError(), is("java.net.UnknownHostException: Unable to connect"));
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:27,代码来源:SpringHttpRequestTransformerTest.java

示例11: log

import org.springframework.http.HttpRequest; //导入依赖的package包/类
private void log(HttpRequest request, byte[] body, ClientHttpResponse response) throws IOException {
    //do logging
    String from = name;
    String to = request.getURI().
            toString().
            replace("http://", "").
            replace("http:// www.", "").
            replace("www.", "").
            replace("/", "%20").
            toLowerCase();

    System.out.println(from);
    System.out.println(to);

    restTemplate.postForObject("http://trace-callback-service/" + from + "/" + to, null, Object.class);
}
 
开发者ID:Clcanny,项目名称:MicroServiceDemo,代码行数:17,代码来源:LoggingRequestInterceptor.java

示例12: initFromRequest

import org.springframework.http.HttpRequest; //导入依赖的package包/类
/**
 * Initialize a builder with a scheme, host,and port (but not path and query).
 */
private static ServletUriComponentsBuilder initFromRequest(HttpServletRequest request) {
	HttpRequest httpRequest = new ServletServerHttpRequest(request);
	UriComponents uriComponents = UriComponentsBuilder.fromHttpRequest(httpRequest).build();
	String scheme = uriComponents.getScheme();
	String host = uriComponents.getHost();
	int port = uriComponents.getPort();

	ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder();
	builder.scheme(scheme);
	builder.host(host);
	if (("http".equals(scheme) && port != 80) || ("https".equals(scheme) && port != 443)) {
		builder.port(port);
	}
	return builder;
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ServletUriComponentsBuilder.java

示例13: fromRequestWithForwardedHostAndPort

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Test
public void fromRequestWithForwardedHostAndPort() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setScheme("http");
	request.setServerName("localhost");
	request.setServerPort(80);
	request.setRequestURI("/mvc-showcase");
	request.addHeader("X-Forwarded-Proto", "https");
	request.addHeader("X-Forwarded-Host", "84.198.58.199");
	request.addHeader("X-Forwarded-Port", "443");

	HttpRequest httpRequest = new ServletServerHttpRequest(request);
	UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();

	assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:ServletUriComponentsBuilderTests.java

示例14: fromHttpRequestWithForwardedHostWithForwardedScheme

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Test
public void fromHttpRequestWithForwardedHostWithForwardedScheme() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setScheme("http");
	request.setServerName("localhost");
	request.setServerPort(10080);
	request.addHeader("X-Forwarded-Host", "example.org");
	request.addHeader("X-Forwarded-Proto", "https");

	HttpRequest httpRequest = new ServletServerHttpRequest(request);
	UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();

	assertEquals("example.org", result.getHost());
	assertEquals("https", result.getScheme());
	assertEquals(-1, result.getPort());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:UriComponentsBuilderTests.java

示例15: fromHttpRequestWithForwardedProtoAndDefaultPort

import org.springframework.http.HttpRequest; //导入依赖的package包/类
@Test
public void fromHttpRequestWithForwardedProtoAndDefaultPort() {
	MockHttpServletRequest request = new MockHttpServletRequest();
	request.setScheme("http");
	request.setServerName("localhost");
	request.setServerPort(80);
	request.setRequestURI("/mvc-showcase");
	request.addHeader("X-Forwarded-Proto", "https");
	request.addHeader("X-Forwarded-Host", "84.198.58.199");
	request.addHeader("X-Forwarded-Port", "443");

	HttpRequest httpRequest = new ServletServerHttpRequest(request);
	UriComponents result = UriComponentsBuilder.fromHttpRequest(httpRequest).build();

	assertEquals("https://84.198.58.199/mvc-showcase", result.toString());
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:17,代码来源:UriComponentsBuilderTests.java


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