View Javadoc

1   /*
2    * $Id: TestComponent.java 21939 2011-05-18 13:32:09Z aperepel $
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  
11  package org.mule.tck.testmodels.services;
12  
13  import java.util.concurrent.atomic.AtomicInteger;
14  
15  import org.apache.commons.logging.Log;
16  import org.apache.commons.logging.LogFactory;
17  
18  public class TestComponent implements ITestComponent
19  {
20      public static final String EXCEPTION_MESSAGE = "Test Service fired an Exception";
21  
22      protected static final Log logger = LogFactory.getLog(TestComponent.class);
23  
24      protected AtomicInteger count = new AtomicInteger(0);
25  
26      public String receive(String message) throws Exception
27      {
28          logger.info("Received: " + message + " number: " + inc() + " in thread: "
29                      + Thread.currentThread().getName());
30          return "Received: " + message;
31      }
32      
33      public String receiveBytes(byte[] message) throws Exception
34      {
35          return receive(new String(message)); 
36      }
37  
38      public String throwsException(String message) throws Exception
39      {
40          throw new TestComponentException(EXCEPTION_MESSAGE);
41      }
42  
43      protected int inc()
44      {
45          return count.incrementAndGet();
46      }
47  
48  }