Package org.apache.http.client.methods

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


    public static HttpAsyncRequestProducer createPut(
            final URI requestURI,
            final byte[] content,
            final ContentType contentType) {
        HttpPut httpput = new HttpPut(requestURI);
        NByteArrayEntity entity = new NByteArrayEntity(content, contentType);
        HttpHost target = URIUtils.extractHost(requestURI);
        return new RequestProducerImpl(target, httpput, entity);
    }
View Full Code Here


        Assert.assertEquals(405, response.getStatusLine().getStatusCode());
    }

    @Test
    public void doNotAllowPut() throws Exception {
        HttpResponse response = httpclient.execute(new HttpPut(getServerUrl()));

        Assert.assertEquals(405, response.getStatusLine().getStatusCode());
    }
View Full Code Here

        {
            httpRequestBase = new HttpGet( url + path );
        }
        else
        {
            HttpPut httpPut = new HttpPut( url + path );

            httpPut.setEntity( new RequestEntityImplementation( data, length, url + path ) );

            httpRequestBase = httpPut;

        }
View Full Code Here

                              provider.getMediator(),
                              abderaFactory);
            }

            // Send an HTTP PUT
            HttpPut putMethod = new HttpPut(uri + "/" + id);
            if (authorizationHeader != null) {
                putMethod.setHeader("Authorization", authorizationHeader);
            }

            HttpResponse response = null;
            try {

                // Write the Atom entry
                StringWriter writer = new StringWriter();
                feedEntry.writeTo(writer);
                //putMethod.setHeader("Content-type", "application/atom+xml; charset=utf-8"); - TUSCANY-3734
                putMethod.setHeader("Content-type", "application/atom+xml");
                putMethod.setEntity(new StringEntity(writer.toString()));

                response = httpClient.execute(putMethod);
                int status = response.getStatusLine().getStatusCode();
                if (status == 200 || status == 201 || status == 412) {
View Full Code Here

        // PUT /edit/the_beach.png HTTP/1.1
        // Host: media.example.org
        // Content-Type: image/png
        // Content-Length: nnn
        // ...binary data...
        HttpPut put = new HttpPut(providerURI + "/" + mediaId);
        put.addHeader("Content-Type", "image/jpg");
        put.addHeader("Title", "Title " + receiptName + "");
        put.addHeader("Slug", "Slug " + receiptName + "");
        put.setEntity(new FileEntity(input, "image/jpg"));

        // Get HTTP client
        HttpClient httpclient = new HttpClientFactory().createHttpClient();
        try {
            // Execute request
View Full Code Here

        // PUT /edit/the_beach.png HTTP/1.1
        // Host: media.example.org
        // Content-Type: image/png
        // Content-Length: nnn
        // ...binary data...
        HttpPut put = new HttpPut(providerURI + "/" + mediaId + "-bogus"); // Does not exist.
        put.addHeader("Content-Type", "image/jpg");
        put.addHeader("Title", "Title " + receiptName + "");
        put.addHeader("Slug", "Slug " + receiptName + "");
        put.setEntity(new FileEntity(input, "image/jpg"));

        // Get HTTP client
        HttpClient httpclient = new HttpClientFactory().createHttpClient();
        try {
            // Execute request
View Full Code Here

       
    }
   
    @Test
    public void testPutConsumer() throws Exception {
        HttpPut put = new HttpPut("http://localhost:" + CXT + "/rest/customerservice/customers");
        StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        put.addHeader("test", "header1;header2");
        put.setEntity(entity);
        HttpClient httpclient = new DefaultHttpClient();

        try {
            HttpResponse response = httpclient.execute(put);
            assertEquals(200, response.getStatusLine().getStatusCode());
View Full Code Here

                        "{\"Product\":{\"description\":\"product 323\",\"id\":323}}");
    }

    @Test
    public void testPutConsumer() throws Exception {
        HttpPut put = new HttpPut("http://localhost:" + PORT1 + "/customerservice/customers");
        StringEntity entity = new StringEntity(PUT_REQUEST, "ISO-8859-1");
        entity.setContentType("text/xml; charset=ISO-8859-1");
        put.setEntity(entity);
        HttpClient httpclient = new DefaultHttpClient();

        try {
            HttpResponse response = httpclient.execute(put);
            assertEquals(200, response.getStatusLine().getStatusCode());
View Full Code Here

        TestCredentialsProvider credsProvider = new TestCredentialsProvider(
                new UsernamePasswordCredentials("test", "test"));

        this.httpclient.setCredentialsProvider(credsProvider);

        HttpPut httpput = new HttpPut("/");

        NByteArrayEntity entity = new NByteArrayEntity(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }) {

            @Override
            public boolean isRepeatable() {
                return false;
            }

        };

        httpput.setEntity(entity);
        httpput.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, true);

        Future<HttpResponse> future = this.httpclient.execute(target, httpput, null);
        HttpResponse response = future.get();
        Assert.assertNotNull(response);
        Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
View Full Code Here

        TestCredentialsProvider credsProvider = new TestCredentialsProvider(
                new UsernamePasswordCredentials("test", "test"));

        this.httpclient.setCredentialsProvider(credsProvider);

        HttpPut httpput = new HttpPut("/");

        NByteArrayEntity requestEntity = new NByteArrayEntity(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 }) {

            @Override
            public boolean isRepeatable() {
                return false;
            }

        };

        httpput.setEntity(requestEntity);
        httpput.getParams().setBooleanParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);

        try {
            Future<HttpResponse> future = this.httpclient.execute(target, httpput, null);
            future.get();
            Assert.fail("ExecutionException should have been thrown");
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.