Examples of RegisteredAction


Examples of com.softwarementors.extjs.djn.api.RegisteredAction

  protected RegisteredStandardMethod getStandardMethod(String actionName, String methodName) {
    assert !StringUtils.isEmpty(actionName);
    assert !StringUtils.isEmpty(methodName);

    RegisteredAction action = getRegistry().getAction(actionName);
    if( action == null ) {
      throw RequestException.forActionNotFound( actionName );
    }

    RegisteredStandardMethod method = action.getStandardMethod(methodName);
    if( method == null ) {
      throw RequestException.forActionMethodNotFound( action.getName(), methodName );
    }
    return method;
  }
View Full Code Here

Examples of com.softwarementors.extjs.djn.api.RegisteredAction

    // Create a new api programmatically
    String apiFile = config.getServletContext().getRealPath("test/ProgrammaticApi.js");
    RegisteredApi api = registry.addApi( "programmaticApi", "test/ProgrammaticApi.js", apiFile, "Djn.programmaticNamespace", "Djn.programmaticNamespace" );
   
    // Register a new action with a method
    RegisteredAction action = api.addAction( CustomRegistryConfiguratorHandlingTest.class, "MyCustomRegistryConfiguratorHandlingTest");
    Method m = getMethod( CustomRegistryConfiguratorHandlingTest.class, "test_programmaticMethod", String.class);
    action.addStandardMethod( "myProgrammaticMethod", m, false);
   
    // Register a poll method
    Method pm = getMethod( CustomRegistryConfiguratorHandlingTest.class, "test_programmaticPollMethod", Map.class);
    action.addPollMethod( "myProgrammaticPollMethod", pm);
  }
View Full Code Here

Examples of com.softwarementors.extjs.djn.api.RegisteredAction

    }

    List<RegisteredAction> actions = new ArrayList<RegisteredAction>();
    for( String actionName : actionNames ) {
      if( this.registry.hasAction( actionName ) ) {
        RegisteredAction existingAction = this.registry.getAction( actionName );
        ApiConfigurationException ex = ApiConfigurationException.forActionAlreadyRegistered(actionName, actionClass, existingAction.getActionClass());
        logger.fatal( ex.getMessage(), ex );
        throw ex;
      }
      RegisteredAction action = api.addAction( actionClass, actionName );
      actions.add( action );
    }
   
    return actions;
  }
View Full Code Here

