Search in sources :

Example 26 with BindingProvider

use of javax.xml.ws.BindingProvider in project bamboobsc by billchen198318.

the class WsServiceUtils method getService.

public static Object getService(String wsClientBeanId, String wsdlAddress) throws Exception {
    if (StringUtils.isBlank(wsClientBeanId)) {
        throw new IllegalArgumentException("error, bean-Id is required!");
    }
    Object serviceObj = AppContext.getBean(wsClientBeanId);
    if (!StringUtils.isBlank(wsdlAddress)) {
        // 更改連線wsdl位置, 不使用原本xml設定檔中設定的連線wsdl位置 
        BindingProvider bindingProvider = (BindingProvider) serviceObj;
        bindingProvider.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, wsdlAddress);
    }
    return serviceObj;
}
Also used : BindingProvider(javax.xml.ws.BindingProvider)

Example 27 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)

Example 28 with BindingProvider

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

the class CxfMessageHeadersRelayTest method addOutOfBoundHeader.

protected static void addOutOfBoundHeader(HeaderTester proxy, boolean invalid) throws JAXBException {
    InvocationHandler handler = Proxy.getInvocationHandler(proxy);
    BindingProvider bp = null;
    try {
        if (handler instanceof BindingProvider) {
            bp = (BindingProvider) handler;
            Map<String, Object> requestContext = bp.getRequestContext();
            requestContext.put(Header.HEADER_LIST, buildOutOfBandHeaderList(invalid));
        }
    } catch (JAXBException ex) {
        throw ex;
    }
}
Also used : JAXBException(javax.xml.bind.JAXBException) BindingProvider(javax.xml.ws.BindingProvider) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 29 with BindingProvider

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

the class CxfMessageHeadersRelayTest method validateReturnedOutOfBandHeader.

protected static void validateReturnedOutOfBandHeader(HeaderTester proxy, boolean expect) {
    InvocationHandler handler = Proxy.getInvocationHandler(proxy);
    BindingProvider bp = null;
    if (!(handler instanceof BindingProvider)) {
        fail("Unable to cast dynamic proxy InocationHandler to BindingProvider type");
    }
    bp = (BindingProvider) handler;
    Map<String, Object> responseContext = bp.getResponseContext();
    validateReturnedOutOfBandHeader(responseContext, expect);
}
Also used : BindingProvider(javax.xml.ws.BindingProvider) InvocationHandler(java.lang.reflect.InvocationHandler)

Example 30 with BindingProvider

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

the class CxfMessageHeadersRelayTest method testInoutOutOfBandHeaderCXFClientRelayWithHeaderInsertion.

@Test
public void testInoutOutOfBandHeaderCXFClientRelayWithHeaderInsertion() throws Exception {
    HeaderService s = new HeaderService(getClass().getClassLoader().getResource("soap_header.wsdl"), HeaderService.SERVICE);
    HeaderTester proxy = s.getSoapPortRelayWithInsertion();
    ((BindingProvider) proxy).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + portE2 + "/CxfMessageHeadersRelayTest/HeaderService/");
    addOutOfBoundHeader(proxy, false);
    Me me = new Me();
    me.setFirstName("john");
    me.setLastName("Doh");
    Me response = proxy.inoutOutOfBandHeader(me);
    assertTrue("Expected the out of band header to propagate but it didn't", response.getFirstName().equals("pass"));
    InvocationHandler handler = Proxy.getInvocationHandler(proxy);
    BindingProvider bp = null;
    if (!(handler instanceof BindingProvider)) {
        fail("Unable to cast dynamic proxy InocationHandler to BindingProvider type");
    }
    bp = (BindingProvider) handler;
    Map<String, Object> responseContext = bp.getResponseContext();
    validateReturnedOutOfBandHeaderWithInsertion(responseContext, true);
}
Also used : BindingProvider(javax.xml.ws.BindingProvider) InvocationHandler(java.lang.reflect.InvocationHandler) Test(org.junit.Test)

Aggregations

BindingProvider (javax.xml.ws.BindingProvider)58 URL (java.net.URL)40 Service (javax.xml.ws.Service)39 Test (org.junit.Test)31 WebServiceException (javax.xml.ws.WebServiceException)17 QName (javax.xml.namespace.QName)12 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)7 ModelPortType (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelPortType)6 ModelService (com.evolveum.midpoint.xml.ns._public.model.model_3.ModelService)6 HashMap (java.util.HashMap)6 File (java.io.File)4 LoggingInInterceptor (org.apache.cxf.interceptor.LoggingInInterceptor)4 LoggingOutInterceptor (org.apache.cxf.interceptor.LoggingOutInterceptor)4 InvocationHandler (java.lang.reflect.InvocationHandler)3 MalformedURLException (java.net.MalformedURLException)3 List (java.util.List)3 DocumentRepositoryService (ihe.iti.xds_b._2007.DocumentRepositoryService)2 ArrayList (java.util.ArrayList)2 SOAPBinding (javax.xml.ws.soap.SOAPBinding)2 HTTPConduit (org.apache.cxf.transport.http.HTTPConduit)2