KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > remoting > transport > http > ssl > custom > HTTPSInvokerTestClient


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.test.remoting.transport.http.ssl.custom;
8
9 import java.util.HashMap JavaDoc;
10 import java.util.Map JavaDoc;
11 import java.util.Properties JavaDoc;
12 import org.jboss.remoting.Client;
13 import org.jboss.remoting.InvokerLocator;
14 import org.jboss.remoting.transport.http.HTTPServerInvoker;
15 import org.jboss.remoting.transport.http.ssl.HTTPSClientInvoker;
16 import org.jboss.test.remoting.transport.http.HTTPInvokerTestServer;
17 import org.jboss.test.remoting.transport.http.ssl.SSLInvokerConstants;
18 import org.jboss.test.remoting.transport.web.ComplexObject;
19
20 import junit.framework.TestCase;
21
22 /**
23  * @author <a HREF="mailto:tom.elrod@jboss.com">Tom Elrod</a>
24  */

25 public class HTTPSInvokerTestClient extends TestCase implements SSLInvokerConstants
26 {
27    public void testInvocation() throws Exception JavaDoc
28    {
29       Client remotingClient = null;
30       try
31       {
32          // since doing basic (using default ssl server socket factory)
33
// need to set the system properties to the truststore
34
String JavaDoc trustStoreFilePath = this.getClass().getResource("../.truststore").getFile();
35          System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
36          // set this property so does not do host verification
37
System.setProperty(HTTPSClientInvoker.IGNORE_HTTPS_HOST, "true");
38
39          String JavaDoc locatorURI = transport + "://" + host + ":" + port;
40          InvokerLocator locator = new InvokerLocator(locatorURI);
41          System.out.println("Calling remoting server with locator uri of: " + locatorURI);
42
43          // This could have been new Client(locator), but want to show that subsystem param is null
44
// Could have also been new Client(locator, "sample");
45
remotingClient = new Client(locator, null);
46
47          Map JavaDoc metadata = new HashMap JavaDoc();
48          metadata.put(Client.RAW, Boolean.TRUE);
49          metadata.put("TYPE", "POST");
50
51          Properties JavaDoc headerProps = new Properties JavaDoc();
52          headerProps.put("SOAPAction", "http://www.example.com/fibonacci");
53          headerProps.put("Content-type", "application/soap+xml");
54
55          metadata.put("HEADER", headerProps);
56
57          Object JavaDoc response = null;
58
59          // test with null return expected
60
response = remotingClient.invoke(HTTPInvokerTestServer.NULL_RETURN_PARAM, metadata);
61
62          assertNull(response);
63
64          response = remotingClient.invoke("Do something", metadata);
65
66          assertEquals(HTTPInvokerTestServer.RESPONSE_VALUE, response);
67
68          headerProps.put("Content-type", HTTPServerInvoker.BINARY);
69          response = remotingClient.invoke(new ComplexObject(2, "foo", true), metadata);
70
71          assertEquals(HTTPInvokerTestServer.OBJECT_RESPONSE_VALUE, response);
72       }
73       catch(Throwable JavaDoc throwable)
74       {
75          throw new Exception JavaDoc(throwable);
76       }
77       finally
78       {
79          if(remotingClient != null)
80          {
81             remotingClient.disconnect();
82          }
83       }
84
85
86    }
87
88
89 }
Popular Tags