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.
22
package org.jboss.test.remoting.marshall.compress;
24
import java.net.InetAddress;
25
import java.util.HashMap;
28
import javax.management.MBeanServer;
30
import junit.framework.TestCase;
32
import org.apache.log4j.ConsoleAppender;
33
import org.apache.log4j.Level;
34
import org.apache.log4j.Logger;
35
import org.apache.log4j.PatternLayout;
36
import org.jboss.logging.XLevel;
37
import org.jboss.remoting.Client;
38
import org.jboss.remoting.InvocationRequest;
39
import org.jboss.remoting.InvokerLocator;
40
import org.jboss.remoting.ServerInvocationHandler;
41
import org.jboss.remoting.ServerInvoker;
42
import org.jboss.remoting.callback.InvokerCallbackHandler;
43
import org.jboss.remoting.marshal.MarshalFactory;
44
import org.jboss.remoting.marshal.Marshaller;
45
import org.jboss.remoting.marshal.UnMarshaller;
46
import org.jboss.remoting.marshal.compress.CompressingMarshaller;
47
import org.jboss.remoting.marshal.compress.CompressingUnMarshaller;
48
import org.jboss.remoting.marshal.http.HTTPMarshaller;
49
import org.jboss.remoting.marshal.http.HTTPUnMarshaller;
50
import org.jboss.remoting.transport.Connector;
51
import org.jboss.remoting.transport.PortUtil;
55
* Unit test for JBREM-927.
57
* @author <a href="ron.sigal@jboss.com">Ron Sigal</a>
58
* @version $Revision: 1.1 $
60
* Copyright Mar 13, 2008
63
public class WrappedHttpUnMarshallerTestCase extends TestCase
65
private static Logger log = Logger.getLogger(WrappedHttpUnMarshallerTestCase.class);
67
private static boolean firstTime = true;
69
protected String host;
71
protected String locatorURI;
72
protected InvokerLocator serverLocator;
73
protected Connector connector;
74
protected TestInvocationHandler invocationHandler;
75
protected String longMessage;
78
public void setUp() throws Exception
83
Logger.getLogger("org.jboss.remoting").setLevel(XLevel.INFO);
84
Logger.getLogger("org.jboss.test.remoting").setLevel(Level.INFO);
85
String pattern = "[%d{ABSOLUTE}] [%t] %5p (%F:%L) - %m%n";
86
PatternLayout layout = new PatternLayout(pattern);
87
ConsoleAppender consoleAppender = new ConsoleAppender(layout);
88
Logger.getRootLogger().addAppender(consoleAppender);
90
Marshaller marshaller = new CompressingMarshaller(new HTTPMarshaller());
91
UnMarshaller unmarshaller = new CompressingUnMarshaller(new HTTPUnMarshaller());
92
MarshalFactory.addMarshaller("compressedHttp", marshaller, unmarshaller);
94
StringBuffer sb = new StringBuffer();
95
for (int i = 0; i < 200; i++)
97
sb.append("abcdefghij");
99
longMessage = sb.toString();
104
public void tearDown()
109
public void testMethod() throws Throwable
111
log.info("entering " + getName());
117
InvokerLocator clientLocator = new InvokerLocator(locatorURI);
118
HashMap clientConfig = new HashMap();
119
clientConfig.put(InvokerLocator.FORCE_REMOTE, "true");
120
addExtraClientConfig(clientConfig);
121
Client client = new Client(clientLocator, clientConfig);
123
log.info("client is connected");
125
Map metadata = new HashMap();
126
metadata.put(Client.RAW, "true");
127
assertEquals(longMessage, client.invoke(longMessage, metadata));
131
log.info(getName() + " PASSES");
135
protected String getTransport()
141
protected void addExtraClientConfig(Map config) {}
142
protected void addExtraServerConfig(Map config) {}
145
protected void setupServer() throws Exception
147
host = InetAddress.getLocalHost().getHostAddress();
148
port = PortUtil.findFreePort(host);
149
locatorURI = getTransport() + "://" + host + ":" + port;
150
locatorURI += "/?datatype=compressedHttp";
151
serverLocator = new InvokerLocator(locatorURI);
152
log.info("Starting remoting server with locator uri of: " + locatorURI);
153
HashMap config = new HashMap();
154
config.put(InvokerLocator.FORCE_REMOTE, "true");
155
addExtraServerConfig(config);
156
connector = new Connector(serverLocator, config);
158
invocationHandler = new TestInvocationHandler();
159
connector.addInvocationHandler("test", invocationHandler);
164
protected void shutdownServer() throws Exception
166
if (connector != null)
171
static class TestInvocationHandler implements ServerInvocationHandler
173
public void addListener(InvokerCallbackHandler callbackHandler) {}
174
public Object invoke(final InvocationRequest invocation) throws Throwable
176
return invocation.getParameter();
178
public void removeListener(InvokerCallbackHandler callbackHandler) {}
179
public void setMBeanServer(MBeanServer server) {}
180
public void setInvoker(ServerInvoker invoker) {}
b'\\ No newline at end of file'