org.apache.http.HttpMessage Java Examples

The following examples show how to use org.apache.http.HttpMessage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HttpActivityExecutor.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
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);
            }
        }
    }
}
 
Example #2
Source File: CachingHttpClient.java    From apigee-android-sdk with Apache License 2.0 6 votes vote down vote up
private String generateViaHeader(HttpMessage msg) {
	final VersionInfo vi = VersionInfo.loadVersionInfo(
			"org.apache.http.client", getClass().getClassLoader());
	final String release = (vi != null) ? vi.getRelease()
			: VersionInfo.UNAVAILABLE;
	final ProtocolVersion pv = msg.getProtocolVersion();
	if ("http".equalsIgnoreCase(pv.getProtocol())) {
		return String.format(
				"%d.%d localhost (Apache-HttpClient/%s (cache))",
				pv.getMajor(), pv.getMinor(), release);
	} else {
		return String.format(
				"%s/%d.%d localhost (Apache-HttpClient/%s (cache))",
				pv.getProtocol(), pv.getMajor(), pv.getMinor(), release);
	}
}
 
Example #3
Source File: HttpClientRequestor.java    From http-api-invoker with MIT License 5 votes vote down vote up
private void addHeaders(HttpRequest request, HttpMessage msg) {
    Map<String, String> headers = request.getHeaders();
    if (headers != null && !headers.isEmpty()) {
        for (Map.Entry<String, String> entry : headers.entrySet()) {
            msg.addHeader(entry.getKey(), entry.getValue());
        }
    }
}
 
Example #4
Source File: HeaderUtil.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public static Headers get(HttpMessage httpMessage) {
    Headers headers = new Headers();
    for (Header header : httpMessage.getAllHeaders()) {
        headers.add(header.getName(), header.getValue());
    }
    return headers;
}
 
Example #5
Source File: ResponseCachingPolicy.java    From apigee-android-sdk with Apache License 2.0 5 votes vote down vote up
protected boolean hasCacheControlParameterFrom(HttpMessage msg,
		String[] params) {
	Header[] cacheControlHeaders = msg
			.getHeaders(HeaderConstants.CACHE_CONTROL);
	for (Header header : cacheControlHeaders) {
		for (HeaderElement elem : header.getElements()) {
			for (String param : params) {
				if (param.equalsIgnoreCase(elem.getName())) {
					return true;
				}
			}
		}
	}
	return false;
}
 
Example #6
Source File: HeaderUtil.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public static Headers get(HttpMessage httpMessage) {
    Headers headers = new Headers();
    for (Header header : httpMessage.getAllHeaders()) {
        headers.add(header.getName(), header.getValue());
    }
    return headers;
}
 
Example #7
Source File: HeaderUtil.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
public static void add(HttpMessage httpMessage, Headers headers) {
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        for (String value : entry.getValue()) {
            httpMessage.addHeader(entry.getKey(), value);
        }
    }
}
 
Example #8
Source File: DefaultCosHttpClient.java    From cos-java-sdk with MIT License 5 votes vote down vote up
/**
 * 设置Http头部,同时添加上公共的类型,长连接,COS SDK标识
 * 
 * @param message
 *            HTTP消息
 * @param headers
 *            用户额外添加的HTTP头部
 */
private void setHeaders(HttpMessage message, Map<String, String> headers) {
	message.setHeader(RequestHeaderKey.ACCEPT, RequestHeaderValue.Accept.ALL);
	message.setHeader(RequestHeaderKey.CONNECTION, RequestHeaderValue.Connection.KEEP_ALIVE);
	message.setHeader(RequestHeaderKey.USER_AGENT, this.config.getUserAgent());

	if (headers != null) {
		for (String headerKey : headers.keySet()) {
			message.setHeader(headerKey, headers.get(headerKey));
		}
	}
}
 
