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.rss;
8   
9   import java.io.IOException;
10  import java.net.InetSocketAddress;
11  import java.net.SocketAddress;
12  
13  import org.simpleframework.http.core.Container;
14  import org.simpleframework.transport.connect.Connection;
15  import org.simpleframework.transport.connect.SocketConnection;
16  
17  /**
18   * HTTP server for testing purposes using the <a
19   * href="http://www.simpleframework.org/">Simple Framework</a> as server
20   * implementation.
21   */
22  public class SimpleHttpServer
23  {
24      private Container container;
25      private SocketAddress address;
26      private Connection connection;
27  
28      public SimpleHttpServer(int port, Container container)
29      {
30          super();
31          this.address = new InetSocketAddress(port);
32          this.container = container;
33      }
34  
35      public void start() throws IOException
36      {
37          connection = new SocketConnection(container);
38          connection.connect(address);
39      }
40  
41      public void stop()
42      {
43          try
44          {
45              if (connection != null)
46              {
47                  connection.close();
48              }
49          }
50          catch (IOException e)
51          {
52              throw new IllegalStateException(e);
53          }
54      }
55  }