protected void assertSync(MuleMessage result) {
    assertNotNull(result);

    String receiverThread = result.getInboundProperty("receiver-thread");
    String flowThread = result.getInboundProperty("processor-thread");
    String dispatcherThread = result.getInboundProperty("dispatcher-thread");

    assertEquals(receiverThread, flowThread);
    assertEquals(flowThread, dispatcherThread);
  }
コード例 #2
0
 @Test
 public void testHttpResponseMove() throws Exception {
   MuleClient client = new MuleClient(muleContext);
   DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, muleContext);
   MuleMessage response =
       client.send("http://localhost:" + dynamicPort.getNumber() + "/resources/move", muleMessage);
   assertEquals(HTTP_BODY, response.getPayloadAsString());
   assertEquals(
       "" + HttpConstants.SC_MOVED_PERMANENTLY, response.getInboundProperty("http.status"));
   assertEquals(
       "http://localhost:9090/resources/moved", response.<Object>getInboundProperty("Location"));
 }
  protected void assertAllProcessingAsync(MuleMessage result) {
    assertNotNull(result);

    String receiverThread = result.getInboundProperty("receiver-thread");
    String flowThread = result.getInboundProperty("processor-thread");
    String dispatcherThread = result.getInboundProperty("dispatcher-thread");

    assertTrue(receiverThread.startsWith("vm.receiver"));
    assertFalse(receiverThread.equals(flowThread));
    assertFalse(flowThread.equals(dispatcherThread));
    assertFalse(receiverThread.equals(dispatcherThread));
  }
コード例 #4
0
  @Override
  public Object transformMessage(final MuleMessage message, final String outputEncoding)
      throws TransformerException {

    BaseNodeRq nodeRq = null;

    // create the context.
    TransformContext context = new TransformContext();
    message.setProperty("txContext", context, PropertyScope.SESSION);

    String contentType = message.getInboundProperty("Content-Type");
    if (contentType != null && contentType.contains("multipart/form-data")) {

      // transform the multipart request to node
      Node node = httpMultipartTransformer.transformMessage(message);

      // run the transform.
      nodeRq = this.httpRqToNodeRq.transform(context, node);

    } else if (message.getProperty("http.request", PropertyScope.INBOUND) != null) {

      // adapt the http request
      String muleQueryString = (String) message.getProperty("http.request", PropertyScope.INBOUND);
      HttpRequestAdapter httpRequest = new HttpRequestAdapter(muleQueryString);

      // run the transform.
      nodeRq = this.httpRqToNodeRq.transform(context, httpRequest);
    }

    return nodeRq;
  }
コード例 #5
0
  @Test
  public void mapsToHelloWorldException() throws Exception {
    LocalMuleClient client = muleContext.getClient();

    MuleMessage result =
        client.send(
            "http://localhost:" + port.getNumber() + "/helloworld/throwException",
            getTestMuleMessage(),
            getHttpOptions());

    assertEquals(
        (Integer) HttpConstants.SC_SERVICE_UNAVAILABLE,
        result.getInboundProperty(HttpConnector.HTTP_STATUS_PROPERTY, 0));
  }
コード例 #6
0
 @Test
 public void testHttpResponseError() throws Exception {
   MuleClient client = new MuleClient(muleContext);
   Map<String, Object> properties = new HashMap<String, Object>();
   properties.put("errorMessage", "ERROR !!!! ");
   DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, properties, muleContext);
   MuleMessage response =
       client.send(
           "http://localhost:" + dynamicPort.getNumber() + "/resources/error",
           muleMessage,
           properties);
   assertTrue(response.getPayloadAsString().contains("ERROR !!!!"));
   assertEquals(
       "" + HttpConstants.SC_INTERNAL_SERVER_ERROR, response.getInboundProperty("http.status"));
 }
コード例 #7
0
 @Test
 public void testHttpResponseAll() throws Exception {
   MuleClient client = new MuleClient(muleContext);
   DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, muleContext);
   MuleMessage response =
       client.send("http://localhost:" + dynamicPort.getNumber() + "/resources/all", muleMessage);
   assertEquals("Custom body", response.getPayloadAsString());
   assertEquals("" + HttpConstants.SC_NOT_FOUND, response.getInboundProperty("http.status"));
   assertEquals(
       "public,no-cache,must-revalidate,max-age=3600,no-transform",
       response.getInboundProperty("Cache-Control"));
   assertEquals("Thu, 01 Dec 2014 16:00:00 GMT", response.getInboundProperty("Expires"));
   assertEquals("http://localhost:9090", response.getInboundProperty("Location"));
   assertEquals("value1", response.getInboundProperty("header1"));
   Cookie[] cookies = (Cookie[]) response.getInboundProperty("Set-Cookie");
   assertEquals(2, cookies.length);
   validateCookie(cookies[0]);
   validateCookie(cookies[1]);
 }
コード例 #8
0
  @Test
  public void testHttpResponseAllWithExpressions() throws Exception {
    MuleClient client = new MuleClient(muleContext);
    Map<String, Object> properties = populateProperties();

    DefaultMuleMessage muleMessage = new DefaultMuleMessage(HTTP_BODY, properties, muleContext);
    MuleMessage response =
        client.send(
            "http://localhost:" + dynamicPort.getNumber() + "/resources/allExpressions",
            muleMessage,
            properties);
    assertEquals("" + HttpConstants.SC_NOT_FOUND, response.getInboundProperty("http.status"));
    assertEquals("max-age=3600", response.getInboundProperty("Cache-Control"));
    assertEquals("Thu, 01 Dec 2014 16:00:00 GMT", response.getInboundProperty("Expires"));
    assertEquals("http://localhost:9090", response.getInboundProperty("Location"));
    assertEquals("value1", response.getInboundProperty("header1"));
    Cookie[] cookies = (Cookie[]) response.getInboundProperty("Set-Cookie");
    assertEquals(2, cookies.length);
    validateCookie(cookies[0]);
    validateCookie(cookies[1]);
  }
 protected void assertAllProcessingInClientThread(MuleMessage result) {
   assertSync(result);
   assertEquals(Thread.currentThread().getName(), result.getInboundProperty("receiver-thread"));
 }
 protected void assertAllProcessingInRecieverThread(MuleMessage result) {
   assertSync(result);
   assertTrue(((String) result.getInboundProperty("receiver-thread")).startsWith("vm.receiver"));
 }