Package org.apache.commons.httpclient.methods

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


            } else if (method.equals(HTTPConstants.DELETE)){
                httpMethod = new DeleteMethod(urlStr);
            } 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 "PATCH";
                    }
                };
View Full Code Here


            } else if (method.equalsIgnoreCase(Method.OPTIONS.getName())) {
                this.httpMethod = new OptionsMethod(requestUri);
            } else if (method.equalsIgnoreCase(Method.TRACE.getName())) {
                this.httpMethod = new TraceMethod(requestUri);
            } else {
                this.httpMethod = new EntityEnclosingMethod(requestUri) {
                    @Override
                    public String getName() {
                        return method;
                    }
                };
View Full Code Here

            }

            // For those method that accept enclosing entites, provide it
            if ((entity != null)
                    && (getHttpMethod() instanceof EntityEnclosingMethod)) {
                final EntityEnclosingMethod eem = (EntityEnclosingMethod) getHttpMethod();
                eem.setRequestEntity(new RequestEntity() {
                    public long getContentLength() {
                        return entity.getSize();
                    }

                    public String getContentType() {
View Full Code Here

   public void testRestPutEmbeddedHotRodGet() throws Exception {
      final String key = "1";

      // 1. Put with REST
      EntityEnclosingMethod put = new PutMethod(cacheFactory1.getRestUrl() + "/" + key);
      put.setRequestEntity(new ByteArrayRequestEntity(
            "<hey>ho</hey>".getBytes(), "application/octet-stream"));
      HttpClient restClient = cacheFactory1.getRestClient();
      restClient.executeMethod(put);
      assertEquals(HttpServletResponse.SC_OK, put.getStatusCode());
      assertEquals("", put.getResponseBodyAsString().trim());

      // 2. Get with Embedded
      assertArrayEquals("<hey>ho</hey>".getBytes(), (byte[])
            cacheFactory2.getEmbeddedCache().get(key));
View Full Code Here

   public void testRestPutEmbeddedMemcachedHotRodGetTest() throws Exception {
      final String key = "3";

      // 1. Put with REST
      EntityEnclosingMethod put = new PutMethod(cacheFactory.getRestUrl() + "/" + key);
      put.setRequestEntity(new ByteArrayRequestEntity(
            "<hey>ho</hey>".getBytes(), "application/octet-stream"));
      HttpClient restClient = cacheFactory.getRestClient();
      restClient.executeMethod(put);
      assertEquals(HttpServletResponse.SC_OK, put.getStatusCode());
      assertEquals("", put.getResponseBodyAsString().trim());

      // 2. Get with Embedded (given a marshaller, it can unmarshall the result)
      assertEquals("<hey>ho</hey>",
            cacheFactory.getEmbeddedCache().get(key));
View Full Code Here

   public void testRestPutEmbeddedHotRodGet() throws Exception {
      final String key = "1";

      // 1. Put with REST
      EntityEnclosingMethod put = new PutMethod(cacheFactory.getRestUrl() + "/" + key);
      put.setRequestEntity(new ByteArrayRequestEntity(
            "<hey>ho</hey>".getBytes(), "application/octet-stream"));
      HttpClient restClient = cacheFactory.getRestClient();
      restClient.executeMethod(put);
      assertEquals(HttpServletResponse.SC_OK, put.getStatusCode());
      assertEquals("", put.getResponseBodyAsString().trim());

      // 2. Get with Embedded
      assertArrayEquals("<hey>ho</hey>".getBytes(), (byte[])
            cacheFactory.getEmbeddedCache().get(key));
View Full Code Here

                    requestEntity = new StringRequestEntity(DOMUtils.getTextContent(partValue), contentType, contentCharset);
                }
            }

            // 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

        for (int i = 0; i < headers.length; i++) {
            Header h = headers[i];
            sb.append("\n\t").append(h.getName()).append(": ").append(h.getValue());
        }
        if (m instanceof EntityEnclosingMethod) {
            EntityEnclosingMethod eem = (EntityEnclosingMethod) m;
            if (eem.getRequestEntity() != null) {
                sb.append("\nRequest Entity:");
                sb.append("\n\tContent-Type:").append(eem.getRequestEntity().getContentType());
                sb.append("\n\tContent-Length:").append(eem.getRequestEntity().getContentLength());
                if (eem.getRequestEntity() instanceof StringRequestEntity) {
                    StringRequestEntity sre = (StringRequestEntity) eem.getRequestEntity();
                    sb.append("\n\tContent-Charset:").append(sre.getCharset());
                    sb.append("\n\tRequest Entity:\n").append(sre.getContent());
                }
            }
        }
View Full Code Here

    checkRepositoryURL();

    String uploadURL = Protocol.getStatementsLocation(getRepositoryURL());

    // Select appropriate HTTP method
    EntityEnclosingMethod method;
    if (overwrite) {
      method = new PutMethod(uploadURL);
    }
    else {
      method = new PostMethod(uploadURL);
    }

    setDoAuthentication(method);

    // Set relevant query parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>(5);
    for (String encodedContext : Protocol.encodeContexts(contexts)) {
      params.add(new NameValuePair(Protocol.CONTEXT_PARAM_NAME, encodedContext));
    }
    if (baseURI != null && baseURI.trim().length() != 0) {
      String encodedBaseURI = Protocol.encodeValue(new URIImpl(baseURI));
      params.add(new NameValuePair(Protocol.BASEURI_PARAM_NAME, encodedBaseURI));
    }
    method.setQueryString(params.toArray(new NameValuePair[params.size()]));

    // Set payload
    method.setRequestEntity(reqEntity);

    // Send request
    try {
      int httpCode = httpClient.executeMethod(method);

      if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
        throw new UnauthorizedException();
      }
      else if (httpCode == HttpURLConnection.HTTP_UNSUPPORTED_TYPE) {
        throw new UnsupportedRDFormatException(method.getResponseBodyAsString());
      }
      else if (!HttpClientUtil.is2xx(httpCode)) {
        ErrorInfo errInfo = ErrorInfo.parse(method.getResponseBodyAsString());

        if (errInfo.getErrorType() == ErrorType.MALFORMED_DATA) {
          throw new RDFParseException(errInfo.getErrorMessage());
        }
        else if (errInfo.getErrorType() == ErrorType.UNSUPPORTED_FILE_FORMAT) {
View Full Code Here

  public void setNamespacePrefix(String prefix, String name)
    throws IOException, RepositoryException, UnauthorizedException
  {
    checkRepositoryURL();

    EntityEnclosingMethod method = new PutMethod(Protocol.getNamespacePrefixLocation(repositoryURL, prefix));
    setDoAuthentication(method);
    method.setRequestEntity(new StringRequestEntity(name, "text/plain", "UTF-8"));

    try {
      int httpCode = httpClient.executeMethod(method);

      if (httpCode == HttpURLConnection.HTTP_UNAUTHORIZED) {
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.