Example usage for org.apache.http.client.methods HttpPut HttpPut

List of usage examples for org.apache.http.client.methods HttpPut HttpPut

Introduction

In this page you can find the example usage for org.apache.http.client.methods HttpPut HttpPut.

Prototype

public HttpPut(final String uri) 

Source Link

Usage

From source file:org.osmsurround.ae.osmrequest.OsmInsertRequest.java

@Override
protected HttpRequestBase createRequest(OsmBasicType amenity, int changesetId) throws Exception {
    ByteArrayOutputStream baos = marshallIntoBaos(amenity, changesetId);

    HttpEntityEnclosingRequestBase request = new HttpPut(
            osmApiBaseUrl + "/api/0.6/" + OsmBasicTypeMap.get(amenity.getClass()) + "/create");

    request.setEntity(new ByteArrayEntity(baos.toByteArray()));
    return request;
}

From source file:functionaltests.RestSchedulerKillTest.java

@Test
public void testKillScheduler() throws Exception {
    String schedulerUrl = getResourceUrl("kill");
    HttpPut httpPut = new HttpPut(schedulerUrl);
    setSessionHeader(httpPut);/*w  ww.j  a va 2s.com*/
    HttpResponse response = executeUriRequest(httpPut);
    assertHttpStatusOK(response);
    assertTrue(Boolean.valueOf(getContent(response)));
    assertTrue(KILLED.equals(getScheduler().getStatus()));
}

From source file:org.opentravel.otm.forum2016.am.UpdateAPIOperation.java

/**
 * @see org.opentravel.otm.forum2016.am.RESTClientOperation#execute()
 *///from  www.jav  a2 s  . co  m
@Override
public APIDetails execute() throws IOException {
    HttpPut request = new HttpPut(APIPublisherConfig.getWSO2PublisherApiBaseUrl() + "/" + api.getId());

    request.setHeader("Content-Type", "application/json");
    request.setEntity(new StringEntity(new Gson().toJson(api.toJson())));
    return execute(request);
}

From source file:com.tinyhydra.botd.BotdServerOperations.java

