Package org.apache.http.client.methods

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


            catch ( MalformedChallengeException ignore )
            {
            }
        }

        HttpPut putMethod = new HttpPut( url );

        firePutStarted( resource, source );

        try
        {
            putMethod.setEntity( httpEntity );

            CloseableHttpResponse response = execute( putMethod );
            try
            {
                int statusCode = response.getStatusLine().getStatusCode();
View Full Code Here


        catch ( IOException e )
        {
            fireTransferError( resource, e, TransferEvent.REQUEST_GET );
        }

        HttpPut putMethod = new HttpPut( url.toString() );

        firePutStarted( resource, source );

        try
        {
            putMethod.setEntity( httpEntity );

            HttpResponse response;
            try
            {
                response = execute( putMethod );
            }
            catch ( IOException e )
            {
                fireTransferError( resource, e, TransferEvent.REQUEST_PUT );

                throw new TransferFailedException( e.getMessage(), e );
            }
            catch ( HttpException e )
            {
                fireTransferError( resource, e, TransferEvent.REQUEST_PUT );

                throw new TransferFailedException( e.getMessage(), e );
            }

            int statusCode = response.getStatusLine().getStatusCode();
            String reasonPhrase = ", ReasonPhrase:" + response.getStatusLine().getReasonPhrase() + ".";
            fireTransferDebug( url + " - Status code: " + statusCode + reasonPhrase );

            // Check that we didn't run out of retries.
            switch ( statusCode )
            {
                // Success Codes
                case HttpStatus.SC_OK: // 200
                case HttpStatus.SC_CREATED: // 201
                case HttpStatus.SC_ACCEPTED: // 202
                case HttpStatus.SC_NO_CONTENT:  // 204
                    break;

                case SC_NULL:
                {
                    TransferFailedException e =
                        new TransferFailedException( "Failed to transfer file: " + url + reasonPhrase );
                    fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
                    throw e;
                }

                case HttpStatus.SC_FORBIDDEN:
                    fireSessionConnectionRefused();
                    throw new AuthorizationException( "Access denied to: " + url + reasonPhrase );

                case HttpStatus.SC_NOT_FOUND:
                    throw new ResourceDoesNotExistException( "File: " + url + " does not exist" + reasonPhrase );

                    //add more entries here
                default:
                {
                    TransferFailedException e = new TransferFailedException(
                        "Failed to transfer file: " + url + ". Return code is: " + statusCode + reasonPhrase );
                    fireTransferError( resource, e, TransferEvent.REQUEST_PUT );
                    throw e;
                }
            }

            firePutCompleted( resource, source );
        }
        finally
        {
            putMethod.abort();
        }
    }
View Full Code Here

    return new ApacheHttpRequest(httpClient, new HttpPost(url));
  }

  @Override
  public ApacheHttpRequest buildPutRequest(String url) {
    return new ApacheHttpRequest(httpClient, new HttpPut(url));
  }
View Full Code Here

      return contentType.startsWith("text/") || "application/xml".equals(contentType) || "application/json".equals(contentType);
   }

   @Override
   public void write(MarshalledEntry entry) {
      HttpPut put = new HttpPut(keyToUri(entry.getKey()));

      InternalMetadata metadata = entry.getMetadata();
      if (metadata != null && metadata.expiryTime() > -1) {
         put.addHeader(TIME_TO_LIVE_SECONDS, Long.toString(timeoutToSeconds(metadata.lifespan())));
         put.addHeader(MAX_IDLE_TIME_SECONDS, Long.toString(timeoutToSeconds(metadata.maxIdle())));
      }

      try {
         String contentType = metadataHelper.getContentType(entry);
         put.setEntity(new ByteArrayEntity(marshall(contentType, entry), ContentType.create(contentType)));
         httpClient.execute(httpHost, put);
      } catch (Exception e) {
         throw new PersistenceException(e);
      } finally {
         put.abort();
      }
   }
