Package com.esri.gpt.framework.context

Examples of com.esri.gpt.framework.context.RequestContext


public String processRequestParams() {

  try {

    // start view preparation phase
    RequestContext context = onPrepareViewStarted();
    HttpServletRequest request = getContextBroker().extractHttpServletRequest();
    Map parameterMap = request.getParameterMap();
    Object url =  parameterMap.get("catalog");

    String catalogUrl = null;
View Full Code Here


* @param format the format
* @return the rest search request url
*/
protected String getRestSearchRequestUrl(String format) {
  SearchCriteria criteria = this.getSearchCriteria();
  RequestContext context =  this.getContextBroker().extractRequestContext();
  HttpServletRequest request = this.getContextBroker().extractHttpServletRequest();
 
  MessageBroker messageBroker = this.getContextBroker().extractMessageBroker();
  RestUrlBuilder builder = RestUrlBuilder.newBuilder(context,request,messageBroker);
  String params = builder.buildParameters(criteria,format,null);
View Full Code Here

    if ((resourceId == null) || (resourceId.length() == 0)) {
      return;
    }
       
    // ensure acl access
    RequestContext rContext = context.getRequestContext();
    AuthenticationStatus auth = rContext.getUser().getAuthenticationStatus();
    boolean bAdmin = auth.getAuthenticatedRoles().hasRole("gptAdministrator");
    if (!bAdmin) {     
      MetadataAcl acl = new MetadataAcl(rContext);
      if (!acl.isPolicyUnrestricted()) {
        LuceneIndexAdapter adapter = new LuceneIndexAdapter(rContext);
View Full Code Here

public Capabilities getCapabilities() {
  return capabilities;
}

public Query newQuery(Criteria crt) {
  RequestContext requestContext = RequestContext.extract(null);
  try {
    ResourceProcessor processor = newProcessor(requestContext);
    return processor.createQuery(context, crt);
  } finally {
    requestContext.onExecutionPhaseCompleted();
  }
}
View Full Code Here

    requestContext.onExecutionPhaseCompleted();
  }
}

public Native getNativeResource() {
  RequestContext requestContext = RequestContext.extract(null);
  try {
    ResourceProcessor processor = newProcessor(requestContext);
    return processor!=null? processor.getNativeResource(context): null;
  } finally {
    requestContext.onExecutionPhaseCompleted();
  }
}
View Full Code Here

   * Run the process.
   */
  @Override
  public void run() {
    LOGGER.info("Harvester scheduled pause run started...");
    RequestContext context = null;
   
    String initialSleepTime = parameters.getValue("initialSleepTime");
    String consecutiveSleepTime = parameters.getValue("consecutiveSleepTime");
    long tInitialTime = parsePeriod(initialSleepTime, DEFAULT_INITIAL_SLEEP_TIME).getValue();
    long tConsecutiveTime = parsePeriod(consecutiveSleepTime, DEFAULT_CONSECUTIVE_SLEEP_TIME).getValue();
   
    // suspend harvesting engine
    getHarvestingEngine().safeSuspend();

   
    try {
      // initial sleep
      Thread.sleep(tInitialTime);
     
      do {
        RemoteIndexerInfo info = checkRemoteIndexers(this.parameters);
        if (checkInterrupted()) return;
        if (info.numActive==0) break;
       
        // consecutive sleep
        Thread.sleep(tConsecutiveTime);
      } while (true);
     
     
    } catch (Throwable t) {
      LOGGER.log(Level.SEVERE,"Error during scheduled pause.",t);
    } finally {
     
      // we are done waiting, resume harvesting
      if (!checkInterrupted()) {
        LOGGER.info("Harvester scheduled pause completed, resuming harvester...");
        getHarvestingEngine().safeResume();
      }
     
      if (context != null) {
        context.onExecutionPhaseCompleted();
      }
      if (this.wasInterrupted) {
        LOGGER.info("Harvester scheduled pause was interrupted.");
      }
    }
View Full Code Here

   * @throws IOException if an I/O error occurs while handling the request
   */
  private void execute(HttpServletRequest request, HttpServletResponse response, String method)
    throws ServletException, IOException {
   
    RequestContext context = null;
    try {
      String msg = "HTTP "+method+", "+request.getRequestURL().toString();
      if ((request.getQueryString() != null) && (request.getQueryString().length() > 0)) {
        msg += "?"+request.getQueryString();
      }
      getLogger().fine(msg);
     
      String sEncoding = request.getCharacterEncoding();
      if ((sEncoding == null) || (sEncoding.trim().length() == 0)) {
        request.setCharacterEncoding("UTF-8");
      }
      context = RequestContext.extract(request);
     
      /// estabish the publisher
      StringAttributeMap params = context.getCatalogConfiguration().getParameters();
      String autoAuthenticate = Val.chkStr(params.getValue("BaseServlet.autoAuthenticate"));
      if (!autoAuthenticate.equalsIgnoreCase("false")) {
        Credentials credentials = getCredentials(request);
        if (credentials != null) {
          this.authenticate(context,credentials);
        }
      }
      Publisher publisher = new Publisher(context);

      // executeUpdate the appropriate action
      if (method.equals("GET")) {
        this.executeGet(request,response,context,publisher);
      } else if (method.equals("POST")) {
        this.executePost(request,response,context,publisher);
      } else if (method.equals("PUT")) {
        this.executePut(request,response,context,publisher);
      } else if (method.equals("DELETE")) {
        this.executeDelete(request,response,context,publisher);
      }
     
    } catch (CredentialsDeniedException e) {
      String sRealm = this.getRealm(context);
      response.setHeader("WWW-Authenticate","Basic realm=\""+sRealm+"\"");
      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    } catch (NotAuthorizedException e) {
      String sRealm = this.getRealm(context);
      response.setHeader("WWW-Authenticate","Basic realm=\""+sRealm+"\"");
      response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
    } catch (ValidationException e) {
      String sMsg = e.toString();
      if (sMsg.contains("XSD violation.")) {
        sMsg = "XSD violation.";
      } else if (sMsg.contains("Invalid metadata document.")) {
        sMsg = "Invalid metadata document.";
      } else {
        sMsg = "Invalid metadata document.";
      }
      String json = Val.chkStr(request.getParameter("errorsAsJson"));
      if (json.length()>0) {
        json = Val.escapeXmlForBrowser(json);
        FacesContextBroker fcb = new FacesContextBroker(request, response);
        MessageBroker msgBroker = fcb.extractMessageBroker();
       
        ArrayList<String> validationMessages = new ArrayList<String>();
        e.getValidationErrors().buildMessages(msgBroker, validationMessages, true);
       
        StringBuilder sb = new StringBuilder();
        sb.append(json).append(" = {\r\n");
        sb.append("message: \"").append(Val.escapeStrForJson(sMsg)).append("\",\r\n");
        sb.append("code: 409,\r\n");
        sb.append("errors: [\r\n");
        for (int i=0; i<validationMessages.size(); i++) {
          if (i>0) {
            sb.append(",\r\n");
          }
          sb.append("\"").append(Val.escapeStrForJson(validationMessages.get(i))).append("\"");
        }
        if (validationMessages.size()>0) {
          sb.append("\r\n");
        }
        sb.append("]}");
       
        LOGGER.log(Level.SEVERE, sb.toString());
        response.getWriter().print(sb.toString());
      } else {
        response.sendError(409,sMsg);
      }
    } catch (ServletException e) {
      String sMsg = e.getMessage();
      int nCode = Val.chkInt(sMsg.substring(0,3),500);
      sMsg = Val.chkStr(sMsg.substring(4));
      String json = Val.chkStr(request.getParameter("errorsAsJson"));
      if (json.length()>0) {
        json = Val.escapeXmlForBrowser(json);
        StringBuilder sb = new StringBuilder();
        sb.append(json).append(" = {\r\n");
        sb.append("message: \"").append(Val.escapeStrForJson(sMsg)).append("\",\r\n");
        sb.append("code: ").append(nCode).append(",\r\n");
        sb.append("errors: [\r\n");
        sb.append("\"").append(Val.escapeStrForJson(sMsg)).append("\"");
        sb.append("]}");
       
        LOGGER.log(Level.SEVERE, sb.toString());
        response.getWriter().print(sb.toString());
      } else {
        response.sendError(nCode,sMsg);
      }
    } catch (Throwable t) {
      String sMsg = t.toString();
      String json = Val.chkStr(request.getParameter("errorsAsJson"));
      if (json.length()>0) {
        json = Val.escapeXmlForBrowser(json);
        StringBuilder sb = new StringBuilder();
        sb.append(json).append(" = {\r\n");
        sb.append("message: \"").append(Val.escapeStrForJson(sMsg)).append("\",\r\n");
        sb.append("code: ").append(500).append(",\r\n");
        sb.append("errors: [\r\n");
        sb.append("\"").append(Val.escapeStrForJson(sMsg)).append("\"");
        sb.append("]}");
       
        LOGGER.log(Level.SEVERE, sb.toString());
        response.getWriter().print(sb.toString());
      } else if (sMsg.contains("The document is owned by another user:")) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN,"The document is owned by another user.");
      } else {
        String sErr = "Exception occured while processing servlet request.";
        getLogger().log(Level.SEVERE,sErr,t);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
            sMsg + sErr);
      }
    } finally {
      if (context != null) context.onExecutionPhaseCompleted();
    }
  } 
View Full Code Here

/**
* Executes query.
*/
public void execute() {
  RequestContext context = RequestContext.extract(null);
 
  boolean success = false;
  long count = 0;
  Result result = null;
  LOGGER.log(Level.FINEST, "[SYNCHRONIZER] Starting harvesting through unit: {0}", unit);
  if (isActive()) {
    dataProcessor.onStart(unit);
  }

  ExecutionUnitHelper helper = new ExecutionUnitHelper(unit);
  // get report builder
  ReportBuilder rp = helper.getReportBuilder();

  try {
    result = executeQuery();
    Iterable<Publishable> records = new PublishablesAdapter(new FlatResourcesAdapter(result.getResources()));
    for (Publishable r : records) {
      if (!isActive()){
        unit.setCleanupFlag(false);
        break;
      }
      count++;
      LOGGER.log(Level.FINEST, "[SYNCHRONIZER] Harvested metadata #{0} of source URI: \"{1}\" through unit: {2}", new Object[]{rp.getHarvestedCount()+1, r.getSourceUri(), unit});
      if (isSuspendedWithAck()) {
        while (isSuspended()) {
          try {
            synchronized (this) {
              wait();
            }
          } catch (InterruptedException ex) {

          }
          if (!isActive()) {
            break;
          }
        }
      }
      if (isActive()) {
        dataProcessor.onMetadata(unit, r);
      }
    }
   
    success = true;
   
    if (isActive()) {
      // save last sync date
      unit.getRepository().setLastSyncDate(rp.getStartTime());
      HrUpdateLastSyncDate updLastSyncDate = new HrUpdateLastSyncDate(context, unit.getRepository());
      updLastSyncDate.execute();
    }
  } catch (Exception ex) {
    rp.setException(ex);
    unit.setCleanupFlag(false);
    LOGGER.log(Level.FINEST, "[SYNCHRONIZER] Failed harvesting through unit: {0}. Cause: {1}", new Object[]{unit, ex.getMessage()});
    dataProcessor.onIterationException(unit, ex);
  } finally {
    try {
      if (!isShutdown()) {
        dataProcessor.onEnd(unit, success);
        context.onExecutionPhaseCompleted();
      }
    } finally {
      if (result!=null) {
        result.destroy();
      }
View Full Code Here

  /**
   * Run the optimization process.
   */
  public void run() {
    LOGGER.info("Optimization run started...");
    RequestContext context = null;
    IndexWriter writer = null;
    Lock backgroundLock = null;
    long tStartMillis = System.currentTimeMillis();
    try {
     
      // initialize
      context = RequestContext.extract(null);
      LuceneIndexAdapter adapter = new LuceneIndexAdapter(context);
      adapter.touch(); // ensures that a proper directory structure exists
      if (this.checkInterrupted()) return;
     
      // obtain the background thread lock,
      // sleep for 10 minutes if busy then try again
      try {
        backgroundLock = adapter.obtainBackgroundLock();
      } catch (LockObtainFailedException lofe) {
        if (this.checkInterrupted()) return;
        try {
          Thread.sleep(10 * 1000);
        } catch (InterruptedException e) {
          throw new IOException(e.toString());
        }
        if (this.checkInterrupted()) return;
        backgroundLock = adapter.obtainBackgroundLock();
      }
     
      // optimize the index
      writer = adapter.newWriter();
      if (this.checkInterrupted()) return;
      writer.optimize();
      adapter.closeWriter(writer);
      writer = null;
     
      // log the summary message
      double dSec = (System.currentTimeMillis() - tStartMillis) / 1000.0;
      StringBuffer msg = new StringBuffer();
      msg.append("Optimization run completed.");
      msg.append(", runtime: ");
      msg.append(Math.round(dSec / 60.0 * 100.0) / 100.0).append(" minutes");
      if (dSec <= 600) {
        msg.append(", ").append(Math.round(dSec * 100.0) / 100.0).append(" seconds");
      }
      LOGGER.info(msg.toString());
     
    } catch (LockObtainFailedException e) {
      LOGGER.log(Level.INFO,"Optimization run aborted, reason: "+e.getMessage());
    } catch (Throwable t) {
      LOGGER.log(Level.SEVERE,"Error optimizing index.",t);
    } finally {
      if (writer != null) {
        try {
          writer.close();
        } catch (Throwable t) {
          LOGGER.log(Level.SEVERE,"Error closing IndexWriter.",t);
        }
      }
      if (backgroundLock != null) {
        try {
          backgroundLock.release();
        } catch (Throwable t) {
          LOGGER.log(Level.WARNING,"Error releasing lock.",t);
        }
      }
      if (context != null) {
        context.onExecutionPhaseCompleted();
      }
      if (this.wasInterrupted) {
        LOGGER.info("LuceneIndexOptimizer run was interrupted.");
      }
    }
View Full Code Here

    record.getResourceLinks().add(link);
  }

  String url = "";
  try {
    RequestContext rContext = this.getRequestContext();
    ServletRequest sRequest = rContext.getServletRequest();
    if (sRequest instanceof HttpServletRequest) {
      HttpServletRequest hSRequest = (HttpServletRequest) sRequest;
      String path = Val.chkStr(hSRequest.getPathInfo()).toLowerCase();
      if (path.contains("catalog/search/search.page")
          || path.contains("catalog/main/home.page")) {
View Full Code Here

TOP

Related Classes of com.esri.gpt.framework.context.RequestContext

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.