Search in sources :

Example 71 with BindingProvider

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();
    }
}
Also used : ProtocolException(javax.xml.ws.ProtocolException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) AttributedURIType(org.apache.cxf.ws.addressing.AttributedURIType) AddressingProperties(org.apache.cxf.ws.addressing.AddressingProperties) BindingProvider(javax.xml.ws.BindingProvider) Test(org.junit.Test)

Example 72 with BindingProvider

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());
}
Also used : Binding(javax.xml.ws.Binding) SOAPBinding(javax.xml.ws.soap.SOAPBinding) HTTPBinding(javax.xml.ws.http.HTTPBinding) Bus(org.apache.cxf.Bus) ArrayList(java.util.ArrayList) Handler(javax.xml.ws.handler.Handler) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) SpringBusFactory(org.apache.cxf.bus.spring.SpringBusFactory) Greeter(org.apache.hello_world_soap_http.Greeter) Test(org.junit.Test)

Example 73 with BindingProvider

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);
    }
}
Also used : BindingProvider(javax.xml.ws.BindingProvider) Method(java.lang.reflect.Method) Client(org.apache.cxf.endpoint.Client) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 74 with BindingProvider

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);
    }
}
Also used : Calculator(com.example.calculator.Calculator) BindingProvider(javax.xml.ws.BindingProvider)

Example 75 with BindingProvider

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;
}
Also used : SOAPBody(javax.xml.soap.SOAPBody) MessageFactory(javax.xml.soap.MessageFactory) QName(javax.xml.namespace.QName) SOAPElement(javax.xml.soap.SOAPElement) Service(javax.xml.ws.Service) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPBodyElement(javax.xml.soap.SOAPBodyElement)

Aggregations

BindingProvider (javax.xml.ws.BindingProvider)147 URL (java.net.URL)87 Test (org.junit.Test)74 Service (javax.xml.ws.Service)65 QName (javax.xml.namespace.QName)41 WebServiceException (javax.xml.ws.WebServiceException)24 Greeter (org.apache.hello_world_soap_http.Greeter)23 DoubleItPortType (org.example.contract.doubleit.DoubleItPortType)18 Bus (org.apache.cxf.Bus)17 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)15 InvocationHandler (java.lang.reflect.InvocationHandler)14 SOAPService (org.apache.hello_world_soap_http.SOAPService)14 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)12 STSClient (org.apache.cxf.ws.security.trust.STSClient)11 Greeter (org.apache.cxf.greeter_control.Greeter)10 GreeterService (org.apache.cxf.greeter_control.GreeterService)10 SOAPBinding (javax.xml.ws.soap.SOAPBinding)9 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)9 Client (org.apache.cxf.endpoint.Client)9 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)8