Package org.apache.commons.httpclient.methods

Examples of org.apache.commons.httpclient.methods.EntityEnclosingMethod


      if (request.getBody() != null)
      {
         if (!(httpMethod instanceof EntityEnclosingMethod))
            throw new RuntimeException("A GET request cannot have a body.");
         ClientRequestEntity requestEntity = new ClientRequestEntity(new HttpClientHeaderWrapper(httpMethod, request.getProviderFactory()), request);
         EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod;
         post.setRequestEntity(requestEntity);
      }
   }
View Full Code Here


      if (request.getBody() != null)
      {
         if (!(httpMethod instanceof EntityEnclosingMethod))
            throw new RuntimeException("A GET request cannot have a body.");
         ClientRequestEntity requestEntity = new ClientRequestEntity(new HttpClientHeaderWrapper(httpMethod, request.getProviderFactory()), request);
         EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod;
         post.setRequestEntity(requestEntity);
      }
   }
View Full Code Here

            } else if (method.equals(HTTPConstants.TRACE)){
                httpMethod = new TraceMethod(urlStr);
            } else if (method.equals(HTTPConstants.OPTIONS)){
                httpMethod = new OptionsMethod(urlStr);
            } else if (method.equals(HTTPConstants.DELETE)){
                httpMethod = new EntityEnclosingMethod(urlStr) {
                    @Override
                    public String getName() { // HC3.1 does not have the method
                        return HTTPConstants.DELETE;
                    }
                };
            } else if (method.equals(HTTPConstants.GET)){
                httpMethod = new GetMethod(urlStr);
            } else if (method.equals(HTTPConstants.PATCH)){
                httpMethod = new EntityEnclosingMethod(urlStr) {
                    @Override
                    public String getName() { // HC3.1 does not have the method
                        return HTTPConstants.PATCH;
                    }
                };
View Full Code Here

                method.releaseConnection();
            }
        }
        s_logger.info("ssp api call:" + apiCallPath + " user="+username+" status="+method.getStatusLine());
        if(method instanceof EntityEnclosingMethod){
            EntityEnclosingMethod emethod = (EntityEnclosingMethod)method;
            RequestEntity reqEntity = emethod.getRequestEntity();
            if(reqEntity instanceof StringRequestEntity){
                StringRequestEntity strReqEntity = (StringRequestEntity)reqEntity;
                s_logger.debug("ssp api request body:"+strReqEntity.getContent());
            }else{
                s_logger.debug("ssp api request body:"+emethod.getRequestEntity());
            }
        }
        s_logger.debug("ssp api response body:" + response);
        return response;
    }
View Full Code Here

                // should not happen because of HttpBindingValidator, but never say never
                throw new IllegalArgumentException("Unsupported content-type!");
            }

            // cast safely, PUT and POST are subclasses of EntityEnclosingMethod
            final EntityEnclosingMethod enclosingMethod = (EntityEnclosingMethod) method;
            enclosingMethod.setRequestEntity(requestEntity);
            enclosingMethod.setContentChunked(params.getBooleanParameter(Properties.PROP_HTTP_REQUEST_CHUNK, false));

        } else {
            // should not happen because of HttpBindingValidator, but never say never
            throw new IllegalArgumentException("Unsupported HTTP method: " + verb);
        }
View Full Code Here

            } else if (method.equals(HTTPConstants.TRACE)){
                httpMethod = new TraceMethod(urlStr);
            } else if (method.equals(HTTPConstants.OPTIONS)){
                httpMethod = new OptionsMethod(urlStr);
            } else if (method.equals(HTTPConstants.DELETE)){
                httpMethod = new EntityEnclosingMethod(urlStr) {
                    @Override
                    public String getName() { // HC3.1 does not have the method
                        return HTTPConstants.DELETE;
                    }
                };
            } else if (method.equals(HTTPConstants.GET)){
                httpMethod = new GetMethod(urlStr);
            } else if (method.equals(HTTPConstants.PATCH)){
                httpMethod = new EntityEnclosingMethod(urlStr) {
                    @Override
                    public String getName() { // HC3.1 does not have the method
                        return HTTPConstants.PATCH;
                    }
                };
View Full Code Here

    // chunking?
    if( httpMethod.getParams().getVersion().equals( HttpVersion.HTTP_1_1 )
        && httpMethod instanceof EntityEnclosingMethod )
    {
      EntityEnclosingMethod entityEnclosingMethod = ( ( EntityEnclosingMethod )httpMethod );
      long limit = settings.getLong( HttpSettings.CHUNKING_THRESHOLD, -1 );
      RequestEntity requestEntity = entityEnclosingMethod.getRequestEntity();
      entityEnclosingMethod.setContentChunked( limit >= 0 && requestEntity != null ? requestEntity
          .getContentLength() > limit : false );
    }
  }
View Full Code Here

    }

    // set body if post method or put method
    if (body != null && body.length() > 0) {
      EntityEnclosingMethod generic = (EntityEnclosingMethod) httpMethod;
//      generic.setRequestEntity(new StringRequestEntity(body.toString()));
            generic.setRequestEntity(new ByteArrayRequestEntity(body.getBytes()));

        }

    httpMethod.setFollowRedirects(false);
    return httpMethod;
View Full Code Here

    }

    // set body if post method or put method
    if (body != null && body.length() > 0 && (httpMethod instanceof PostMethod || httpMethod instanceof PutMethod)) {
      EntityEnclosingMethod post = (EntityEnclosingMethod) httpMethod;
//      post.setRequestEntity(new StringRequestEntity(body.toString()));
            post.setRequestEntity(new ByteArrayRequestEntity(body.getBytes()));

    }

    httpMethod.setFollowRedirects(false);
    return httpMethod;
View Full Code Here

        return mesResponse;
    }
   
    protected static HttpResponse post(String url, String user, String password, String body) throws IOException {
        HttpClient httpClient = new HttpClient();
        EntityEnclosingMethod method = new PostMethod(url);
        addAuthHeader(method, user, password);
       
        method.setRequestBody(body);
       
        String contentType = "application/xml; charset=utf8";
        method.setRequestHeader("Content-type", contentType);
       
        int status = httpClient.executeMethod(method);
        InputStream responseBody = method.getResponseBodyAsStream();
       
        HttpResponse res = new HttpResponse(status, responseBody);
        return res;
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.methods.EntityEnclosingMethod

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.