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