Beispiel #1
0
  // This is not called by anything?!
  protected void stopListeners() throws MuleException {
    @SuppressWarnings("unchecked")
    List<InboundEndpoint> endpoints = getIncomingEndpoints();

    for (InboundEndpoint endpoint : endpoints) {
      MessageReceiver receiver =
          ((AbstractConnector) endpoint.getConnector()).getReceiver(this, endpoint);
      if (receiver != null) {
        receiver.stop();
      }
    }
  }
Beispiel #2
0
  // This is not called by anything?!
  protected void stopListeners() throws MuleException {
    InboundEndpoint endpoint;
    List endpoints = getIncomingEndpoints();

    for (Iterator it = endpoints.iterator(); it.hasNext(); ) {
      endpoint = (InboundEndpoint) it.next();
      MessageReceiver receiver =
          ((AbstractConnector) endpoint.getConnector()).getReceiver(this, endpoint);
      if (receiver != null) {
        receiver.stop();
      }
    }
  }
Beispiel #3
0
  protected void startListeners() throws MuleException {
    @SuppressWarnings("unchecked")
    List<InboundEndpoint> endpoints = getIncomingEndpoints();

    for (InboundEndpoint endpoint : endpoints) {
      MessageReceiver receiver =
          ((AbstractConnector) endpoint.getConnector()).getReceiver(this, endpoint);
      if (receiver != null
          && endpoint.getConnector().isStarted()
          && endpoint.getInitialState().equals(ImmutableEndpoint.INITIAL_STATE_STARTED)) {
        receiver.start();
      }
    }
  }
Beispiel #4
0
  protected void startListeners() throws MuleException {
    InboundEndpoint endpoint;
    List endpoints = getIncomingEndpoints();

    for (Iterator it = endpoints.iterator(); it.hasNext(); ) {
      endpoint = (InboundEndpoint) it.next();
      MessageReceiver receiver =
          ((AbstractConnector) endpoint.getConnector()).getReceiver(this, endpoint);
      if (receiver != null
          && endpoint.getConnector().isStarted()
          && endpoint.getInitialState().equals(ImmutableEndpoint.INITIAL_STATE_STARTED)) {
        receiver.start();
      }
    }
  }
Beispiel #5
0
  protected void connectListeners() throws MuleException {
    @SuppressWarnings("unchecked")
    List<InboundEndpoint> endpoints = getIncomingEndpoints();

    for (InboundEndpoint endpoint : endpoints) {
      AbstractConnector connector = (AbstractConnector) endpoint.getConnector();
      MessageReceiver receiver = connector.getReceiver(this, endpoint);
      if (receiver != null && connector.isConnected()) {
        try {
          receiver.connect();
        } catch (Exception e) {
          throw new ModelException(
              MessageFactory.createStaticMessage(
                  "Failed to connect listener " + receiver + " for endpoint " + endpoint.getName()),
              e);
        }
      }
    }
  }
Beispiel #6
0
  protected void connectListeners() throws MuleException {
    InboundEndpoint endpoint;
    List endpoints = getIncomingEndpoints();

    for (Iterator it = endpoints.iterator(); it.hasNext(); ) {
      endpoint = (InboundEndpoint) it.next();
      MessageReceiver receiver =
          ((AbstractConnector) endpoint.getConnector()).getReceiver(this, endpoint);
      if (receiver != null) {
        try {
          receiver.connect();
        } catch (Exception e) {
          throw new ModelException(
              MessageFactory.createStaticMessage(
                  "Failed to connect listener " + receiver + " for endpoint " + endpoint.getName()),
              e);
        }
      }
    }
  }
