Exemplo n.º 1
0
    protected HttpResponse buildFailureResponse(RequestLine requestLine, MuleMessage message)
        throws TransformerException {
      EndpointURI uri = endpoint.getEndpointURI();
      String failedPath =
          uri.getScheme()
              + "://"
              + uri.getHost()
              + ":"
              + uri.getPort()
              + message.getProperty(HttpConnector.HTTP_REQUEST_PATH_PROPERTY);

      if (logger.isDebugEnabled()) {
        logger.debug("Failed to bind to " + failedPath);
      }

      HttpResponse response = new HttpResponse();
      response.setStatusLine(requestLine.getHttpVersion(), HttpConstants.SC_NOT_FOUND);
      response.setBody(HttpMessages.cannotBindToAddress(failedPath).toString());
      RequestContext.setEvent(
          new DefaultMuleEvent(
              new DefaultMuleMessage(response),
              endpoint,
              new DefaultMuleSession(service, connector.getMuleContext()),
              true));
      // The DefaultResponseTransformer will set the necessary headers
      return transformResponse(response);
    }
 /**
  * Create an endpoint and check its properties.
  *
  * @throws Exception if something goes wrong
  */
 public void testValidEndpointURI() throws Exception {
   EndpointURI endpointUri =
       new MuleEndpointURI("legstar-wmq://CICS01.BRIDGE.REQUEST.QUEUE", muleContext);
   endpointUri.initialise();
   assertEquals("legstar-wmq", endpointUri.getScheme());
   assertEquals("legstar-wmq", endpointUri.getSchemeMetaInfo());
   assertEquals("CICS01.BRIDGE.REQUEST.QUEUE", endpointUri.getAddress());
 }
Exemplo n.º 3
0
 @Test
 public void testUrlWithProvider() throws Exception {
   EndpointURI url = new MuleEndpointURI("vm://some.queue?endpointName=vmProvider", muleContext);
   url.initialise();
   assertEquals(VMConnector.VM, url.getScheme());
   assertEquals("some.queue", url.getAddress());
   assertEquals("vmProvider", url.getEndpointName());
   assertEquals("vm://some.queue?endpointName=vmProvider", url.toString());
   assertEquals(1, url.getParams().size());
 }
 /**
  * Get user/password from URI.
  *
  * @throws Exception if something goes wrong
  */
 public void testUserPasswordURI() throws Exception {
   EndpointURI endpointUri =
       new MuleEndpointURI("legstar-wmq://user:[email protected]", muleContext);
   endpointUri.initialise();
   assertEquals("legstar-wmq", endpointUri.getScheme());
   assertEquals("legstar-wmq", endpointUri.getSchemeMetaInfo());
   assertEquals("CICS01.BRIDGE.REQUEST.QUEUE", endpointUri.getAddress());
   assertEquals("user:password", endpointUri.getUserInfo());
   assertEquals("user", endpointUri.getUser());
   assertEquals("password", endpointUri.getPassword());
 }
Exemplo n.º 5
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);
  }