Example usage for org.apache.commons.httpclient HttpMethodBase setRequestHeader

List of usage examples for org.apache.commons.httpclient HttpMethodBase setRequestHeader

Introduction

In this page you can find the example usage for org.apache.commons.httpclient HttpMethodBase setRequestHeader.

Prototype

@Override
public void setRequestHeader(String headerName, String headerValue) 

Source Link

Document

Set the specified request header, overwriting any previous value.

Usage

From source file:com.eucalyptus.blockstorage.CreateSnapshotTest.java

@Test
public void testSendDummy() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty("euca.objectstorage.url") + "/meh/ttt.wsl?gg=vol&hh=snap";

    HttpMethodBase method = new PutMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");

    httpClient.executeMethod(method);//  ww  w .  j a  v  a  2s  .co  m
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

From source file:com.eucalyptus.blockstorage.tests.CreateSnapshotTest.java

@Test
public void testSendDummy() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty(WalrusProperties.URL_PROPERTY) + "/meh/ttt.wsl?gg=vol&hh=snap";

    HttpMethodBase method = new PutMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");

    httpClient.executeMethod(method);//from   w  w w.jav a  2 s.  co m
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

From source file:com.eucalyptus.blockstorage.CreateSnapshotTest.java

@Test
public void testGetSnapshotInfo() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty("euca.objectstorage.url")
            + "/snapset-FuXLn1MUHJ66BkK0/snap-zVl2kZJmjhxnEg..";

    HttpMethodBase method = new GetMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");
    method.setRequestHeader("EucaOperation", "GetSnapshotInfo");
    httpClient.executeMethod(method);//ww w . j  ava2 s.  c  om
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

From source file:com.eucalyptus.blockstorage.tests.CreateSnapshotTest.java

@Test
public void testGetSnapshotInfo() throws Exception {
    HttpClient httpClient = new HttpClient();
    String addr = System.getProperty(WalrusProperties.URL_PROPERTY)
            + "/snapset-FuXLn1MUHJ66BkK0/snap-zVl2kZJmjhxnEg..";

    HttpMethodBase method = new GetMethod(addr);
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", (new Date()).toString());
    method.setRequestHeader("Expect", "100-continue");
    method.setRequestHeader("EucaOperation", "GetSnapshotInfo");
    httpClient.executeMethod(method);//from   w  w  w  .  jav a 2  s  .co  m
    String responseString = method.getResponseBodyAsString();
    System.out.println(responseString);
    method.releaseConnection();
}

From source file:com.rometools.propono.atom.client.BasicAuthStrategy.java

@Override
public void addAuthentication(final HttpClient httpClient, final HttpMethodBase method)
        throws ProponoException {
    httpClient.getParams().setAuthenticationPreemptive(true);
    final String header = "Basic " + credentials;
    method.setRequestHeader("Authorization", header);
}

From source file:com.serena.rlc.jenkins.plugins.rlcnotifier.RLCSite.java

private void setDirectSsoInteractionHeader(HttpMethodBase method) {
    method.setRequestHeader("DirectSsoInteraction", "true");
}

From source file:com.denimgroup.threadfix.importer.impl.remoteprovider.utils.DefaultRequestConfigurer.java

@Override
public void configure(HttpMethodBase method) {
    if (username != null && password != null) {
        String login = username + ":" + password;
        String encodedLogin = DatatypeConverter.printBase64Binary(login.getBytes());

        method.setRequestHeader("Authorization", "Basic " + encodedLogin);
    }/*  w  w w .j a  v a  2s  . c  om*/

    method.setRequestHeader("Content-type", contentType);

    if (headerNames != null && headerVals != null && headerNames.length == headerVals.length) {
        for (int i = 0; i < headerNames.length; i++) {
            method.setRequestHeader(headerNames[i], headerVals[i]);
        }
    }

    if (method instanceof PostMethod) {
        PostMethod postVersion = (PostMethod) method;
        if (parameterNames != null && parameterVals != null && parameterNames.length == parameterVals.length) {
            for (int i = 0; i < parameterNames.length; i++) {
                postVersion.setParameter(parameterNames[i], parameterVals[i]);
            }
        }

        if (requestBody != null) {
            postVersion.setRequestEntity(getRequestEntity());
        }
    } // if it's a get then the parameters should be in the URL
}

