javax.xml.ws.Dispatch Java Examples

The following examples show how to use javax.xml.ws.Dispatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WSServiceDelegate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public <T> Dispatch<T> createDispatch(QName portName, Class<T> aClass, Service.Mode mode, WebServiceFeatureList features) {
    WSEndpointReference wsepr = null;
    boolean isAddressingEnabled = false;
    AddressingFeature af = features.get(AddressingFeature.class);
    if (af == null) {
        af = this.features.get(AddressingFeature.class);
    }
    if (af != null && af.isEnabled())
        isAddressingEnabled = true;
    MemberSubmissionAddressingFeature msa = features.get(MemberSubmissionAddressingFeature.class);
    if (msa == null) {
        msa = this.features.get(MemberSubmissionAddressingFeature.class);
    }
    if (msa != null && msa.isEnabled())
        isAddressingEnabled = true;
    if(isAddressingEnabled && wsdlService != null && wsdlService.get(portName) != null) {
        wsepr = wsdlService.get(portName).getEPR();
    }
    return createDispatch(portName, wsepr, aClass, mode, features);
}
 
Example #2
Source File: WSServiceDelegate.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public <T> Dispatch<T> createDispatch(QName portName, Class<T> aClass, Service.Mode mode, WebServiceFeatureList features) {
    WSEndpointReference wsepr = null;
    boolean isAddressingEnabled = false;
    AddressingFeature af = features.get(AddressingFeature.class);
    if (af == null) {
        af = this.features.get(AddressingFeature.class);
    }
    if (af != null && af.isEnabled())
        isAddressingEnabled = true;
    MemberSubmissionAddressingFeature msa = features.get(MemberSubmissionAddressingFeature.class);
    if (msa == null) {
        msa = this.features.get(MemberSubmissionAddressingFeature.class);
    }
    if (msa != null && msa.isEnabled())
        isAddressingEnabled = true;
    if(isAddressingEnabled && wsdlService != null && wsdlService.get(portName) != null) {
        wsepr = wsdlService.get(portName).getEPR();
    }
    return createDispatch(portName, wsepr, aClass, mode, features);
}
 
Example #3
Source File: WSServiceDelegate.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
protected Dispatch<Object> createDispatch(QName portName, WSEndpointReference wsepr, JAXBContext jaxbContext, Service.Mode mode, WebServiceFeatureList features) {
    PortInfo port = safeGetPort(portName);

    ComponentFeature cf = features.get(ComponentFeature.class);
    if (cf != null && !Target.STUB.equals(cf.getTarget())) {
        throw new IllegalArgumentException();
    }
    ComponentsFeature csf = features.get(ComponentsFeature.class);
    if (csf != null) {
        for (ComponentFeature cfi : csf.getComponentFeatures()) {
            if (!Target.STUB.equals(cfi.getTarget()))
                throw new IllegalArgumentException();
        }
    }
    features.addAll(this.features);

    BindingImpl binding = port.createBinding(features, null, null);
    binding.setMode(mode);
    Dispatch<Object> dispatch = Stubs.createJAXBDispatch(
            port, binding, jaxbContext, mode,wsepr);
     serviceInterceptor.postCreateDispatch((WSBindingProvider)dispatch);
     return dispatch;
}
 
