View Javadoc

1   /*
2    * $Id: HttpStatusCodeCallback.java 19026 2010-08-16 07:30:47Z dirk.olmes $
3    * -------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  package org.mule.module.ibeans.spi.support;
11  
12  import org.mule.message.DefaultExceptionPayload;
13  import org.mule.module.ibeans.spi.MuleResponseMessage;
14  
15  import org.ibeans.impl.test.MockMessageCallback;
16  
17  /**
18   * Sets a Http status code on the result message created on a mock invocation
19   */
20  public class HttpStatusCodeCallback implements MockMessageCallback<MuleResponseMessage>
21  {
22      private int status;
23  
24      public HttpStatusCodeCallback(int status)
25      {
26          this.status = status;
27      }
28  
29      public void onMessage(MuleResponseMessage response)
30      {
31          //TODO should this really be read/write
32          response.setStatusCode(String.valueOf(status));
33          if(status >= 400)
34          {
35              response.getMessage().setExceptionPayload(new DefaultExceptionPayload(new Exception("Mock Http Error")));
36          }
37      }
38  }