Example #9
Source File: HeaderUtil.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
public static void add(HttpMessage httpMessage, Headers headers) {
    for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
        for (String value : entry.getValue()) {
            httpMessage.addHeader(entry.getKey(), value);
        }
    }
}
 
Example #10
Source File: DefaultCosHttpClient.java    From cos-java-sdk-v4 with MIT License 5 votes vote down vote up
/**
 * 设置Http头部,同时添加上公共的类型,长连接,COS SDK标识
 * 
 * @param message HTTP消息
 * @param headers 用户额外添加的HTTP头部
 */
private void setHeaders(HttpMessage message, Map<String, String> headers) {
    message.setHeader(RequestHeaderKey.ACCEPT, RequestHeaderValue.Accept.ALL);
    message.setHeader(RequestHeaderKey.CONNECTION, RequestHeaderValue.Connection.KEEP_ALIVE);
    message.setHeader(RequestHeaderKey.USER_AGENT, this.config.getUserAgent());

    if (headers != null) {
        for (String headerKey : headers.keySet()) {
            message.setHeader(headerKey, headers.get(headerKey));
        }
    }
}
 
Example #11
Source File: InstagramGenericUtil.java    From instagram4j with Apache License 2.0 5 votes vote down vote up
public static Optional<String> getFirstHeaderValue(HttpMessage req, String name) {
	Header[] header = req.getHeaders(name);
	
	if(header.length > 0) {
		return Optional.of(header[0].getValue());
	}
	
	return Optional.empty();
}
 
Example #12
Source File: HttpClientRequestor.java    From http-api-invoker with MIT License 5 votes vote down vote up
private void addCookies(HttpRequest request, HttpMessage msg) {
    Map<String, String> cookies = request.getCookies();
    if (cookies == null || cookies.isEmpty()) {
        return;
    }
    StringBuilder sb = new StringBuilder();
    for (Map.Entry<String, String> entry : cookies.entrySet()) {
        sb.append(entry.getKey()).append("=").append(entry.getValue()).append(";");
    }
    msg.addHeader("Cookie", sb.substring(0, sb.length()));
}
 
Example #13
Source File: HttpClientFactory.java    From rug-cli with GNU General Public License v3.0 4 votes vote down vote up
public static void authorizationHeader(HttpMessage msg, String username, String password) {
    if (username != null && password != null) {
        msg.addHeader("Authorization", encodeBaseAuthHeader(username, password));
    }
}
 
Example #14
Source File: RequestHeaderAuthenticationStrategy.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
private Optional<Header> getBearerHeader(final HttpMessage message, final String headerName) {
  return Arrays.stream(message.getHeaders(headerName))
      .filter(header -> header.getValue().startsWith(BEARER_SCHEME))
      .findAny();
}
 
Example #15
Source File: HttpClientFactory.java    From rug-cli with GNU General Public License v3.0 4 votes vote down vote up
public static void authorizationHeader(HttpMessage msg, String token) {
    if (token != null) {
        msg.addHeader("Authorization", "Bearer " + token);
    }
}
 
Example #16
Source File: HttpClientFactory.java    From rug-cli with GNU General Public License v3.0 4 votes vote down vote up
public static void header(HttpMessage msg, String key, String value) {
    if (value != null) {
        msg.addHeader(key, value);
    }
}
 
Example #17
Source File: BatchRefineTransformer.java    From p3-batchrefine with Apache License 2.0 4 votes vote down vote up
protected void logMessage(HttpMessage message) {
    if (fLogger.isDebugEnabled()) {
        fLogger.debug(message.toString());
    }
}
 
Example #18
Source File: OpenstackMetadataProxyHandler.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Obtains the Http message.
 *
 * @return Http message
 */
public HttpMessage getMessage() {
    return message;
}
 
Example #19
Source File: OpenstackMetadataProxyHandler.java    From onos with Apache License 2.0 2 votes vote down vote up
/**
 * Configures the Http message.
 *
 * @param message Http message
 */
public void setMessage(HttpMessage message) {
    this.message = message;
}