Example #4
Source File: Stubs.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@link Dispatch} stub that connects to the given pipe.
 *
 * @param portInfo
 *      see <a href="#param">common parameters</a>
 * @param owner
 *      see <a href="#param">common parameters</a>
 * @param binding
 *      see <a href="#param">common parameters</a>
 * @param clazz
 *      Type of the {@link Dispatch} to be created.
 *      See {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param mode
 *      The mode of the dispatch.
 *      See {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param epr
 *      see <a href="#param">common parameters</a>
 * TODO: are these parameters making sense?
 */
public static <T> Dispatch<T> createDispatch(WSPortInfo portInfo,
                                             WSService owner,
                                             WSBinding binding,
                                             Class<T> clazz, Service.Mode mode,
                                             @Nullable WSEndpointReference epr) {
    if (clazz == SOAPMessage.class) {
        return (Dispatch<T>) createSAAJDispatch(portInfo, binding, mode, epr);
    } else if (clazz == Source.class) {
        return (Dispatch<T>) createSourceDispatch(portInfo, binding, mode, epr);
    } else if (clazz == DataSource.class) {
        return (Dispatch<T>) createDataSourceDispatch(portInfo, binding, mode, epr);
    } else if (clazz == Message.class) {
        if(mode==Mode.MESSAGE)
            return (Dispatch<T>) createMessageDispatch(portInfo, binding, epr);
        else
            throw new WebServiceException(mode+" not supported with Dispatch<Message>");
    } else if (clazz == Packet.class) {
        if(mode==Mode.MESSAGE)
            return (Dispatch<T>) createPacketDispatch(portInfo, binding, epr);
        else
            throw new WebServiceException(mode+" not supported with Dispatch<Packet>");
    } else
        throw new WebServiceException("Unknown class type " + clazz.getName());
}
 
Example #5
Source File: DispatchHandlerInvocationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeWithDOMSourcPayloadMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);

    AddNumbersService service = new AddNumbersService(wsdl, serviceName);
    assertNotNull(service);

    Dispatch<DOMSource> disp = service.createDispatch(portName, DOMSource.class, Mode.PAYLOAD);
    setAddress(disp, addNumbersAddress);

    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);

    InputStream is2 = this.getClass().getResourceAsStream("resources/GreetMeDocLiteralReqPayload.xml");
    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapReq = factory.createMessage(null, is2);
    DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());

    DOMSource response = disp.invoke(domReqMessage);
    assertNotNull(response);
}
 
Example #6
Source File: WSServiceDelegate.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public <T> Dispatch<T> createDispatch(QName portName, WSEndpointReference wsepr, Class<T> aClass, Service.Mode mode, WebServiceFeatureList features) {
    PortInfo port = safeGetPort(portName);

    ComponentFeature cf = features.get(ComponentFeature.class);
    if (cf != null && !Target.STUB.equals(cf.getTarget())) {
        throw new IllegalArgumentException();
    }
    ComponentsFeature csf = features.get(ComponentsFeature.class);
    if (csf != null) {
        for (ComponentFeature cfi : csf.getComponentFeatures()) {
            if (!Target.STUB.equals(cfi.getTarget()))
                throw new IllegalArgumentException();
        }
    }
    features.addAll(this.features);

    BindingImpl binding = port.createBinding(features, null, null);
    binding.setMode(mode);
    Dispatch<T> dispatch = Stubs.createDispatch(port, this, binding, aClass, mode, wsepr);
    serviceInterceptor.postCreateDispatch((WSBindingProvider) dispatch);
    return dispatch;
}
 
Example #7
Source File: WSServiceDelegate.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public <T> Dispatch<T> createDispatch(QName portName, Class<T> aClass, Service.Mode mode, WebServiceFeatureList features) {
    WSEndpointReference wsepr = null;
    boolean isAddressingEnabled = false;
    AddressingFeature af = features.get(AddressingFeature.class);
    if (af == null) {
        af = this.features.get(AddressingFeature.class);
    }
    if (af != null && af.isEnabled())
        isAddressingEnabled = true;
    MemberSubmissionAddressingFeature msa = features.get(MemberSubmissionAddressingFeature.class);
    if (msa == null) {
        msa = this.features.get(MemberSubmissionAddressingFeature.class);
    }
    if (msa != null && msa.isEnabled())
        isAddressingEnabled = true;
    if(isAddressingEnabled && wsdlService != null && wsdlService.get(portName) != null) {
        wsepr = wsdlService.get(portName).getEPR();
    }
    return createDispatch(portName, wsepr, aClass, mode, features);
}
 
Example #8
Source File: DispatchHandlerInvocationTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testInvokeWithJAXBMessageModeXMLBinding() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);

    XMLService service = new XMLService();
    assertNotNull(service);

    JAXBContext jc = JAXBContext.newInstance("org.apache.hello_world_xml_http.wrapped.types");
    Dispatch<Object> disp = service.createDispatch(portNameXML, jc, Mode.MESSAGE);
    setAddress(disp, greeterAddress);

    TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
    addHandlersProgrammatically(disp, handler);

    org.apache.hello_world_xml_http.wrapped.types.GreetMe req =
        new org.apache.hello_world_xml_http.wrapped.types.GreetMe();
    req.setRequestType("tli");

    Object response = disp.invoke(req);
    assertNotNull(response);
    org.apache.hello_world_xml_http.wrapped.types.GreetMeResponse value =
        (org.apache.hello_world_xml_http.wrapped.types.GreetMeResponse)response;
    assertEquals("Hello tli", value.getResponseType());
}
 
