Package org.apache.commons.httpclient.methods

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


        StringWriter sw = new StringWriter();
        Marshaller m = context.createMarshaller();
        m.marshal(element, sw);
        PostMethod postMethod = new PostMethod(getBaseURI());
        try {
            postMethod.setRequestEntity(new ByteArrayRequestEntity(sw.toString().getBytes(),
                                                                   "text/xml"));
            httpClient.executeMethod(postMethod);
            assertEquals(204, postMethod.getStatusCode());
        } finally {
            postMethod.releaseConnection();
View Full Code Here


            StringWriter sw = new StringWriter();
            marshaller.marshal(newDepartment, sw);
            HttpClient client = new HttpClient();
            postMethod = new PostMethod(getBaseURI());
            RequestEntity reqEntity =
                new ByteArrayRequestEntity(sw.toString().getBytes(), "text/xml");
            postMethod.setRequestEntity(reqEntity);
            client.executeMethod(postMethod);

            newDepartment = new Department();
            newDepartment.setDepartmentId("2");
            newDepartment.setDepartmentName("Sales");
            sw = new StringWriter();
            marshaller.marshal(newDepartment, sw);
            client = new HttpClient();
            postMethod = new PostMethod(getBaseURI());
            reqEntity = new ByteArrayRequestEntity(sw.toString().getBytes(), "text/xml");
            postMethod.setRequestEntity(reqEntity);
            client.executeMethod(postMethod);

            // now let's get the list of Departments that we just created
            // (should be 2)
View Full Code Here

            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

            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

                        // serialized java object
                        Serializable obj = in.getMandatoryBody(Serializable.class);
                        // write object to output stream
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        HttpHelper.writeObjectToStream(bos, obj);
                        answer = new ByteArrayRequestEntity(bos.toByteArray(), HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
                        IOHelper.close(bos);
                    } else if (data instanceof File || data instanceof GenericFile) {
                        // file based (could potentially also be a FTP file etc)
                        File file = in.getBody(File.class);
                        if (file != null) {
View Full Code Here

                        // serialized java object
                        Serializable obj = in.getMandatoryBody(Serializable.class);
                        // write object to output stream
                        ByteArrayOutputStream bos = new ByteArrayOutputStream();
                        HttpHelper.writeObjectToStream(bos, obj);
                        answer = new ByteArrayRequestEntity(bos.toByteArray(), HttpConstants.CONTENT_TYPE_JAVA_SERIALIZED_OBJECT);
                        IOHelper.close(bos);
                    } else if (data instanceof File || data instanceof GenericFile) {
                        // file based (could potentially also be a FTP file etc)
                        File file = in.getBody(File.class);
                        if (file != null) {
View Full Code Here

            if (log.isDebugEnabled()) {
                log.debug("Outbound SOAP message is:\n" + XMLHelper.prettyPrintXML(marshaller.marshall(message)));
            }
            XMLHelper.writeNode(marshaller.marshall(message), writer);
            return new ByteArrayRequestEntity(arrayOut.toByteArray(), "text/xml");
        } catch (MarshallingException e) {
            throw new SOAPClientException("Unable to marshall SOAP envelope", e);
        }
    }
View Full Code Here

        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

        RequestEntity entity = in.getBody(RequestEntity.class);
        if (entity == null) {
            byte[] data = in.getBody(byte[].class);
            String contentType = in.getHeader("Content-Type", String.class);
            if (contentType != null) {
                return new ByteArrayRequestEntity(data, contentType);
            }
            else {
                return new ByteArrayRequestEntity(data);
            }
        }
        return entity;
    }
View Full Code Here

                }
            }
            else if (dataClass.isArray() && Byte.TYPE.equals(dataClass.getComponentType()))
            {
                byte[] dataBytes = (byte[])data;
                ByteArrayRequestEntity requestEntity = new ByteArrayRequestEntity(dataBytes, context.getContentType());
                ((EntityEnclosingMethod)httpMethod).setRequestEntity(requestEntity);
            }
            else if (data instanceof InputStream)
            {
                InputStreamRequestEntity requestEntity = new InputStreamRequestEntity((InputStream)data, context.getContentType());
View Full Code Here

TOP

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

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.