Beispiel #7
0
    protected HttpResponse doRequest(HttpRequest request, RequestLine requestLine)
        throws IOException, MuleException {
      Map headers = parseHeaders(request);

      // TODO Mule 2.0 generic way to set stream message adapter
      MessageAdapter adapter = buildStandardAdapter(request, headers);

      MuleMessage message = new DefaultMuleMessage(adapter);

      String path = (String) message.getProperty(HttpConnector.HTTP_REQUEST_PROPERTY);
      int i = path.indexOf('?');
      if (i > -1) {
        path = path.substring(0, i);
      }

      message.setProperty(HttpConnector.HTTP_REQUEST_PATH_PROPERTY, path);

      if (logger.isDebugEnabled()) {
        logger.debug(message.getProperty(HttpConnector.HTTP_REQUEST_PROPERTY));
      }

      message.setProperty(
          HttpConnector.HTTP_CONTEXT_PATH_PROPERTY,
          HttpConnector.normalizeUrl(endpoint.getEndpointURI().getPath()));

      // determine if the request path on this request denotes a different receiver
      MessageReceiver receiver = getTargetReceiver(message, endpoint);

      HttpResponse response;
      // the response only needs to be transformed explicitly if
      // A) the request was not served or B) a null result was returned
      if (receiver != null) {
        preRouteMessage(message);
        MuleMessage returnMessage = receiver.routeMessage(message, endpoint.isSynchronous(), null);

        Object tempResponse;
        if (returnMessage != null) {
          tempResponse = returnMessage.getPayload();
        } else {
          tempResponse = NullPayload.getInstance();
        }
        // This removes the need for users to explicitly adding the response transformer
        // ObjectToHttpResponse in their config
        if (tempResponse instanceof HttpResponse) {
          response = (HttpResponse) tempResponse;
        } else {
          response = transformResponse(returnMessage);
        }

        response.disableKeepAlive(!((HttpConnector) connector).isKeepAlive());

        // Check if endpoint has a keep-alive property configured. Note the translation from
        // keep-alive in the schema to keepAlive here.
        boolean endpointOverride = Boolean.parseBoolean((String) endpoint.getProperty("keepAlive"));

        Header connectionHeader = request.getFirstHeader("Connection");
        if (connectionHeader != null) {
          String value = connectionHeader.getValue();
          if ("keep-alive".equalsIgnoreCase(value) && !endpointOverride) {
            response.setKeepAlive(true);
            Header header =
                new Header(
                    HttpConstants.HEADER_KEEP_ALIVE,
                    "timeout=" + ((HttpConnector) connector).getKeepAliveTimeout());
            response.addHeader(header);
          } else if ("close".equalsIgnoreCase(value)) {
            response.setKeepAlive(false);
          } else if (response.getHttpVersion().greaterEquals(HttpVersion.HTTP_1_1)) {
            response.setKeepAlive(true);
          } else {
            response.setKeepAlive(false);
          }
        }
      } else {
        response = buildFailureResponse(requestLine, message);
      }
      return response;
    }