Example #9
Source File: WSServiceDelegate.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public <T> Dispatch<T> createDispatch(QName portName, Class<T> aClass, Service.Mode mode, WebServiceFeatureList features) {
    WSEndpointReference wsepr = null;
    boolean isAddressingEnabled = false;
    AddressingFeature af = features.get(AddressingFeature.class);
    if (af == null) {
        af = this.features.get(AddressingFeature.class);
    }
    if (af != null && af.isEnabled())
        isAddressingEnabled = true;
    MemberSubmissionAddressingFeature msa = features.get(MemberSubmissionAddressingFeature.class);
    if (msa == null) {
        msa = this.features.get(MemberSubmissionAddressingFeature.class);
    }
    if (msa != null && msa.isEnabled())
        isAddressingEnabled = true;
    if(isAddressingEnabled && wsdlService != null && wsdlService.get(portName) != null) {
        wsepr = wsdlService.get(portName).getEPR();
    }
    return createDispatch(portName, wsepr, aClass, mode, features);
}
 
Example #10
Source File: DispatchOpTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testResolveOperationWithSource() throws Exception {
    ServiceImpl service =
        new ServiceImpl(getBus(), getClass().getResource(WSDL_RESOURCE), SERVICE_NAME, null);

    Dispatch<Source> disp = service.createDispatch(
            PORT_NAME, Source.class, Service.Mode.PAYLOAD);
    disp.getRequestContext().put(MessageContext.WSDL_OPERATION, OP_NAME);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, ADDRESS);

    d.setMessageObserver(new MessageReplayObserver(RESP_RESOURCE));

    BindingOperationVerifier bov = new BindingOperationVerifier();
    ((DispatchImpl<?>)disp).getClient().getOutInterceptors().add(bov);

    Document doc = StaxUtils.read(getResourceAsStream(REQ_RESOURCE));
    DOMSource source = new DOMSource(doc);
    Source res = disp.invoke(source);
    assertNotNull(res);

    BindingOperationInfo boi = bov.getBindingOperationInfo();
    assertNotNull(boi);

    assertEquals(OP_NAME, boi.getName());
}
 
