Package org.sonatype.nexus.extdirect.model

Examples of org.sonatype.nexus.extdirect.model.Response


          catch (Exception e) {
            log.error("Could not log in anonymous user");
          }
        }

        Response response = null;
        EventDataBuilder builder = null;

        // Maybe record analytics events
        if (eventRecorder != null && eventRecorder.isEnabled()) {
          builder = new EventDataBuilder("Ext.Direct")
              .set("type", method.getType().name())
              .set("name", method.getName())
              .set("action", method.getActionName());
        }

        MDC.put(getClass().getName(), method.getFullName());

        try {
          response = asResponse(super.invokeMethod(method, actionInstance, parameters));
        }
        catch (InvocationTargetException e) {
          response = handleException(method, e.getTargetException());
        }
        catch (Throwable e) {
          response = handleException(method, e);
        }
        finally {
          // Record analytics event
          if (builder != null) {
            if (response != null) {
              builder.set("success", response.isSuccess());
            }
            eventRecorder.record(builder.build());
          }

          MDC.remove(getClass().getName());
        }

        return response;
      }

      private Response handleException(final RegisteredMethod method, final Throwable e) {
        log.debug("Failed to invoke action method: {}, java-method: {}", method.getFullName(),
            method.getFullJavaMethodName(), e);

        if (e instanceof InvalidConfigurationException) {
          InvalidConfigurationException cause = (InvalidConfigurationException) e;
          ValidationResponse vr = cause.getValidationResponse();
          if (vr == null || vr.getValidationErrors() == null || vr.getValidationErrors().size() == 0) {
            return asResponse(error(e));
          }
          return asResponse(invalid(cause));
        }

        if (e instanceof ConstraintViolationException) {
          ConstraintViolationException cause = (ConstraintViolationException) e;
          Set<ConstraintViolation<?>> violations = cause.getConstraintViolations();
          if (violations == null || violations.size() == 0) {
            return asResponse(error(e));
          }
          return asResponse(invalid(cause));
        }

        return asResponse(error(e));
      }

      private Response asResponse(final Object result) {
        Response response;
        if (result == null) {
          response = success();
        }
        else {
          if (result instanceof Response) {
View Full Code Here

TOP

Related Classes of org.sonatype.nexus.extdirect.model.Response

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.