2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.test.remoting.configuration;
25
import junit.framework.TestCase;
26
import org.jboss.remoting.Client;
27
import org.jboss.remoting.InvokerLocator;
28
import org.jboss.remoting.InvokerRegistry;
29
import org.jboss.remoting.ServerInvoker;
30
import org.jboss.remoting.transport.Connector;
31
import org.jboss.remoting.transport.PortUtil;
32
import org.jboss.test.remoting.transport.mock.MockServerInvocationHandler;
33
import org.w3c.dom.Document;
35
import javax.xml.parsers.DocumentBuilderFactory;
36
import java.io.ByteArrayInputStream;
37
import java.net.InetAddress;
41
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
43
public class HTTPConfigurationTestCase extends TestCase
45
private String transport = "http";
46
private int serverPort = 6666;
47
private int clientPort = 7777;
48
private String hostName = null;
49
private String hostIP = null;
50
private String path = "foo/bar";
51
private Connector connector = null;
53
public void setUp() throws Exception
55
hostName = InetAddress.getLocalHost().getHostName();
56
hostIP = InetAddress.getLocalHost().getHostAddress();
58
connector = new Connector();
59
StringBuffer buf = new StringBuffer();
60
buf.append("<?xml version=\"1.0\"?>\n");
61
buf.append("<config>");
62
buf.append("<invoker transport=\"" + transport + "\">");
63
buf.append("<attribute name=\"serverBindAddress\">" + hostName + "</attribute>");
64
buf.append("<attribute name=\"serverBindPort\">" + serverPort + "</attribute>");
65
buf.append("<attribute name=\"clientConnectAddress\" isParam=\"true\">" + hostIP + "</attribute>");
66
buf.append("<attribute name=\"clientConnectPort\" isParam=\"true\">" + clientPort + "</attribute>");
67
buf.append("<attribute name=\"path\">" + path + "</attribute>");
68
buf.append("</invoker>");
69
buf.append("<handlers>");
70
buf.append(" <handler subsystem=\"mock\">" + MockServerInvocationHandler.class.getName() + "</handler>\n");
71
buf.append("</handlers>");
72
buf.append("</config>");
73
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(buf.toString().getBytes()));
74
//connector.setInvokerLocator(locator.getLocatorURI());
75
connector.setConfiguration(xml.getDocumentElement());
81
public void testClientConfiguration() throws Exception
84
// make sure the client's view of the locator will be as configured
85
ServerInvoker[] serverInvokers = InvokerRegistry.getServerInvokers();
87
if(serverInvokers != null && serverInvokers.length > 0)
89
InvokerLocator locator = serverInvokers[0].getLocator();
90
String locatorHost = locator.getHost();
91
int locatorPort = locator.getPort();
92
String locatorURIString = locator.getLocatorURI();
94
System.out.println("locator host = " + locatorHost);
95
System.out.println("locator port = " + locatorPort);
96
System.out.println("locator uri = " + locatorURIString);
97
assertEquals(hostIP, locatorHost);
98
assertEquals(clientPort, locatorPort);
101
// check for server bind port (assume is the server since no exception thrown before)
102
boolean portAvailable = PortUtil.checkPort(serverPort, hostName);
103
assertTrue(!portAvailable);
105
// make sure can call ont
106
Client client = new Client(new InvokerLocator(transport + "://" + hostName + ":" + serverPort));
108
String param = "foobar";
112
ret = client.invoke(param);
114
catch(Throwable throwable)
116
throwable.printStackTrace();
118
assertEquals(param, ret);
122
public void tearDown() throws Exception
124
if(connector != null)
131
public static void main(String[] args)
133
HTTPConfigurationTestCase testCase = new HTTPConfigurationTestCase();
137
testCase.testClientConfiguration();
b'\\ No newline at end of file'