Examples of ByteArrayRequestEntity


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

            ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
            for (int c = 0; c < 5000000; ++c) {
                originalContent.write(c);
            }
            byte[] entity = originalContent.toByteArray();
            postMethod.setRequestEntity(new ByteArrayRequestEntity(entity, "text/xml"));
            client.executeMethod(postMethod);
            assertEquals(277, postMethod.getStatusCode());

            InputStream respStream = postMethod.getResponseBodyAsStream();
            for (int c = 0; c < entity.length; ++c) {
View Full Code Here

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

            ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
            for (int c = 0; c < 5000000; ++c) {
                originalContent.write(c);
            }
            byte[] entity = originalContent.toByteArray();
            postMethod.setRequestEntity(new ByteArrayRequestEntity(entity, "text/xml"));
            client.executeMethod(postMethod);
            assertEquals(277, postMethod.getStatusCode());

            InputStream respStream = postMethod.getResponseBodyAsStream();
            for (int c = 0; c < entity.length; ++c) {
View Full Code Here

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

            ByteArrayOutputStream originalContent = new ByteArrayOutputStream();
            for (int c = 0; c < 5000000; ++c) {
                originalContent.write(c);
            }
            byte[] entity = originalContent.toByteArray();
            postMethod.setRequestEntity(new ByteArrayRequestEntity(entity, "text/xml"));
            client.executeMethod(postMethod);
            assertEquals(277, postMethod.getStatusCode());

            InputStream respStream = postMethod.getResponseBodyAsStream();
            for (int c = 0; c < entity.length; ++c) {
View Full Code Here

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

      assertTrue(l.removed.isEmpty());
      assertTrue(l.modified.isEmpty());
      assertTrue(l.visited.isEmpty());

      EntityEnclosingMethod put = new PutMethod(restUrl + "/k");
      put.setRequestEntity(new ByteArrayRequestEntity(
            "v".getBytes(), "application/octet-stream"));
      remote.executeMethod(put);

      assertEquals(1, l.createdCounter);
      assertEquals("v".getBytes(), (byte[]) l.created.get("k"));
      assertTrue(l.removed.isEmpty());
      assertEquals(1, l.modifiedCounter);
      assertEquals("v".getBytes(), (byte[]) l.modified.get("k"));
      assertTrue(l.visited.isEmpty());


      EntityEnclosingMethod put2 = new PutMethod(restUrl + "/key");
      put2.setRequestEntity(new ByteArrayRequestEntity(
            "value".getBytes(), "application/octet-stream"));
      remote.executeMethod(put2);

      assertEquals(2, l.createdCounter);
      assertTrue(l.removed.isEmpty());
      assertEquals(2, l.modifiedCounter);
      assertTrue(l.visited.isEmpty());

      EntityEnclosingMethod put3 = new PutMethod(restUrl + "/key");
      put3.setRequestEntity(new ByteArrayRequestEntity(
            "modifiedValue".getBytes(), "application/octet-stream"));
      remote.executeMethod(put3);

      assertEquals(2, l.createdCounter);
      assertTrue(l.removed.isEmpty());
      assertEquals(3, l.modifiedCounter);
      assertEquals("modifiedValue".getBytes(), (byte[]) l.modified.get("key"));
      assertTrue(l.visited.isEmpty());

      EntityEnclosingMethod post = new PutMethod(restUrl + "/k");
      post.setRequestEntity(new ByteArrayRequestEntity(
            "replacedValue".getBytes(), "application/octet-stream"));
      remote.executeMethod(post);

      assertEquals(2, l.createdCounter);
      assertTrue(l.removed.isEmpty());
View Full Code Here

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

        if (getConfiguration().isStreamingEnabled()) {
            return new StreamingRequestEntity(writer);
        } else {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            writer.write(baos);
            return new ByteArrayRequestEntity(baos.toByteArray(), writer.getContentType());
        }
    }
View Full Code Here

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

        }
        HttpClient agent = new HttpClient();
        PostMethod postMethod = new PostMethod(epr.getAddress());
        try {
            postMethod.setRequestEntity(new ByteArrayRequestEntity(
                    XML.toString(jsonObject).getBytes()));
            agent.executeMethod(postMethod);

            if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
                processResponse(postMethod, msgContext);
View Full Code Here

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

        return execute(httpget, n);
    }

    public Stats post(URI target, byte[] content, int n) throws Exception {
        PostMethod httppost = new PostMethod(target.toASCIIString());
        httppost.setRequestEntity(new ByteArrayRequestEntity(content));
        return execute(httppost, n);
    }
View Full Code Here

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

        return requestBuffer;
    }

    @Override
    protected void onSendAfterWrite(WebServiceMessage message) throws IOException {
        postMethod.setRequestEntity(new ByteArrayRequestEntity(requestBuffer.toByteArray()));
        requestBuffer = null;
        try {
            httpClient.executeMethod(postMethod);
        } catch (IllegalStateException ex) {
            if ("Connection factory has been shutdown.".equals(ex.getMessage())) {
View Full Code Here

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

                httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_FORM_URLENCODED)
                && httpServletRequest.getHeader("content-encoding") == null) {
            requestByteArray = IOUtils.toByteArray(body);

            // this is binary.. just return it as is
            requestEntity = new ByteArrayRequestEntity(requestByteArray);

            // Get the client POST data as a Map if content type is: application/x-www-form-urlencoded
            // We do this manually since some data is not properly parseable by the servlet request
            Map<String, String[]> mapPostParameters = HttpUtilities.mapUrlEncodedParameters(requestByteArray);

            // Iterate the parameter names
            for (String stringParameterName : mapPostParameters.keySet()) {
                // Iterate the values for each parameter name
                String[] stringArrayParameterValues = mapPostParameters
                        .get(stringParameterName);
                for (String stringParameterValue : stringArrayParameterValues) {
                    // Create a NameValuePair and store in list

                    // add an & if there is already data
                    if (requestBody.length() > 0) {
                        requestBody.append("&");
                    }

                    requestBody.append(stringParameterName);

                    // not everything has a value so lets check
                    if (stringParameterValue.length() > 0) {
                        requestBody.append("=");
                        requestBody.append(stringParameterValue);
                    }
                }
            }
        } else if (httpServletRequest.getContentType() != null &&
                httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_MESSAGEPACK)) {

            /**
             * Convert input stream to bytes for it to be read by the deserializer
             * Unpack and iterate the list to see the contents
             */
            MessagePack msgpack = new MessagePack();
            requestByteArray = IOUtils.toByteArray(body);
            requestEntity = new ByteArrayRequestEntity(requestByteArray);
            ByteArrayInputStream byteArrayIS = new ByteArrayInputStream(requestByteArray);
            Unpacker unpacker = msgpack.createUnpacker(byteArrayIS);

            for (Value message : unpacker) {
                deserialisedMessages += message;
                deserialisedMessages += "\n";
            }

            history.setRequestBodyDecoded(true);
        } else {
            requestByteArray = IOUtils.toByteArray(body);

            // this is binary.. just return it as is
            requestEntity = new ByteArrayRequestEntity(requestByteArray);

            // decode this for history if it is encoded
            String requestBodyString = PluginHelper.getByteArrayDataAsString(httpServletRequest.getHeader("content-encoding"), requestByteArray);
            requestBody.append(requestBodyString);

            // mark in history if the body has been decoded
            if (! requestBodyString.equals(new String(requestByteArray)))
                history.setRequestBodyDecoded(true);
        }

        // set post body in history object
        history.setRequestPostData(requestBody.toString());

        // set post body in proxy request object
        methodProxyRequest.setRequestEntity(requestEntity);

        /**
         * Set the history to have decoded messagepack. Pass the byte data back to request
         */
        if (httpServletRequest.getContentType() != null &&
                httpServletRequest.getContentType().contains(STRING_CONTENT_TYPE_MESSAGEPACK)) {
            history.setRequestPostData(deserialisedMessages);
            ByteArrayRequestEntity byteRequestEntity = new ByteArrayRequestEntity(requestByteArray);
            methodProxyRequest.setRequestEntity(byteRequestEntity);

        }
    }
View Full Code Here

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

   */
  public Response put(Cluster cluster, String path, Header[] headers,
      byte[] content) throws IOException {
    PutMethod method = new PutMethod();
    try {
      method.setRequestEntity(new ByteArrayRequestEntity(content));
      int code = execute(cluster, method, headers, path);
      headers = method.getResponseHeaders();
      content = method.getResponseBody();
      return new Response(code, headers, content);
    } finally {
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.