Package com.esri.gpt.framework.http

Examples of com.esri.gpt.framework.http.HttpClientRequest


  String url = xml.substring(xml.indexOf("<gptAgsUrl>") + 11,
      xml.indexOf("</gptAgsUrl>")).trim();

  if (url != null && url.length() > 0){
    Publisher publisher = new Publisher(context);
        HttpClientRequest httpClient = HttpClientRequest.newRequest();
        ProcessingContext pContext = new ProcessingContext(context,publisher,httpClient,null,false);
        ProcessorFactory factory = new ProcessorFactory();
        ResourceProcessor processor = factory.interrogate(pContext,url);
        if (processor == null) {
          axlResponse = "Unable to process resource.";
View Full Code Here


   * @throws JSONException if parsing response failed
   */
  public void execute() throws AgpServerException, AgpPublishException {
    try {
      StringHandler handler = new StringHandler();
      HttpClientRequest request = new HttpClientRequest();
      request.setContentHandler(handler);
      request.setCredentialProvider(credentialProvider);
      request.setMethodName(MethodName.POST);

      String token = fetchToken();
      request.setUrl(getDeleteUrl(token));
      execute(request);
      checkError(handler.getContent());
    } catch (IOException ex) {
      throw new AgpPublishException("Error executing request.", ex);
    }
View Full Code Here

      Envelope extent = itemInfo.getExtent();
      if (extent != null && !extent.isEmpty()) {
        content += "&extent=" + extent.getMinX() + "," + extent.getMinY() + ","
            + extent.getMaxX() + "," + extent.getMaxY();
      }
      HttpClientRequest httpClient = new HttpClientRequest();
      httpClient.setContentProvider(new StringProvider(content,
          "application/x-www-form-urlencoded"));
      httpClient.setUrl(this.addItemUrl);
      httpClient.setRequestHeader("Referer", this.referer);
      httpClient.setMethodName(MethodName.POST);
      httpClient.execute();

      int nHttpResponseCode = httpClient.getResponseInfo().getResponseCode();
      if ((nHttpResponseCode < 200) || (nHttpResponseCode > 299)) {
        throw new JSONException("Add item request failed: HTTP "
            + nHttpResponseCode);
      }

      String resp = httpClient.readResponseAsCharacters();
      if (resp.length() > 0) {
        JSONObject jsoResponse;
        try {
          jsoResponse = new JSONObject(resp);
        } catch (JSONException e) {
View Full Code Here

        + URLEncoder.encode("username", "UTF-8") + "="
        + URLEncoder.encode(this.credentialProvider.getUsername(), "UTF-8")
        + "&" + URLEncoder.encode("password", "UTF-8") + "="
        + URLEncoder.encode(this.credentialProvider.getPassword(), "UTF-8");

    HttpClientRequest httpClient = new HttpClientRequest();
    // send the request
    content += "&expiration=525600&referer=" + this.referer;

    httpClient.setContentProvider(new StringProvider(content,
        "application/x-www-form-urlencoded"));

    httpClient.setRequestHeader("Referer", this.referer);
    httpClient.setUrl(this.ep.getGenerateTokenUrl());
    httpClient.setMethodName(MethodName.POST);

    // expiration
    httpClient.execute();

    int nHttpResponseCode = httpClient.getResponseInfo().getResponseCode();
    if ((nHttpResponseCode < 200) || (nHttpResponseCode > 299)) {
      throw new IOException("Request failed: HTTP " + nHttpResponseCode);
    }

    String resp = httpClient.readResponseAsCharacters();
    JSONObject jsoToken = new JSONObject(resp);
    if (jsoToken.has("token")) {
      this.token = jsoToken.getString("token");
      this.publicationStatus = true;
    } else {
View Full Code Here

        if (itemId != null && itemId.length() > 0) {
          this.shareItemUrl = shareItemUrl.replace("{0}",
              this.credentialProvider.getUsername());
          content = "f=json&token=" + URLEncoder.encode(this.token, "UTF-8");
          content += "&everyone=true&items=" + this.itemId;
          HttpClientRequest httpClient = new HttpClientRequest();
          httpClient.setContentProvider(new StringProvider(content,
              "application/x-www-form-urlencoded"));
          httpClient.setRequestHeader("Referer", this.referer);
          httpClient.setUrl(this.shareItemUrl);
          httpClient.setMethodName(MethodName.POST);
          httpClient.execute();

          int nHttpResponseCode = httpClient.getResponseInfo().getResponseCode();
          if ((nHttpResponseCode < 200) || (nHttpResponseCode > 299)) {
            LOGGER.info("Share item request failed: HTTP " + nHttpResponseCode);
          } else {
            this.publicationStatus = true;
            LOGGER.info("Item shared with everyone." + nHttpResponseCode);
View Full Code Here

  public String execute() throws AgpPublishException, AgpServerException {
    try {
      // prepare multi-part request
      MultiPartContentProvider provider = new MultiPartContentProvider();
      StringHandler handler = new StringHandler();
      HttpClientRequest request = new HttpClientRequest();
      request.setCredentialProvider(credentialProvider);
      request.setContentProvider(provider);
      request.setMethodName(HttpClientRequest.MethodName.POST);
      request.setContentHandler(handler);
      request.setUrl(getFolderUrl(getFolderName()) + "/addItem");

      // extract ESRI item info from metadata and build map of attributes out of it
      Node esriItemInfo = extractItemInfo(getMetadata());
      Map<String, List<String>> attributes = extractEsriItemAttributes(esriItemInfo);
View Full Code Here

   * @throws AgpServerException server exception
   * @throws AgpPublishException publish exception
   */
  private void share(String id, String token) throws AgpServerException, AgpPublishException {
    StringHandler handler = new StringHandler();
    HttpClientRequest request = new HttpClientRequest();

    request.setUrl(getItemUrl(getFolderName(), id) + "/share?everyone=true&f=json&token=" + token);
    request.setCredentialProvider(credentialProvider);
    request.setContentHandler(handler);
    request.setMethodName(HttpClientRequest.MethodName.POST);

    execute(request);
    checkError(handler.getContent());
  }
View Full Code Here

protected void executeRequest(CredentialProvider provider, String serviceUrl,String requestBody) throws Exception {
// setActionStatus(ACTION_STATUS_NONE);
// setAxlResponse("");
  String sMsg;
  String sErrPfx = "ArcIMS Service Communication Error: ";
  HttpClientRequest httpClient = new HttpClientRequest();
  // send the request
  try {  
 
    httpClient.setCredentialProvider(provider);
    httpClient.setUrl(serviceUrl);
   // httpClient.setTimeoutMillisecs(service.getTimeoutMillisecs());
    httpClient.setMethodName(MethodName.POST);
//   httpClient.setAxlRequest(getAxlRequest());
    StringProvider cprov = new StringProvider(requestBody,"text/xml");
    httpClient.setContentProvider(cprov);
    StringHandler sh = new StringHandler();
    httpClient.setContentHandler(sh);
 
    httpClient.execute();
   
//   setAxlResponse(httpClient.getAxlResponse());
    int nHttpResponseCode = httpClient.getResponseInfo().getResponseCode();
    if ((nHttpResponseCode < 200) || (nHttpResponseCode > 299)) {
      throw new IOException("Request failed: HTTP "+nHttpResponseCode);
    }
  } catch (MalformedURLException em) {
  //  setActionStatus(ACTION_STATUS_ERROR);
    sMsg = sErrPfx+"The PublishServer was configured with a malformed URL";
    throw new ImsServiceException(sMsg,em);
  } catch (UnknownHostException eu) {
//   setActionStatus(ACTION_STATUS_ERROR);
    sMsg = sErrPfx+"The PublishServer was configured with an unknown host";
    throw new ImsServiceException(sMsg,eu);
  } catch (Exception e) {
//   setActionStatus(ACTION_STATUS_ERROR);
    int nHttpResponseCode = httpClient.getResponseInfo().getResponseCode();
    if (nHttpResponseCode == 0) {
      sMsg = Val.chkStr(e.getMessage());
      sMsg = sErrPfx+sMsg;
      throw new ImsServiceException(sMsg,e);
    } else {
      sMsg = sErrPfx+"[HTTP "+nHttpResponseCode+"] "+httpClient.getResponseInfo().getResponseMessage();
      throw new ImsServiceException(sMsg,e);
    }
  }
 
  String response = httpClient.readResponseAsCharacters();
 
  // parse the response
  if (response.length() == 0) {
    throw new Exception(sErrPfx+"Empty response.");
  } else {
View Full Code Here

public String read(String sourceUri) throws IOException {
  LOGGER.finer("Reading metadata of source URI: \"" +sourceUri+ "\" through proxy: "+this);
  try {
    sourceUri = Val.chkStr(sourceUri).replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
    HttpClientRequest cr = new HttpClientRequest();
    cr.setUrl(info.newReadMetadataUrl(sourceUri));
    XmlHandler sh = new XmlHandler(false);
    cr.setContentHandler(sh);
    cr.setCredentialProvider(info.newCredentialProvider());
    cr.setBatchHttpClient(info.getBatchHttpClient());
    cr.execute();
    Document doc = sh.getDocument();
    XPath xPath = XPathFactory.newInstance().newXPath();
    Node node = (Node) xPath.evaluate(
        "/feed/entry",
        doc, XPathConstants.NODE);
View Full Code Here

            String oldFParam = "f="+fParam;
            String jsonFParam = "f=json";
            url = url.replace(oldFParam, jsonFParam);
          }   
      }
      HttpClientRequest cr = new HttpClientRequest()
        cr.setUrl(url);
        String response = Val.chkStr(cr.readResponseAsCharacters());
        if(response.length() > 0){
          JSONObject jso = new JSONObject(response);
            String total = jso.has("total") ? jso.getString("total") : "-1";
            return Integer.parseInt(total);
        }
View Full Code Here

TOP

Related Classes of com.esri.gpt.framework.http.HttpClientRequest

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.