~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to examples/org/jboss/remoting/samples/transporter/custom/server/HTTPServer.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.jboss.remoting.samples.transporter.custom.server;
2
 
 
3
 
import org.jboss.remoting.detection.jndi.JNDIDetector;
4
 
import org.jboss.remoting.network.NetworkRegistry;
5
 
import org.jboss.remoting.samples.transporter.basic.CustomerProcessor;
6
 
import org.jboss.remoting.samples.transporter.basic.CustomerProcessorImpl;
7
 
import org.jboss.remoting.transporter.InternalTransporterServices;
8
 
import org.jboss.remoting.transporter.TransporterServer;
9
 
import org.w3c.dom.Document;
10
 
import org.w3c.dom.Element;
11
 
import org.xml.sax.SAXException;
12
 
 
13
 
import javax.management.MBeanServer;
14
 
import javax.management.MBeanServerFactory;
15
 
import javax.management.ObjectName;
16
 
import javax.xml.parsers.DocumentBuilderFactory;
17
 
import javax.xml.parsers.ParserConfigurationException;
18
 
import java.io.ByteArrayInputStream;
19
 
import java.io.IOException;
20
 
import java.net.InetAddress;
21
 
 
22
 
/**
23
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
24
 
 */
25
 
public class HTTPServer
26
 
{
27
 
   private TransporterServer server = null;
28
 
 
29
 
   public void start() throws Exception
30
 
   {
31
 
      initTransporterServices();
32
 
 
33
 
      Element xmlConfig = getXmlConfig();
34
 
 
35
 
      server = TransporterServer.createTransporterServer(xmlConfig, new CustomerProcessorImpl(),
36
 
                                                         CustomerProcessor.class.getName(), true);
37
 
   }
38
 
 
39
 
   private Element getXmlConfig() throws ParserConfigurationException, IOException, SAXException
40
 
   {
41
 
 
42
 
      String transport = "http";
43
 
      String host = "localhost";
44
 
      int port = 5600;
45
 
 
46
 
      StringBuffer buf = new StringBuffer();
47
 
      buf.append("<?xml version=\"1.0\"?>\n");
48
 
      buf.append("<config>");
49
 
      buf.append("<invoker transport=\"" + transport + "\">");
50
 
      buf.append("<attribute name=\"serverBindAddress\">" + host + "</attribute>");
51
 
      buf.append("<attribute name=\"serverBindPort\">" + port + "</attribute>");
52
 
      buf.append("</invoker>");
53
 
      buf.append("</config>");
54
 
      Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
55
 
      return xml.getDocumentElement();
56
 
 
57
 
   }
58
 
 
59
 
   public void stop()
60
 
   {
61
 
      if (server != null)
62
 
      {
63
 
         server.stop();
64
 
      }
65
 
   }
66
 
 
67
 
   private void initTransporterServices() throws Exception
68
 
   {
69
 
      // create MBeanServer
70
 
      MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer();
71
 
 
72
 
      NetworkRegistry registry = NetworkRegistry.getInstance();
73
 
 
74
 
      String host = InetAddress.getLocalHost().getHostAddress();
75
 
      JNDIDetector jndiDetector = new JNDIDetector();
76
 
      jndiDetector.setPort(JNDIServer.JNDI_PORT);
77
 
      jndiDetector.setHost(host);
78
 
      jndiDetector.setContextFactory("org.jnp.interfaces.NamingContextFactory");
79
 
      jndiDetector.setURLPackage("org.jboss.naming:org.jnp.interfaces");
80
 
 
81
 
 
82
 
      InternalTransporterServices transporterService = InternalTransporterServices.getInstance();
83
 
 
84
 
      transporterService.setup(mbeanServer,
85
 
                               jndiDetector, new ObjectName("remoting:type=Detector,transport=jndi"),
86
 
                               registry, new ObjectName("remoting:type=NetworkRegistry"),
87
 
                               true, true);
88
 
 
89
 
      //TODO: -TME Have to start the detector after setup() call?
90
 
      jndiDetector.start();
91
 
 
92
 
   }
93
 
 
94
 
 
95
 
   public static void main(String[] args)
96
 
   {
97
 
      HTTPServer server = new HTTPServer();
98
 
      try
99
 
      {
100
 
         server.start();
101
 
 
102
 
         Thread.currentThread().sleep(60000);
103
 
 
104
 
      }
105
 
      catch (Exception e)
106
 
      {
107
 
         e.printStackTrace();
108
 
      }
109
 
      finally
110
 
      {
111
 
         server.stop();
112
 
      }
113
 
   }
114
 
}