本文整理匯總了Java中org.apache.commons.httpclient.HttpMethodBase.getResponseHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpMethodBase.getResponseHeaders方法的具體用法?Java HttpMethodBase.getResponseHeaders怎麽用?Java HttpMethodBase.getResponseHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.HttpMethodBase
的用法示例。
在下文中一共展示了HttpMethodBase.getResponseHeaders方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: showHeaders
import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
@SuppressWarnings("unused")
private final void showHeaders(final HttpMethodBase methodBase) {
final Header[] headers = methodBase.getResponseHeaders();
for (int i = 0; i < headers.length; i++) {
System.out.println("header name: " + headers[i].getName());
System.out.println("header value: " + headers[i].getValue());
}
}
示例2: calculateHeadersSize
import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
/**
* Calculate response headers size
*
* @return the size response headers (in bytes)
*/
private static int calculateHeadersSize(HttpMethodBase httpMethod) {
int headerSize = httpMethod.getStatusLine().toString().length()+2; // add a \r\n
Header[] rh = httpMethod.getResponseHeaders();
for (Header responseHeader : rh) {
headerSize += responseHeader.toString().length(); // already include the \r\n
}
headerSize += 2; // last \r\n before response data
return headerSize;
}
示例3: debugMethod
import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
public static void debugMethod(HttpMethodBase method)
{
HttpClient client = new HttpClient();
InputStream is = null;
try {
System.out.println(method.getName() + " "
+ method.getURI() + " HTTP/1.1");
client.executeMethod(method);
System.out.println(method.getStatusLine());
boolean len = false;
for ( Header header : method.getResponseHeaders() )
{
if ( header.getName().equals("Content-Length") ) { len = true; }
System.out.print(header.toExternalForm());
}
String body = method.getResponseBodyAsString();
if ( body == null ) { return; }
if (!len) { System.out.println("Content-Length: " + body.length());}
is = getInputStream(method);
dumpInputStream(is, System.out);
}
catch (IOException e) {
e.printStackTrace();
}
finally { IOUtils.closeQuietly(is); method.releaseConnection(); }
}
示例4: debugMethod
import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
public synchronized static void debugMethod(HttpMethodBase method
, PrintStream ps)
{
HttpClient client = getClient();
InputStream is = null;
try {
ps.println(method.getName() + " "
+ method.getURI() + " HTTP/1.1");
client.executeMethod(method);
ps.println(method.getStatusLine());
boolean len = false;
for ( Header header : method.getResponseHeaders() )
{
if ( CONTENT_LENGTH.equals(header.getName()) ) { len = true; }
ps.print(header.toExternalForm());
}
String body = method.getResponseBodyAsString();
if ( body == null ) { return; }
if (!len) { ps.println(CONTENT_LENGTH + ": " + body.length());}
dumpInputStream(getInputStream(method), ps);
}
catch (IOException e) {
e.printStackTrace();
}
finally { closeMethod(method); }
}
示例5: printResponseHeaders
import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
public static Header[] printResponseHeaders(HttpMethodBase httpget) throws IOException {
System.out.println("Printing Response Header...\n");
Header[] headers = httpget.getResponseHeaders();
for (Header header : headers) {
System.out.println("Key : " + header.getName()
+ " ,Value : " + header.getValue());
}
return headers;
}
示例6: obtainHTTPHeaderInformation
import org.apache.commons.httpclient.HttpMethodBase; //導入方法依賴的package包/類
/**
* Collect the HTTP header information and set them in the message context
*
* @param method HttpMethodBase from which to get information
* @param msgContext the MessageContext in which to place the information... OR NOT!
* @throws AxisFault if problems occur
*/
protected void obtainHTTPHeaderInformation(HttpMethodBase method,
MessageContext msgContext) throws AxisFault {
// Set RESPONSE properties onto the REQUEST message context. They will need to be copied off the request context onto
// the response context elsewhere, for example in the OutInOperationClient.
Map transportHeaders = new CommonsTransportHeaders(method.getResponseHeaders());
msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, transportHeaders);
msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE, new Integer(method.getStatusCode()));
Header header = method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);
if (header != null) {
HeaderElement[] headers = header.getElements();
MessageContext inMessageContext = msgContext.getOperationContext().getMessageContext(
WSDLConstants.MESSAGE_LABEL_IN_VALUE);
Object contentType = header.getValue();
Object charSetEnc = null;
for (int i = 0; i < headers.length; i++) {
NameValuePair charsetEnc = headers[i].getParameterByName(
HTTPConstants.CHAR_SET_ENCODING);
if (charsetEnc != null) {
charSetEnc = charsetEnc.getValue();
}
}
if (inMessageContext != null) {
inMessageContext
.setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
inMessageContext
.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
} else {
// Transport details will be stored in a HashMap so that anybody interested can
// retrieve them
HashMap transportInfoMap = new HashMap();
transportInfoMap.put(Constants.Configuration.CONTENT_TYPE, contentType);
transportInfoMap.put(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
//the HashMap is stored in the outgoing message.
msgContext.setProperty(Constants.Configuration.TRANSPORT_INFO_MAP,
transportInfoMap);
}
}
String sessionCookie = null;
// Process old style headers first
Header[] cookieHeaders = method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE);
String customCoookiId = (String) msgContext.getProperty(Constants.CUSTOM_COOKIE_ID);
// process all the cookieHeaders, when load balancer is fronted it may require some cookies to function.
sessionCookie = processCookieHeaders(cookieHeaders);
// Overwrite old style cookies with new style ones if present
cookieHeaders = method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE2);
for (int i = 0; i < cookieHeaders.length; i++) {
HeaderElement[] elements = cookieHeaders[i].getElements();
for (int e = 0; e < elements.length; e++) {
HeaderElement element = elements[e];
if (Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName()) ||
Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
sessionCookie = processCookieHeader(element);
}
if(customCoookiId!=null&&customCoookiId.equalsIgnoreCase(element.getName())){
sessionCookie = processCookieHeader(element);
}
}
}
if (sessionCookie != null && !sessionCookie.isEmpty()) {
msgContext.getServiceContext().setProperty(HTTPConstants.COOKIE_STRING, sessionCookie);
}
}