Package java.net

Examples of java.net.HttpURLConnection


public class JSONCodecTest extends TestCase {
  public static String END_POINT = "http://localhost:8080/unitTest/json/parameter";
 
  protected String postOnEndPoint(String postBody) throws MalformedURLException, IOException {
    HttpURLConnection connection = (HttpURLConnection) new URL(END_POINT).openConnection();
    connection.setRequestProperty("Content-Type", "application/json");
    connection.setDoOutput(true);
    connection.getOutputStream().write(postBody.getBytes());
    BufferedReader bufReader = new BufferedReader(new InputStreamReader(connection.getResponseCode() < 300 ? connection.getInputStream() :
      connection.getErrorStream()));
    StringBuffer buf = new StringBuffer();
    String str = bufReader.readLine();
    while(str != null){
      buf.append(str);
      str = bufReader.readLine();
    }
    bufReader.close();
    connection.disconnect();
    return buf.toString();
  }
View Full Code Here


        return buff.toString();
    }

    /** {@inheritDoc} */
    public InConnection getInbound() throws IOException, WsConfigurationException {
        HttpURLConnection connection = (HttpURLConnection)m_url.openConnection();
        connection.connect();
        return createInConnection(connection);
    }
View Full Code Here

    }

    /** {@inheritDoc} */
    public OutConnection getOutbound(MessageProperties properties, XmlOptions xmlOptions) throws IOException,
            WsConfigurationException {
        HttpURLConnection connection = (HttpURLConnection)m_url.openConnection();
        connection.setDoInput(false);
        setupOutput(connection, properties);
        connection.connect();
        return createOutConnection(connection, properties, xmlOptions);
    }
View Full Code Here

    }

    /** {@inheritDoc} */
    public DuplexConnection getDuplex(MessageProperties properties, XmlOptions xmlOptions) throws IOException,
            WsConfigurationException {
        HttpURLConnection connection = (HttpURLConnection)m_url.openConnection();
        connection.setDoInput(true);
        setupOutput(connection, properties);
        connection.connect();
        return new SimpleDuplexConnection(createInConnection(connection),
            createOutConnection(connection, properties, xmlOptions));
    }
View Full Code Here

            // validate bucket name
            if(!Utils.validateBucketName(bucket, callingFormat))
                throw new IllegalArgumentException("Invalid Bucket Name: " + bucket);

            HttpURLConnection request=makeRequest("PUT", bucket, "", null, headers);
            if(body != null) {
                request.setDoOutput(true);
                request.getOutputStream().write(body.getBytes("UTF-8"));
            }
            return new Response(request);
        }
View Full Code Here

         * Check if the specified bucket exists (via a HEAD request)
         * @param bucket The name of the bucket to check
         * @return true if HEAD access returned success
         */
        public boolean checkBucketExists(String bucket) throws IOException {
            HttpURLConnection response=makeRequest("HEAD", bucket, "", null, null);
            int httpCode=response.getResponseCode();

            if(httpCode >= 200 && httpCode < 300)
                return true;
            if(httpCode == HttpURLConnection.HTTP_NOT_FOUND) // bucket doesn't exist
                return false;
            throw new IOException("bucket '" + bucket + "' could not be accessed (rsp=" +
                    httpCode + " (" + response.getResponseMessage() + "). Maybe the bucket is owned by somebody else or " +
                    "the authentication failed");

        }
View Full Code Here

         * @param object  An S3Object containing the data to write.
         * @param headers A Map of String to List of Strings representing the http
         *                headers to pass (can be null).
         */
        public Response put(String bucket, String key, S3Object object, Map headers) throws IOException {
            HttpURLConnection request=
                    makeRequest("PUT", bucket, Utils.urlencode(key), null, headers, object);

            request.setDoOutput(true);
            request.getOutputStream().write(object.data == null? new byte[]{} : object.data);

            return new Response(request);
        }
View Full Code Here

            return new Response(request);
        }

        public Response put(String preSignedUrl, S3Object object, Map headers) throws IOException {
            HttpURLConnection request = makePreSignedRequest("PUT", preSignedUrl, headers);
            request.setDoOutput(true);
            request.getOutputStream().write(object.data == null? new byte[]{} : object.data);

            return new Response(request);
        }
View Full Code Here

        public Response putBucketRequestPayment(String bucket, String requestPaymentXMLDoc, Map headers)
                throws IOException {
            Map pathArgs=new HashMap();
            pathArgs.put("requestPayment", null);
            S3Object object=new S3Object(requestPaymentXMLDoc.getBytes(), null);
            HttpURLConnection request=makeRequest("PUT", bucket, "", pathArgs, headers, object);

            request.setDoOutput(true);
            request.getOutputStream().write(object.data == null? new byte[]{} : object.data);

            return new Response(request);
        }
View Full Code Here

         */
        public Response putBucketLogging(String bucket, String loggingXMLDoc, Map headers) throws IOException {
            Map pathArgs=new HashMap();
            pathArgs.put("logging", null);
            S3Object object=new S3Object(loggingXMLDoc.getBytes(), null);
            HttpURLConnection request=makeRequest("PUT", bucket, "", pathArgs, headers, object);

            request.setDoOutput(true);
            request.getOutputStream().write(object.data == null? new byte[]{} : object.data);

            return new Response(request);
        }
View Full Code Here

TOP

Related Classes of java.net.HttpURLConnection

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.