Example usage for org.apache.http.params CoreProtocolPNames PROTOCOL_VERSION

List of usage examples for org.apache.http.params CoreProtocolPNames PROTOCOL_VERSION

Introduction

In this page you can find the example usage for org.apache.http.params CoreProtocolPNames PROTOCOL_VERSION.

Prototype

String PROTOCOL_VERSION

To view the source code for org.apache.http.params CoreProtocolPNames PROTOCOL_VERSION.

Click Source Link

Usage

From source file:org.energyos.espi.datacustodian.console.ImportUsagePoint.java

public static void main(String[] args) {
    if (args.length == 2) {
        try {/*from ww w .j a v a  2s. c  om*/
            String filename = args[0];
            String url = args[1];

            DefaultHttpClient client = new DefaultHttpClient();
            client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
            upload(filename, url, client);
            client.getConnectionManager().shutdown();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("Usage: import_usage_point.sh filename url");
        System.out.println("");
        System.out.println("Example:");
        System.out.println("");
        System.out.println(
                "  import_usage_point.sh etc/usage_point.xml http://localhost:8080/custodian/retailcustomers/1/upload");
    }
}

From source file:com.cloudhopper.sxmp.SubmitMain.java

static public void main(String[] args) throws Exception {
    String url = "http://localhost:9080/api/sxmp/1.0";

    // create a submit request
    SubmitRequest submit = new SubmitRequest();

    submit.setAccount(new Account("customer1", "password1"));

    submit.setDeliveryReport(Boolean.TRUE);

    MobileAddress sourceAddr = new MobileAddress();
    sourceAddr.setAddress(MobileAddress.Type.NETWORK, "40404");
    submit.setSourceAddress(sourceAddr);

    submit.setOperatorId(24);/*from   w ww.j av a 2s  .co  m*/

    MobileAddress destAddr = new MobileAddress();
    destAddr.setAddress(MobileAddress.Type.INTERNATIONAL, "+14155551212");

    submit.setDestinationAddress(destAddr);

    submit.setText(
            "Test abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijbcdefghij",
            TextEncoding.UTF_8);
    //submit.setText("Hello World");

    // Get file to be posted
    HttpClient client = new DefaultHttpClient();

    client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);

    long totalStart = System.currentTimeMillis();
    int count = 1;

    for (int i = 0; i < count; i++) {
        long start = System.currentTimeMillis();

        // execute request
        try {
            HttpPost post = new HttpPost(url);

            //ByteArrayEntity entity = new ByteArrayEntity(data);
            StringEntity entity = new StringEntity(SxmpWriter.createString(submit));
            entity.setContentType("text/xml; charset=\"iso-8859-1\"");
            post.setEntity(entity);

            ResponseHandler<String> responseHandler = new BasicResponseHandler();

            String responseBody = client.execute(post, responseHandler);
            long stop = System.currentTimeMillis();

            logger.debug("----------------------------------------");
            logger.debug("Response took " + (stop - start) + " ms");
            logger.debug(responseBody);
            logger.debug("----------------------------------------");
        } finally {
            // do nothing
        }
    }

    long totalEnd = System.currentTimeMillis();

    logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests");

    double seconds = ((double) (totalEnd - totalStart)) / 1000;
    double smspersec = ((double) count) / seconds;
    logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2));

}

From source file:com.cloudhopper.sxmp.demo.SubmitMain.java