Example #11
Source File: Stubs.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@link Dispatch} stub that connects to the given pipe.
 *
 * @param portName
 *      see {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param owner
 *      see <a href="#param">common parameters</a>
 * @param binding
 *      see <a href="#param">common parameters</a>
 * @param clazz
 *      Type of the {@link Dispatch} to be created.
 *      See {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param mode
 *      The mode of the dispatch.
 *      See {@link Service#createDispatch(QName, Class, Service.Mode)}.
 * @param next
 *      see <a href="#param">common parameters</a>
 * @param epr
 *      see <a href="#param">common parameters</a>
 * TODO: are these parameters making sense?
 */
@SuppressWarnings("unchecked")
    public static <T> Dispatch<T> createDispatch(QName portName,
                                             WSService owner,
                                             WSBinding binding,
                                             Class<T> clazz, Service.Mode mode, Tube next,
                                             @Nullable WSEndpointReference epr) {
    if (clazz == SOAPMessage.class) {
        return (Dispatch<T>) createSAAJDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == Source.class) {
        return (Dispatch<T>) createSourceDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == DataSource.class) {
        return (Dispatch<T>) createDataSourceDispatch(portName, owner, binding, mode, next, epr);
    } else if (clazz == Message.class) {
        if(mode==Mode.MESSAGE)
            return (Dispatch<T>) createMessageDispatch(portName, owner, binding, next, epr);
        else
            throw new WebServiceException(mode+" not supported with Dispatch<Message>");
    } else if (clazz == Packet.class) {
        return (Dispatch<T>) createPacketDispatch(portName, owner, binding, next, epr);
    } else
        throw new WebServiceException("Unknown class type " + clazz.getName());
}
 
Example #12
Source File: DispatchXMLClientServerTest.java    From cxf with Apache License 2.0 6 votes vote down vote up
@Test
public void testJAXBMESSAGE() throws Exception {
    Service service = Service.create(SERVICE_NAME);
    assertNotNull(service);
    service.addPort(PORT_NAME, "http://cxf.apache.org/bindings/xformat",
                    "http://localhost:"
                    + port
                    + "/XMLService/XMLDispatchPort");


    GreetMe gm = new GreetMe();
    gm.setRequestType("CXF");
    JAXBContext ctx = JAXBContext.newInstance(ObjectFactory.class);
    Dispatch<Object> disp = service.createDispatch(PORT_NAME, ctx, Service.Mode.MESSAGE);
    GreetMeResponse resp = (GreetMeResponse)disp.invoke(gm);
    assertNotNull(resp);
    assertEquals("Hello CXF", resp.getResponseType());

    try {
        disp.invoke(null);
        fail("Should have thrown a fault");
    } catch (WebServiceException ex) {
        //expected
    }
}
 
Example #13
Source File: WSServiceDelegate.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
protected Dispatch<Object> createDispatch(QName portName, JAXBContext jaxbContext, Service.Mode mode, WebServiceFeatureList features) {
    WSEndpointReference wsepr = null;
    boolean isAddressingEnabled = false;
    AddressingFeature af = features.get(AddressingFeature.class);
    if (af == null) {
        af = this.features.get(AddressingFeature.class);
    }
    if (af != null && af.isEnabled())
        isAddressingEnabled = true;
    MemberSubmissionAddressingFeature msa = features.get(MemberSubmissionAddressingFeature.class);
    if (msa == null) {
        msa = this.features.get(MemberSubmissionAddressingFeature.class);
    }
    if (msa != null && msa.isEnabled())
        isAddressingEnabled = true;
    if(isAddressingEnabled && wsdlService != null && wsdlService.get(portName) != null) {
        wsepr = wsdlService.get(portName).getEPR();
    }
    return createDispatch(portName, wsepr, jaxbContext, mode, features);
}
 
Example #14
Source File: JaxWsProviderWrapper.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings({"unchecked"})
public <T> Dispatch<T> createDispatch(final QName portName, final Class<T> type, final Service.Mode mode, final WebServiceFeature... features) {
    return (Dispatch<T>) invoke21Delegate(serviceDelegate, createDispatchInterface,
        portName,
        type,
        mode,
        features);
}
 
Example #15
Source File: ProviderWrapper.java    From tomee with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
public Dispatch<Object> createDispatch(final QName portName, final JAXBContext context, final Service.Mode mode, final WebServiceFeature... features) {
    return (Dispatch<Object>) invoke21Delegate(serviceDelegate, createDispatchJaxBContext,
        portName,
        context,
        mode,
        features);
}
 
Example #16
Source File: ServiceImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public Dispatch<Object> createDispatch(EndpointReference endpointReference,
                                       JAXBContext context,
                                       Mode mode,
                                       WebServiceFeature... features) {
    EndpointReferenceType ref = ProviderImpl.convertToInternal(endpointReference);
    QName portName = EndpointReferenceUtils.getPortQName(ref, bus);
    updatePortInfoAddress(portName, EndpointReferenceUtils.getAddress(ref));
    return createDispatch(portName, context, mode, features);
}
 
Example #17
Source File: DispatchHandlerInvocationTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvokeWithJAXBUnwrapPayloadMode() throws Exception {
    URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
    assertNotNull(wsdl);

    org.apache.cxf.systest.handlers.AddNumbersServiceUnwrap service =
        new org.apache.cxf.systest.handlers.AddNumbersServiceUnwrap(wsdl, serviceName);
    assertNotNull(service);

    JAXBContext jc = JAXBContext.newInstance(
        org.apache.cxf.systest.handlers.types.AddNumbers.class,
        org.apache.cxf.systest.handlers.types.AddNumbersResponse.class);

    Dispatch<Object> disp = service.createDispatch(portName, jc, Service.Mode.PAYLOAD);
    setAddress(disp, addNumbersAddress);

    TestHandler handler = new TestHandler();
    TestSOAPHandler soapHandler = new TestSOAPHandler();
    addHandlersProgrammatically(disp, handler, soapHandler);

    org.apache.cxf.systest.handlers.types.AddNumbers req =
        new org.apache.cxf.systest.handlers.types.AddNumbers();
    req.setArg0(10);
    req.setArg1(20);

    org.apache.cxf.systest.handlers.types.AddNumbersResponse response =
        (org.apache.cxf.systest.handlers.types.AddNumbersResponse)disp.invoke(req);
    assertNotNull(response);
    assertEquals(222, response.getReturn());
}
 
Example #18
Source File: WSEndpointReference.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull <T> Dispatch<T> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull Class<T> type,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),type,mode,features);
}
 
