Package org.apache.http.client.methods

Examples of org.apache.http.client.methods.HttpPut


                        "{\"Product\":{\"description\":\"product 323\",\"id\":323}}");
    }

    @Test
    public void testPutConsumer() throws Exception {
        HttpPut put = new HttpPut("http://localhost:9000/customerservice/customers");
        StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        put.setEntity(entity);
        HttpClient httpclient = new DefaultHttpClient();

        try {
            HttpResponse response = httpclient.execute(put);
            assertEquals(200, response.getStatusLine().getStatusCode());
View Full Code Here


    {
        try {
            long id = counter.incrementAndGet() ;
            String requestURI = url ;
            String baseIRI = determineBaseIRI(requestURI) ;
            HttpPut httpput = new HttpPut(requestURI);
            if ( log.isDebugEnabled() )
                log.debug(format("[%d] %s %s",id , httpput.getMethod(), httpput.getURI().toString())) ;
           
            httpput.setEntity(entity) ;
            DefaultHttpClient httpclient = new SystemDefaultHttpClient();
            applyAuthentication(httpclient, url, httpContext);
            HttpResponse response = httpclient.execute(httpput) ;
            httpResponse(id, response, baseIRI, null) ;
            httpclient.getConnectionManager().shutdown();
View Full Code Here

      } else if (request.getMethod().equals(HttpMethod.GET)) {
         apacheRequest = new HttpGet(request.getEndpoint());
      } else if (request.getMethod().equals(HttpMethod.DELETE)) {
         apacheRequest = new HttpDelete(request.getEndpoint());
      } else if (request.getMethod().equals(HttpMethod.PUT)) {
         apacheRequest = new HttpPut(request.getEndpoint());
         apacheRequest.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);
      } else if (request.getMethod().equals(HttpMethod.POST)) {
         apacheRequest = new HttpPost(request.getEndpoint());
      } else {
         final String method = request.getMethod();
View Full Code Here

    } else if (method.equals(HttpMethods.HEAD)) {
      requestBase = new HttpHead(url);
    } else if (method.equals(HttpMethods.POST)) {
      requestBase = new HttpPost(url);
    } else if (method.equals(HttpMethods.PUT)) {
      requestBase = new HttpPut(url);
    } else if (method.equals(HttpMethods.TRACE)) {
      requestBase = new HttpTrace(url);
    } else if (method.equals(HttpMethods.OPTIONS)) {
      requestBase = new HttpOptions(url);
    } else {
View Full Code Here

            BasicScheme basicAuth = new BasicScheme();
            localcontext.setAttribute( "preemptive-auth", basicAuth );
            client.addRequestInterceptor( new PreemptiveAuth(), 0 );
        }
        URI url = URI.create( sUrl );
        HttpPut p = new HttpPut( url );

        try {
            // new file and and entity
            File file = new File( item.imagePath );

            byte[] bytes = Utils.toByteArray( file );
            ByteArrayEntity requestEntity = new ByteArrayEntity( bytes );

            HttpParams params = client.getParams();
            params.setParameter( CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1 );
            params.setParameter( CoreConnectionPNames.SO_TIMEOUT, new Integer( 15000 ) );
            params.setParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, new Integer( 15000 ) );

            p.setEntity( requestEntity );

            p.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);

            Log.i( TAG, "execute" );
            HttpResponse response = client.execute( p );

            StatusLine line = response.getStatusLine();
            Log.i( TAG, "complete: " + line );

            // return code indicates upload failed so throw exception
            if( line.getStatusCode() < 200 || line.getStatusCode() >= 300 ) {
                throw new Exception( "Failed upload" );
            }

            // shut down connection
            client.getConnectionManager().shutdown();

            // notify user that file has been uploaded
            notification.finished();
        } catch( Exception e ) {
            Log.e( TAG, "exception: " + sUrl, e );
            // file upload failed so abort post and close connection
            p.abort();
            client.getConnectionManager().shutdown();

            // get user preferences and number of retries for failed upload
            SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences( context );
            int maxRetries = Integer.valueOf( prefs.getString( "retries", "" ).substring( 1 ) );
View Full Code Here

                    logger.trace("payload: [{}]", IOUtils.toString(post.getEntity().getContent()));
                }
            }
            req = post;
        } else if (method.equals("PUT")){
            final HttpPut put = new HttpPut(url);
            if(payload != null) {
                put.setEntity(new ByteArrayEntity(payload));
                if (logger.isTraceEnabled()) {
                    logger.trace("payload: [{}]", IOUtils.toString(put.getEntity().getContent()));
                }
            }
            req = put;
        } else if (method.equals("DELETE")) {
            req = new HttpDelete(url);
View Full Code Here

        delete(path, new HashMap<String, String>());
    }

    public Map<String, Object> put(String path, Object payload) throws HTTPError {
        URI uri = buildUri(path);
        HttpPut request = new HttpPut(uri);
        addHeaders(request);
        request.setEntity(new StringEntity(
                serialize(payload),
                ContentType.APPLICATION_JSON));
        return op(request);
    }
View Full Code Here

   */
  @Override
  @SuppressWarnings ( "unchecked" )
  public <T> T put ( URL url, T obj, Map<String, String> newHeaders ) throws Exception
  {
    HttpPut put = new HttpPut(url.toURI());
    setupMethod(put, newHeaders);
    writeObject(obj, put);
    HttpResponse response = execute(put);
    if (response.getEntity() == null) return null;
    return (T) readObject(obj.getClass(), response);
View Full Code Here

  }

  private EtcdResult set0(String key, List<BasicNameValuePair> data, int[] httpErrorCodes, int... expectedErrorCodes)
      throws EtcdClientException {
    URI uri = buildKeyUri("v2/keys", key, "");
    HttpPut request = new HttpPut(uri);
    UrlEncodedFormEntity entity = new UrlEncodedFormEntity(data, Charsets.UTF_8);
    request.setEntity(entity);

    return syncExecute(request, httpErrorCodes, expectedErrorCodes);
  }
View Full Code Here

        throws DirectMemoryException
    {
        String uri = buildRequestWithKey( request );
        log.debug( "put request to: {}", uri );

        HttpPut httpPut = new HttpPut( uri );
        httpPut.addHeader( "Content-Type", getRequestContentType( request ) );

        if ( request.getExpiresIn() > 0 )
        {
            httpPut.addHeader( DirectMemoryHttpConstants.EXPIRES_IN_HTTP_HEADER,
                               Integer.toString( request.getExpiresIn() ) );
        }

        if ( request.getExchangeType() == ExchangeType.TEXT_PLAIN )
        {
            httpPut.addHeader( DirectMemoryHttpConstants.SERIALIZER_HTTP_HEADER,
                               request.getSerializer().getClass().getName() );
        }

        httpPut.setEntity( new ByteArrayEntity( getPutContent( request ) ) );

        try
        {
            HttpResponse response = httpClient.execute( httpPut );
            StatusLine statusLine = response.getStatusLine();
View Full Code Here

TOP

Related Classes of org.apache.http.client.methods.HttpPut

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.