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.transport.http.errors;
25
import junit.framework.TestCase;
26
import org.jboss.remoting.Client;
27
import org.jboss.remoting.InvokerLocator;
28
import org.jboss.remoting.transport.http.WebServerError;
29
import org.jboss.test.remoting.transport.web.WebInvocationHandler;
31
import java.util.HashMap;
33
import java.util.Properties;
36
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
38
public class ErrorHTTPInvokerTestClient extends TestCase
40
// Default locator values
41
private String transport = "http";
42
private String host = "localhost";
43
private int port = 8888;
45
public String getLocatorURI()
47
return transport + "://" + host + ":" + port;
52
* In this case, the payload will be sent raw, the Exception will be return raw,
53
* and HTTPClientInvoker should return a WebServerError.
55
public void testRawInvocation() throws Exception
57
Client remotingClient = null;
61
InvokerLocator locator = new InvokerLocator(getLocatorURI());
62
System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
64
remotingClient = new Client(locator);
65
remotingClient.connect();
67
Map metadata = new HashMap();
68
metadata.put(Client.RAW, Boolean.TRUE);
69
metadata.put("TYPE", "POST");
71
Properties headerProps = new Properties();
72
headerProps.put("Content-type", "application/soap+xml");
74
metadata.put("HEADER", headerProps);
78
Object response = remotingClient.invoke(WebInvocationHandler.THROW_EXCEPTION_PARAM, metadata);
79
assertTrue("Did not get exception thrown as expected.", false);
81
catch(WebServerError wse)
83
assertTrue("Caught exception as expected", true);
86
catch(Throwable throwable)
88
throw new Exception(throwable);
92
if(remotingClient != null)
94
remotingClient.disconnect();
102
* In this case, the payload will be wrapped in an InvocationRequest, the Exception
103
* will be wrapped in an InvocationRequest, and the original Exception should be
106
public void testCookedInvocation() throws Exception
108
Client remotingClient = null;
112
InvokerLocator locator = new InvokerLocator(getLocatorURI());
113
System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
115
remotingClient = new Client(locator);
116
remotingClient.connect();
118
Map metadata = new HashMap();
119
metadata.put("TYPE", "POST");
123
Object response = remotingClient.invoke(WebInvocationHandler.THROW_EXCEPTION_PARAM, metadata);
124
assertTrue("Did not get exception thrown as expected.", false);
128
assertTrue("Caught exception as expected",
129
ErrorHTTPInvokerTestServer.EXCEPTION_MSG.equals(e.getMessage()));
132
catch(Throwable throwable)
134
throw new Exception(throwable);
138
if(remotingClient != null)
140
remotingClient.disconnect();
146
public static void main(String[] args)
148
ErrorHTTPInvokerTestClient client = new ErrorHTTPInvokerTestClient();
151
client.testRawInvocation();
152
client.testCookedInvocation();
b'\\ No newline at end of file'