use of javax.xml.ws.BindingProvider in project cxf by apache.
the class MAPTestBase method testExplicitMAPs.
@Test
public void testExplicitMAPs() throws Exception {
try {
String msgId = "urn:uuid:12345-" + Math.random();
Map<String, Object> requestContext = ((BindingProvider) greeter).getRequestContext();
AddressingProperties maps = new AddressingProperties();
AttributedURIType id = ContextUtils.getAttributedURI(msgId);
maps.setMessageID(id);
requestContext.put(CLIENT_ADDRESSING_PROPERTIES, maps);
String greeting = greeter.greetMe("explicit1");
assertEquals("unexpected response received from service", "Hello explicit1", greeting);
checkVerification();
// message ID fault is expected
try {
greeter.greetMe("explicit2");
fail("expected ProtocolException on duplicate message ID");
} catch (ProtocolException pe) {
assertEquals("expected duplicate message ID failure", "Duplicate Message ID " + msgId, pe.getMessage());
checkVerification();
}
// clearing the message ID ensure a duplicate is not sent
maps.setMessageID(null);
// maps.setRelatesTo(ContextUtils.getRelatesTo(id.getValue()));
greeting = greeter.greetMe("explicit3");
assertEquals("unexpected response received from service", "Hello explicit3", greeting);
} catch (UndeclaredThrowableException ex) {
throw (Exception) ex.getCause();
}
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class WSSecurityClientTest method testTimestampSignEncrypt.
@Test
public void testTimestampSignEncrypt() throws Exception {
Bus b = new SpringBusFactory().createBus("org/apache/cxf/systest/ws/security/client.xml");
BusFactory.setDefaultBus(b);
final javax.xml.ws.Service svc = javax.xml.ws.Service.create(WSDL_LOC, GREETER_SERVICE_QNAME);
final Greeter greeter = svc.getPort(TIMESTAMP_SIGN_ENCRYPT_PORT_QNAME, Greeter.class);
updateAddressPort(greeter, test.getPort());
// Add a No-Op JAX-WS SoapHandler to the dispatch chain to
// verify that the SoapHandlerInterceptor can peacefully co-exist
// with the explicitly configured SAAJOutInterceptor
//
@SuppressWarnings("rawtypes") List<Handler> handlerChain = new ArrayList<>();
Binding binding = ((BindingProvider) greeter).getBinding();
TestOutHandler handler = new TestOutHandler();
handlerChain.add(handler);
binding.setHandlerChain(handlerChain);
greeter.sayHi();
assertTrue("expected Handler.handleMessage() to be called", handler.handleMessageCalledOutbound);
assertFalse("expected Handler.handleFault() not to be called", handler.handleFaultCalledOutbound);
((java.io.Closeable) greeter).close();
b.shutdown(true);
BusFactory.setDefaultBus(getStaticBus());
}
use of javax.xml.ws.BindingProvider in project cxf by apache.
the class TestUtil method setAddress.
// extra methods to help support the dynamic port allocations
public static void setAddress(Object o, String address) {
if (o instanceof BindingProvider) {
((BindingProvider) o).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
}
Client c = null;
if (o instanceof Client) {
c = (Client) o;
}
if (c == null) {
try {
InvocationHandler i = Proxy.getInvocationHandler(o);
c = (Client) i.getClass().getMethod("getClient").invoke(i);
} catch (Throwable t) {
// ignore
}
}
if (c == null) {
try {
final Method m = o.getClass().getDeclaredMethod("getClient");
ReflectionUtil.setAccessible(m);
c = (Client) m.invoke(o);
} catch (Throwable t) {
// ignore
}
}
if (c != null) {
c.getEndpoint().getEndpointInfo().setAddress(address);
}
}
use of javax.xml.ws.BindingProvider in project Payara by payara.
the class SOAPWebConsumer method addUsingSOAPConsumer.
private void addUsingSOAPConsumer(String[] args) {
com.example.calculator.Calculator port = null;
try {
System.out.println(" After creating CalculatorService");
port = service.getCalculatorPort();
System.out.println(" After getting port");
// Get Stub
BindingProvider stub = (BindingProvider) port;
String endpointURI = "http://localhost:12011/calculatorendpoint";
stub.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointURI);
System.out.println(" After setting endpoint address URI");
System.out.println(" Using SOAP binding's consumer to add 1 + 2 = " + port.add(1, 2));
stat.addStatus(testId, stat.PASS);
} catch (Exception e) {
e.printStackTrace();
stat.addStatus(testId, stat.FAIL);
}
}
use of javax.xml.ws.BindingProvider in project camel by apache.
the class Client method invoke.
public String invoke() throws Exception {
// Service Qname as defined in the WSDL.
QName serviceName = new QName("http://apache.org/hello_world_soap_http", "SOAPService");
// Port QName as defined in the WSDL.
QName portName = new QName("http://apache.org/hello_world_soap_http", "SoapOverHttpRouter");
// Create a dynamic Service instance
Service service = Service.create(serviceName);
// Add a port to the Service
service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress);
// Create a dispatch instance
Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
// Use Dispatch as BindingProvider
BindingProvider bp = dispatch;
MessageFactory factory = ((SOAPBinding) bp.getBinding()).getMessageFactory();
// Create SOAPMessage Request
SOAPMessage request = factory.createMessage();
// Request Body
SOAPBody body = request.getSOAPBody();
// Compose the soap:Body payload
QName payloadName = new QName("http://apache.org/hello_world_soap_http/types", "greetMe", "ns1");
SOAPBodyElement payload = body.addBodyElement(payloadName);
SOAPElement message = payload.addChildElement("requestType");
message.addTextNode("Hello Camel!!");
System.out.println("Send out the request: Hello Camel!!");
// Invoke the endpoint synchronously
// Invoke endpoint operation and read response
SOAPMessage reply = dispatch.invoke(request);
// process the reply
body = reply.getSOAPBody();
QName responseName = new QName("http://apache.org/hello_world_soap_http/types", "greetMeResponse");
SOAPElement bodyElement = (SOAPElement) body.getChildElements(responseName).next();
String responseMessageText = bodyElement.getTextContent();
System.out.println("Get the response: " + responseMessageText);
return responseMessageText;
}
Aggregations