Example usage for org.apache.commons.httpclient Header Header

List of usage examples for org.apache.commons.httpclient Header Header

Introduction

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

Prototype

public Header(String paramString1, String paramString2) 

Source Link

Usage

From source file:org.pentaho.di.sdk.samples.carte.AddJobSample.java

public static void addJobToServlet(String urlString, String xml, String authentication) throws Exception {
    PostMethod method = new PostMethod(urlString);
    method.setRequestEntity(new ByteArrayRequestEntity(xml.getBytes("UTF-8")));
    method.setDoAuthentication(true);/*  w  w  w. ja v a  2s .  com*/
    method.addRequestHeader(new Header("Content-Type", "text/xml;charset=UTF-8"));
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during job submission.");
    }
    System.out.println("Server response:");
    System.out.println(response);
}

From source file:org.pentaho.di.sdk.samples.carte.AddTransSample.java

public static void addTransToServlet(String urlString, String xml, String authentication) throws Exception {
    PostMethod method = new PostMethod(urlString);
    method.setRequestEntity(new ByteArrayRequestEntity(xml.getBytes("UTF-8")));
    method.setDoAuthentication(true);// www . ja  va  2 s. com
    method.addRequestHeader(new Header("Content-Type", "text/xml;charset=UTF-8"));
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during transformation  submission.");
    }
    System.out.println("Server response:");
    System.out.println(response);
}

From source file:org.pentaho.di.sdk.samples.carte.AllocateServerSocketSample.java

public static void allocateServerSocket(String urlString, String authentication) throws Exception {
    GetMethod method = new GetMethod(urlString);
    method.setDoAuthentication(true);//from  www .  j a va  2 s. com
    method.addRequestHeader(new Header("Content-Type", "text/xml;charset=UTF-8"));
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during ports allocation.");
    }
    System.out.println("Server response:");
    System.out.println(response);
}

From source file:org.pentaho.di.sdk.samples.carte.BextSequenceSample.java

public static void sendGetSlavesRequest(String urlString, String authentication) throws Exception {
    GetMethod method = new GetMethod(urlString);
    method.setDoAuthentication(true);/* w w w  . ja va2 s  .c o  m*/
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during sequense allocation. "
                + "Most probably you don't have the sequence configured for your Carte server.");
    }
    System.out.println("Server response:");
    System.out.println(response);
}

From source file:org.pentaho.di.sdk.samples.carte.CleanupTransSample.java

public static void sendGetSlavesRequest(String urlString, String authentication) throws Exception {
    GetMethod method = new GetMethod(urlString);
    method.setDoAuthentication(true);//from  ww  w  . j ava 2 s  .c  om
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during transformation preparation for execution.");
    }
    System.out.println("Server response:");
    System.out.println(response);
}

From source file:org.pentaho.di.sdk.samples.carte.ExecuteTransSample.java

public static void sendExecuteRequest(String urlString, String authentication) throws Exception {
    GetMethod method = new GetMethod(urlString);
    method.setDoAuthentication(true);//from ww  w .  ja va2s  .  c  om
    method.addRequestHeader(new Header("Content-Type", "text/xml;charset=UTF-8"));
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during transformation execution.");
    }
    System.out.println("Server response (expected to be empty):");
    System.out.println(response);
}

From source file:org.pentaho.di.sdk.samples.carte.GetJobImageSample.java

public static void sendGetImageRequest(String urlString, String authentication, String fileName)
        throws Exception {
    GetMethod method = new GetMethod(urlString);
    method.setDoAuthentication(true);/*from   w ww . j av  a 2s .co  m*/
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    byte[] response = method.getResponseBody();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during getting job image.");
    }
    System.out.println("Image was stored to " + fileName);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(fileName);
        fos.write(response);
        fos.flush();
    } finally {
        fos.close();
    }
}

From source file:org.pentaho.di.sdk.samples.carte.GetJobStatusSample.java

public static void sendGetSlavesRequest(String urlString, String authentication) throws Exception {
    GetMethod method = new GetMethod(urlString);
    method.setDoAuthentication(true);//w w  w .  j av  a 2s . co m
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during getting job status.");
    }
    System.out.println("Server response:");
    System.out.println(response);
}

From source file:org.pentaho.di.sdk.samples.carte.GetSlavesSample.java

public static void sendGetSlavesRequest(String urlString, String authentication) throws Exception {
    GetMethod method = new GetMethod(urlString);
    method.setDoAuthentication(true);/*from  w  w  w . java 2  s.c o m*/
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during getting slave servers.");
    }
    System.out.println("Server response:");
    System.out.println(response);
}

From source file:org.pentaho.di.sdk.samples.carte.GetStatusSample.java

public static void sendGetStatusRequest(String urlString, String authentication) throws Exception {
    GetMethod method = new GetMethod(urlString);
    method.setDoAuthentication(true);/*from w  w  w .  j  a  va 2s  .  c  o m*/
    //adding authorization token
    if (authentication != null) {
        method.addRequestHeader(new Header("Authorization", authentication));
    }

    //executing method
    HttpClient client = new HttpClient();
    int code = client.executeMethod(method);
    String response = method.getResponseBodyAsString();
    method.releaseConnection();
    if (code >= 400) {
        System.out.println("Error occurred during getting server status.");
    }
    System.out.println("Server response:");
    System.out.println(response);
}