/** * 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()); }
/** * 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()); }
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; }
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); }
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; }
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); }
private Dispatch<Source> getDispatch() { Service helloService = Service.create(getClass().getResource("/META-INF/wsdl/GreetingService-1.0/GreetingService.wsdl"), new QName("http://hello.respiro.kantega.org/ws/greet-1.0", "GreetingService")); Dispatch<Source> helloPort = helloService.createDispatch(new QName("http://hello.respiro.kantega.org/ws/greet-1.0", "GreetingPort"), Source.class, Service.Mode.PAYLOAD); BindingProvider prov = (BindingProvider)helloPort; Map<String,Object> rc = prov.getRequestContext(); rc.put(BindingProvider.SOAPACTION_USE_PROPERTY, true); rc.put(BindingProvider.SOAPACTION_URI_PROPERTY, "greet"); rc.put(BindingProvider.USERNAME_PROPERTY, "joe"); rc.put(BindingProvider.PASSWORD_PROPERTY, "joe"); rc.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:" + Utils.getReststopPort() + "/ws/dummy/greeting-1.0"); return helloPort; }
public boolean testConfigurationChangeOnDispatch() throws Exception { Service service = Service.create(new URL(address + "?wsdl"), serviceName); Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE); org.apache.cxf.endpoint.Endpoint ep = ((DispatchImpl<SOAPMessage>)dispatch).getClient().getEndpoint(); assert(ep.get("propA") == null); assert(ep.get("propB") == null); ep.put("propZ", "valueZ"); ClientConfigurer configurer = ClientConfigUtil.resolveClientConfigurer(); configurer.setConfigProperties(dispatch, "META-INF/jaxws-client-config.xml", "Custom Client Config"); if (!ep.get("propA").equals("fileValueA") || !ep.get("propB").equals("fileValueB") || !ep.get("propZ").equals("valueZ")) { return false; } configurer.setConfigProperties(dispatch, "META-INF/jaxws-client-config.xml", "Another Client Config"); return (ep.get("propA") == null && ep.get("propB") == null && ep.get("propC").equals("fileValueC") && ep.get("propZ").equals("valueZ")); }
public boolean testDefaultClientConfigurationOnDispatch() throws Exception { final URL wsdlURL = new URL(address + "?wsdl"); final ClientConfig defaultClientConfig = TestUtils.getAndVerifyDefaultClientConfiguration(); // -- modify default conf -- try { final Map<String, String> props = new HashMap<String, String>(); props.put("propA", "valueA"); TestUtils.registerClientConfigAndReload(new ClientConfig(defaultClientConfig.getConfigName(), null, null, props, null)); // -- Service service = Service.create(wsdlURL, serviceName); Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE); return (((DispatchImpl<SOAPMessage>)dispatch).getClient().getEndpoint().get("propA").equals("valueA")); } finally { // -- restore default conf -- TestUtils.registerClientConfigAndReload(defaultClientConfig); // -- } }
public boolean testCustomClientConfigurationOnDispatch() throws Exception { final URL wsdlURL = new URL(address + "?wsdl"); final String testConfigName = "MyTestConfig"; try { //-- add test client configuration TestUtils.addTestCaseClientConfiguration(testConfigName); // -- Service service = Service.create(wsdlURL, serviceName); Dispatch<SOAPMessage> dispatch = service.createDispatch(portName, SOAPMessage.class, Mode.MESSAGE); org.apache.cxf.endpoint.Endpoint ep = ((DispatchImpl<SOAPMessage>)dispatch).getClient().getEndpoint(); ep.put("propZ", "valueZ"); ClientConfigUtil.setConfigProperties(dispatch, null, testConfigName); return (ep.get("propT").equals("valueT") && ep.get("propZ").equals("valueZ")); } finally { // -- remove test client configuration -- TestUtils.removeTestCaseClientConfiguration(testConfigName); // -- } }
@Test @RunAsClient public void testAddingIncomptiableHandler() throws Exception { try { Dispatch<Source> source = createDispatchSource(); @SuppressWarnings("rawtypes") List<Handler> handlers = new ArrayList<Handler>(); handlers.add(new SOAPHandler()); source.getBinding().setHandlerChain(handlers); fail("WebServiceException is not thrown"); } catch (WebServiceException e) { //expected and do nothing } }
@Test @RunAsClient public void testCreateDispatchUsingEPRAndSource() throws Exception { Dispatch<Source> dispatch = service.createDispatch(PORT_QNAME, Source.class, Mode.PAYLOAD); assertNotNull("Dispatch is null", dispatch); this.invokeSourceDispatch(dispatch); epr = dispatch.getEndpointReference(); printEPR(epr); dispatch = service.createDispatch(epr, Source.class, Service.Mode.PAYLOAD, ADDRESSING_ENABLED); assertNotNull("Dispatch is null", dispatch); this.invokeSourceDispatch(dispatch); epr = dispatch.getEndpointReference(); printEPR(epr); dispatch = service.createDispatch(epr, Source.class, Service.Mode.PAYLOAD, ADDRESSING_DISABLED); assertNotNull("Dispatch is null", dispatch); this.invokeSourceDispatch(dispatch); epr = dispatch.getEndpointReference(); printEPR(epr); }
@Test @RunAsClient public void testCreateDispatchUsingEPRAndJAXBContext() throws Exception { Dispatch<Object> dispatch = service.createDispatch(PORT_QNAME, this.createJAXBContext(), Mode.PAYLOAD); assertNotNull("Dispatch is null", dispatch); this.invokeObjectDispatch(dispatch); epr = dispatch.getEndpointReference(); printEPR(epr); dispatch = service.createDispatch(epr, this.createJAXBContext(), Service.Mode.PAYLOAD, ADDRESSING_ENABLED); assertNotNull("Dispatch is null", dispatch); this.invokeObjectDispatch(dispatch); epr = dispatch.getEndpointReference(); printEPR(epr); dispatch = service.createDispatch(epr, this.createJAXBContext(), Service.Mode.PAYLOAD, ADDRESSING_DISABLED); assertNotNull("Dispatch is null", dispatch); this.invokeObjectDispatch(dispatch); epr = dispatch.getEndpointReference(); printEPR(epr); }
@Test @RunAsClient public void testProviderDispatch() throws Exception { String targetNS = "http://ws.com/"; QName serviceName = new QName(targetNS, "Provider"); QName portName = new QName(targetNS, "ProviderPort"); Service service = Service.create(serviceName); service.addPort(portName, HTTPBinding.HTTP_BINDING, baseURL.toString()); Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD); Source resPayload = dispatch.invoke(new DOMSource(DOMUtils.parse("<ns2:input xmlns:ns2='http://ws.com/'><arg0>hello</arg0></ns2:input>"))); Element docElement = DOMUtils.sourceToElement(resPayload); Element response = ((Element)DOMUtils.getChildElements(docElement, "return").next()); assertEquals("hello", response.getTextContent()); }
public boolean testCustomClientConfigurationOnDispatchFromFile() throws Exception { final String reqString = "<ns1:echo xmlns:ns1=\"http://clientConfig.jaxws.ws.test.jboss.org/\"><arg0>Kermit</arg0></ns1:echo>"; QName serviceName = new QName("http://clientConfig.jaxws.ws.test.jboss.org/", "EndpointImplService"); QName portName = new QName("http://clientConfig.jaxws.ws.test.jboss.org/", "EndpointPort"); URL wsdlURL = new URL(address + "?wsdl"); Service service = Service.create(wsdlURL, serviceName); Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD); BindingProvider bp = (BindingProvider)dispatch; @SuppressWarnings("rawtypes") List<Handler> hc = bp.getBinding().getHandlerChain(); hc.add(new UserHandler()); bp.getBinding().setHandlerChain(hc); ClientConfigUtil.setConfigHandlers(bp, "META-INF/jaxws-client-config.xml", "Custom Client Config"); Source resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString))); resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString))); resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString))); String resStr = DOMUtils.getTextContent(DOMUtils.sourceToElement(resSource).getElementsByTagName("return").item(0)); return ("Kermit|RoutOut|CustomOut|UserOut|LogOut|endpoint|LogIn|UserIn|CustomIn|RoutIn".equals(resStr)); }
public boolean testCustomClientConfigurationFromFileUsingFeatureOnDispatch() throws Exception { final String reqString = "<ns1:echo xmlns:ns1=\"http://clientConfig.jaxws.ws.test.jboss.org/\"><arg0>Kermit</arg0></ns1:echo>"; QName serviceName = new QName("http://clientConfig.jaxws.ws.test.jboss.org/", "EndpointImplService"); QName portName = new QName("http://clientConfig.jaxws.ws.test.jboss.org/", "EndpointPort"); URL wsdlURL = new URL(address + "?wsdl"); Service service = Service.create(wsdlURL, serviceName); Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD, new ClientConfigFeature("META-INF/jaxws-client-config.xml", "Custom Client Config")); BindingProvider bp = (BindingProvider)dispatch; @SuppressWarnings("rawtypes") List<Handler> hc = bp.getBinding().getHandlerChain(); hc.add(new UserHandler()); bp.getBinding().setHandlerChain(hc); Source resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString))); resSource = dispatch.invoke(new DOMSource(DOMUtils.parse(reqString))); String resStr = DOMUtils.getTextContent(DOMUtils.sourceToElement(resSource).getElementsByTagName("return").item(0)); return ("Kermit|RoutOut|CustomOut|UserOut|LogOut|endpoint|LogIn|UserIn|CustomIn|RoutIn".equals(resStr)); }
public <T> Dispatch<T> createDispatch(Class<T> type, Mode mode) throws IOException { if (this.wsdlService == null) { Bus bus = BusFactory.getThreadDefaultBus(); BusFactory.setThreadDefaultBus(this.mcf.getBus()); try { this.wsdlService = Service.create(this.mcf.getWsdlUrl(), this.mcf.getServiceQName()); } finally { BusFactory.setThreadDefaultBus(bus); } if (LogManager.isMessageToBeRecorded(LogConstants.CTX_WS, MessageLevel.DETAIL)) { LogManager.logDetail(LogConstants.CTX_WS, "Created the WSDL service for", this.mcf.getWsdl()); //$NON-NLS-1$ } } Dispatch<T> dispatch = this.wsdlService.createDispatch(this.mcf.getPortQName(), type, mode); configureWSSecurity(dispatch); setDispatchProperties(dispatch, "SOAP12"); //$NON-NLS-1$ return dispatch; }
@Test @RunAsClient public void testWebService() throws Exception { URL wsdlURL = new URL(baseURL + "?wsdl"); QName serviceName = new QName(targetNS, "PingEndpointService"); QName portName = new QName(targetNS, "PingEndpointPort"); Service service = Service.create(wsdlURL, serviceName); Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD); dispatch.getRequestContext().put(BindingProvider.SOAPACTION_USE_PROPERTY, true); dispatch.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "uri:placeBuyOrder"); String payload = "<ns1:ping xmlns:ns1='" + targetNS + "'/>"; Source retObj = dispatch.invoke(new StreamSource(new StringReader(payload))); Element docElement = DOMUtils.sourceToElement(retObj); Element retElement = DOMUtils.getFirstChildElement(docElement); assertEquals("return", retElement.getLocalName()); assertEquals("\"uri:placeBuyOrder\"", retElement.getFirstChild().getNodeValue()); }
@Test @RunAsClient public void testDocBareDispatchService() throws Exception { QName serviceName = new QName(targetNS, "DocBareService"); QName portName = new QName(targetNS, "DocBarePort"); URL wsdlURL = new URL(baseURL + "/DocBareService?wsdl"); Service service = Service.create(wsdlURL, serviceName); JAXBContext jbc = JAXBContext.newInstance(new Class[] { SubmitBareRequest.class, SubmitBareResponse.class }); @SuppressWarnings("rawtypes") Dispatch dispatch = service.createDispatch(portName, jbc, Mode.PAYLOAD); SubmitBareRequest poReq = new SubmitBareRequest("Ferrari"); @SuppressWarnings("unchecked") SubmitBareResponse poRes = (SubmitBareResponse)dispatch.invoke(poReq); assertEquals("Ferrari", poRes.getProduct()); }
@Test @RunAsClient public void testWebService() throws Exception { URL wsdlURL = new URL(baseURL + "/TestService?wsdl"); QName serviceName = new QName(targetNS, "PingEndpointService"); QName portName = new QName(targetNS, "PingEndpointPort"); Service service = Service.create(wsdlURL, serviceName); Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD); String payload = "<ns1:ping xmlns:ns1='http://oneway.samples.jaxws.ws.test.jboss.org/'/>"; dispatch.invokeOneWay(new StreamSource(new StringReader(payload))); //sleep 5 sec as invokeOneWay is supposed to be non-blocking subject to the capabilities of the underlying protocol Thread.sleep(5000); payload = "<ns1:feedback xmlns:ns1='http://oneway.samples.jaxws.ws.test.jboss.org/'/>"; Source retObj = dispatch.invoke(new StreamSource(new StringReader(payload))); Element docElement = DOMUtils.sourceToElement(retObj); Element retElement = DOMUtils.getFirstChildElement(docElement); DOMWriter.printNode(retElement, false); assertEquals("return", retElement.getNodeName()); assertEquals("result: ok", retElement.getTextContent()); }
@Test @RunAsClient public void testProviderDispatch() throws Exception { Dispatch<SOAPMessage> dispatch = createDispatch("ProviderEndpoint"); SOAPMessage reqMsg = getRequestMessage(); SOAPMessage resMsg = dispatch.invoke(reqMsg); SOAPEnvelope resEnv = resMsg.getSOAPPart().getEnvelope(); SOAPHeader soapHeader = resEnv.getHeader(); if (soapHeader != null) soapHeader.detachNode(); assertEquals(DOMUtils.parse(msgString), resEnv); }
@Test @RunAsClient public void testIllegalDispatchAccess() throws Exception { URL wsdlURL = new URL(baseURL + "/TestService?wsdl"); QName serviceName = new QName(targetNS, "EndpointService"); QName portName = new QName(targetNS, "EndpointPort"); String reqPayload = "<ns1:noWebMethod xmlns:ns1='" + targetNS + "'>" + " <String_1>Hello</String_1>" + "</ns1:noWebMethod>"; Service service = Service.create(wsdlURL, serviceName); Dispatch<Source> dispatch = service.createDispatch(portName, Source.class, Mode.PAYLOAD); try { dispatch.invoke(new StreamSource(new StringReader(reqPayload))); fail("SOAPFaultException expected"); } catch (SOAPFaultException ex) { // ignore } }