Package com.esri.gpt.framework.http

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


   */
  private String makeResourceXml(String title, String resourceUrl,
      String protocolType) {
    String response = "";
    if (protocolType != null && protocolType.trim().equalsIgnoreCase("csw")) {
      HttpClientRequest client = new HttpClientRequest();
      client.setUrl(resourceUrl);
      client.setConnectionTimeMs(5000);
      client.setResponseTimeOutMs(10000);
      try {
        response = Val.chkStr(client.readResponseAsCharacters());
        if (client.getResponseInfo().getContentType().toLowerCase().contains(
            "xml")
            && response.length() > 0) {
          return response;
        }
      } catch (IOException e) {
View Full Code Here


   * @throws JSONException
   */
  private void loadFolder(ItemListener itemListener, FolderListener folderListener, String currentFolder) throws AgpServerException, AgpPublishException {
    try {
      StringHandler handler = new StringHandler();
      HttpClientRequest request = new HttpClientRequest();
      request.setCredentialProvider(credentialProvider);
      request.setContentHandler(handler);
      request.setMethodName(HttpClientRequest.MethodName.POST);

      String token = fetchToken();

      request.setUrl(getContentUrl(token, currentFolder));
      execute(request);
      checkError(handler.getContent());

      processFolderContent(itemListener, folderListener, currentFolder, handler.getContent());
    } catch (IOException ex) {
View Full Code Here

  urlString = urlString.replaceAll("\\n", "");
  urlString = urlString.replaceAll("\\t", "");
  urlString = urlString.replaceAll("\\r", "");
  urlString = urlString.replaceAll(" ", "");

  HttpClientRequest client = HttpClientRequest.newRequest();
  client.setBatchHttpClient(getBatchHttpClient());
  client.setUrl(urlString);
  client.setRetries(1);
 
  usr = Val.chkStr(usr);
  pwd = Val.chkStr(pwd);
  if (usr.length() > 0 || pwd.length() > 0) {
    CredentialProvider provider = new CredentialProvider(usr, pwd);
    client.getCredentialProvider();
    client.setCredentialProvider(provider);
  }
  if (this.getReadTimeout() > 0) {
    client.setResponseTimeOutMs(this.getReadTimeout());
  }
  if (this.getConnectTimeout() > 0) {
    client.setConnectionTimeMs(this.getConnectTimeout());
  }

  // Send a request
  if (Val.chkStr(method).equalsIgnoreCase("post")) {
    ContentProvider contentProvider = new StringProvider(postdata, "text/xml");
    client.setContentProvider(contentProvider);
   
  } else {
    client.setMethodName(MethodName.GET);
  }

  String response = client.readResponseAsCharacters();
  LOG.finer(" CSW Response : " + response);
  return new ByteArrayInputStream(response.getBytes("UTF-8"));
 
}
View Full Code Here

  public void executeRequest(String url,
                             AgpProperties requestHeader,
                             ContentProvider contentProvider,
                             ContentHandler contentHandler)
    throws Exception {
    HttpClientRequest http = new HttpClientRequest();
    http.setRetries(-1);
    http.setBatchHttpClient(this.batchHttpClient);
    http.setUrl(url);
    if (requestHeader != null) {
      for (AgpProperty prop: requestHeader.values()) {
        http.setRequestHeader(prop.getName(),prop.getValue());
      }
    }
    http.setContentProvider(contentProvider);
    http.setContentHandler(contentHandler);
   
    try {
      http.execute();
    } catch (HttpClientException ex) {
      boolean doThrow = true;
      if (ex.getHttpStatusCode()==302) {
        // This part of the code deals with redirect issue which accurs when
        // harvesting from arcgis.com
        Header hdrLocation = http.getResponseInfo().getResponseHeader("Location");
        if (hdrLocation!=null) {
          String location = Val.chkStr(hdrLocation.getValue());
          if (url.endsWith("/data") && location.contains("ago-item-storage")) {
            location = location.replaceAll("^https:", "http:");
            doThrow = false;
            HttpClientRequest http2 = new HttpClientRequest();
            http2.setUrl(location);
            http2.setRetries(-1);
            http2.setContentHandler(contentHandler);
            http2.execute();
          }
        }
      }
      if (doThrow) {
        throw ex;
View Full Code Here

  public String execute() throws AgpServerException, AgpPublishException {
    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(getItemUrl(getFolderName(), getItemId()) + "/update");

      // 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

  public SearchResult search(SearchParams params) throws IOException {
    if (params.getNum()<1) return null;
    if (params.getStart()<1) return null;
   
    ItemInfoJsonAdapter itemInfoAdapter = new ItemInfoJsonAdapter();
    HttpClientRequest cr = new HttpClientRequest();
    cr.setUrl(url + "/search?q=" +params.getQuery()+ "&f=json&num=" +params.getNum()+ "&start=" + params.getStart());
    cr.execute();
   
    try {
      List<ESRI_ItemInformation> infos = new ArrayList<ESRI_ItemInformation>();
      String json = cr.readResponseAsCharacters();
      JSONObject jso = new JSONObject(json);
      String nextStart = jso.getString("nextStart");
      JSONArray records = jso.getJSONArray("results");
      for (int idx = 0; idx < records.length(); idx++) {
          JSONObject record = records.optJSONObject(idx);
View Full Code Here

* @param resourceUrl
* @return resource xml
* @throws IOException
*/
public String makeResourceXmlFromResponse(String resourceUrl) throws IOException {
  HttpClientRequest client = new HttpClientRequest();
  client.setUrl(resourceUrl);
  String response = Val.chkStr(client.readResponseAsCharacters());
  if (client.getResponseInfo().getResponseCode()!=HttpURLConnection.HTTP_OK) {
    throw new IOException("Invalid response received: "+client.getResponseInfo().getResponseMessage());
  }
  return response;
}
View Full Code Here

        restUrl += "&f=json";
      }
    }
    LOGGER.finer("Attempting to read ArcGIS Server JSON response for:\n"+restUrl);
   
    HttpClientRequest client = HttpClientRequest.newRequest();
    client.setUrl(restUrl);
    String sResponse = Val.chkStr(client.readResponseAsCharacters());
   
    // attempt to create a JSON object from the response
    if (sResponse.length() > 0) {
      JSONObject jso = new JSONObject(sResponse);
      this.wasJson = true;
View Full Code Here

          if (lc.indexOf("service=") == -1) tryAgsFirst = true;
        }
      }
     
      // execute
      HttpClientRequest client = HttpClientRequest.newRequest();
      client.setUrl(this.systemId);
      if (tryAgsFirst) {
        try {
          xml = this.readAgsXml(this.systemId);
        } catch (Exception e) {
          if (this.wasJson) {
            throw e;
          } else {
            String result = client.readResponseAsCharacters();
            StringReader reader = new StringReader(result);
            StringWriter writer = new StringWriter();
            transform(new StreamSource(reader),new StreamResult(writer));
            xml = Val.chkStr(writer.toString());
          }
        }
       
      } else {
        try {
          String result = client.readResponseAsCharacters();
          StringReader reader = new StringReader(result);
          StringWriter writer = new StringWriter();
          transform(new StreamSource(reader),new StreamResult(writer));
          xml = Val.chkStr(writer.toString());
        } catch (TransformerException te) {
View Full Code Here

  private ResourceProcessor interrogateHttpEndpoint(ProcessingContext context, URL url, UsernamePasswordCredentials credentials)
    throws IOException {
   
    // read the character response from the endpoint
    String fullUrl = url.toExternalForm();
    HttpClientRequest httpClient = context.getHttpClient();
    httpClient.setUrl(fullUrl);
    httpClient.setCredentialProvider(
      credentials==null || credentials.getUsername().length()==0 || credentials.getPassword().length()==0?
        null:
        new CredentialProvider(credentials.getUsername(),credentials.getPassword())
    );
    String response = Val.chkStr(httpClient.readResponseAsCharacters());
   
    if (response.length() > 0) {
     
      // first try ArcGIS Server
      boolean interrofgateAGS = true;
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.