/** Process the result got from data sources. */
 @Override
 public void processResult(Operation operation, Object resultObj, Map<String, Object> keyMap)
     throws BaseCollectionException {
   // TODO Auto-generated method stub
   _logger.info("Processing VNX Mount Query response: {}", resultObj);
   final PostMethod result = (PostMethod) resultObj;
   try {
     ResponsePacket responsePacket =
         (ResponsePacket) _unmarshaller.unmarshal(result.getResponseBodyAsStream());
     // Extract session information from the response header.
     Header[] headers = result.getResponseHeaders(VNXFileConstants.CELERRA_SESSION);
     if (null != headers && headers.length > 0) {
       keyMap.put(VNXFileConstants.CELERRA_SESSION, headers[0].getValue());
       _logger.info("Received celerra session info from the Server.");
     }
     if (null != responsePacket.getPacketFault()) {
       Status status = responsePacket.getPacketFault();
       processErrorStatus(status, keyMap);
     } else {
       List<Object> mountList = getQueryResponse(responsePacket);
       // process the mount list
       processMountList(mountList, keyMap);
       keyMap.put(VNXFileConstants.CMD_RESULT, VNXFileConstants.CMD_SUCCESS);
     }
   } catch (final Exception ex) {
     _logger.error(
         "Exception occurred while processing the vnx fileShare response due to {}",
         ex.getMessage());
     keyMap.put(VNXFileConstants.FAULT_DESC, ex.getMessage());
     keyMap.put(VNXFileConstants.CMD_RESULT, VNXFileConstants.CMD_FAILURE);
   } finally {
     result.releaseConnection();
   }
   return;
 }
  public String jasperAuthen(String username, String password) throws HttpException, IOException {
    logger.info("Authenticate : Jasper Report Server");

    Header[] headers = null;
    String sessionCookie = "";

    this.httpClient = new HttpClient();
    PostMethod mPost = new PostMethod(restLoginUrl);

    Header mtHeader = new Header();
    mtHeader.setName("content-type");
    mtHeader.setValue("application/x-www-form-urlencoded");
    mtHeader.setName("accept");

    mPost.addParameter("j_username", username);
    mPost.addParameter("j_password", password);
    mPost.addRequestHeader(mtHeader);

    httpClient.executeMethod(mPost);

    headers = mPost.getResponseHeaders();
    mPost.releaseConnection();

    sessionCookie = headers[2].getValue();
    logger.debug("SessionCookie is {}", sessionCookie);

    return sessionCookie;
  }
示例#3
0
  private static boolean createRepo(
      final String scmUrl, final String password, final String repository) {
    HttpClient client = new HttpClient();
    String uri = scmUrl + API + "/projects";
    LOGGER.debug("Create Repo: {}", uri);
    PostMethod post = new PostMethod(uri);

    post.setParameter("name", repository);
    post.setParameter("private_token", password);
    try {
      int result = client.executeMethod(post);
      LOGGER.info("Return code: " + result);
      for (Header header : post.getResponseHeaders()) {
        LOGGER.info(header.toString().trim());
      }
      LOGGER.info(post.getResponseBodyAsString());
    } catch (HttpException e) {
      e.printStackTrace();
      return false;
    } catch (IOException e) {
      e.printStackTrace();
      return false;
    } finally {
      post.releaseConnection();
    }
    return true;
  }
示例#4
0
  /**
   * Allows to send a POST request, with parameters using JSON format
   *
   * @param path path to be used for the POST request
   * @param data paremeters to be used (JSON format) as a string
   */
  @SuppressWarnings("unchecked")
  public void sendPost(final String path, final String data) throws Exception {
    String fullpath = path;
    if (path.startsWith("/")) fullpath = baseUrl + path;

    log.info("Sending POST request to " + fullpath);
    final PostMethod method = new PostMethod(fullpath);
    for (final Map.Entry<String, String> header : requestHeaders.entrySet())
      method.setRequestHeader(header.getKey(), header.getValue());
    if (data != null) {
      JSONObject jsonObject = null;
      try {
        jsonObject = JSONHelper.toJSONObject(data);
        for (final Iterator<String> iterator = jsonObject.keySet().iterator();
            iterator.hasNext(); ) {
          final String param = iterator.next();
          method.setParameter(
              param, (jsonObject.get(param) != null) ? jsonObject.get(param).toString() : null);
        }
      } catch (final ParseException e) {
        log.error("Sorry, parameters are not proper JSON...", e);
        throw new IOException(e.getMessage(), e);
      }
    }
    try {
      final int statusCode = httpClient.executeMethod(method);
      response =
          new ResponseWrapper(
              method.getResponseBodyAsString(), method.getResponseHeaders(), statusCode);
    } catch (final IOException e) {
      log.error(e.getMessage(), e);
      throw new IOException(e.getMessage(), e);
    } finally {
      method.releaseConnection();
    }
  }