public static void CastVote(final Activity activity, final Handler handler, final String email,
        final String shopId, final String shopRef) {
    new Thread() {
        @Override//from  ww w  . ja  v a 2  s .  co  m
        public void run() {
            try {
                URI uri = new URI(activity.getResources().getString(R.string.server_url));
                HttpClient client = new DefaultHttpClient();
                HttpPut put = new HttpPut(uri);

                JSONObject voteObj = new JSONObject();

                // user's phone-account-email-address is used to prevent multiple votes
                // the server will validate. 'shopId' is a consistent id for a specific location
                // but can't be used to get more data. 'shopRef' is an id that changes based on
                // some criteria that google places has imposed, but will let us grab data later on
                // and various Ref codes with the same id will always resolve to the same location.
                voteObj.put(JSONvalues.email.toString(), email);
                voteObj.put(JSONvalues.shopId.toString(), shopId);
                voteObj.put(JSONvalues.shopRef.toString(), shopRef);
                put.setEntity(new StringEntity(voteObj.toString()));

                HttpResponse response = client.execute(put);
                InputStream is = response.getEntity().getContent();
                int ch;
                StringBuffer sb = new StringBuffer();
                while ((ch = is.read()) != -1) {
                    sb.append((char) ch);
                }
                if (sb.toString().equals("0")) {
                    Utils.PostToastMessageToHandler(handler, "Vote cast!", Toast.LENGTH_SHORT);
                    // Set a local flag to prevent duplicate voting
                    SharedPreferences settings = activity.getSharedPreferences(Const.GenPrefs, 0);
                    SharedPreferences.Editor editor = settings.edit();
                    editor.putLong(Const.LastVoteDate, Utils.GetDate());
                    editor.commit();
                } else {
                    // The user shouldn't see this. The above SharedPreferences code will be evaluated
                    // when the user hits the Vote button. If the user gets sneaky and deletes local data though,
                    // the server will catch the duplicate vote based on the user's email address and send back a '1'.
                    Utils.PostToastMessageToHandler(handler,
                            "Vote refused. You've probably already voted today.", Toast.LENGTH_LONG);
                }
                GetTopTen(activity, handler, true);
                // Catch blocks. Return a generic error if anything goes wrong.
                //TODO: implement some better/more appropriate error handling.
            } catch (URISyntaxException usex) {
                usex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (UnsupportedEncodingException ueex) {
                ueex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (ClientProtocolException cpex) {
                cpex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (IOException ioex) {
                ioex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            } catch (JSONException jex) {
                jex.printStackTrace();
                Utils.PostToastMessageToHandler(handler,
                        "There was a problem submitting your vote. Poor signal? Please try again.",
                        Toast.LENGTH_LONG);
            }
        }
    }.start();
}

From source file:com.atomiton.watermanagement.ngo.util.HttpRequestResponseHandler.java

public static void sendPut(String serverURL, String postBody) throws Exception {

    CloseableHttpClient client = HttpClients.createDefault();
    HttpPut post = new HttpPut(serverURL);

    StringEntity entity = new StringEntity(postBody, "UTF-8");

    post.setEntity(entity);//from ww  w .  j  a  v a2  s . c o m

    HttpResponse response = client.execute(post);
    // System.out.println("\nSending 'PUT' request to URL : " + serverURL);

    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer result = new StringBuffer();
    String line = "";
    while ((line = rd.readLine()) != null) {
        result.append(line);
    }
    client.close();
    // System.out.println(result.toString());
}

From source file:org.privatenotes.sync.web.AnonymousConnection.java

@Override
public String put(String uri, String data) throws UnknownHostException {

    // Prepare a request object
    HttpPut httpPut = new HttpPut(uri);

    try {//  w  w  w .  j  a v a2 s .c om
        // The default http content charset is ISO-8859-1, JSON requires UTF-8
        httpPut.setEntity(new StringEntity(data, "UTF-8"));
    } catch (UnsupportedEncodingException e1) {
        e1.printStackTrace();
        return null;
    }

    httpPut.setHeader("Content-Type", "application/json");
    HttpResponse response = execute(httpPut);
    return parseResponse(response);
}

From source file:com.msopentech.odatajclient.engine.client.http.DefaultHttpUriRequestFactory.java

@Override
public HttpUriRequest createHttpUriRequest(final HttpMethod method, final URI uri) {
    HttpUriRequest result;/* w ww . j  a  v a2 s .c  om*/

    switch (method) {
    case POST:
        result = new HttpPost(uri);
        break;

    case PUT:
        result = new HttpPut(uri);
        break;

    case PATCH:
        result = new HttpPatch(uri);
        break;

    case MERGE:
        result = new HttpMerge(uri);
        break;

    case DELETE:
        result = new HttpDelete(uri);
        break;

    case GET:
    default:
        result = new HttpGet(uri);
        break;
    }

    return result;
}

From source file:functionaltests.RestfulSchedulerFreezeTest.java

@Test
public void testFreezeScheduler() throws Exception {
    String resourceUrl = getResourceUrl("freeze");
    HttpPut httpPut = new HttpPut(resourceUrl);
    setSessionHeader(httpPut);//from  ww w  . jav a2  s.c  o  m
    HttpResponse response = executeUriRequest(httpPut);
    assertHttpStatusOK(response);
    assertTrue(Boolean.valueOf(getContent(response)));
    Scheduler scheduler = RestFuncTHelper.getScheduler();
    assertEquals(SchedulerStatus.FROZEN, scheduler.getStatus());
}

From source file:com.strato.hidrive.api.connection.httpgateway.request.InputStreamPutRequest.java

@Override
protected HttpRequestBase createHttpRequest(String requestUri, HttpRequestParamsVisitor<?> visitor)
        throws UnsupportedEncodingException {
    HttpPut httpPut = new HttpPut(requestUri + visitor.getHttpRequestParams());
    httpPut.setEntity(new InputStreamEntity(getInputStream(), getStreamLength()));
    return httpPut;
}

From source file:org.fcrepo.auth.integration.AbstractResourceIT.java

protected static HttpPut putObjMethod(final String pid) {
    return new HttpPut(serverAddress + pid);
}