View Full Code Here

    assertEquals(HttpStatusCodes.BAD_REQUEST.getStatusCode(), response.getStatusLine().getStatusCode());
  }

  @Test
  public void put() throws Exception {
    final HttpPut put = new HttpPut(URI.create(getEndpoint().toString() + "aaa/bbb/ccc"));
    final HttpResponse response = getHttpClient().execute(put);

    assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(), response.getStatusLine().getStatusCode());
    final String payload = StringHelper.inputStreamToString(response.getEntity().getContent());
    assertTrue(payload.contains("error"));
View Full Code Here

    assertTrue(payload.contains("error"));
  }

  @Test
  public void putWithContent() throws Exception {
    final HttpPut put = new HttpPut(URI.create(getEndpoint().toString()));
    final String xml =
        "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
            "<entry xmlns=\"" + Edm.NAMESPACE_ATOM_2005 + "\"" +
            " xmlns:m=\"" + Edm.NAMESPACE_M_2007_08 + "\"" +
            " xmlns:d=\"" + Edm.NAMESPACE_D_2007_08 + "\"" +
            " xml:base=\"https://server.at.some.domain.com/path.to.some.service/ReferenceScenario.svc/\">" +
            "</entry>";
    final HttpEntity entity = new StringEntity(xml);
    put.setEntity(entity);
    final HttpResponse response = getHttpClient().execute(put);

    assertEquals(HttpStatusCodes.METHOD_NOT_ALLOWED.getStatusCode(), response.getStatusLine().getStatusCode());
    final String payload = StringHelper.inputStreamToString(response.getEntity().getContent());
    assertTrue(payload.contains("error"));
View Full Code Here

    HttpRequestBase request =
        httpMethod == ODataHttpMethod.GET ? new HttpGet() :
            httpMethod == ODataHttpMethod.DELETE ? new HttpDelete() :
                httpMethod == ODataHttpMethod.POST ? new HttpPost() :
                    httpMethod == ODataHttpMethod.PUT ? new HttpPut() : new HttpPatch();
    request.setURI(URI.create(getEndpoint() + uri));
    if (additionalHeader != null) {
      request.addHeader(additionalHeader, additionalHeaderValue);
    }
    if (requestBody != null) {
View Full Code Here

    try {
      if ("POST".equals(methodType) || "PUT".equals(methodType)) {
        HttpEntityEnclosingRequestBase enclosingMethod = ("POST".equals(methodType))
            ? new HttpPost(requestUri)
        : new HttpPut(requestUri);

            if (request.getPostBodyLength() > 0) {
              enclosingMethod.setEntity(new InputStreamEntity(request.getPostBody(), request.getPostBodyLength()));
            }
            httpMethod = enclosingMethod;
View Full Code Here

      response = execRequest(httpGet, args, content);
    } else if (StringUtil.equalsIgnoreCase(method, METHOD_POST)) {
      HttpPost httpPost = new HttpPost(url);
      response = execRequest(httpPost, args, content);
    } else if (StringUtil.equalsIgnoreCase(method, METHOD_PUT)) {
      HttpPut httpPut = new HttpPut(url);
      response = execRequest(httpPut, args, content);
    } else if (StringUtil.equalsIgnoreCase(method, METHOD_DELETE)) {
      HttpDelete httpDelete = new HttpDelete(url);
      response = execRequest(httpDelete, args, content);
    } else if (StringUtil.equalsIgnoreCase(method,METHOD_DELETE_BODY)){
View Full Code Here

    if (smethod.equalsIgnoreCase("get")) {
      HttpGet method = new HttpGet(uri);
      ProxyProfiler.profileTimedRequest(timedObject, "create HttpGet");
      return method;
    } else if (smethod.equalsIgnoreCase("put")) {
      HttpPut method = new HttpPut(uri);
      method = (HttpPut) prepareMethodWithUpdatedContent(method, request);
      ProxyProfiler.profileTimedRequest(timedObject, "create HttpPut");
      return method;
    } else if (smethod.equalsIgnoreCase("post")) {
      HttpPost method = new HttpPost(uri);
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.