示例#5
0
    public void run() {
      AccountManager am = AccountManager.get(getActivity());
      Account account = AccountUtils.getCurrentOwnCloudAccount(getActivity());
      OwnCloudVersion ocv =
          new OwnCloudVersion(am.getUserData(account, AccountAuthenticator.KEY_OC_VERSION));
      String url =
          am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL)
              + AccountUtils.getWebdavPath(ocv);

      Log.d("share", "sharing for version " + ocv.toString());

      if (ocv.compareTo(new OwnCloudVersion(0x040000)) >= 0) {
        String APPS_PATH = "/apps/files_sharing/";
        String SHARE_PATH = "ajax/share.php";

        String SHARED_PATH = "/apps/files_sharing/get.php?token=";

        final String WEBDAV_SCRIPT = "webdav.php";
        final String WEBDAV_FILES_LOCATION = "/files/";

        WebdavClient wc =
            OwnCloudClientUtils.createOwnCloudClient(
                account, getActivity().getApplicationContext());
        HttpConnectionManagerParams params = new HttpConnectionManagerParams();
        params.setMaxConnectionsPerHost(wc.getHostConfiguration(), 5);

        // wc.getParams().setParameter("http.protocol.single-cookie-header", true);
        // wc.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

        PostMethod post =
            new PostMethod(
                am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL)
                    + APPS_PATH
                    + SHARE_PATH);

        post.addRequestHeader("Content-type", "application/x-www-form-urlencoded; charset=UTF-8");
        post.addRequestHeader(
            "Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
        List<NameValuePair> formparams = new ArrayList<NameValuePair>();
        Log.d("share", mPath + "");
        formparams.add(new BasicNameValuePair("sources", mPath));
        formparams.add(new BasicNameValuePair("uid_shared_with", "public"));
        formparams.add(new BasicNameValuePair("permissions", "0"));
        post.setRequestEntity(
            new StringRequestEntity(URLEncodedUtils.format(formparams, HTTP.UTF_8)));

        int status;
        try {
          PropFindMethod find = new PropFindMethod(url + "/");
          find.addRequestHeader(
              "Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));
          Log.d("sharer", "" + url + "/");

          for (org.apache.commons.httpclient.Header a : find.getRequestHeaders()) {
            Log.d("sharer-h", a.getName() + ":" + a.getValue());
          }

          int status2 = wc.executeMethod(find);

          Log.d("sharer", "propstatus " + status2);

          GetMethod get =
              new GetMethod(am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + "/");
          get.addRequestHeader(
              "Referer", am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL));

          status2 = wc.executeMethod(get);

          Log.d("sharer", "getstatus " + status2);
          Log.d("sharer", "" + get.getResponseBodyAsString());

          for (org.apache.commons.httpclient.Header a : get.getResponseHeaders()) {
            Log.d("sharer", a.getName() + ":" + a.getValue());
          }

          status = wc.executeMethod(post);
          for (org.apache.commons.httpclient.Header a : post.getRequestHeaders()) {
            Log.d("sharer-h", a.getName() + ":" + a.getValue());
          }
          for (org.apache.commons.httpclient.Header a : post.getResponseHeaders()) {
            Log.d("sharer", a.getName() + ":" + a.getValue());
          }
          String resp = post.getResponseBodyAsString();
          Log.d("share", "" + post.getURI().toString());
          Log.d("share", "returned status " + status);
          Log.d("share", " " + resp);

          if (status != HttpStatus.SC_OK
              || resp == null
              || resp.equals("")
              || resp.startsWith("false")) {
            return;
          }

          JSONObject jsonObject = new JSONObject(resp);
          String jsonStatus = jsonObject.getString("status");
          if (!jsonStatus.equals("success"))
            throw new Exception("Error while sharing file status != success");

          String token = jsonObject.getString("data");
          String uri =
              am.getUserData(account, AccountAuthenticator.KEY_OC_BASE_URL) + SHARED_PATH + token;
          Log.d("Actions:shareFile ok", "url: " + uri);

        } catch (Exception e) {
          e.printStackTrace();
        }

      } else if (ocv.compareTo(new OwnCloudVersion(0x030000)) >= 0) {

      }
    }