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