Example #19
Source File: JaxWSHookIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@Override
public void preProcess(Dispatch t, Object proxy, Method method, Object[] args) {

    String httpAction = method.getName();

    if (!"invoke".equals(method.getName())) {
        return;
    }

    doStart(httpAction);
}
 
Example #20
Source File: JaxWSHookIT.java    From uavstack with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("rawtypes")
public Dispatch createDispatch(Dispatch d, Service s, Object[] args) {

    Binding binding = ((BindingProvider) d).getBinding();
    List<Handler> handlerChain = binding.getHandlerChain();
    handlerChain.add(this.handler);
    binding.setHandlerChain(handlerChain);

    final String wsdlLocation = getServiceURL(s);

    Dispatch tProxy = JDKProxyInvokeUtil.newProxyInstance(this.getClass().getClassLoader(),
            new Class[] { Dispatch.class },
            new JDKProxyInvokeHandler<Dispatch>(d, new DispatchProcessor(wsdlLocation.toString(), this.handler)));
    return tProxy;
}
 
Example #21
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testSOAPMessageInvokeToOneWay() throws Exception {
    SOAPService service = new SOAPService(null, SERVICE_NAME);
    service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING,
                    "http://localhost:" + greeterPort
                    + "/SOAPDispatchService/SoapDispatchPort");
    assertNotNull(service);

    Dispatch<SOAPMessage> disp = service
        .createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);

    //message is "one way", but there really isn't a way for us to know that
    //as we don't have a wsdl or other source of operation information to
    //compare the payload to.
    InputStream is1 = getClass().getResourceAsStream("resources/GreetMe1WDocLiteralReq2.xml");
    SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
    assertNotNull(soapReqMsg1);

    //Version 1:
    //we'll just call invoke
    disp.invoke(soapReqMsg1);

    //Version 2:
    //We want to handle things asynchronously
    AsyncHandler<SOAPMessage> callback = new AsyncHandler<SOAPMessage>() {
        public void handleResponse(Response<SOAPMessage> res) {
            synchronized (this) {
                notifyAll();
            }
        }
    };
    synchronized (callback) {
        disp.invokeAsync(soapReqMsg1, callback);
        callback.wait();
    }
}
 
Example #22
Source File: SampleWsApplicationClient.java    From cxf with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String address = "http://localhost:8080/Service/Hello";
    String request = "<q0:sayHello xmlns:q0=\"http://service.ws.sample/\"><myname>Elan</myname></q0:sayHello>";

    StreamSource source = new StreamSource(new StringReader(request));
    Service service = Service.create(new URL(address + "?wsdl"), 
                                     new QName("http://service.ws.sample/" , "HelloService"));
    Dispatch<Source> disp = service.createDispatch(new QName("http://service.ws.sample/" , "HelloPort"),
                                                   Source.class, Mode.PAYLOAD);
    
    Source result = disp.invoke(source);
    String resultAsString = StaxUtils.toString(result);
    System.out.println(resultAsString);
   
}
 
