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


Java HttpMessage类代码示例

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


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

示例1: serialize

import org.apache.http.HttpMessage; //导入依赖的package包/类
/**
 * Writes out the content of the given HTTP entity to the session output
 * buffer based on properties of the given HTTP message.
 *
 * @param outbuffer the output session buffer.
 * @param message the HTTP message.
 * @param entity the HTTP entity to be written out.
 * @throws HttpException in case of HTTP protocol violation.
 * @throws IOException in case of an I/O error.
 */
public void serialize(
        final SessionOutputBuffer outbuffer,
        final HttpMessage message,
        final HttpEntity entity) throws HttpException, IOException {
    if (outbuffer == null) {
        throw new IllegalArgumentException("Session output buffer may not be null");
    }
    if (message == null) {
        throw new IllegalArgumentException("HTTP message may not be null");
    }
    if (entity == null) {
        throw new IllegalArgumentException("HTTP entity may not be null");
    }
    OutputStream outstream = doSerialize(outbuffer, message);
    entity.writeTo(outstream);
    outstream.close();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:EntitySerializer.java

示例2: moveMIMEHeadersToHTTPHeader

import org.apache.http.HttpMessage; //导入依赖的package包/类
public static void moveMIMEHeadersToHTTPHeader (@Nonnull final MimeMessage aMimeMsg,
                                                @Nonnull final HttpMessage aHttpMsg) throws MessagingException
{
  ValueEnforcer.notNull (aMimeMsg, "MimeMsg");
  ValueEnforcer.notNull (aHttpMsg, "HttpMsg");

  // Move all mime headers to the HTTP request
  final Enumeration <Header> aEnum = aMimeMsg.getAllHeaders ();
  while (aEnum.hasMoreElements ())
  {
    final Header h = aEnum.nextElement ();
    // Make a single-line HTTP header value!
    aHttpMsg.addHeader (h.getName (), HttpHeaderMap.getUnifiedValue (h.getValue ()));

    // Remove from MIME message!
    aMimeMsg.removeHeader (h.getName ());
  }
}
 
开发者ID:phax,项目名称:ph-as4,代码行数:19,代码来源:MessageHelperMethods.java

示例3: completeRequest

import org.apache.http.HttpMessage; //导入依赖的package包/类
/** helper function to fill  the request with header entries .
 * */
private static HttpMessage completeRequest(HttpMessage request,
    List<NameValuePair> headerEntries){
  if (null == request){
    logger.error("unable to complete request as the passed request object is null");
    return request;
  }

  // dump all the header entries to the request.
  if (null != headerEntries && headerEntries.size() > 0){
    for (NameValuePair pair : headerEntries){
      request.addHeader(pair.getName(), pair.getValue());
    }
  }
  return request;
}
 
开发者ID:JasonBian,项目名称:azkaban,代码行数:18,代码来源:RestfulApiClient.java

示例4: setHeaders

import org.apache.http.HttpMessage; //导入依赖的package包/类
protected void setHeaders(final HttpMessage base, final String headers) throws IOException {
    try (BufferedReader reader = new BufferedReader(new StringReader(headers))) {
        String line = reader.readLine();
        while (line != null) {
            int colonIndex = line.indexOf(":");
            if (colonIndex > 0) {
                String headerName = line.substring(0, colonIndex);
                if (line.length() > colonIndex + 2) {
                    base.addHeader(headerName, line.substring(colonIndex + 1));
                } else {
                    base.addHeader(headerName, null);
                }
                line = reader.readLine();

            } else {
                throw new FlowableException(HTTP_TASK_REQUEST_HEADERS_INVALID);
            }
        }
    }
}
 
开发者ID:flowable,项目名称:flowable-engine,代码行数:21,代码来源:HttpActivityExecutor.java

示例5: generateViaHeader

import org.apache.http.HttpMessage; //导入依赖的package包/类
private String generateViaHeader(final HttpMessage msg) {

        final ProtocolVersion pv = msg.getProtocolVersion();
        final String existingEntry = viaHeaders.get(pv);
        if (existingEntry != null) {
            return existingEntry;
        }

        final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
        final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;

        String value;
        if ("http".equalsIgnoreCase(pv.getProtocol())) {
            value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getMajor(), pv.getMinor(),
                    release);
        } else {
            value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), pv.getMajor(),
                    pv.getMinor(), release);
        }
        viaHeaders.put(pv, value);

        return value;
    }
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:24,代码来源:CachingHttpClient.java

示例6: generateViaHeader

