Package com.esri.gpt.framework.http

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


   * @throws IOException
   * @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) {
      throw new AgpPublishException("Error loading folder content.", ex);
    }
  }
View Full Code Here


    StringBuilder params = new StringBuilder();
    connection.appendToken(params);
    AgpProperties hdr = connection.makeRequestHeaderProperties();
    AgpClient client = connection.ensureClient();
    StringProvider provider = new StringProvider(params.toString(),sType);
    StringHandler handler = new StringHandler();
   
    client.executeRequest(sUrl,hdr,provider,handler);
    return Val.removeBOM(handler.getContent());
  }
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);

      // obtain security token from the server
      String token = fetchToken();
     
      // set predefined data
      provider.add("token", token);
      provider.add("f", "json");
     
      // go through the list of all attributes at push it to the multi-part request
      if (!getUpdateMetadataOnly()) {
        processEsriItemAttributes(provider, attributes);
      }

      // if attributes already contain something to upload do not upload metadata;
      // it has to be done in a second round
      if (!attributes.containsKey("file") || getUpdateMetadataOnly()) {
        // set metadata
        if (!getMetadata().isEmpty()) {
          provider.add("metadata", getMetadata().getBytes("UTF-8"), "metadata.xml", "text/xml", "UTF-8");
        }
      }

      // execute request and checks for errors
      execute(request);
      checkError(handler.getContent());
     
      // get created item id
      String id = extractId(handler.getContent());
     
      // if attributes contained something to upload now it's a time to upload
      // actual metadata; do it through update
      if (attributes.containsKey("file") && !getUpdateMetadataOnly()) {
        AgpUpdateRequest upd = new AgpUpdateRequest(requestContext, credentialProvider, id, getFolderName(), getMetadata());
View Full Code Here

  public JSONObject executeJsonRequest(String url,
                                       AgpProperties requestHeader,
                                       ContentProvider contentProvider)
    throws Exception {
    LOGGER.finest("Sending URL: "+url);
    StringHandler handler = new StringHandler();
    this.executeRequest(url,requestHeader,contentProvider,handler);
    String sResponse = handler.getContent();
    LOGGER.finest("Response for URL: "+url+"\n"+sResponse);
   
    JSONObject jsoResponse = null;
    try {
      if (sResponse == null) {
View Full Code Here

   * @throws IOException if accessing end point failed
   * @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

   */
  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);

      // obtain security token from the server
      String token = fetchToken();
     
      // set predefined data
      provider.add("token", token);
      provider.add("f", "json");
      provider.add("overwrite", Boolean.toString(getOverwrite()));

      // go through the list of all attributes at push it to the multi-part request
      processEsriItemAttributes(provider, attributes);
     
      // if attributes already contain something to upload do not upload metadata;
      // it has to be done in a second round
      if (!attributes.containsKey("file")) {
        // set metadata
        if (!getMetadata().isEmpty()) {
          provider.add("metadata", getMetadata().getBytes("UTF-8"), "metadata.xml", "text/xml", "UTF-8");
        }
      }

      // execute request and checks for errors
      execute(request);
      checkError(handler.getContent());

      // get newly created item id
      String id = extractId(handler.getContent());
     
      // share that item
      share(id, token);
     
      // if attributes contained something to upload now it's a time to upload
View Full Code Here

   * @param token token
   * @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

   // 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());
View Full Code Here

  LOGGER.log(Level.FINER, "Reading metadata of source URI: \"{0}\" through proxy: {1}", new Object[]{sourceUri, this});
  sourceUri = Val.chkStr(sourceUri).replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
  HttpClientRequest cr = new HttpClientRequest();
  cr.setBatchHttpClient(this.info.getBatchHttpClient());
  cr.setUrl(sourceUri);
  StringHandler sh = new StringHandler();
  cr.setContentHandler(sh);
  cr.setCredentialProvider(info.newCredentialProvider());
  cr.execute();
  String mdText = sh.getContent();
  LOGGER.log(Level.FINER, "Received metadata of source URI: \"{0}\" through proxy: {1}", new Object[]{sourceUri, this});
  LOGGER.finest(mdText);
  return mdText;
}
View Full Code Here

    url = Val.chkStr(url).replaceAll("\\{", "%7B").replaceAll("\\}", "%7D");
    HttpClientRequest cr = new HttpClientRequest();
    cr.setUrl(url);

    StringHandler sh = new StringHandler();
    cr.setContentHandler(sh);

    cr.execute();

    String mdText = sh.getContent();
    LOGGER.finer("Received metadata of id: \"" +sourceUri+ "\" through proxy: "+this);
    LOGGER.finest(mdText);
    return mdText;

  } catch (XPathExpressionException ex) {
View Full Code Here

TOP

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

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.