Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ResponseWriterCallback |
|
| 5.0;5 |
1 | /* | |
2 | * $Id: ResponseWriterCallback.java 10489 2008-01-23 17:53:38Z dfeist $ | |
3 | * -------------------------------------------------------------------------------------- | |
4 | * Copyright (c) MuleSource, Inc. All rights reserved. http://www.mulesource.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.tck.functional; | |
11 | ||
12 | import org.mule.api.MuleEventContext; | |
13 | ||
14 | /** | |
15 | * A test callback that writes the results of a service invocation to the response output stream | |
16 | * of the event | |
17 | * This should only be used when testing Asynchronous calls with the {@link FunctionalTestComponent} otherwise | |
18 | * you will get duplicate messages, since both this class and the {@link FunctionalTestComponent} will write | |
19 | * a return message back to the callee. | |
20 | * | |
21 | * @see org.mule.tck.functional.FunctionalTestComponent | |
22 | */ | |
23 | 6 | public class ResponseWriterCallback extends CounterCallback |
24 | { | |
25 | ||
26 | public void eventReceived(MuleEventContext context, Object component) throws Exception | |
27 | { | |
28 | 0 | if (context.isSynchronous()) |
29 | { | |
30 | 0 | throw new IllegalStateException("The ResponseWriterCallback should not be used for synchronous tests as it will cause two copies of the message to be written back to the client"); |
31 | } | |
32 | 0 | super.eventReceived(context, component); |
33 | ||
34 | 0 | String result = context.getMessageAsString() + " Received Async"; |
35 | 0 | if (context.getOutputStream() == null) |
36 | { | |
37 | 0 | throw new IllegalArgumentException("event context does not have an OutputStream associated"); |
38 | } | |
39 | ||
40 | 0 | context.getOutputStream().write(result.getBytes()); |
41 | 0 | context.getOutputStream().flush(); |
42 | 0 | } |
43 | ||
44 | } |