protected void setAddress(Object o, String address) { TestUtil.setAddress(o, address); }
public static void updateAddressPort(Object o, int port) throws MalformedURLException { String address = null; if (o instanceof BindingProvider) { address = ((BindingProvider)o).getRequestContext() .get(BindingProvider.ENDPOINT_ADDRESS_PROPERTY).toString(); } else if (o instanceof Client) { Client c = (Client)o; address = c.getEndpoint().getEndpointInfo().getAddress(); } if (address != null && address.startsWith("http")) { // http and https are ok URL url = new URL(address); url = new URL(url.getProtocol(), url.getHost(), port, url.getFile()); setAddress(o, url.toString()); } //maybe simple frontend proxy? }
@Test public void testNoAuth() throws Exception { URL wsdl = getClass().getResource("../greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter mortimer = service.getPort(mortimerQ, Greeter.class); assertNotNull("Port is null", mortimer); TestUtil.setAddress(mortimer, "http://localhost:" + PORT + "/digestauth/greeter"); try { String answer = mortimer.sayHi(); Assert.fail("Unexpected reply (" + answer + "). Should throw exception"); } catch (Exception e) { Throwable cause = e.getCause(); assertEquals(HTTPException.class, cause.getClass()); HTTPException he = (HTTPException)cause; assertEquals(401, he.getResponseCode()); } }
@Test public void testDigestAuth() throws Exception { URL wsdl = getClass().getResource("../greeting.wsdl"); assertNotNull("WSDL is null", wsdl); SOAPService service = new SOAPService(wsdl, serviceName); assertNotNull("Service is null", service); Greeter mortimer = service.getPort(mortimerQ, Greeter.class); assertNotNull("Port is null", mortimer); TestUtil.setAddress(mortimer, "http://localhost:" + PORT + "/digestauth/greeter"); Client client = ClientProxy.getClient(mortimer); HTTPConduit http = (HTTPConduit) client.getConduit(); AuthorizationPolicy authPolicy = new AuthorizationPolicy(); authPolicy.setAuthorizationType("Digest"); authPolicy.setUserName("foo"); authPolicy.setPassword("bar"); http.setAuthorization(authPolicy); String answer = mortimer.sayHi(); assertEquals("Unexpected answer: " + answer, "Hi", answer); }