Search in sources :

Example 11 with Header

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("===============================");
}
Also used : URIException(org.apache.commons.httpclient.URIException) Header(org.apache.commons.httpclient.Header) URI(org.apache.commons.httpclient.URI)

Example 12 with Header

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);
}
Also used : Header(org.apache.commons.httpclient.Header) PutMethod(org.apache.commons.httpclient.methods.PutMethod) HttpInputStream(com.zimbra.cs.service.UserServlet.HttpInputStream) ByteArrayRequestEntity(org.apache.commons.httpclient.methods.ByteArrayRequestEntity) Pair(com.zimbra.common.util.Pair)

Example 13 with Header

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;
}
Also used : Header(org.apache.commons.httpclient.Header) InputStream(java.io.InputStream)

Example 14 with Header

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);
        }
    }
}
Also used : Header(org.apache.commons.httpclient.Header) IOException(java.io.IOException)

Example 15 with Header

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;
}
Also used : Element(com.zimbra.common.soap.Element) ArrayList(java.util.ArrayList) XmlParseException(com.zimbra.common.soap.XmlParseException) IOException(java.io.IOException) Header(org.apache.commons.httpclient.Header) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Aggregations

Header (org.apache.commons.httpclient.Header)88 GetMethod (org.apache.commons.httpclient.methods.GetMethod)22 Test (org.junit.Test)22 IOException (java.io.IOException)20 HttpClient (org.apache.commons.httpclient.HttpClient)19 PostMethod (org.apache.commons.httpclient.methods.PostMethod)19 HttpMethod (org.apache.commons.httpclient.HttpMethod)17 NameValuePair (org.apache.commons.httpclient.NameValuePair)16 ArrayList (java.util.ArrayList)15 InputStream (java.io.InputStream)13 HttpException (org.apache.commons.httpclient.HttpException)13 PutMethod (org.apache.commons.httpclient.methods.PutMethod)10 Account (com.zimbra.cs.account.Account)9 ServiceException (com.zimbra.common.service.ServiceException)6 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)6 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)6 Pair (com.zimbra.common.util.Pair)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 HashMap (java.util.HashMap)5 DefaultHttpMethodRetryHandler (org.apache.commons.httpclient.DefaultHttpMethodRetryHandler)5