import org.apache.http.HttpMessage; //导入依赖的package包/类
private String generateViaHeader(final HttpMessage msg) {

        final ProtocolVersion pv = msg.getProtocolVersion();
        final String existingEntry = viaHeaders.get(pv);
        if (existingEntry != null) {
            return existingEntry;
        }

        final VersionInfo vi = VersionInfo.loadVersionInfo("org.apache.http.client", getClass().getClassLoader());
        final String release = (vi != null) ? vi.getRelease() : VersionInfo.UNAVAILABLE;

        String value;
        final int major = pv.getMajor();
        final int minor = pv.getMinor();
        if ("http".equalsIgnoreCase(pv.getProtocol())) {
            value = String.format("%d.%d localhost (Apache-HttpClient/%s (cache))", major, minor,
                    release);
        } else {
            value = String.format("%s/%d.%d localhost (Apache-HttpClient/%s (cache))", pv.getProtocol(), major,
                    minor, release);
        }
        viaHeaders.put(pv, value);

        return value;
    }
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:26,代码来源:CachingExec.java

示例7: addCMCHeaders

import org.apache.http.HttpMessage; //导入依赖的package包/类
/**
 * Helper method to set the HTTP headers required for all HTTP requests.
 *
 * @param httpMessage HTTP message
 */
private void addCMCHeaders(HttpMessage httpMessage) {
    // Set the Accepts and Content Type headers
    httpMessage.addHeader(HttpHeaders.ACCEPT, "application/json");
    httpMessage.addHeader(HttpHeaders.CONTENT_TYPE, "application/json");

    // Custom header for CSRF protection
    httpMessage.addHeader("X-Requested-By", "12345");

    // Add a user agent header
    httpMessage.addHeader("User-Agent", "cmc-java " + CMC_VERSION);

    // Set the basic authorization headers.
    String auth = accountID + ":" + authenticationToken;
    byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(StandardCharsets.US_ASCII));
    String authHeader = "Basic " + new String(encodedAuth, StandardCharsets.US_ASCII);
    httpMessage.addHeader(HttpHeaders.AUTHORIZATION, authHeader);
}
 
开发者ID:cloudmessagingcenter,项目名称:cmc-java,代码行数:23,代码来源:ApacheHttpClientDelegate.java

示例8: recordCookie

import org.apache.http.HttpMessage; //导入依赖的package包/类
protected void recordCookie(HttpMessage httpMessage, Trace trace) {
    org.apache.http.Header[] cookies = httpMessage.getHeaders("Cookie");
    for (org.apache.http.Header header : cookies) {
        final String value = header.getValue();
        if (StringUtils.hasLength(value)) {
            if (cookieSampler.isSampling()) {
                final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
                recorder.recordAttribute(AnnotationKey.HTTP_COOKIE, StringUtils.abbreviate(value, 1024));
            }

            // Can a cookie have 2 or more values?
            // PMD complains if we use break here
            return;
        }
    }
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:17,代码来源:HttpRequestExecutorExecuteMethodInterceptor.java

示例9: recordEntity

import org.apache.http.HttpMessage; //导入依赖的package包/类
protected void recordEntity(HttpMessage httpMessage, Trace trace) {
    if (httpMessage instanceof HttpEntityEnclosingRequest) {
        final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) httpMessage;
        try {
            final HttpEntity entity = entityRequest.getEntity();
            if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
                if (entitySampler.isSampling()) {
                    final String entityString = entityUtilsToString(entity, Charsets.UTF_8_NAME, 1024);
                    final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
                    recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityString);
                }
            }
        } catch (Exception e) {
            logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e);
        }
    }
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:18,代码来源:HttpRequestExecutorExecuteMethodInterceptor.java

示例10: recordEntity

import org.apache.http.HttpMessage; //导入依赖的package包/类
protected void recordEntity(HttpMessage httpMessage, SpanEventRecorder recorder) {
    if (httpMessage instanceof HttpEntityEnclosingRequest) {
        final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) httpMessage;
        try {
            final HttpEntity entity = entityRequest.getEntity();
            if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
                if (entitySampler.isSampling()) {
                    final String entityString = entityUtilsToString(entity, Charsets.UTF_8_NAME, 1024);
                    recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityString);
                }
            }
        } catch (Exception e) {
            logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e);
        }
    }
}
 
开发者ID:naver,项目名称:pinpoint,代码行数:17,代码来源:DefaultClientExchangeHandlerImplStartMethodInterceptor.java

示例11: getCoapOptionsContentTypeTest