Example #23
Source File: WSSecurityClientTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
private static Dispatch<Source> createUsernameTokenDispatcher(boolean decoupled, String port) {
    final Service service = Service.create(
        GREETER_SERVICE_QNAME
    );
    service.addPort(
        USERNAME_TOKEN_PORT_QNAME,
        decoupled ? SOAPBinding.SOAP11HTTP_BINDING : HTTPBinding.HTTP_BINDING,
        "http://localhost:" + port + "/GreeterService/UsernameTokenPort"
    );
    final Dispatch<Source> dispatcher = service.createDispatch(
        USERNAME_TOKEN_PORT_QNAME,
        Source.class,
        Service.Mode.MESSAGE,
        new AddressingFeature(decoupled, decoupled)
    );
    final java.util.Map<String, Object> requestContext =
        dispatcher.getRequestContext();
    requestContext.put(
        MessageContext.HTTP_REQUEST_METHOD,
        "POST"
    );
    if (decoupled) {
        HTTPConduit cond = (HTTPConduit)((DispatchImpl<?>)dispatcher).getClient().getConduit();
        cond.getClient().setDecoupledEndpoint("http://localhost:" + DEC_PORT + "/decoupled");
    }
    return dispatcher;
}
 
Example #24
Source File: DispatchImpl.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Deprecated
public static Dispatch<Source> createSourceDispatch(QName port, Mode mode, WSServiceDelegate owner, Tube pipe, BindingImpl binding, WSEndpointReference epr) {
    if(isXMLHttp(binding))
        return new RESTSourceDispatch(port,mode,owner,pipe,binding,epr);
    else
        return new SOAPSourceDispatch(port,mode,owner,pipe,binding,epr);
}
 
Example #25
Source File: Test.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws IOException, TransformerException {

        try {
            String address = deployWebservice();
            Service service = Service.create(new URL(address), ServiceImpl.SERVICE_NAME);

            Dispatch<Source> d = service.createDispatch(ServiceImpl.PORT_NAME, Source.class, Service.Mode.MESSAGE);
            Source response = d.invoke(new StreamSource(new StringReader(XML_REQUEST)));

            String resultXml = toString(response);

            log("= request ======== \n");
            log(XML_REQUEST);
            log("= result ========= \n");
            log(resultXml);
            log("\n==================");

            boolean xsAnyMixedPartSame = resultXml.contains(XS_ANY_MIXED_PART);
            log("resultXml.contains(XS_ANY_PART) = " + xsAnyMixedPartSame);
            if (!xsAnyMixedPartSame) {
                fail("The xs:any content=mixed part is supposed to be same in request and response.");
                throw new RuntimeException();
            }

            log("TEST PASSED");
        } finally {
            stopWebservice();

            // if you need to debug or explore wsdl generation result
            // comment this line out:
            deleteGeneratedFiles();
        }
    }
 
Example #26
Source File: WSEndpointReference.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a {@link Dispatch} that can be used to talk to this EPR.
 *
 * <p>
 * All the normal WS-Addressing processing happens automatically,
 * such as setting the endpoint address to {@link #getAddress() the address},
 * and sending the reference parameters associated with this EPR as
 * headers, etc.
 */
public @NotNull <T> Dispatch<T> createDispatch(
    @NotNull Service jaxwsService,
    @NotNull Class<T> type,
    @NotNull Service.Mode mode,
    WebServiceFeature... features) {

    // TODO: implement it in a better way
    return jaxwsService.createDispatch(toSpec(),type,mode,features);
}
 
Example #27
Source File: ServiceImpl.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Override
public <T> Dispatch<T> createDispatch(EndpointReference endpointReference,
                                      Class<T> type,
                                      Mode mode,
                                      WebServiceFeature... features) {
    EndpointReferenceType ref = ProviderImpl.convertToInternal(endpointReference);
    QName portName = EndpointReferenceUtils.getPortQName(ref, bus);
    updatePortInfoAddress(portName, EndpointReferenceUtils.getAddress(ref));
    return createDispatch(portName,
                          type, mode, features);
}
 
Example #28
Source File: DispatchClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testStAXSourcePAYLOAD() throws Exception {

    URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
    assertNotNull(wsdl);

    Service service = Service.create(wsdl, SERVICE_NAME);
    assertNotNull(service);

    Dispatch<StAXSource> disp = service.createDispatch(PORT_NAME, StAXSource.class, Service.Mode.PAYLOAD);
    disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                 "http://localhost:"
                                 + greeterPort
                                 + "/SOAPDispatchService/SoapDispatchPort");
    QName opQName = new QName("http://apache.org/hello_world_soap_http", "greetMe");
    disp.getRequestContext().put(MessageContext.WSDL_OPERATION, opQName);

    // Test request-response
    InputStream is = getClass().getResourceAsStream("resources/GreetMeDocLiteralSOAPBodyReq.xml");
    StAXSource staxSourceReq = new StAXSource(StaxUtils.createXMLStreamReader(is));
    assertNotNull(staxSourceReq);
    Source resp = disp.invoke(staxSourceReq);
    assertNotNull(resp);
    assertTrue(resp instanceof StAXSource);
    String expected = "Hello TestSOAPInputMessage";
    String actual = StaxUtils.toString(StaxUtils.read(resp));
    assertTrue("Expected: " + expected, actual.contains(expected));
}
 
