1 22 package org.jboss.test.webservice.addressrewrite; 23 24 import java.net.URL ; 25 26 import javax.management.Attribute ; 27 import javax.management.ObjectName ; 28 import javax.xml.namespace.QName ; 29 import javax.xml.rpc.Call ; 30 import javax.xml.rpc.Service ; 31 import javax.xml.rpc.ServiceFactory ; 32 33 import org.jboss.test.JBossTestCase; 34 35 40 public class AddressRewriteTestCase extends JBossTestCase 41 { 42 private static String NAMESPACE = "http://test.jboss.org/ws4eesimple"; 43 private String WSDL_LOCATION = "http://" + getServerHost() + ":8080/ws4ee-addressrewrite?wsdl"; 44 private String WSDL_LOCATION_SEC = "http://" + getServerHost() + ":8080/ws4ee-addressrewrite-sec?wsdl"; 45 46 private ObjectName objectName; 47 private Boolean alwaysModifySOAPAddress; 48 private String wsHost; 49 50 53 public AddressRewriteTestCase(String name) 54 { 55 super(name); 56 } 57 58 public void setUp() throws Exception 59 { 60 ObjectName ws4eeServiceName = new ObjectName ("jboss.ws4ee:service=AxisService"); 61 ObjectName jbosswsServiceName = new ObjectName ("jboss.ws:service=ServiceEndpointManager"); 62 63 if (getServer().isRegistered(ws4eeServiceName)) 64 objectName = ws4eeServiceName; 65 else if (getServer().isRegistered(jbosswsServiceName)) 66 objectName = jbosswsServiceName; 67 68 alwaysModifySOAPAddress = (Boolean )getServer().getAttribute(objectName, "AlwaysModifySOAPAddress"); 69 wsHost = (String )getServer().getAttribute(objectName, "WebServiceHost"); 70 } 71 72 public void tearDown() throws Exception 73 { 74 Attribute attr = new Attribute ("AlwaysModifySOAPAddress", alwaysModifySOAPAddress); 75 getServer().setAttribute(objectName, attr); 76 } 77 78 public void testRewrite() throws Exception 79 { 80 setupAlwaysModify(new Boolean (true)); 81 deploy("ws4ee-addressrewrite.war"); 82 try 83 { 84 ServiceFactory serviceFactory = ServiceFactory.newInstance(); 85 86 Service service = serviceFactory.createService(new URL (WSDL_LOCATION), new QName (NAMESPACE, "ValidURLService")); 87 Call call = (Call )service.createCall(new QName (NAMESPACE, "ValidURLPort"), "sayHello"); 88 assertEquals("http://" + wsHost + ":8080/ws4ee-addressrewrite", call.getTargetEndpointAddress()); 89 90 service = serviceFactory.createService(new URL (WSDL_LOCATION), new QName (NAMESPACE, "InvalidURLService")); 91 call = (Call )service.createCall(new QName (NAMESPACE, "InvalidURLPort"), "sayHello"); 92 assertEquals("http://" + wsHost + ":8080/ws4ee-addressrewrite", call.getTargetEndpointAddress()); 93 94 service = serviceFactory.createService(new URL (WSDL_LOCATION), new QName (NAMESPACE, "ValidSecureURLService")); 95 call = (Call )service.createCall(new QName (NAMESPACE, "ValidSecureURLPort"), "sayHello"); 96 assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite", call.getTargetEndpointAddress()); 97 98 service = serviceFactory.createService(new URL (WSDL_LOCATION), new QName (NAMESPACE, "InvalidSecureURLService")); 99 call = (Call )service.createCall(new QName (NAMESPACE, "InvalidSecureURLPort"), "sayHello"); 100 assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite", call.getTargetEndpointAddress()); 101 } 102 finally 103 { 104 undeploy("ws4ee-addressrewrite.war"); 105 } 106 } 107 108 113 public void testSecureRewrite() throws Exception 114 { 115 deploy("ws4ee-addressrewrite-sec.war"); 116 try 117 { 118 ServiceFactory serviceFactory = ServiceFactory.newInstance(); 119 120 Service service = serviceFactory.createService(new URL (WSDL_LOCATION_SEC), new QName (NAMESPACE, "ValidURLService")); 121 Call call = (Call )service.createCall(new QName (NAMESPACE, "ValidURLPort"), "sayHello"); 122 assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite-sec", call.getTargetEndpointAddress()); 123 124 service = serviceFactory.createService(new URL (WSDL_LOCATION_SEC), new QName (NAMESPACE, "InvalidURLService")); 125 call = (Call )service.createCall(new QName (NAMESPACE, "InvalidURLPort"), "sayHello"); 126 assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite-sec", call.getTargetEndpointAddress()); 127 128 service = serviceFactory.createService(new URL (WSDL_LOCATION_SEC), new QName (NAMESPACE, "ValidSecureURLService")); 129 call = (Call )service.createCall(new QName (NAMESPACE, "ValidSecureURLPort"), "sayHello"); 130 assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite-sec", call.getTargetEndpointAddress()); 131 132 service = serviceFactory.createService(new URL (WSDL_LOCATION_SEC), new QName (NAMESPACE, "InvalidSecureURLService")); 133 call = (Call )service.createCall(new QName (NAMESPACE, "InvalidSecureURLPort"), "sayHello"); 134 assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite-sec", call.getTargetEndpointAddress()); 135 } 136 finally 137 { 138 undeploy("ws4ee-addressrewrite-sec.war"); 139 } 140 } 141 142 public void testNoRewrite() throws Exception 143 { 144 setupAlwaysModify(new Boolean (false)); 145 deploy("ws4ee-addressrewrite.war"); 146 try 147 { 148 ServiceFactory serviceFactory = ServiceFactory.newInstance(); 149 150 Service service = serviceFactory.createService(new URL (WSDL_LOCATION), new QName (NAMESPACE, "ValidURLService")); 151 Call call = (Call )service.createCall(new QName (NAMESPACE, "ValidURLPort"), "sayHello"); 152 assertEquals("http://somehost:80/somepath", call.getTargetEndpointAddress()); 153 154 service = serviceFactory.createService(new URL (WSDL_LOCATION), new QName (NAMESPACE, "InvalidURLService")); 155 call = (Call )service.createCall(new QName (NAMESPACE, "InvalidURLPort"), "sayHello"); 156 assertEquals("http://" + wsHost + ":8080/ws4ee-addressrewrite", call.getTargetEndpointAddress()); 157 158 service = serviceFactory.createService(new URL (WSDL_LOCATION), new QName (NAMESPACE, "ValidSecureURLService")); 159 call = (Call )service.createCall(new QName (NAMESPACE, "ValidSecureURLPort"), "sayHello"); 160 assertEquals("https://somehost:443/some-secure-path", call.getTargetEndpointAddress()); 161 162 service = serviceFactory.createService(new URL (WSDL_LOCATION), new QName (NAMESPACE, "InvalidSecureURLService")); 163 call = (Call )service.createCall(new QName (NAMESPACE, "InvalidSecureURLPort"), "sayHello"); 164 assertEquals("https://" + wsHost + ":8443/ws4ee-addressrewrite", call.getTargetEndpointAddress()); 165 } 166 finally 167 { 168 undeploy("ws4ee-addressrewrite.war"); 169 } 170 } 171 172 private void setupAlwaysModify(Boolean value) throws Exception 173 { 174 Attribute attr = new Attribute ("AlwaysModifySOAPAddress", value); 175 getServer().setAttribute(objectName, attr); 176 } 177 } | Popular Tags |