static public void main(String[] args) throws Exception {

    String url = "http://127.0.0.1:8080/api/sxmp/1.0";
    String phone = "+14155551212";
    int operator = 1;
    if (args.length > 0)
        url = args[0];//from  ww w  .j a  v  a 2 s .c  om
    if (args.length > 1)
        phone = args[1];
    if (args.length > 2)
        operator = Integer.parseInt(args[2]);

    // create a submit request
    SubmitRequest submit = new SubmitRequest();
    submit.setAccount(new Account("customer1", "password1"));
    submit.setDeliveryReport(Boolean.TRUE);

    MobileAddress sourceAddr = new MobileAddress();
    sourceAddr.setAddress(MobileAddress.Type.NETWORK, "40404");
    submit.setSourceAddress(sourceAddr);
    submit.setOperatorId(operator);

    submit.setPriority(Priority.URGENT);

    MobileAddress destAddr = new MobileAddress();
    destAddr.setAddress(MobileAddress.Type.INTERNATIONAL, phone);

    submit.setDestinationAddress(destAddr);
    submit.setText("Hello World");

    // Get file to be posted
    HttpClient client = new DefaultHttpClient();

    client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);

    long totalStart = System.currentTimeMillis();
    int count = 1;

    for (int i = 0; i < count; i++) {
        long start = System.currentTimeMillis();

        // execute request
        try {
            HttpPost post = new HttpPost(url);

            //ByteArrayEntity entity = new ByteArrayEntity(data);
            StringEntity entity = new StringEntity(SxmpWriter.createString(submit));
            entity.setContentType("text/xml; charset=\"iso-8859-1\"");
            post.setEntity(entity);

            ResponseHandler<String> responseHandler = new BasicResponseHandler();

            String responseBody = client.execute(post, responseHandler);
            long stop = System.currentTimeMillis();

            logger.debug("----------------------------------------");
            logger.debug("Response took " + (stop - start) + " ms");
            logger.debug(responseBody);
            logger.debug("----------------------------------------");
        } finally {
            // do nothing
        }
    }

    long totalEnd = System.currentTimeMillis();

    logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests");

    double seconds = ((double) (totalEnd - totalStart)) / 1000;
    double smspersec = ((double) count) / seconds;
    logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2));

}

From source file:com.cloudhopper.sxmp.DeliverMain.java

static public void main(String[] args) throws Exception {
    // create a deliver request
    DeliverRequest deliver = new DeliverRequest();

    deliver.setAccount(new Account("customer1", "password1"));

    deliver.setOperatorId(2);/*from   w w  w  .  j a va2  s  .  co  m*/

    MobileAddress sourceAddr = new MobileAddress();
    sourceAddr.setAddress(MobileAddress.Type.INTERNATIONAL, "+13135551212");
    deliver.setSourceAddress(sourceAddr);

    MobileAddress destAddr = new MobileAddress();
    destAddr.setAddress(MobileAddress.Type.NETWORK, "55555");
    deliver.setDestinationAddress(destAddr);

    deliver.setText(
            "This is a new message that I want to send that's a little larger than normal &!#@%20*()$#@!~");

    // target url
    //String url = "http://localhost:9080/api/sxmp/1.0";
    //String url = "http://lyn-stratus-001/api/sxmp/1.0";
    //String url = "http://localhost:9080/api/sxmp/1.0";
    //String strURL = "http://sfd-twtr-gw.cloudhopper.com/api/sxmp/1.0";
    String url = "http://lyn-stratus-lab5:9080/api/sxmp/1.0";

    // Get file to be posted
    HttpClient client = new DefaultHttpClient();

    client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);

    // convert request into a byte array
    //byte[] data = SxmpWriter.createByteArray(submit);

    //logger.debug(StringUtil.toHexString(data));

    long totalStart = System.currentTimeMillis();
    int count = 5000;

    for (int i = 0; i < count; i++) {
        long start = System.currentTimeMillis();

        // execute request
        try {
            HttpPost post = new HttpPost(url);

            //ByteArrayEntity entity = new ByteArrayEntity(data);
            StringEntity entity = new StringEntity(SxmpWriter.createString(deliver));
            entity.setContentType("text/xml; charset=\"iso-8859-1\"");
            post.setEntity(entity);

            ResponseHandler<String> responseHandler = new BasicResponseHandler();

            String responseBody = client.execute(post, responseHandler);
            long stop = System.currentTimeMillis();

            logger.debug("----------------------------------------");
            logger.debug("Response took " + (stop - start) + " ms");
            logger.debug(responseBody);
            logger.debug("----------------------------------------");
        } finally {
            // do nothing
        }
    }

    long totalEnd = System.currentTimeMillis();

    logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests");

    double seconds = ((double) (totalEnd - totalStart)) / 1000;
    double smspersec = ((double) count) / seconds;
    logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2));

}

From source file:Technique.PostFile.java

public static void upload(String files) throws Exception {

    String userHome = System.getProperty("user.home");
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost("http://localhost/image/up.php");
    File file = new File(files);
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody contentFile = new FileBody(file);
    mpEntity.addPart("userfile", contentFile);
    httppost.setEntity(mpEntity);//from www.  j  a  v a 2 s . co  m
    System.out.println("executing request " + httppost.getRequestLine());
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    if (!(response.getStatusLine().toString()).equals("HTTP/1.1 200 OK")) {
        // Successfully Uploaded
    } else {
        // Did not upload. Add your logic here. Maybe you want to retry.
    }
    System.out.println(response.getStatusLine());
    if (resEntity != null) {
        System.out.println(EntityUtils.toString(resEntity));
    }
    if (resEntity != null) {
        resEntity.consumeContent();
    }
    httpclient.getConnectionManager().shutdown();
}

