~ubuntu-branches/ubuntu/raring/libjboss-remoting-java/raring

« back to all changes in this revision

Viewing changes to tests/org/jboss/test/remoting/transport/http/errors/ErrorHTTPInvokerTestClient.java

  • Committer: Package Import Robot
  • Author(s): Torsten Werner
  • Date: 2011-09-09 14:01:03 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: package-import@ubuntu.com-20110909140103-hqokx61534tas9rg
Tags: 2.5.3.SP1-1
* Newer but not newest upstream release. Do not build samples.
* Change debian/watch to upstream's svn repo.
* Add patch to fix compile error caused by tomcat update.
  (Closes: #628303)
* Switch to source format 3.0.
* Switch to debhelper level 7.
* Remove useless Depends.
* Update Standards-Version: 3.9.2.
* Update README.source.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
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.
6
 
*
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.
11
 
*
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.
16
 
*
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.
21
 
*/
22
 
 
23
 
package org.jboss.test.remoting.transport.http.errors;
24
 
 
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;
30
 
 
31
 
import java.util.HashMap;
32
 
import java.util.Map;
33
 
import java.util.Properties;
34
 
 
35
 
/**
36
 
 * @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
37
 
 */
38
 
public class ErrorHTTPInvokerTestClient extends TestCase
39
 
{
40
 
   // Default locator values
41
 
   private String transport = "http";
42
 
   private String host = "localhost";
43
 
   private int port = 8888;
44
 
 
45
 
   public String getLocatorURI()
46
 
   {
47
 
      return transport + "://" + host + ":" + port;
48
 
   }
49
 
 
50
 
 
51
 
   /**
52
 
    * In this case, the payload will be sent raw, the Exception will be return raw,
53
 
    * and HTTPClientInvoker should return a WebServerError.
54
 
    */
55
 
   public void testRawInvocation() throws Exception
56
 
   {
57
 
      Client remotingClient = null;
58
 
 
59
 
      try
60
 
      {
61
 
         InvokerLocator locator = new InvokerLocator(getLocatorURI());
62
 
         System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
63
 
 
64
 
         remotingClient = new Client(locator);
65
 
         remotingClient.connect();
66
 
 
67
 
         Map metadata = new HashMap();
68
 
         metadata.put(Client.RAW, Boolean.TRUE);
69
 
         metadata.put("TYPE", "POST");
70
 
 
71
 
         Properties headerProps = new Properties();
72
 
         headerProps.put("Content-type", "application/soap+xml");
73
 
 
74
 
         metadata.put("HEADER", headerProps);
75
 
 
76
 
         try
77
 
         {
78
 
            Object response = remotingClient.invoke(WebInvocationHandler.THROW_EXCEPTION_PARAM, metadata);
79
 
            assertTrue("Did not get exception thrown as expected.", false);
80
 
         }
81
 
         catch(WebServerError wse)
82
 
         {
83
 
            assertTrue("Caught exception as expected", true);
84
 
         }
85
 
      }
86
 
      catch(Throwable throwable)
87
 
      {
88
 
         throw new Exception(throwable);
89
 
      }
90
 
      finally
91
 
      {
92
 
         if(remotingClient != null)
93
 
         {
94
 
            remotingClient.disconnect();
95
 
         }
96
 
      }
97
 
 
98
 
   }
99
 
 
100
 
   
101
 
   /**
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
104
 
    * thrown.
105
 
    */
106
 
   public void testCookedInvocation() throws Exception
107
 
   {
108
 
      Client remotingClient = null;
109
 
 
110
 
      try
111
 
      {
112
 
         InvokerLocator locator = new InvokerLocator(getLocatorURI());
113
 
         System.out.println("Calling remoting server with locator uri of: " + getLocatorURI());
114
 
 
115
 
         remotingClient = new Client(locator);
116
 
         remotingClient.connect();
117
 
 
118
 
         Map metadata = new HashMap();
119
 
         metadata.put("TYPE", "POST");
120
 
 
121
 
         try
122
 
         {
123
 
            Object response = remotingClient.invoke(WebInvocationHandler.THROW_EXCEPTION_PARAM, metadata);
124
 
            assertTrue("Did not get exception thrown as expected.", false);
125
 
         }
126
 
         catch(Exception e)
127
 
         {
128
 
            assertTrue("Caught exception as expected",
129
 
                        ErrorHTTPInvokerTestServer.EXCEPTION_MSG.equals(e.getMessage()));
130
 
         }
131
 
      }
132
 
      catch(Throwable throwable)
133
 
      {
134
 
         throw new Exception(throwable);
135
 
      }
136
 
      finally
137
 
      {
138
 
         if(remotingClient != null)
139
 
         {
140
 
            remotingClient.disconnect();
141
 
         }
142
 
      }
143
 
 
144
 
   }
145
 
 
146
 
   public static void main(String[] args)
147
 
   {
148
 
      ErrorHTTPInvokerTestClient client = new ErrorHTTPInvokerTestClient();
149
 
      try
150
 
      {
151
 
         client.testRawInvocation();
152
 
         client.testCookedInvocation();
153
 
      }
154
 
      catch(Exception e)
155
 
      {
156
 
         e.printStackTrace();
157
 
      }
158
 
   }
159
 
}
 
 
b'\\ No newline at end of file'