Example #29
Source File: DispatchXMLClientServerTest.java    From cxf with Apache License 2.0 5 votes vote down vote up
@Test
public void testStreamSourceMESSAGE() throws Exception {
    /*URL wsdl = getClass().getResource("/wsdl/hello_world_xml_wrapped.wsdl");
    assertNotNull(wsdl);

    XMLService service = new XMLService(wsdl, serviceName);
    assertNotNull(service);*/
    Service service = Service.create(SERVICE_NAME);
    assertNotNull(service);
    service.addPort(PORT_NAME, "http://cxf.apache.org/bindings/xformat",
                    "http://localhost:"
                    + port
                    + "/XMLService/XMLDispatchPort");

    InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml");
    StreamSource reqMsg = new StreamSource(is);
    assertNotNull(reqMsg);

    Dispatch<Source> disp = service.createDispatch(PORT_NAME, Source.class, Service.Mode.MESSAGE);
    Source source = disp.invoke(reqMsg);
    assertNotNull(source);

    String streamString = StaxUtils.toString(source);
    Document doc = StaxUtils.read(new StringReader(streamString));
    assertEquals("greetMeResponse", doc.getFirstChild().getLocalName());
    assertEquals("Hello tli", doc.getFirstChild().getTextContent());
}
 
Example #30
Source File: HandlerInvocationTest.java    From cxf with Apache License 2.0 4 votes vote down vote up
@Test
public void testHandlersInvokedForDispatch() throws Exception {
    Dispatch<SOAPMessage> disp = service
        .createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);
    setAddress(disp, "http://localhost:" + port + "/HandlerTest/SoapPort");

    TestHandler<LogicalMessageContext> handler1 = new TestHandler<>(false);
    TestHandler<LogicalMessageContext> handler2 = new TestHandler<>(false);
    TestSOAPHandler soapHandler1 = new TestSOAPHandler(false);
    TestSOAPHandler soapHandler2 = new TestSOAPHandler(false);

    addHandlersToChain(disp, handler1, handler2, soapHandler1, soapHandler2);

    InputStream is = getClass().getResourceAsStream("PingReq.xml");
    SOAPMessage outMsg = MessageFactory.newInstance().createMessage(null, is);

    SOAPMessage inMsg = disp.invoke(outMsg);
    assertNotNull(inMsg);

    assertEquals("handle message was not invoked", 2, handler1.getHandleMessageInvoked());
    assertEquals("handle message was not invoked", 2, handler2.getHandleMessageInvoked());
    assertEquals("handle message was not invoked", 2, soapHandler1.getHandleMessageInvoked());
    assertEquals("handle message was not invoked", 2, soapHandler2.getHandleMessageInvoked());

    assertEquals("close must be called", 1, handler1.getCloseInvoked());
    assertEquals("close must be called", 1, handler2.getCloseInvoked());
    assertEquals("close must be called", 1, soapHandler1.getCloseInvoked());
    assertEquals("close must be called", 1, soapHandler2.getCloseInvoked());

    // the server has encoded into the response the order in
    // which the handlers have been invoked, parse it and make
    // sure everything is ok

    // expected order for inbound interceptors
    String[] handlerNames = {"soapHandler4", "soapHandler3", "handler2", "handler1", "servant",
                             "handler1", "handler2", "soapHandler3", "soapHandler4"};

    List<String> resp = getHandlerNames(inMsg.getSOAPPart().getEnvelope().getBody());
    assertEquals(handlerNames.length, resp.size());

    Iterator<String> iter = resp.iterator();
    for (String expected : handlerNames) {
        assertEquals(expected, iter.next());
    }
}