Search in sources :

Example 51 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class ClientServerXMLTest method testAddPort.

@Test
public void testAddPort() throws Exception {
    URL url = getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl");
    Service service = Service.create(url, wrapServiceName);
    assertNotNull(service);
    service.addPort(wrapFakePortName, "http://cxf.apache.org/bindings/xformat", "http://localhost:" + WRAP_PORT + "/XMLService/XMLPort");
    String response1 = new String("Hello ");
    String response2 = new String("Bonjour");
    org.apache.hello_world_xml_http.wrapped.Greeter greeter = service.getPort(wrapPortName, org.apache.hello_world_xml_http.wrapped.Greeter.class);
    updateAddressPort(greeter, WRAP_PORT);
    try {
        String username = System.getProperty("user.name");
        String reply = greeter.greetMe(username);
        assertNotNull("no response received from service", reply);
        assertEquals(response1 + username, reply);
        reply = greeter.sayHi();
        assertNotNull("no response received from service", reply);
        assertEquals(response2, reply);
        BindingProvider bp = (BindingProvider) greeter;
        Map<String, Object> responseContext = bp.getResponseContext();
        Integer responseCode = (Integer) responseContext.get(Message.RESPONSE_CODE);
        assertEquals(200, responseCode.intValue());
        greeter.greetMeOneWay(System.getProperty("user.name"));
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Service(javax.xml.ws.Service) XMLHeaderService(org.apache.headers.XMLHeaderService) XMLService(org.apache.hello_world_xml_http.bare.XMLService) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 52 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class MultiplexHttpAddressClientServerTest method testWithManualMultiplexEprCreation.

@Test
public void testWithManualMultiplexEprCreation() throws Exception {
    Service numService = Service.create(NumberFactoryImpl.NUMBER_SERVICE_QNAME);
    Number num = numService.getPort(Number.class);
    InvocationHandler handler = Proxy.getInvocationHandler(num);
    BindingProvider bp = (BindingProvider) handler;
    bp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, NUMBER_SERVANT_ADDRESS_ROOT + "103");
    IsEvenResponse numResp = num.isEven();
    assertTrue("103 is not even", Boolean.FALSE.equals(numResp.isEven()));
}
Also used : Number(org.apache.cxf.factory_pattern.Number) Service(javax.xml.ws.Service) NumberService(org.apache.cxf.factory_pattern.NumberService) NumberFactoryService(org.apache.cxf.factory_pattern.NumberFactoryService) BindingProvider(javax.xml.ws.BindingProvider) IsEvenResponse(org.apache.cxf.factory_pattern.IsEvenResponse) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.Test)

Example 53 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class IntFaultClientServerTest method testBasicConnection.

@Test
public void testBasicConnection() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/hello_world_fault.wsdl");
    assertNotNull("WSDL is null", wsdl);
    SOAPService service = new SOAPService(wsdl, serviceName);
    assertNotNull("Service is null", service);
    Greeter greeter = service.getSoapPort();
    ClientProxy.getClient(greeter).getInInterceptors().add(new LoggingInInterceptor());
    ClientProxy.getClient(greeter).getOutInterceptors().add(new LoggingOutInterceptor());
    updateAddressPort(greeter, PORT);
    try {
        greeter.testDocLitFault("fault");
    } catch (BadRecordLitFault e) {
        assertEquals(5, e.getFaultInfo());
        assertSoapHeader((BindingProvider) greeter);
    }
}
Also used : SOAPService(org.apache.intfault.SOAPService) BadRecordLitFault(org.apache.intfault.BadRecordLitFault) LoggingOutInterceptor(org.apache.cxf.ext.logging.LoggingOutInterceptor) Greeter(org.apache.intfault.Greeter) LoggingInInterceptor(org.apache.cxf.ext.logging.LoggingInInterceptor) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 54 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class ClientMtomXopWithJMSTest method createPort.

private static <T> T createPort(QName serviceName, QName portName, Class<T> serviceEndpointInterface, boolean enableMTOM) throws Exception {
    JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
    factory.setBus(bus);
    factory.setServiceName(serviceName);
    factory.setServiceClass(serviceEndpointInterface);
    factory.setWsdlURL(ClientMtomXopTest.class.getResource("/wsdl/mtom_xop.wsdl").toExternalForm());
    factory.setFeatures(Collections.singletonList(cff));
    factory.getInInterceptors().add(new TestMultipartMessageInterceptor());
    factory.getOutInterceptors().add(new TestAttachmentOutInterceptor());
    @SuppressWarnings("unchecked") T proxy = (T) factory.create();
    BindingProvider bp = (BindingProvider) proxy;
    SOAPBinding binding = (SOAPBinding) bp.getBinding();
    binding.setMTOMEnabled(true);
    return proxy;
}
Also used : JaxWsProxyFactoryBean(org.apache.cxf.jaxws.JaxWsProxyFactoryBean) SOAPBinding(javax.xml.ws.soap.SOAPBinding) BindingProvider(javax.xml.ws.BindingProvider)

Example 55 with BindingProvider

use of javax.xml.ws.BindingProvider in project cxf by apache.

the class PolicyHandlerFaultResponseTest method testFaultResponse.

@Test
public void testFaultResponse() throws Exception {
    String address = "http://localhost:" + PORT + "/policytest";
    URL wsdlURL = new URL(address + "?wsdl");
    Service service = Service.create(wsdlURL, serviceName);
    service.addPort(new QName("http://handler.policy.ws.systest.cxf.apache.org/", "HelloPolicyServicePort"), SOAPBinding.SOAP11HTTP_BINDING, address);
    HelloService port = service.getPort(new QName("http://handler.policy.ws.systest.cxf.apache.org/", "HelloPolicyServicePort"), HelloService.class);
    Map<String, Object> context = ((BindingProvider) port).getRequestContext();
    context.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, address);
    context.put(SecurityConstants.CALLBACK_HANDLER, new CommonPasswordCallback());
    context.put(SecurityConstants.SIGNATURE_PROPERTIES, "alice.properties");
    context.put(SecurityConstants.SIGNATURE_USERNAME, "alice");
    try {
        port.checkHello("input");
        fail("Exception is expected");
    } catch (MyFault e) {
        assertEquals("Fault is not expected", "myMessage", e.getMessage());
    }
}
Also used : QName(javax.xml.namespace.QName) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

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