Examples of com.softwarementors.extjs.djn.api.RegisteredAction

  private void scanAndRegisterActionClass(List<RegisteredAction> actions) {
    assert actions != null;
    assert !actions.isEmpty();
   
    RegisteredAction actionTemplate = actions.get(0);
   
    // *All* methods are candidates, including those in base classes,
    // even if the base class does not have a DirectAction annotation!
    List<Method> allMethods = new ArrayList<Method>();
    Class<?> cls = actionTemplate.getActionClass();
    while( cls != null ) {
      Method[] methods = cls.getDeclaredMethods(); // Get private, protected and other methods!
      Collections.addAll( allMethods, methods );
      cls = cls.getSuperclass();
    }
   
    for( Method method : allMethods ) {
      // Check if the kind of direct method -if any
      DirectMethod methodAnnotation = method.getAnnotation(DirectMethod.class);
      boolean isStandardMethod = methodAnnotation != null;
      if( !isStandardMethod ) {
        isStandardMethod = method.getName().startsWith(STANDARD_METHOD_NAME_PREFIX);
      }
     
      DirectFormPostMethod postMethodAnnotation = method.getAnnotation(DirectFormPostMethod.class);
      boolean isFormPostMethod = postMethodAnnotation != null;
      if( !isFormPostMethod ) {
        isFormPostMethod = method.getName().startsWith(FORM_POST_METHOD_NAME_PREFIX)
      }
     
      DirectPollMethod pollMethodAnnotation = method.getAnnotation(DirectPollMethod.class);
      boolean isPollMethod = pollMethodAnnotation != null;
      if( !isPollMethod ) {
        isPollMethod = method.getName().startsWith( POLL_METHOD_NAME_PREFIX );
      }
     
      // Check that a method is just of only one kind of method
      if( isStandardMethod && isFormPostMethod ) {
        ApiConfigurationException ex = ApiConfigurationException.forMethodCantBeStandardAndFormPostMethodAtTheSameTime(actionTemplate, method);
        logger.fatal( ex.getMessage(), ex );
        throw ex;
      }
      if( (methodAnnotation != null || postMethodAnnotation != null) && isPollMethod) {
        ApiConfigurationException ex = ApiConfigurationException.forPollMethodCantBeStandardOrFormPostMethodAtTheSameTime(actionTemplate, method);
        logger.fatal( ex.getMessage(), ex );
        throw ex;
      }

      // Process standard and form post methods together, as they are very similar
      if( isStandardMethod || isFormPostMethod) {
       
        String methodName = "";
        if( isStandardMethod ) {
          methodName = getStandardMethodName(method, methodAnnotation);
        }
        else {
          methodName = getFormPostMethodName( method, postMethodAnnotation);
        }       
        if( actionTemplate.hasStandardMethod(methodName)  ) {
          ApiConfigurationException ex = ApiConfigurationException.forMethodAlreadyRegisteredInAction(methodName, actionTemplate.getName());
          logger.fatal( ex.getMessage(), ex );
          throw ex;
        }
       
        if( isFormPostMethod && !RegisteredStandardMethod.isValidFormHandlingMethod(method)) {
          ApiConfigurationException ex = ApiConfigurationException.forMethodHasWrongParametersForAFormHandler( actionTemplate.getName(), methodName );
          logger.fatal( ex.getMessage(), ex );
          throw ex;
        }

        for( RegisteredAction actionToRegister : actions ) {
View Full Code Here

Examples of foo.domaintest.action.ActionDelegator.RegisteredAction

  /** Execute a GET or POST request by injecting and running the appropriate {@link Action}. */
  @Override
  public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    // The poorly named method getRequestURI gives the path.
    RegisteredAction registeredAction = DELEGATOR.getRegisteredAction(request.getRequestURI());
    Action action = registeredAction.getAction();
    String origin = request.getHeader(ORIGIN);
    String method = request.getMethod();
    if (!(("GET".equals(request.getMethod()) && action instanceof GetAction)
        || ("POST".equals(request.getMethod()) && action instanceof PostAction)
        || ("OPTIONS".equals(method) && origin != null))) {
      response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, "Unsupported method.");
      return;
    }
    // Turn off reflected-XSS filtering in modern browsers. Without this, you couldn't execute a
    // script from a page served via /echo. This protection is useless to us because /stash allows
    // for a far more powerful stored-XSS (albeit short lived), and in any case we allow scripts.
    response.addHeader(X_XSS_PROTECTION, "0");
    // Enable Cross-Origin Resource Sharing. See http://www.w3.org/TR/cors/ for details.
    if (origin != null) {
      response.addHeader(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
      if ("OPTIONS".equals(method)) {  // Only allow OPTIONS to support CORS preflight.
        return;
      }
    }
    ObjectGraph requestGraph = GLOBAL_GRAPH
        .plus(new RequestModule(request, response, registeredAction.getPath()))
        .plus(REQUEST_MODULES);
    Metrics metrics = requestGraph.get(Metrics.class);
    try {
      requestGraph.inject(action).run();
    } catch (HttpErrorException e) {
      metrics.setResponseCode(e.getResponseCode());
      metrics.addActivity("error")// Mark this as user error.
      response.sendError(e.getResponseCode(), e.getMessage());
    } catch (Exception e) {
      logger.log(Level.SEVERE, e.getMessage(), e);
      response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Bad request");
      return// Return without exporting metrics.
    }
    if (registeredAction.isExportingMetrics()) {
      metrics.export();
    }
  }
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.