From source file:com.denimgroup.threadfix.importer.impl.remoteprovider.utils.RemoteProviderHttpUtilsImpl.java

@Override
@Nonnull/*from   w  w  w.  j a  v a  2  s .c  om*/
public HttpResponse getUrl(String url, final String username, final String password) {
    assert url != null;

    return getUrlWithConfigurer(url, new RequestConfigurer() {
        @Override
        public void configure(HttpMethodBase method) {
            if (username != null && password != null) {
                String login = username + ":" + password;
                String encodedLogin = DatatypeConverter.printBase64Binary(login.getBytes());
                method.setRequestHeader("Authorization", "Basic " + encodedLogin);
            }
            method.setRequestHeader("Content-type", "text/xml; charset=UTF-8");
        }
    });
}

From source file:edu.ucsb.eucalyptus.cloud.ws.HttpTransfer.java

public HttpMethodBase constructHttpMethod(String verb, String addr, String eucaOperation, String eucaHeader) {
    String date = new Date().toString();
    String httpVerb = verb;/*from   ww  w  . j  ava 2s.  c om*/
    String addrPath;
    try {
        java.net.URI addrUri = new URL(addr).toURI();
        addrPath = addrUri.getPath().toString();
        String query = addrUri.getQuery();
        if (query != null) {
            addrPath += "?" + query;
        }
    } catch (Exception ex) {
        LOG.error(ex, ex);
        return null;
    }
    String data = httpVerb + "\n" + date + "\n" + addrPath + "\n";

    HttpMethodBase method = null;
    if (httpVerb.equals("PUT")) {
        method = new PutMethodWithProgress(addr);
    } else if (httpVerb.equals("DELETE")) {
        method = new DeleteMethod(addr);
    } else {
        method = new GetMethod(addr);
    }
    method.setRequestHeader("Authorization", "Euca");
    method.setRequestHeader("Date", date);
    //method.setRequestHeader("Expect", "100-continue");
    method.setRequestHeader(StorageProperties.EUCALYPTUS_OPERATION, eucaOperation);
    if (eucaHeader != null) {
        method.setRequestHeader(StorageProperties.EUCALYPTUS_HEADER, eucaHeader);
    }
    try {
        PrivateKey ccPrivateKey = SystemCredentials.lookup(Storage.class).getPrivateKey();
        Signature sign = Signature.getInstance("SHA1withRSA");
        sign.initSign(ccPrivateKey);
        sign.update(data.getBytes());
        byte[] sig = sign.sign();

        method.setRequestHeader("EucaSignature", new String(Base64.encode(sig)));
    } catch (Exception ex) {
        LOG.error(ex, ex);
    }
    return method;
}

From source file:com.cloud.network.bigswitch.BigSwitchBcfApi.java

private void setHttpHeader(final HttpMethodBase m) {
    m.setRequestHeader(CONTENT_TYPE, CONTENT_JSON);
    m.setRequestHeader(ACCEPT, CONTENT_JSON);
    m.setRequestHeader(HTTP_HEADER_INSTANCE_ID, CLOUDSTACK_INSTANCE_ID + "-" + zoneId);
    if (StringUtils.isNotEmpty(hash)) {
        m.setRequestHeader(HASH_MATCH, hash);
    }/*  w  w  w  .j  av a  2 s .  com*/

    String authString = username + ":" + password;
    String encodedAuthString = "Basic "
            + Base64.encodeBase64String(authString.getBytes(Charset.forName("UTF-8")));
    m.setRequestHeader("Authorization", encodedAuthString);
}