1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.jelly.tags.jetty;
18
19 import java.io.IOException;
20
21 import org.apache.commons.jelly.JellyTagException;
22 import org.apache.commons.jelly.TagSupport;
23 import org.apache.commons.jelly.XMLOutput;
24
25 import org.mortbay.http.SocketListener;
26 import org.mortbay.util.InetAddrPort;
27
28 /***
29 * Declare a socket listener for a Jetty http server
30 *
31 * @author rtl
32 * @version $Id: SocketListenerTag.java 155420 2005-02-26 13:06:03Z dirkv $
33 */
34 public class SocketListenerTag extends TagSupport {
35
36 /*** parameter port with default*/
37 private int _port = JettyHttpServerTag.DEFAULT_PORT;
38
39 /*** parameter host, with default */
40 private String _host = JettyHttpServerTag.DEFAULT_HOST;
41
42 /*** Creates a new instance of SocketListenerTag */
43 public SocketListenerTag() {
44 }
45
46 /***
47 * Perform the tag functionality. In this case, add a socket listener
48 * for the specified host and port to the parent server,
49 *
50 * @param xmlOutput where to send output
51 * @throws Exception when an error occurs
52 */
53 public void doTag(XMLOutput xmlOutput) throws JellyTagException {
54 JettyHttpServerTag httpserver = (JettyHttpServerTag) findAncestorWithClass(
55 JettyHttpServerTag.class);
56 if ( httpserver == null ) {
57 throw new JellyTagException( "<socketListener> tag must be enclosed inside a <server> tag" );
58 }
59
60 try {
61 httpserver.addListener(
62 new SocketListener(new InetAddrPort(getHost(), getPort())));
63 }
64 catch (IOException e) {
65 throw new JellyTagException(e);
66 }
67
68 invokeBody(xmlOutput);
69 }
70
71
72
73
74 /***
75 * Getter for property port.
76 *
77 * @return value of property port.
78 */
79 public int getPort() {
80 return _port;
81 }
82
83 /***
84 * Setter for property port.
85 *
86 * @param port New value of property port.
87 */
88 public void setPort(int port) {
89 _port = port;
90 }
91
92 /***
93 * Getter for property host.
94 *
95 * @return value of property host.
96 */
97 public String getHost() {
98 return _host;
99 }
100
101 /***
102 * Setter for property host.
103 *
104 * @param host New value of property host.
105 */
106 public void setHost(String host) {
107 _host = host;
108 }
109
110 }