KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > http > HttpSoapConnector


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.components.http;
18
19 import javax.jbi.JBIException;
20 import javax.jbi.component.ComponentContext;
21
22 import org.mortbay.jetty.Connector;
23 import org.mortbay.jetty.Server;
24 import org.mortbay.jetty.bio.SocketConnector;
25 import org.mortbay.jetty.handler.ContextHandler;
26 import org.mortbay.jetty.servlet.ServletHandler;
27 import org.mortbay.jetty.servlet.ServletHolder;
28 import org.mortbay.jetty.servlet.ServletMapping;
29 import org.mortbay.thread.BoundedThreadPool;
30
31 public class HttpSoapConnector extends HttpSoapInOutBinding {
32     private Connector listener = new SocketConnector();
33     
34     /**
35      * The maximum number of threads for the Jetty SocketListener. It's set
36      * to 256 by default to match the default value in Jetty.
37      */

38     private int maxThreads = 256;
39
40     private Server server;
41
42     private String JavaDoc host;
43
44     private int port;
45
46     /**
47      * Constructor
48      *
49      * @param host
50      * @param port
51      */

52     public HttpSoapConnector(String JavaDoc host, int port, boolean defaultInOut) {
53         this.host = host;
54         this.port = port;
55         this.defaultInOut = defaultInOut;
56     }
57
58     public HttpSoapConnector() {
59     }
60
61     /**
62      * Constructor
63      *
64      * @param listener
65      */

66     public HttpSoapConnector(Connector listener) {
67         this.listener = listener;
68     }
69
70     /**
71      * Called when the Component is initialized
72      *
73      * @param cc
74      * @throws JBIException
75      */

76     public void init(ComponentContext cc) throws JBIException {
77         super.init(cc);
78         //should set all ports etc here - from the naming context I guess ?
79
if (listener == null) {
80             listener = new SocketConnector();
81         }
82         listener.setHost(host);
83         listener.setPort(port);
84         server = new Server();
85         BoundedThreadPool btp = new BoundedThreadPool();
86         btp.setMaxThreads(getMaxThreads());
87         server.setThreadPool(btp);
88     }
89
90     /**
91      * start the Component
92      *
93      * @throws JBIException
94      */

95     public void start() throws JBIException {
96         server.setConnectors(new Connector[] { listener });
97         ContextHandler context = new ContextHandler();
98         context.setContextPath("/");
99         ServletHolder holder = new ServletHolder();
100         holder.setName("jbiServlet");
101         holder.setClassName(BindingServlet.class.getName());
102         ServletHandler handler = new ServletHandler();
103         handler.setServlets(new ServletHolder[] { holder });
104         ServletMapping mapping = new ServletMapping();
105         mapping.setServletName("jbiServlet");
106         mapping.setPathSpec("/*");
107         handler.setServletMappings(new ServletMapping[] { mapping });
108         context.setHandler(handler);
109         server.setHandler(context);
110         context.setAttribute("binding", this);
111         try {
112             server.start();
113         }
114         catch (Exception JavaDoc e) {
115             throw new JBIException("Start failed: " + e, e);
116         }
117     }
118
119     /**
120      * stop
121      */

122     public void stop() throws JBIException {
123         try {
124             if (server != null) {
125                 server.stop();
126             }
127         } catch (Exception JavaDoc e) {
128             throw new JBIException("Stop failed: " + e, e);
129         }
130     }
131
132     /**
133      * shutdown
134      */

135     public void shutDown() throws JBIException {
136         server = null;
137     }
138
139     // Properties
140
//-------------------------------------------------------------------------
141
public int getPort() {
142         return port;
143     }
144
145     public void setPort(int port) {
146         this.port = port;
147     }
148
149     public Server getServer() {
150         return server;
151     }
152
153     public void setServer(Server server) {
154         this.server = server;
155     }
156
157     public String JavaDoc getHost() {
158         return host;
159     }
160
161     public void setHost(String JavaDoc host) {
162         this.host = host;
163     }
164
165     public int getMaxThreads() {
166         return maxThreads;
167     }
168
169     public void setMaxThreads(int maxThreads) {
170         this.maxThreads = maxThreads;
171     }
172 }
173
Popular Tags