Package org.exoplatform.common.http.client

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


   public HTTPResponse restore(String node, String version) throws IOException, ModuleException
   {
      NVPair[] query = new NVPair[1];
      query[0] = new NVPair("version", version);

      HTTPResponse response = Get(workspacePath + node, query);
      response.getStatusCode();

      return response;
   }
View Full Code Here


      headers[0] =
         new NVPair(ExtHttpHeaders.DESTINATION, this.getProtocol() + "://" + this.getHost() + ":" + this.getPort()
            + workspacePath + destination);
      headers[1] = new NVPair(HttpHeaders.CONTENT_LENGTH, Integer.toString("".length()));

      HTTPResponse response = ExtensionMethod("MOVE", workspacePath + path, "".getBytes(), headers);
      response.getStatusCode();

      return response;
   }
View Full Code Here

      NVPair[] headers = new NVPair[2];
      headers[0] = new NVPair(HttpHeaders.CONTENT_TYPE, "text/xml; charset='utf-8'");
      headers[1] = new NVPair(HttpHeaders.CONTENT_LENGTH, Integer.toString(xmlBody.length()));

      HTTPResponse response = ExtensionMethod("SEARCH", workspacePath, xmlBody.getBytes(), headers);
      response.getStatusCode();

      return response;
   }
View Full Code Here

      NVPair[] headers = new NVPair[2];
      headers[0] = new NVPair(HttpHeaders.CONTENT_TYPE, "text/xml; charset='utf-8'");
      headers[1] = new NVPair(HttpHeaders.CONTENT_LENGTH, Integer.toString(xmlBody.length()));

      HTTPResponse response = ExtensionMethod("SEARCH", workspacePath, xmlBody.getBytes(), headers);
      response.getStatusCode();

      return response;
   }
View Full Code Here

         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.
               // Client may get empty response, may not read stream twice.
               LOG.debug("DELETE. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
               byte[] data = resp.getData();
               if (data != null)
               {
                  LOG.debug("DELETE. Text : " + new String(data));
               }
            }
View Full Code Here

         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.
               // Client may get empty response, may not read stream twice.
               LOG.debug("GET. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
               byte[] data = resp.getData();
               if (data != null)
               {
                  LOG.debug("GET. Text : " + new String(data));
               }
            }
View Full Code Here

         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())
            {
               // Do not read data if debug is off.
               // Client may get empty response, may not read stream twice.
               LOG.debug("POST. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
               byte[] data = resp.getData();
               if (data != null)
               {
                  LOG.debug("POST. Text : " + new String(data));
               }
            }
View Full Code Here

         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())
            {
               // Do not read data if debug is off.
               // Client may get empty response, may not read stream twice.
               LOG.debug("PUT. received status " + resp.getStatusCode() + ", " + resp.getReasonLine());
               byte[] data = resp.getData();
               if (data != null)
               {
                  LOG.debug("PUT Received : " + new String(data));
               }
            }
View Full Code Here

         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

         //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
               System.exit(0);
            }
         }
         else
         {
            // basic authorization
            if (realm == null)
            {
               realm = getRealm(complURL);
               if (realm == null)
               {
                  throw new BackupExecuteException(
                     "Can not connect to server using basic authentication. Try to use form authentication.");
               }
            }

            connection.addBasicAuthorization(realm, login, password);
         }

         HTTPResponse resp;
         if (postData == null)
         {
            resp = connection.Post(url.getFile());
         }
         else
         {
            NVPair[] pairs = new NVPair[2];
            pairs[0] = new NVPair("Content-Type", "application/json; charset=UTF-8");
            pairs[1] = new NVPair("Content-Length", Integer.toString(postData.length()));

            resp = connection.Post(url.getFile(), postData.getBytes(), pairs);
         }

         BackupAgentResponse responce = new BackupAgentResponse(resp.getData(), resp.getStatusCode());
         return responce;
      }
      catch (ModuleException e)
      {
         throw new BackupExecuteException(e.getMessage(), e);
View Full Code Here

TOP

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

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.