Search in sources :

Example 1 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project pinpoint by naver.

the class HttpMethodBaseExecuteMethodInterceptor method setHttpTraceHeader.

private void setHttpTraceHeader(final Object target, final Object[] args, TraceId nextId) {
    if (target instanceof HttpMethod) {
        final HttpMethod httpMethod = (HttpMethod) target;
        httpMethod.setRequestHeader(Header.HTTP_TRACE_ID.toString(), nextId.getTransactionId());
        httpMethod.setRequestHeader(Header.HTTP_SPAN_ID.toString(), String.valueOf(nextId.getSpanId()));
        httpMethod.setRequestHeader(Header.HTTP_PARENT_SPAN_ID.toString(), String.valueOf(nextId.getParentSpanId()));
        httpMethod.setRequestHeader(Header.HTTP_FLAGS.toString(), String.valueOf(nextId.getFlags()));
        httpMethod.setRequestHeader(Header.HTTP_PARENT_APPLICATION_NAME.toString(), traceContext.getApplicationName());
        httpMethod.setRequestHeader(Header.HTTP_PARENT_APPLICATION_TYPE.toString(), Short.toString(traceContext.getServerTypeCode()));
        final String host = getHost(httpMethod, args);
        if (host != null) {
            httpMethod.setRequestHeader(Header.HTTP_HOST.toString(), host);
        }
    }
}
Also used : HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 2 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project pinpoint by naver.

the class HttpMethodBaseExecuteMethodInterceptor method setHttpSampledHeader.

private void setHttpSampledHeader(final Object target) {
    if (isDebug) {
        logger.debug("set Sampling flag=false");
    }
    if (target instanceof HttpMethod) {
        final HttpMethod httpMethod = (HttpMethod) target;
        httpMethod.setRequestHeader(Header.HTTP_SAMPLED.toString(), SamplingFlagUtils.SAMPLING_RATE_FALSE);
    }
}
Also used : HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 3 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project tdi-studio-se by Talend.

the class MDMTransaction method commit.

public void commit() throws IOException {
    HttpClient client = new HttpClient();
    client.getState().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    HttpMethod method = new PostMethod(url + "/" + id);
    method.setDoAuthentication(true);
    try {
        //$NON-NLS-1$ //$NON-NLS-2$
        method.setRequestHeader("Cookie", getStickySession() + "=" + sessionId);
        client.executeMethod(method);
    } catch (HttpException e) {
        throw e;
    } catch (IOException e) {
        throw e;
    } finally {
        method.releaseConnection();
    }
    int statuscode = method.getStatusCode();
    if (statuscode >= 400) {
        throw new MDMTransactionException("Commit failed. The commit operation has returned the code " + statuscode + ".");
    }
}
Also used : PostMethod(org.apache.commons.httpclient.methods.PostMethod) HttpClient(org.apache.commons.httpclient.HttpClient) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod) UsernamePasswordCredentials(org.apache.commons.httpclient.UsernamePasswordCredentials)

Example 4 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project zm-mailbox by Zimbra.

the class WebDavClient method sendMultiResponseRequest.

public Collection<DavObject> sendMultiResponseRequest(DavRequest req) throws IOException, DavException {
    ArrayList<DavObject> ret = new ArrayList<DavObject>();
    HttpMethod m = null;
    try {
        m = executeFollowRedirect(req);
        int status = m.getStatusCode();
        if (status >= 400) {
            throw new DavException("DAV server returned an error: " + status, status);
        }
        Document doc = W3cDomUtil.parseXMLToDom4jDocUsingSecureProcessing(m.getResponseBodyAsStream());
        Element top = doc.getRootElement();
        for (Object obj : top.elements(DavElements.E_RESPONSE)) {
            if (obj instanceof Element) {
                ret.add(new DavObject((Element) obj));
            }
        }
    } catch (XmlParseException e) {
        throw new DavException("can't parse response", e);
    } finally {
        if (m != null) {
            m.releaseConnection();
        }
    }
    return ret;
}
Also used : DavException(com.zimbra.cs.dav.DavException) Element(org.dom4j.Element) ArrayList(java.util.ArrayList) XmlParseException(com.zimbra.common.soap.XmlParseException) Document(org.dom4j.Document) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Example 5 with HttpMethod

use of org.apache.commons.httpclient.HttpMethod in project zm-mailbox by Zimbra.

the class ElasticSearchIndexTest method indexStoreAvailable.

@Override
protected boolean indexStoreAvailable() {
    String indexUrl = String.format("%s?_status", LC.zimbra_index_elasticsearch_url_base.value());
    HttpMethod method = new GetMethod(indexUrl);
    try {
        ElasticSearchConnector connector = new ElasticSearchConnector();
        connector.executeMethod(method);
    } catch (HttpException e) {
        ZimbraLog.index.error("Problem accessing the ElasticSearch Index store", e);
        return false;
    } catch (IOException e) {
        ZimbraLog.index.error("Problem accessing the ElasticSearch Index store", e);
        return false;
    }
    return true;
}
Also used : ElasticSearchConnector(com.zimbra.cs.index.elasticsearch.ElasticSearchConnector) GetMethod(org.apache.commons.httpclient.methods.GetMethod) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException) HttpMethod(org.apache.commons.httpclient.HttpMethod)

Aggregations

HttpMethod (org.apache.commons.httpclient.HttpMethod)204 HttpClient (org.apache.commons.httpclient.HttpClient)131 GetMethod (org.apache.commons.httpclient.methods.GetMethod)117 IOException (java.io.IOException)72 InputStream (java.io.InputStream)65 HttpException (org.apache.commons.httpclient.HttpException)34 Test (org.junit.Test)34 ArrayList (java.util.ArrayList)33 HashMap (java.util.HashMap)29 Map (java.util.Map)28 PostMethod (org.apache.commons.httpclient.methods.PostMethod)26 Element (org.w3c.dom.Element)22 Header (org.apache.commons.httpclient.Header)20 NameValuePair (org.apache.commons.httpclient.NameValuePair)17 List (java.util.List)14 FileInputStream (java.io.FileInputStream)12 UsernamePasswordCredentials (org.apache.commons.httpclient.UsernamePasswordCredentials)10 HttpTest (org.apache.sling.commons.testing.integration.HttpTest)10 SAXBuilder (org.jdom.input.SAXBuilder)10 Element (org.jdom.Element)9