From source file:org.factpub.ui.gui.network.PostFile.java

public static List<String> uploadToFactpub(File file) throws Exception {
    List<String> status = new ArrayList<String>();
    int i = 0;/*from   ww  w. ja  va2s . co m*/

    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

    String postUrl = FEConstants.SERVER_POST_HANDLER + "?id=" + AuthMediaWikiIdHTTP.authorisedUser + "&ps="
            + AuthMediaWikiIdHTTP.userPassword;

    HttpPost httppost = new HttpPost(postUrl);

    System.out.println(postUrl);

    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file, "json");

    // name must be "uploadfile". this is same on the server side.
    mpEntity.addPart(FEConstants.SERVER_UPLOAD_FILE_NAME, cbFile);

    httppost.setEntity(mpEntity);
    System.out.println("executing request " + httppost.getRequestLine());
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    System.out.println(response.getStatusLine());

    if (response.getStatusLine().toString().contains("502 Bad Gateway")) {
        status.add("Looks server is down.");
    } else {
        if (resEntity != null) {
            status.add(EntityUtils.toString(resEntity));
            System.out.println(status.get(i));
            i++;
        }

        if (resEntity != null) {
            resEntity.consumeContent();
        }
    }
    httpclient.getConnectionManager().shutdown();

    //String status = "Upload Success!";
    return status;
}

From source file:net.translatewiki.app.TranslateWikiApp.java

public static MWApi createMWApi() {
    DefaultHttpClient client = new DefaultHttpClient();
    // Because WMF servers support only HTTP/1.0. Biggest difference that
    // this makes is support for Chunked Transfer Encoding. 
    // I have this here so if any 1.1 features start being used, it 
    // throws up. 
    client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_0);
    return new MWApi(API_URL, client);
}

From source file:ch.mbae.pusher.transport.HttpClientPusherTransport.java

/**
 * create a  http transportn using a single http client
 * for all requests/*w  w w  .  j  a v  a2 s .  com*/
 */
public HttpClientPusherTransport() {
    ClientConnectionManager cm = new ThreadSafeClientConnManager();

    this.httpClient = new DefaultHttpClient(cm);
    this.httpClient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); // set default to HTTP 1.1
    this.httpClient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8");
}

From source file:com.catchoom.servicerecognition.CatchoomApplication.java

@Override
public void onCreate() {
    super.onCreate();

    // Set up//from  w ww  .  j a  va  2 s .co m
    CatchoomApplication.preferences = getSharedPreferences(CatchoomApplication.PREFS_EDITOR_NAME,
            Context.MODE_PRIVATE);
    HttpParams httpParams = new BasicHttpParams();
    httpParams.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    CatchoomApplication.catchoom = new Catchoom();
    imageManager = new ImageManager();
    context = getApplicationContext();
}

From source file:com.android.fastergallery.common.HttpClientFactory.java

/**
 * Creates an HttpClient with the specified userAgent string.
 * /*  w w  w  .  j a  va2  s  . c o  m*/
 * @param userAgent
 *            the userAgent string
 * @return the client
 */
public static HttpClient newHttpClient(String userAgent) {
    // AndroidHttpClient is available on all platform releases,
    // but is hidden until API Level 8
    try {
        Class<?> clazz = Class.forName("android.net.http.AndroidHttpClient");
        Method newInstance = clazz.getMethod("newInstance", String.class);
        Object instance = newInstance.invoke(null, userAgent);

        HttpClient client = (HttpClient) instance;

        // ensure we default to HTTP 1.1
        HttpParams params = client.getParams();
        params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);

        // AndroidHttpClient sets these two parameters thusly by default:
        // HttpConnectionParams.setSoTimeout(params, 60 * 1000);
        // HttpConnectionParams.setConnectionTimeout(params, 60 * 1000);

        // however it doesn't set this one...
        ConnManagerParams.setTimeout(params, 60 * 1000);

        return client;
    } catch (InvocationTargetException e) {
        throw new RuntimeException(e);
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new RuntimeException(e);
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}