use of org.apache.commons.httpclient.Header in project zm-mailbox by Zimbra.
the class ProvUtil method sendSoapMessage.
@Override
public void sendSoapMessage(PostMethod postMethod, Element envelope, HttpState httpState) {
console.println("========== SOAP SEND ==========");
if (debugLevel == SoapDebugLevel.high) {
try {
URI uri = postMethod.getURI();
console.println(uri.toString());
} catch (URIException e) {
if (verboseMode) {
e.printStackTrace(errConsole);
} else {
console.println("Unable to get request URL, error=" + e.getMessage());
}
}
Header[] headers = postMethod.getRequestHeaders();
for (Header header : headers) {
// trim the ending crlf
console.println(header.toString().trim());
}
console.println();
}
sendStart = System.currentTimeMillis();
console.println(envelope.prettyPrint());
console.println("===============================");
}
use of org.apache.commons.httpclient.Header in project zm-mailbox by Zimbra.
the class WebDavClient method sendPut.
public HttpInputStream sendPut(String href, byte[] buf, String contentType, String etag, Collection<Pair<String, String>> headers) throws IOException {
boolean done = false;
PutMethod put = null;
while (!done) {
put = new PutMethod(mBaseUrl + href);
put.setRequestEntity(new ByteArrayRequestEntity(buf, contentType));
if (mDebugEnabled && contentType.startsWith("text"))
ZimbraLog.dav.debug("PUT payload: \n" + new String(buf, "UTF-8"));
if (etag != null)
put.setRequestHeader(DavProtocol.HEADER_IF_MATCH, etag);
if (headers != null)
for (Pair<String, String> h : headers) put.addRequestHeader(h.getFirst(), h.getSecond());
executeMethod(put, Depth.zero);
int ret = put.getStatusCode();
if (ret == HttpStatus.SC_MOVED_PERMANENTLY || ret == HttpStatus.SC_MOVED_TEMPORARILY) {
Header newLocation = put.getResponseHeader("Location");
if (newLocation != null) {
href = newLocation.getValue();
ZimbraLog.dav.debug("redirect to new url = " + href);
put.releaseConnection();
continue;
}
}
done = true;
}
return new HttpInputStream(put);
}
use of org.apache.commons.httpclient.Header in project intellij-community by JetBrains.
the class GenericRepository method executeMethod.
private String executeMethod(HttpMethod method) throws Exception {
String responseBody;
getHttpClient().executeMethod(method);
Header contentType = method.getResponseHeader("Content-Type");
if (contentType != null && contentType.getValue().contains("charset")) {
// ISO-8859-1 if charset wasn't specified in response
responseBody = StringUtil.notNullize(method.getResponseBodyAsString());
} else {
InputStream stream = method.getResponseBodyAsStream();
responseBody = stream == null ? "" : StreamUtil.readText(stream, CharsetToolkit.UTF8_CHARSET);
}
if (method.getStatusCode() != HttpStatus.SC_OK) {
throw new Exception("Request failed with HTTP error: " + method.getStatusText());
}
return responseBody;
}
use of org.apache.commons.httpclient.Header in project intellij-community by JetBrains.
the class TaskUtil method prettyFormatResponseToLog.
public static void prettyFormatResponseToLog(@NotNull Logger logger, @NotNull HttpMethod response) {
if (logger.isDebugEnabled() && response.hasBeenUsed()) {
try {
String content = TaskResponseUtil.getResponseContentAsString(response);
Header header = response.getRequestHeader(HTTP.CONTENT_TYPE);
String contentType = header == null ? "text/plain" : header.getElements()[0].getName().toLowerCase(Locale.ENGLISH);
if (contentType.contains("xml")) {
prettyFormatXmlToLog(logger, content);
} else if (contentType.contains("json")) {
prettyFormatJsonToLog(logger, content);
} else {
logger.debug(content);
}
} catch (IOException e) {
logger.error(e);
}
}
}
use of org.apache.commons.httpclient.Header in project zm-mailbox by Zimbra.
the class ExchangeFreeBusyProvider method getFreeBusyForHost.
public List<FreeBusy> getFreeBusyForHost(String host, ArrayList<Request> req) throws IOException {
ArrayList<FreeBusy> ret = new ArrayList<FreeBusy>();
int fb_interval = LC.exchange_free_busy_interval_min.intValueWithinRange(5, 1444);
Request r = req.get(0);
ServerInfo serverInfo = (ServerInfo) r.data;
if (serverInfo == null) {
ZimbraLog.fb.warn("no exchange server info for user " + r.email);
return ret;
}
if (!serverInfo.enabled) {
return ret;
}
String url = constructGetUrl(serverInfo, req);
ZimbraLog.fb.debug("fetching fb from url=" + url);
HttpMethod method = new GetMethod(url);
Element response = null;
try {
int status = sendRequest(method, serverInfo);
if (status != 200)
return getEmptyList(req);
if (ZimbraLog.fb.isDebugEnabled()) {
Header cl = method.getResponseHeader("Content-Length");
int contentLength = 10240;
if (cl != null)
contentLength = Integer.valueOf(cl.getValue());
String buf = new String(com.zimbra.common.util.ByteUtil.readInput(method.getResponseBodyAsStream(), contentLength, contentLength), "UTF-8");
ZimbraLog.fb.debug(buf);
response = Element.parseXML(buf);
} else
response = Element.parseXML(method.getResponseBodyAsStream());
} catch (XmlParseException e) {
ZimbraLog.fb.warn("error parsing fb response from exchange", e);
return getEmptyList(req);
} catch (IOException e) {
ZimbraLog.fb.warn("error parsing fb response from exchange", e);
return getEmptyList(req);
} finally {
method.releaseConnection();
}
for (Request re : req) {
String fb = getFbString(response, re.email);
ret.add(new ExchangeUserFreeBusy(fb, re.email, fb_interval, re.start, re.end));
}
return ret;
}
Aggregations