Beispiel #8
0
  @SuppressWarnings("unchecked")
  protected void registerReceiverWithMuleService(MessageReceiver receiver, EndpointURI ep)
      throws MuleException {
    CxfMessageReceiver cxfReceiver = (CxfMessageReceiver) receiver;
    Server server = cxfReceiver.getServer();

    uriToServer.put(server.getEndpoint().getEndpointInfo().getAddress(), server);

    // TODO MULE-2228 Simplify this API
    SedaService c = new SedaService();

    String uniqueServiceName = createServiceName(server.getEndpoint());
    c.setName(uniqueServiceName);

    c.setModel(muleContext.getRegistry().lookupSystemModel());

    CxfServiceComponent svcComponent = new CxfServiceComponent(this, (CxfMessageReceiver) receiver);
    svcComponent.setBus(bus);

    c.setComponent(new DefaultJavaComponent(new SingletonObjectFactory(svcComponent)));

    // No determine if the endpointUri requires a new connector to be
    // registed in the case of http we only need to register the new
    // endpointUri if the port is different
    String endpoint = receiver.getEndpointURI().getAddress();
    String scheme = ep.getScheme().toLowerCase();

    InboundEndpoint originalEndpoint = receiver.getEndpoint();
    boolean sync = originalEndpoint.isSynchronous();

    // If we are using sockets then we need to set the endpoint name appropiately
    // and if using http/https
    // we need to default to POST and set the Content-Type
    if (scheme.equals("http")
        || scheme.equals("https")
        || scheme.equals("ssl")
        || scheme.equals("tcp")
        || scheme.equals("servlet")) {
      originalEndpoint.getProperties().put(HttpConnector.HTTP_METHOD_PROPERTY, "POST");
      originalEndpoint.getProperties().put(HttpConstants.HEADER_CONTENT_TYPE, "text/xml");
    }

    QName serviceName = server.getEndpoint().getEndpointInfo().getName();

    EndpointBuilder protocolEndpointBuilder = new EndpointURIEndpointBuilder(endpoint, muleContext);
    protocolEndpointBuilder.setSynchronous(sync);
    protocolEndpointBuilder.setName(ep.getScheme() + ":" + serviceName.getLocalPart());
    protocolEndpointBuilder.setTransactionConfig(originalEndpoint.getTransactionConfig());

    EndpointBuilder receiverEndpointBuilder =
        new EndpointURIEndpointBuilder(originalEndpoint, muleContext);

    // Apply the transformers to the correct endpoint
    EndpointBuilder transformerEndpoint;
    if (cxfReceiver.isApplyTransformersToProtocol()) {
      transformerEndpoint = protocolEndpointBuilder;
      receiverEndpointBuilder.setTransformers(Collections.emptyList());
      receiverEndpointBuilder.setResponseTransformers(Collections.emptyList());
    } else {
      transformerEndpoint = receiverEndpointBuilder;
    }

    // Ensure that the transformers aren't empty before setting them. Otherwise Mule will get
    // confused
    // and won't add the default transformers.
    if (originalEndpoint.getTransformers() != null
        && !originalEndpoint.getTransformers().isEmpty()) {
      transformerEndpoint.setTransformers(originalEndpoint.getTransformers());
    }

    if (originalEndpoint.getResponseTransformers() != null
        && !originalEndpoint.getResponseTransformers().isEmpty()) {
      transformerEndpoint.setResponseTransformers(originalEndpoint.getResponseTransformers());
    }

    // apply the filters to the correct endpoint
    EndpointBuilder filterEndpoint;
    if (cxfReceiver.isApplyFiltersToProtocol()) {
      filterEndpoint = protocolEndpointBuilder;
      receiverEndpointBuilder.setFilter(null);
    } else {
      filterEndpoint = receiverEndpointBuilder;
    }
    filterEndpoint.setFilter(originalEndpoint.getFilter());

    // apply the security filter to the correct endpoint
    EndpointBuilder secFilterEndpoint;
    if (cxfReceiver.isApplySecurityToProtocol()) {
      secFilterEndpoint = protocolEndpointBuilder;
      receiverEndpointBuilder.setSecurityFilter(null);
    } else {
      secFilterEndpoint = receiverEndpointBuilder;
    }
    secFilterEndpoint.setSecurityFilter(originalEndpoint.getSecurityFilter());

    String connectorName = (String) originalEndpoint.getProperty(CxfConstants.PROTOCOL_CONNECTOR);
    if (connectorName != null) {
      protocolEndpointBuilder.setConnector(
          muleContext.getRegistry().lookupConnector(connectorName));
    }

    InboundEndpoint protocolEndpoint =
        muleContext
            .getRegistry()
            .lookupEndpointFactory()
            .getInboundEndpoint(protocolEndpointBuilder);

    InboundEndpoint receiverEndpoint =
        muleContext
            .getRegistry()
            .lookupEndpointFactory()
            .getInboundEndpoint(receiverEndpointBuilder);

    receiver.setEndpoint(receiverEndpoint);

    c.setInboundRouter(new DefaultInboundRouterCollection());
    c.getInboundRouter().addEndpoint(protocolEndpoint);
    services.add(c);
  }