use of javax.xml.ws.BindingProvider in project spring-framework by spring-projects.
the class JaxWsSupportTests method doTestJaxWsPortAccess.
private void doTestJaxWsPortAccess(WebServiceFeature... features) throws Exception {
GenericApplicationContext ac = new GenericApplicationContext();
GenericBeanDefinition serviceDef = new GenericBeanDefinition();
serviceDef.setBeanClass(OrderServiceImpl.class);
ac.registerBeanDefinition("service", serviceDef);
GenericBeanDefinition exporterDef = new GenericBeanDefinition();
exporterDef.setBeanClass(SimpleJaxWsServiceExporter.class);
exporterDef.getPropertyValues().add("baseAddress", "http://localhost:9999/");
ac.registerBeanDefinition("exporter", exporterDef);
GenericBeanDefinition clientDef = new GenericBeanDefinition();
clientDef.setBeanClass(JaxWsPortProxyFactoryBean.class);
clientDef.getPropertyValues().add("wsdlDocumentUrl", "http://localhost:9999/OrderService?wsdl");
clientDef.getPropertyValues().add("namespaceUri", "http://jaxws.remoting.springframework.org/");
clientDef.getPropertyValues().add("username", "juergen");
clientDef.getPropertyValues().add("password", "hoeller");
clientDef.getPropertyValues().add("serviceName", "OrderService");
clientDef.getPropertyValues().add("serviceInterface", OrderService.class);
clientDef.getPropertyValues().add("lookupServiceOnStartup", Boolean.FALSE);
if (features != null) {
clientDef.getPropertyValues().add("portFeatures", features);
}
ac.registerBeanDefinition("client", clientDef);
GenericBeanDefinition serviceFactoryDef = new GenericBeanDefinition();
serviceFactoryDef.setBeanClass(LocalJaxWsServiceFactoryBean.class);
serviceFactoryDef.getPropertyValues().add("wsdlDocumentUrl", "http://localhost:9999/OrderService?wsdl");
serviceFactoryDef.getPropertyValues().add("namespaceUri", "http://jaxws.remoting.springframework.org/");
serviceFactoryDef.getPropertyValues().add("serviceName", "OrderService");
ac.registerBeanDefinition("orderService", serviceFactoryDef);
ac.registerBeanDefinition("accessor", new RootBeanDefinition(ServiceAccessor.class));
AnnotationConfigUtils.registerAnnotationConfigProcessors(ac);
try {
ac.refresh();
OrderService orderService = ac.getBean("client", OrderService.class);
assertTrue(orderService instanceof BindingProvider);
((BindingProvider) orderService).getRequestContext();
String order = orderService.getOrder(1000);
assertEquals("order 1000", order);
try {
orderService.getOrder(0);
fail("Should have thrown OrderNotFoundException");
} catch (OrderNotFoundException ex) {
// expected
} catch (RemoteAccessException ex) {
// ignore - probably setup issue with JAX-WS provider vs JAXB
}
ServiceAccessor serviceAccessor = ac.getBean("accessor", ServiceAccessor.class);
order = serviceAccessor.orderService.getOrder(1000);
assertEquals("order 1000", order);
try {
serviceAccessor.orderService.getOrder(0);
fail("Should have thrown OrderNotFoundException");
} catch (OrderNotFoundException ex) {
// expected
} catch (WebServiceException ex) {
// ignore - probably setup issue with JAX-WS provider vs JAXB
}
} catch (BeanCreationException ex) {
if ("exporter".equals(ex.getBeanName()) && ex.getRootCause() instanceof ClassNotFoundException) {
// ignore - probably running on JDK without the JAX-WS impl present
} else {
throw ex;
}
} finally {
ac.close();
}
}
use of javax.xml.ws.BindingProvider in project nhin-d by DirectProject.
the class DocumentRepositoryUtils method getDocumentRepositoryPortType.
/**
* Construct a DocumentRepositoryPortType object using the provided
* endpoint.
*
* @param endpoint
* The XDR endpoint.
* @param wsdlPath
* The path to the WSDL.
* @return a DocumentRepositoryPortType object.
* @throws Exception
*/
public static DocumentRepositoryPortType getDocumentRepositoryPortType(String endpoint, URL wsdlPath) throws Exception {
QName qname = new QName("urn:ihe:iti:xds-b:2007", "DocumentRepository_Service");
DocumentRepositoryService service = new DocumentRepositoryService(wsdlPath, qname);
service.setHandlerResolver(new RepositoryHandlerResolver());
DocumentRepositoryPortType port = service.getDocumentRepositoryPortSoap12(new MTOMFeature(true, 1));
BindingProvider bp = (BindingProvider) port;
SOAPBinding binding = (SOAPBinding) bp.getBinding();
binding.setMTOMEnabled(true);
bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpoint);
return port;
}
use of javax.xml.ws.BindingProvider in project wildfly by wildfly.
the class EJBEndpointNoClassLevelSecurityAnnotationAuthenticationTestCase method accessHelloForNoneWithValidRole2.
@Test
public void accessHelloForNoneWithValidRole2() throws Exception {
URL wsdlURL = new URL(baseUrl, deploymentWsdlURL);
Service service = Service.create(wsdlURL, serviceName);
EJBEndpointIface proxy = service.getPort(EJBEndpointIface.class);
Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
reqContext.put(BindingProvider.USERNAME_PROPERTY, "user2");
reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password2");
try {
proxy.helloForNone("World");
Assert.fail("Test should fail, user shouldn't be allowed to invoke that method");
} catch (WebServiceException e) {
// failure is expected
Assert.assertEquals(getNotAllowedExceptionMessage("helloForNone"), e.getCause().getMessage());
}
}
use of javax.xml.ws.BindingProvider in project wildfly by wildfly.
the class PojoEndpointAuthenticationTestCase method accessHelloWithValidUser1.
@Test
public void accessHelloWithValidUser1() throws Exception {
URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-pojo/POJOAuthService?wsdl");
Service service = Service.create(wsdlURL, serviceName);
PojoEndpointIface proxy = service.getPort(PojoEndpointIface.class);
Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
reqContext.put(BindingProvider.USERNAME_PROPERTY, "user1");
reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password1");
final String result = proxy.hello("World");
Assert.assertEquals("Hello World!", result);
}
use of javax.xml.ws.BindingProvider in project wildfly by wildfly.
the class PojoEndpointAuthenticationTestCase method accessHelloWithBadPassword.
@Test
public void accessHelloWithBadPassword() throws Exception {
URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-pojo/POJOAuthService?wsdl");
Service service = Service.create(wsdlURL, serviceName);
PojoEndpointIface proxy = service.getPort(PojoEndpointIface.class);
Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
reqContext.put(BindingProvider.USERNAME_PROPERTY, "user1");
reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password-XYZ");
try {
proxy.hello("World");
Assert.fail("Test should fail, HTTP response '401: Unauthorized' was expected");
} catch (WebServiceException e) {
// failure is expected
Assert.assertTrue("HTTPException '401: Unauthorized' was expected", e.getCause().getMessage().contains("401: Unauthorized"));
}
}
Aggregations