Example #1
0
 protected HttpResponse doBad(RequestLine requestLine) throws MuleException {
   MuleMessage message = new DefaultMuleMessage(NullPayload.getInstance());
   MuleEvent event =
       new DefaultMuleEvent(
           message,
           endpoint,
           new DefaultMuleSession(message, new NullSessionHandler(), connector.getMuleContext()),
           true);
   OptimizedRequestContext.unsafeSetEvent(event);
   HttpResponse response = new HttpResponse();
   response.setStatusLine(requestLine.getHttpVersion(), HttpConstants.SC_BAD_REQUEST);
   response.setBody(HttpMessages.malformedSyntax().toString() + HttpConstants.CRLF);
   return transformResponse(response);
 }
Example #2
0
 protected HttpResponse doOtherValid(RequestLine requestLine, String method)
     throws MuleException {
   MuleMessage message = new DefaultMuleMessage(NullPayload.getInstance());
   MuleEvent event =
       new DefaultMuleEvent(
           message,
           endpoint,
           new DefaultMuleSession(message, new NullSessionHandler(), connector.getMuleContext()),
           true);
   OptimizedRequestContext.unsafeSetEvent(event);
   HttpResponse response = new HttpResponse();
   response.setStatusLine(requestLine.getHttpVersion(), HttpConstants.SC_METHOD_NOT_ALLOWED);
   response.setBody(HttpMessages.methodNotAllowed(method).toString() + HttpConstants.CRLF);
   return transformResponse(response);
 }
  private MuleEvent invokeInternal(MuleEvent event) throws MuleException {
    // Ensure we have event in ThreadLocal
    OptimizedRequestContext.unsafeSetEvent(event);

    if (logger.isTraceEnabled()) {
      logger.trace(
          String.format(
              "Invoking %s component for service %s",
              this.getClass().getName(), flowConstruct.getName()));
    }

    if (!lifecycleManager.getState().isStarted() || lifecycleManager.getState().isStopping()) {
      throw new LifecycleException(CoreMessages.isStopped(flowConstruct.getName()), this);
    }

    // Invoke component implementation and gather statistics
    try {
      fireComponentNotification(
          event.getMessage(), ComponentMessageNotification.COMPONENT_PRE_INVOKE);

      long startTime = 0;
      if (statistics.isEnabled()) {
        startTime = System.currentTimeMillis();
      }

      Object result = doInvoke(event);

      if (statistics.isEnabled()) {
        statistics.addExecutionTime(System.currentTimeMillis() - startTime);
      }

      MuleEvent resultEvent = createResultEvent(event, result);
      // Components only have access to the original event, so propogate the
      // stop further processing
      resultEvent.setStopFurtherProcessing(event.isStopFurtherProcessing());
      fireComponentNotification(
          resultEvent.getMessage(), ComponentMessageNotification.COMPONENT_POST_INVOKE);

      return resultEvent;
    } catch (MuleException me) {
      throw me;
    } catch (Exception e) {
      throw new ComponentException(CoreMessages.failedToInvoke(this.toString()), event, this, e);
    }
  }
Example #4
0
 public void run() {
   try {
     event = OptimizedRequestContext.criticalSetEvent(event);
     Object replyTo = event.getMessage().getReplyTo();
     ReplyToHandler replyToHandler =
         getReplyToHandler(event.getMessage(), (InboundEndpoint) event.getEndpoint());
     MuleMessage result = invokeComponent(event);
     dispatchToOutboundRouter(event, result);
     processReplyTo(event, result, replyToHandler, replyTo);
   } catch (Exception e) {
     event.getSession().setValid(false);
     if (e instanceof MessagingException) {
       handleException(e);
     } else {
       handleException(
           new MessagingException(
               CoreMessages.eventProcessingFailedFor(getName()), event.getMessage(), e));
     }
   }
 }
Example #5
0
  public MuleMessage sendEvent(MuleEvent event) throws MuleException {
    if (stopping.get() || stopped.get()) {
      throw new ServiceException(CoreMessages.componentIsStopped(name), event.getMessage(), this);
    }

    try {
      waitIfPaused(event);
    } catch (InterruptedException e) {
      throw new ServiceException(event.getMessage(), this, e);
    }

    if (stats.isEnabled()) {
      stats.incReceivedEventSync();
    }
    if (logger.isDebugEnabled()) {
      logger.debug(
          "Service: "
              + name
              + " has received synchronous event on: "
              + event.getEndpoint().getEndpointURI());
    }
    event = OptimizedRequestContext.unsafeSetEvent(event);
    return doSend(event);
  }