Package org.exoplatform.common.http.client

Examples of org.exoplatform.common.http.client.HTTPConnection


      }

      try
      {
         URL url = new URL(urlParam);
         HTTPConnection conn = new HTTPConnection(url);
         conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
         NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
            Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
         conn.setAllowUserInteraction(false);
         NVPair credentials = getCredentials(url);
         if (credentials != null)
         {
            conn.addBasicAuthorization(null, credentials.getName(), credentials.getValue());
         }
         HTTPResponse resp = null;
         if (entity != null)
         {
            HttpOutputStream stream = new HttpOutputStream();
            resp = conn.Put(url.getFile(), stream, headerPairs);
            byte[] buf = new byte[1024];
            int r = -1;
            while ((r = entity.read(buf)) != -1)
            {
               stream.write(buf, 0, r);
            }
            stream.close();
         }
         else
         {
            resp = conn.Put(url.getFile(), new byte[0], headerPairs);
         }

         if (resp.getStatusCode() >= 300)
         {
            if (LOG.isDebugEnabled())
View Full Code Here


         throw new WebApplicationException(e, createErrorResponse(e, 404));
      }
      try
      {
         URL url = new URL(urlParam);
         HTTPConnection conn = new HTTPConnection(url);
         conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
         NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
            Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
         conn.setAllowUserInteraction(false);
         NVPair credentials = getCredentials(url);
         if (credentials != null)
         {
            conn.addBasicAuthorization(null, credentials.getName(), credentials.getValue());
         }
         HTTPResponse resp = conn.Delete(url.getFile(), headerPairs);
         if (resp.getStatusCode() >= 300)
         {
            if (LOG.isDebugEnabled())
            {
               // Do not read data if debug is off.
View Full Code Here

         throw new WebApplicationException(e, createErrorResponse(e, 404));
      }
      try
      {
         URL url = new URL(urlParam);
         HTTPConnection conn = new HTTPConnection(url);
         conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
         NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
            Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
         conn.setAllowUserInteraction(false);
         NVPair credentials = getCredentials(url);
         if (credentials != null)
         {
            conn.addBasicAuthorization(null, credentials.getName(), credentials.getValue());
         }
         HTTPResponse resp = conn.Get(url.getFile(), (NVPair[])null, headerPairs);
         if (resp.getStatusCode() >= 300)
         {
            if (LOG.isDebugEnabled())
            {
               // Do not read data if debug is off.
View Full Code Here

      }

      try
      {
         URL url = new URL(urlParam);
         HTTPConnection conn = new HTTPConnection(url);
         conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
         NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
            Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
         conn.setAllowUserInteraction(false);
         NVPair credentials = getCredentials(url);
         if (credentials != null)
         {
            conn.addBasicAuthorization(null, credentials.getName(), credentials.getValue());
         }
         HTTPResponse resp = null;
         if (entity != null)
         {
            HttpOutputStream stream = new HttpOutputStream();
            resp = conn.Post(url.getFile(), stream, headerPairs);
            byte[] buf = new byte[1024];
            int r = -1;
            while ((r = entity.read(buf)) != -1)
            {
               stream.write(buf, 0, r);
            }
            stream.close();
         }
         else
         {
            resp = conn.Post(url.getFile(), (NVPair[])null, headerPairs);
         }

         if (resp.getStatusCode() >= 300)
         {
            if (LOG.isDebugEnabled())
View Full Code Here

      }

      try
      {
         URL url = new URL(urlParam);
         HTTPConnection conn = new HTTPConnection(url);
         conn.setTimeout(DEFAULT_CONNECT_TIMEOUT_MS);
         NVPair[] headerPairs = toNVPair(headers.getRequestHeaders(), //
            Collections.singleton(new CaseInsensitiveStringWrapper(HttpHeaders.HOST)));
         conn.setAllowUserInteraction(false);
         NVPair credentials = getCredentials(url);
         if (credentials != null)
         {
            conn.addBasicAuthorization(null, credentials.getName(), credentials.getValue());
         }
         HTTPResponse resp = null;
         if (entity != null)
         {
            HttpOutputStream stream = new HttpOutputStream();
            resp = conn.Put(url.getFile(), stream, headerPairs);
            byte[] buf = new byte[1024];
            int r = -1;
            while ((r = entity.read(buf)) != -1)
            {
               stream.write(buf, 0, r);
            }
            stream.close();
         }
         else
         {
            resp = conn.Put(url.getFile(), new byte[0], headerPairs);
         }

         if (resp.getStatusCode() >= 300)
         {
            if (LOG.isDebugEnabled())
View Full Code Here

      AuthorizationHandler ah = AuthorizationInfo.getAuthHandler();

      try
      {
         URL url = new URL(sUrl);
         HTTPConnection connection = new HTTPConnection(url);
         connection.removeModule(CookieModule.class);
         AuthorizationInfo.setAuthHandler(null);

         HTTPResponse resp = connection.Get(url.getFile());

         String authHeader = resp.getHeader("WWW-Authenticate");
         if (authHeader == null)
         {
            return null;
View Full Code Here

      {
         // execute the POST
         String complURL = protocol + "://" + host + sURL;

         URL url = new URL(complURL);
         HTTPConnection connection = new HTTPConnection(url);
         connection.setAllowUserInteraction(false);

         //authentication
         if (formAuthentication != null)
         {
            //form authentication
            HTTPResponse respLogin;

            URL urlLogin = new URL(protocol + "://" + host + formAuthentication.getFormPath());

            HTTPConnection connectionLogin = new HTTPConnection(urlLogin);
            connectionLogin.setAllowUserInteraction(false);

            NVPair[] formParams = new NVPair[formAuthentication.getFormParams().size()];
            int pairCount = 0;
            for (String key : formAuthentication.getFormParams().keySet())
            {
               formParams[pairCount++] = new NVPair(key, formAuthentication.getFormParams().get(key));
            }

            if ("POST".equalsIgnoreCase(formAuthentication.getMethod()))
            {
               respLogin = connectionLogin.Post(urlLogin.getFile(), formParams);
            }
            else
            {
               respLogin = connectionLogin.Get(urlLogin.getFile(), formParams);
            }

            if (Response.Status.OK.getStatusCode() != respLogin.getStatusCode())
            {
               System.out.println("Form authentication is fail, status code : " + respLogin.getStatusCode()); //NOSONAR
View Full Code Here

      {
         // execute the GET
         String complURL = protocol + "://" + host + sURL;

         URL url = new URL(complURL);
         HTTPConnection connection = new HTTPConnection(url);
         connection.setAllowUserInteraction(false);

         //authentication
         if (formAuthentication != null)
         {
            //form authentication
            HTTPResponse respLogin;

            URL urlLogin = new URL(protocol + "://" + host + formAuthentication.getFormPath());

            HTTPConnection connectionLogin = new HTTPConnection(urlLogin);
            connectionLogin.setAllowUserInteraction(false);

            NVPair[] formParams = new NVPair[formAuthentication.getFormParams().size()];
            int pairCount = 0;
            for (String key : formAuthentication.getFormParams().keySet())
            {
               formParams[pairCount++] = new NVPair(key, formAuthentication.getFormParams().get(key));
            }

            if ("POST".equalsIgnoreCase(formAuthentication.getMethod()))
            {
               respLogin = connectionLogin.Post(urlLogin.getFile(), formParams);
            }
            else
            {
               respLogin = connectionLogin.Get(urlLogin.getFile(), formParams);
            }

            if (Response.Status.OK.getStatusCode() != respLogin.getStatusCode())
            {
               System.out.println("Form authentication is fail, status code : " + respLogin.getStatusCode()); //NOSONAR
View Full Code Here

   public static final String ROOTPASS = "exo";

   public static HTTPConnection GetAuthConnection()
   {
      HTTPConnection connection = new HTTPConnection(HOST, WebDav.PORT_INT);
      connection.addBasicAuthorization(REALM, ROOTID, ROOTPASS);

      return connection;
   }
View Full Code Here

         if (remotePath.contains("?version"))
         {
            remotePath = remotePath.substring(0, remotePath.lastIndexOf("?"));
         }

         HTTPConnection connection = WebDavUtils.getAuthConnection(config);

         String type = localPath.substring(localPath.lastIndexOf('.'));
         String mimetype = TextUtils.getMimeType(type);

         NVPair mimeHeader = new NVPair(WebDavProp.CONTENTTYPE, mimetype);

         NVPair[] headers = new NVPair[]
         {mimeHeader};

         HTTPResponse response =
                  connection.Put(WebDavUtils.getFullPath(config) + TextUtils.EncodePath(remotePath), WebDavUtils
                           .getBytes(inFile), headers);

         int status = response.getStatusCode();
         if (status == HTTPStatus.CREATED)
         {
View Full Code Here

TOP

Related Classes of org.exoplatform.common.http.client.HTTPConnection

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.