Examples of AsnContext


Examples of com.esri.gpt.server.assertion.components.AsnContext

   */
  public AsnResponse handleRequest(HttpServletRequest request, HttpServletResponse response)
    throws Exception {
   
    // initialize
    AsnContext context = this.getAssertionContext();
    AsnFactory factory = context.getAssertionFactory();
    AsnRequestOptions rOptions = context.getRequestOptions();
    AsnResponse opResponse = context.getOperationResponse();
    ParseHelper pHelper = new ParseHelper();
    String[] parsed;
   
    // parse the HTTP request
    if (request != null) {
   
      // set the IP address
      rOptions.setIPAddress(request.getRemoteAddr());
     
      // parse an operations request
      boolean isOperationsRequest = false;
      if (request.getRequestURI() != null) {
        isOperationsRequest = request.getRequestURI().toLowerCase().endsWith("/operations");
      }
      if (isOperationsRequest) {
        rOptions.setSubject(AsnConstants.APP_URN_PREFIX);
        rOptions.setPredicate(AsnConstants.APP_URN_PREFIX+":assertion:operations");
       
      // parse a non-operations request
      } else {
 
        // subject
        parsed = pHelper.getParameterValues(request,"s");
        if ((parsed == null) || (parsed.length) == 0) {
          parsed = pHelper.getParameterValues(request,"subject");
        }
        if ((parsed != null) && (parsed.length) > 0) {
          rOptions.setSubject(parsed[0]);
        }
       
        // predicate
        parsed = pHelper.getParameterValues(request,"p");
        if ((parsed == null) || (parsed.length) == 0) {
          parsed = pHelper.getParameterValues(request,"predicate");
        }
        if ((parsed != null) && (parsed.length) > 0) {
          rOptions.setPredicate(parsed[0]);
        }
       
        // value
        parsed = pHelper.getParameterValues(request,"v");
        if ((parsed == null) || (parsed.length) == 0) {
          parsed = pHelper.getParameterValues(request,"value");
        }
        if ((parsed != null) && (parsed.length) > 0) {
          rOptions.setValue(parsed[0]);
        }
       
        // output format
        parsed = pHelper.getParameterValues(request,"f");
        if ((parsed == null) || (parsed.length) == 0) {
          parsed = pHelper.getParameterValues(request,"format");
        }
        if ((parsed != null) && (parsed.length) > 0) {
          opResponse.setOutputFormat(parsed[0]);
        }
       
        // start and max records start=&max=
        parsed = pHelper.getParameterValues(request,"start");
        if ((parsed == null) || (parsed.length) == 0) {
          parsed = pHelper.getParameterValues(request,"startRecord");
          if ((parsed == null) || (parsed.length) == 0) {
            parsed = pHelper.getParameterValues(request,"startPosition");
          }
        }
        if ((parsed != null) && (parsed.length) > 0) {
          rOptions.setStartRecord(Math.max(Val.chkInt(parsed[0],1),1));
        }
        parsed = pHelper.getParameterValues(request,"max");
        if ((parsed == null) || (parsed.length) == 0) {
          parsed = pHelper.getParameterValues(request,"maxRecords");
        }
        if ((parsed != null) && (parsed.length) > 0) {
          rOptions.setMaxRecords(Val.chkInt(parsed[0],10));
        }
      }
    }
   
    try {
     
      // determine the handler
      AsnOperationHandler handler = factory.makeOperationHandler(context);
     
      // ensure a valid value if required
      AsnValue asnValue = context.getOperation().getValue();
      if (asnValue != null) {
        AsnValueType asnValueType = asnValue.getValueType();
        if (asnValueType != null) {
          String val = Val.chkStr(rOptions.getValue());
          int maxChars = asnValueType.getMaxCharacters();
          if (asnValueType.getRequired() && (val.length() == 0) && (request != null)) {
            val = Val.chkStr(this.readInputCharacters(request,maxChars));
            if (val.length() == 0) val = null;
            rOptions.setValue(val);
          }
          if ((maxChars >= 0) && (val != null) && (val.length() > maxChars)) {
            val = Val.chkStr(val.substring(0,maxChars));
          }
          if ((val != null) && (val.length() > 0)) {
            AsnValueFilter vFilter = asnValueType.makeValueFilter(context);
            if (vFilter != null) {
              val = Val.chkStr(vFilter.filter(val));
            }
          }
          AsnSupportedValues supported = asnValueType.getSupportedValues();
          if (supported != null) {
            val = supported.getSupportedValue(val);
            if (val != null) {
              asnValue.setTextValue(val);
            } else {
              String msg = "The supplied value is not supported - "+val;
              throw new AsnInvalidOperationException(msg);
            }
          } else {
            if ((val != null) && (val.length() == 0)) val = null;
            asnValue.setTextValue(val);
            if (asnValueType.getRequired() && (val == null)) {
              String msg = "A value is required.";
              throw new AsnInvalidOperationException(msg);
            }
          }
        }
      }
     
      // ensure a message broker if required
      if (context.getOperation().getUIResources() != null) {
        if ((request != null) && (response != null)) {
          FacesContextBroker fcb = new FacesContextBroker(request,response);
          context.setMessageBroker(fcb.extractMessageBroker());
        }
      }
     
      // handle the operation
      handler.handle(context);
     
    } catch (NotAuthorizedException e) {
      throw e;
    } catch (AsnInsufficientPrivilegeException e) {
      context.getOperationResponse().exceptionToResponse(context,e);
      LOGGER.log(Level.FINER,e.toString(),e);
    } catch (AsnInvalidOperationException e) {
      context.getOperationResponse().exceptionToResponse(context,e);
      LOGGER.log(Level.FINER,e.toString(),e);
    } catch (Exception e) {
      context.getOperationResponse().exceptionToResponse(context,e);
      LOGGER.log(Level.SEVERE,e.toString(),e);
    }
       
    // return the response
    return context.getOperationResponse();
   
  }
View Full Code Here

Examples of com.esri.gpt.server.assertion.components.AsnContext

   */
  public AsnRequestHandler makeRequestHandler(HttpServletRequest request,
                                              RequestContext requestContext) {
   
    // make the operation context
    AsnContext context = new AsnContext();
    context.setAssertionFactory(this);
    context.setRequestContext(requestContext);
   
    // make and return the request handler
    AsnRequestHandler handler = new AsnRequestHandler();
    handler.setAssertionContext(context);
    return handler;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.