import org.apache.http.HttpMessage; //导入依赖的package包/类
@Test
public final void getCoapOptionsContentTypeTest() {
	// create the message
	HttpMessage httpMessage = new BasicHttpRequest("get", "http://localhost");

	// create the header
	String headerName = "content-type";
	String headerValue = "text/plain";
	Header header = new BasicHeader(headerName, headerValue);
	httpMessage.addHeader(header);

	// translate the header
	List<Option> options = HttpTranslator.getCoapOptions(httpMessage.getAllHeaders());
	// the context-type should not be handled by this method
	assertTrue(options.isEmpty());
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:17,代码来源:HttpTranslatorTest.java

示例12: getCoapOptionsMaxAgeTest

import org.apache.http.HttpMessage; //导入依赖的package包/类
@Test
public final void getCoapOptionsMaxAgeTest() {
	// create the message
	HttpMessage httpMessage = new BasicHttpRequest("get", "http://localhost");

	// create the header
	String headerName = "cache-control";
	int maxAge = 25;
	String headerValue = "max-age=" + maxAge;
	Header header = new BasicHeader(headerName, headerValue);
	httpMessage.addHeader(header);

	// translate the header
	List<Option> options = HttpTranslator.getCoapOptions(httpMessage.getAllHeaders());
	assertFalse(options.isEmpty());
	assertTrue(options.size() == 1);

	// get the option list
	Message coapMessage = new GETRequest();
	coapMessage.setOptions(options);
	Option testedOption = coapMessage.getFirstOption(OptionNumberRegistry.MAX_AGE);
	assertNotNull(testedOption);
	assertEquals(maxAge, testedOption.getIntValue());
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:25,代码来源:HttpTranslatorTest.java

示例13: getCoapOptionsMaxAgeTest2

import org.apache.http.HttpMessage; //导入依赖的package包/类
@Test
public final void getCoapOptionsMaxAgeTest2() {
	// create the message
	HttpMessage httpMessage = new BasicHttpRequest("get", "http://localhost");

	// create the header
	String headerName = "cache-control";
	String headerValue = "no-cache";
	Header header = new BasicHeader(headerName, headerValue);
	httpMessage.addHeader(header);

	// translate the header
	List<Option> options = HttpTranslator.getCoapOptions(httpMessage.getAllHeaders());
	assertFalse(options.isEmpty());
	assertTrue(options.size() == 1);

	// get the option list
	Message coapMessage = new GETRequest();
	coapMessage.setOptions(options);
	Option testedOption = coapMessage.getFirstOption(OptionNumberRegistry.MAX_AGE);
	assertNotNull(testedOption);
	assertEquals(0, testedOption.getIntValue());
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:24,代码来源:HttpTranslatorTest.java

示例14: getCoapOptionsTest

import org.apache.http.HttpMessage; //导入依赖的package包/类
/**
 * Test method for
 * {@link ch.ethz.inf.vs.californium.util.HttpTranslator#getCoapOptions(org.apache.http.HttpMessage)}
 * .
 */
@Test
public final void getCoapOptionsTest() {
	// create the message
	HttpMessage httpMessage = new BasicHttpRequest("get", "http://localhost");

	// create the header
	String headerName = "if-match";
	String headerValue = "\"737060cd8c284d8af7ad3082f209582d\"";
	Header header = new BasicHeader(headerName, headerValue);
	httpMessage.addHeader(header);

	// translate the header
	List<Option> options = HttpTranslator.getCoapOptions(httpMessage.getAllHeaders());
	assertFalse(options.isEmpty());

	// get the option list
	Message coapMessage = new GETRequest();
	coapMessage.setOptions(options);
	int optionNumber = Integer.parseInt(HttpTranslator.HTTP_TRANSLATION_PROPERTIES.getProperty("http.message.header." + headerName));
	assertEquals(coapMessage.getFirstOption(optionNumber).getStringValue(), headerValue);
}
 
开发者ID:Orange-OpenSource,项目名称:holico,代码行数:27,代码来源:HttpTranslatorTest.java

示例15: setHeaders

import org.apache.http.HttpMessage; //导入依赖的package包/类
/**
 * Sets the headers of an HTTP request necessary to execute. 
 * 
 * @param httpMessage   The HTTP request to add the basic headers.
 * @param headers       A map of key-value pairs representing the headers.
 */
public static void setHeaders( HttpMessage httpMessage, Map<String,String> headers )
{
	if( headers == null )
	{
		httpMessage.setHeader( "Accept-Language", "en-us,en;q=0.5" );
		return;
	} 
	else if( !headers.containsKey( "Accept-Language" ) ) 
	{
		headers.put( "Accept-Language", "en-us,en;q=0.5" );
	}
	
	for( Map.Entry<String, String> entry : headers.entrySet() )
	{
		httpMessage.setHeader( entry.getKey(), entry.getValue() );
	}
}
 
开发者ID:jacksonicson,项目名称:rain,代码行数:24,代码来源:HttpTransport.java


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