本文整理汇总了Java中org.apache.commons.httpclient.HttpMethod.addRequestHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.addRequestHeader方法的具体用法?Java HttpMethod.addRequestHeader怎么用?Java HttpMethod.addRequestHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.addRequestHeader方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setHeaders
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Will write all request headers stored in the request to the method that
* are not in the set of banned headers.
* The Accept-Endocing header is also changed to allow compressed content
* connection to the server even if the end client doesn't support that.
* A Via headers is created as well in compliance with the RFC.
*
* @param method The HttpMethod used for this connection
* @param request The incoming request
* @throws HttpException
*/
protected void setHeaders(HttpMethod method, HttpServletRequest request) throws HttpException {
Enumeration headers = request.getHeaderNames();
String connectionToken = request.getHeader("connection");
while (headers.hasMoreElements()) {
String name = (String) headers.nextElement();
boolean isToken = (connectionToken != null && name.equalsIgnoreCase(connectionToken));
if (!isToken && !bannedHeaders.contains(name.toLowerCase())) {
Enumeration value = request.getHeaders(name);
while (value.hasMoreElements()) {
method.addRequestHeader(name, (String) value.nextElement());
}
}
}
setProxySpecificHeaders(method, request);
}
示例2: executeURI
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Execute a transaction method given a complete URI.
* @param method the transaction method
* @param headers HTTP header values to send
* @param uri a properly urlencoded URI
* @return the HTTP response code
* @throws IOException
*/
public int executeURI(HttpMethod method, Header[] headers, String uri)
throws IOException {
method.setURI(new URI(uri, true));
for (Map.Entry<String, String> e: extraHeaders.entrySet()) {
method.addRequestHeader(e.getKey(), e.getValue());
}
if (headers != null) {
for (Header header: headers) {
method.addRequestHeader(header);
}
}
long startTime = System.currentTimeMillis();
int code = httpClient.executeMethod(method);
long endTime = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug(method.getName() + " " + uri + " " + code + " " +
method.getStatusText() + " in " + (endTime - startTime) + " ms");
}
return code;
}
示例3: setAllHeaders
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Will write all the headers included in the request to the method.
* The difference between this method and setHeaders in BasicRequestHandler
* is that the BasicRequestHandler will also add Via, x-forwarded-for, etc.
* These "special" headers should not be added when the proxy is target
* directly with a Max-Forwards: 0 headers.
* @param method The method to write to
* @param request The incoming request
* @see RequestHandlerBase#setHeaders(HttpMethod, HttpServletRequest)
*/
private void setAllHeaders(HttpMethod method, HttpServletRequest request) {
Enumeration headers = request.getHeaderNames();
while (headers.hasMoreElements()) {
String name = (String) headers.nextElement();
Enumeration value = request.getHeaders(name);
while (value.hasMoreElements()) {
method.addRequestHeader(name, (String) value.nextElement());
}
}
}
示例4: getDocument
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
@Override
public Document getDocument(Document document, DocumentFactory factory) throws IOException {
HttpMethod request = new GetMethod(baseURL);
request.addRequestHeader("Authorization", String.format("Bearer %s", bearerToken)); //TODO
request.setPath(path + document.getId());
int status = client.executeMethod(request);
if(status == 200) {
JsonNode json = mapper.readValue(request.getResponseBody(), JsonNode.class);
for(FieldDescriptor descriptor : factory.listFields()) {
try {
Object value = getValue(json, descriptor);
if(value != null) {
document.setValue(descriptor, value);
} else LOG.warn("No data found for id {}", document.getId());
} catch (IOException e) {
LOG.warn("Cannot use data for id {}: {}", document.getId(), e.getMessage());
}
}
return document;
} else throw new IOException(request.getStatusText());
}
示例5: setBasicAuthorization
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private void setBasicAuthorization(HttpMethod method, String userName, String password) {
String userpass = userName + ":" + password;
String
basicAuth =
"Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
method.addRequestHeader(new Header("Authorization", basicAuth));
}
示例6: doAuthenticateDefault
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private static boolean doAuthenticateDefault(
HttpMethod method,
HttpConnection conn,
HttpState state,
boolean proxy)
throws AuthenticationException {
if (method == null) {
throw new IllegalArgumentException("HTTP method may not be null");
}
if (state == null) {
throw new IllegalArgumentException("HTTP state may not be null");
}
String host = null;
if (conn != null) {
host = proxy ? conn.getProxyHost() : conn.getHost();
}
Credentials credentials = proxy
? state.getProxyCredentials(null, host) : state.getCredentials(null, host);
if (credentials == null) {
return false;
}
if (!(credentials instanceof UsernamePasswordCredentials)) {
throw new InvalidCredentialsException(
"Credentials cannot be used for basic authentication: "
+ credentials.toString());
}
String auth = BasicScheme.authenticate(
(UsernamePasswordCredentials) credentials,
method.getParams().getCredentialCharset());
if (auth != null) {
String s = proxy ? PROXY_AUTH_RESP : WWW_AUTH_RESP;
Header header = new Header(s, auth, true);
method.addRequestHeader(header);
return true;
} else {
return false;
}
}
示例7: retrieve
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
@Override
public Object retrieve(IDataSource snDataSource, Object object) throws RetrieverException {
HttpClient client = (HttpClient)snDataSource.connect();
// We should use an encoded query in this case because URL parameters do not support the full semantics of a filter.
String serviceUrl = AppProperties.getProperty("service_url");
String restPath = AppProperties.getProperty("rest_path");
String resultLimit = AppProperties.getProperty("result_limit");
String period_of_time = AppProperties.getProperty("period_of_time");
String url1 = "?sysparm_query=active%3Dtrue%5Estate!%3D6%5Esys_created_onRELATIVEGE%40hour%40ago%40" + period_of_time;
String url2 = "%5Eassignment_group%3D81db147e2b5c79444dde23f119da153b&sysparm_display_value=true&sysparm_fields=sys_id%2Cnumber%2Cshort_description%2Cdescription&sysparm_limit=" + resultLimit;
String finalUrl = serviceUrl + restPath + url1 + url2;
HttpMethod method = new GetMethod(finalUrl);
method.addRequestHeader("Accept", "application/json");
String message = "";
try {
int status = client.executeMethod(method);
log.info("Status:" + status);
BufferedReader rd = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream()));
message = org.apache.commons.io.IOUtils.toString(rd);
} catch (IOException ioe) {
throw new RetrieverException(ioe.toString());
}
// remove leading and ending "{"
int index = message.indexOf("\"result\":");
message = message.substring(index+9, message.length()-1);
Gson gson = new Gson();
ServiceNowTicket[] wrapper = null;
try {
wrapper = gson.fromJson(message, ServiceNowTicket[].class);
} catch (Exception e) {
log.error(e.toString());
}
if (wrapper == null) {
log.error("Problem retrieving information from ServiceNow");
return null;
}
log.info("number of fetched tickets: " + wrapper.length);
List<ServiceNowTicket> ticketList = Arrays.asList(wrapper);
for (Iterator<ServiceNowTicket> it = ticketList.iterator(); it.hasNext();) {
ServiceNowTicket ticket = it.next();
log.info("Fetching IP address and date");
String source = StringUtils.substringBetween(ticket.getDescription(), "<Source>", "</Source>");
String timeStamp = StringUtils.substringBetween(source, "<TimeStamp>", "</TimeStamp>");
String ipAddress = StringUtils.substringBetween(source, "<IP_Address>", "</IP_Address>");
log.info("--------------------------");
log.info("Sys_Id: " + ticket.getSysId());
log.info("Number: " + ticket.getNumber());
log.info("Timestamp: " + timeStamp);
log.info("IPAddress: " + ipAddress);
log.info("--------------------------");
log.info("");
ClaimService service = new ClaimService();
try {
// fixing timestamp
timeStamp = fixTimeStampFormat(timeStamp);
// Sends data to ElasticSearch to find CWL
IDataSource esDataSource = new ElasticSearchDataSource();
esDataSource.connect();
// Sends data to CWL database to find email address, first and last name
// save data in the database
service.addTicket(ticket.getNumber(), ticket.getDescription(), java.sql.Timestamp.valueOf(timeStamp), ipAddress);
} catch (Exception de) {
log.error(de.toString());
}
}
return null;
}
示例8: addUserNameToHeader
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private void addUserNameToHeader(HttpMethod method, HttpServletRequest req) throws ServletException,
NotLoggedInException {
method.addRequestHeader("X-VOSS-REQUESTED-USER", checkAAA(req));
}
示例9: addAcceptEncodingHeader
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private void addAcceptEncodingHeader(HttpMethod method, HttpServletRequest req) {
method.addRequestHeader("Accept-encoding", "gzip,deflate");
}