javax.xml.ws.Dispatch类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(14.3k)|赞(0)|评价(0)|浏览(206)

本文整理了Java中javax.xml.ws.Dispatch类的一些代码示例,展示了Dispatch类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dispatch类的具体详情如下:
包路径:javax.xml.ws.Dispatch
类名称:Dispatch

Dispatch介绍

[英]The Dispatch interface provides support for the dynamic invocation of a service endpoint operations. The javax.xml.ws.Serviceclass acts as a factory for the creation of Dispatchinstances.
[中]Dispatch接口为服务端点操作的动态调用提供支持。javax。xml。ws。Serviceclass充当创建Dispatchinstances的工厂。

代码示例

代码示例来源:origin: org.picketlink/picketlink-trust-jbossws

public Map<String, Object> getRequestContext()
{
 return parent.getRequestContext();
}

代码示例来源:origin: stackoverflow.com

import javax.xml.bind.JAXBContext;
import javax.xml.namespace.QName;
import javax.xml.ws.Dispatch;
import javax.xml.ws.Service;
import javax.xml.ws.soap.SOAPBinding;
import blog.jaxws.provider.*;

public class Demo {

  public static void main(String[] args) throws Exception {
    QName serviceName = new QName("http://service.jaxws.blog/", "FindCustomerService");
    Service service = Service.create(serviceName);
    QName portQName = new QName("http://example.org", "SimplePort");
    service.addPort(portQName, SOAPBinding.SOAP11HTTP_BINDING, "http://localhost:8080/Provider/FindCustomerService?wsdl");

    JAXBContext jc = JAXBContext.newInstance(FindCustomerRequest.class, FindCustomerResponse.class);
    Dispatch<Object> sourceDispatch = service.createDispatch(portQName, jc, Service.Mode.PAYLOAD);
    FindCustomerRequest request = new FindCustomerRequest();
    FindCustomerResponse response = (FindCustomerResponse) sourceDispatch.invoke(request);
    System.out.println(response.getValue().getFirstName());
  }

}

代码示例来源:origin: org.picketlink/picketlink-trust-jbossws

@SuppressWarnings("unchecked")
public void invokeOneWay(Source msg)
{
 parent.invokeOneWay(msg);
}

代码示例来源:origin: apache/cxf

@Test
public void testDuplicateHeaders() throws Exception {
  URL wsdl = getClass().getResource("/wsdl_systest_wsspec/add_numbers.wsdl");
  assertNotNull("WSDL is null", wsdl);
  AddNumbersService service = new AddNumbersService(wsdl, serviceName);
  QName portName = new QName("http://apache.org/cxf/systest/ws/addr_feature/", "AddNumbersPort");
  Dispatch<SOAPMessage> disp = service.createDispatch(portName, SOAPMessage.class,
                            Service.Mode.MESSAGE,
                            new AddressingFeature(false, false));
  disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
               "http://localhost:" + PORT + "/jaxws/add");
  InputStream msgIns = getClass().getResourceAsStream("./duplicate-wsa-header-msg.xml");
  String msg = new String(IOUtils.readBytesFromStream(msgIns));
  msg = msg.replaceAll("$PORT", PORT);
  ByteArrayInputStream bout = new ByteArrayInputStream(msg.getBytes());
  SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, bout);
  assertNotNull(soapReqMsg);
  try {
    disp.invoke(soapReqMsg);
    fail("SOAPFaultFxception is expected");
  } catch (SOAPFaultException ex) {
    assertTrue("WSA header exception is expected",
          ex.getMessage().indexOf("A header representing a Message Addressing") > -1);
  }
}

代码示例来源:origin: apache/cxf

public ProbeMatchesType probe(ProbeType params, int timeout) {
  Dispatch<Object> disp = this.getDispatchInternal(false, version.getProbeAction());
  if (adHoc) {
    disp.getRequestContext().put("udp.multi.response.timeout", timeout);
    final ProbeMatchesType response = new ProbeMatchesType();
    AsyncHandler<Object> handler = new AsyncHandler<Object>() {
            QName sn = version.getServiceName();
            if (h.getTypes().contains(sn)
              || h.getTypes().contains(new QName("", sn.getLocalPart()))) {
    disp.invokeAsync(new ObjectFactory().createProbe(params), handler);
    return response;
  Object o = disp.invoke(new ObjectFactory().createProbe(params));
  while (o instanceof JAXBElement) {
    o = ((JAXBElement)o).getValue();

代码示例来源:origin: be.e_contract.mycarenet/mycarenet-ehealth-saml-sts

/**
 * Main constructor.
 * 
 * @param location
 *            the URL of the eHealth STS web service.
 */
public EHealthSTSClient(String location) {
  EHealthSamlStsService service = EHealthSamlStsServiceFactory.newInstance();
  QName portQName = new QName("urn:be:ehealth:saml:sts:1.0", "EHealthSamlStsPort");
  this.dispatch = service.createDispatch(portQName, Source.class, Service.Mode.PAYLOAD);
  this.dispatch.getRequestContext().put(Dispatch.ENDPOINT_ADDRESS_PROPERTY, location);
  Binding binding = dispatch.getBinding();
  @SuppressWarnings("rawtypes")
  List<Handler> handlerChain = binding.getHandlerChain();
  this.wsSecuritySOAPHandler = new WSSecuritySOAPHandler();
  handlerChain.add(this.wsSecuritySOAPHandler);
  handlerChain.add(new LoggingHandler());
  binding.setHandlerChain(handlerChain);
}

代码示例来源:origin: apache/cxf

Source.class, Mode.PAYLOAD);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
               "http://localhost:" + PORT + "/jaxws/add");
disp.invoke(new StreamSource(new StringReader(req)));
               Source.class, Mode.PAYLOAD);
disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
               "http://localhost:" + PORT + "/jaxws/add");
disp.getRequestContext().put(MessageContext.WSDL_OPERATION,
               new QName("http://apache.org/cxf/systest/ws/addr_feature/",
                    "addNumbers"));
disp.invoke(new StreamSource(new StringReader(req)));

代码示例来源:origin: apache/cxf

@org.junit.Test
public void testProviderSource() throws Exception {
  QName providerServiceName = new QName("http://apache.org/hello_world_xml_http/bare",
                     "HelloProviderService");
  QName providerPortName = new QName("http://apache.org/hello_world_xml_http/bare", "HelloProviderPort");
  URL wsdl = new URL("http://localhost:" + EmptySoapProviderServer.REG_PORT
            + "/helloProvider/helloPort?wsdl");
  assertNotNull(wsdl);
  XMLService service = new XMLService(wsdl, providerServiceName, new LoggingFeature());
  assertNotNull(service);
  Dispatch<Source> dispatch = service.createDispatch(providerPortName, Source.class,
                            javax.xml.ws.Service.Mode.PAYLOAD);
  String str = new String("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"><soap:Body>"
             + "<ns2:in xmlns=\"http://apache.org/hello_world_xml_http/bare/types\""
             + " xmlns:ns2=\"http://apache.org/hello_world_xml_http/bare\">"
             + "<elem1>empty</elem1><elem2>this is element 2</elem2><elem3>42</elem3></ns2:in>"
             + "</soap:Body></soap:Envelope>");
  StreamSource req = new StreamSource(new StringReader(str));
  Source resSource = dispatch.invoke(req);
  Assert.assertNull("null result is expected", resSource);
}

代码示例来源:origin: apache/cxf

@Test
public void testInvokeWithDOMSourcMessageModeXMLBinding() throws Exception {
  URL wsdl = getClass().getResource("/wsdl/addNumbers.wsdl");
  assertNotNull(wsdl);
  XMLService service = new XMLService();
  assertNotNull(service);
  Dispatch<DOMSource> disp = service.createDispatch(portNameXML, DOMSource.class, Mode.MESSAGE);
  setAddress(disp, addNumbersAddress);
  TestHandlerXMLBinding handler = new TestHandlerXMLBinding();
  addHandlersProgrammatically(disp, handler);
  InputStream is = getClass().getResourceAsStream("/messages/XML_GreetMeDocLiteralReq.xml");
  MessageFactory factory = MessageFactory.newInstance();
  SOAPMessage soapReq = factory.createMessage(null, is);
  DOMSource domReqMessage = new DOMSource(soapReq.getSOAPPart());
  DOMSource response = disp.invoke(domReqMessage);
  assertNotNull(response);
}

代码示例来源:origin: apache/cxf

Dispatch<DOMSource> disp = service.createDispatch(PORT_NAME, DOMSource.class, Service.Mode.MESSAGE);
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
DOMSource domReqMsg = new DOMSource(soapReqMsg.getSOAPPart());
assertNotNull(domReqMsg);
DOMSource domResMsg = disp.invoke(domReqMsg);
assertNotNull(domResMsg);
String expected = "Hello TestSOAPInputMessage";
SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
DOMSource domReqMsg1 = new DOMSource(soapReqMsg1.getSOAPPart());
assertNotNull(domReqMsg1);
disp.invokeOneWay(domReqMsg1);
assertNotNull(domReqMsg2);
Response<DOMSource> response = disp.invokeAsync(domReqMsg2);
DOMSource domRespMsg2 = response.get();
assertNotNull(domReqMsg2);
Future<?> fd = disp.invokeAsync(domReqMsg3, tdsh);
assertNotNull(fd);
waitForFuture(fd);

代码示例来源:origin: apache/cxf

@Test
public void testSOAPMessageWithMalformedResponse() throws Exception {
  URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
  assertNotNull(wsdl);
  SOAPService service = new SOAPService(wsdl, SERVICE_NAME);
  assertNotNull(service);
  Dispatch<SOAPMessage> disp = service
    .createDispatch(PORT_NAME, SOAPMessage.class, Service.Mode.MESSAGE);
  disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                 "http://localhost:"
                 + greeterPort
                 + "/SOAPDispatchService/SoapDispatchPort");
  // Test async callback
  InputStream is3 = getClass().getResourceAsStream("resources/GreetMeDocLiteralReq3.xml");
  SOAPMessage soapReqMsg3 = MessageFactory.newInstance().createMessage(null, is3);
  assertNotNull(soapReqMsg3);
  TestSOAPMessageHandler tsmh = new TestSOAPMessageHandler();
  Future<?> f = disp.invokeAsync(soapReqMsg3, tsmh);
  assertNotNull(f);
  waitForFuture(f);
  assertEquals("AsyncHandler shouldn't get invoked more than once", asyncHandlerInvokedCount, 1);
}

代码示例来源:origin: apache/cxf

disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
               "http://localhost:"
               + greeterPort
SOAPMessage soapReqMsg = MessageFactory.newInstance().createMessage(null, is);
assertNotNull(soapReqMsg);
SOAPMessage soapResMsg = disp.invoke(soapReqMsg);
SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
assertNotNull(soapReqMsg1);
disp.invokeOneWay(soapReqMsg1);
assertNotNull(soapReqMsg2);
Response<?> response = disp.invokeAsync(soapReqMsg2);
SOAPMessage soapResMsg2 = (SOAPMessage)response.get();
assertNotNull(soapResMsg2);
assertNotNull(soapReqMsg3);
TestSOAPMessageHandler tsmh = new TestSOAPMessageHandler();
Future<?> f = disp.invokeAsync(soapReqMsg3, tsmh);
assertNotNull(f);
waitForFuture(f);

代码示例来源:origin: apache/cxf

SOAPMessage soapReqMsg1 = MessageFactory.newInstance().createMessage(null, is1);
assertNotNull(soapReqMsg1);
disp.invoke(soapReqMsg1);
  disp.invokeAsync(soapReqMsg1, callback);
  callback.wait();

代码示例来源:origin: stackoverflow.com

SOAPMessage.class, Service.Mode.MESSAGE);
dispatch.getRequestContext().put(Dispatch.SOAPACTION_USE_PROPERTY, new Boolean(true));
dispatch.getRequestContext().put(Dispatch.SOAPACTION_URI_PROPERTY, soapActionUri);
SOAPMessage message = messageFactory.createMessage();
SOAPMessage response = (SOAPMessage) dispatch.invoke(message);

代码示例来源:origin: apache/cxf

disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
               "http://localhost:"
               + greeterPort
               + "/SOAPDispatchService/SoapDispatchPort");
SAXSource saxSourceResp = disp.invoke(saxSourceReq);
assertNotNull(saxSourceResp);
String expected = "Hello TestSOAPInputMessage";
SAXSource saxSourceReq1 = new SAXSource(inputSource1);
assertNotNull(saxSourceReq1);
disp.invokeOneWay(saxSourceReq1);
assertNotNull(saxSourceReq2);
Response<SAXSource> response = disp.invokeAsync(saxSourceReq2);
SAXSource saxSourceResp2 = response.get();
assertNotNull(saxSourceResp2);
assertNotNull(saxSourceReq3);
TestSAXSourceHandler tssh = new TestSAXSourceHandler();
Future<?> fd = disp.invokeAsync(saxSourceReq3, tssh);
assertNotNull(fd);
waitForFuture(fd);

代码示例来源:origin: org.switchyard.components/switchyard-component-soap

@SuppressWarnings("unchecked")
Map<String, List<String>> httpHeaders =
  (Map<String, List<String>>) _dispatcher.getRequestContext().get(MessageContext.HTTP_REQUEST_HEADERS);
if (httpHeaders == null) {
  httpHeaders = new HashMap<String, List<String>>();
  _dispatcher.getRequestContext()
       .put(MessageContext.HTTP_REQUEST_HEADERS, httpHeaders);
      CastUtils.cast((Map<?, ?>)_dispatcher.getRequestContext().get(org.apache.cxf.message.Message.PROTOCOL_HEADERS));
  if (reqHeaders.containsKey(org.apache.cxf.binding.soap.SoapBindingConstants.SOAP_ACTION)) {
    reqHeaders.remove(org.apache.cxf.binding.soap.SoapBindingConstants.SOAP_ACTION);
  _dispatcher.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY, "\"" + action + "\"");
  _dispatcher.invokeOneWay(soapMessage);
  response = _dispatcher.invoke(soapMessage);

代码示例来源:origin: be.e_contract.mycarenet/mycarenet-ehealth-ehealthbox

public String invoke(String request) {
  Source responseSource = this.publicationDispatch
      .invoke(new StreamSource(new StringReader(request)));
  LOG.debug("response Source type: "
      + responseSource.getClass().getName());
  return toString(responseSource);
}

代码示例来源:origin: apache/cxf

@Test
public void testDispatchActionMissmatch() throws Exception {
  String req = "<S:Envelope xmlns:S=\"http://schemas.xmlsoap.org/soap/envelope/\">"
        + "<S:Body><addNumbers3 xmlns=\"http://apache.org/cxf/systest/ws/addr_feature/\">"
        + "<number1>1</number1><number2>2</number2></addNumbers3>"
        + "</S:Body></S:Envelope>";
  //String base = "http://apache.org/cxf/systest/ws/addr_feature/AddNumbersPortType/";
  String expectedOut = "http://bad.action";
  URL wsdl = getClass().getResource("/wsdl_systest_wsspec/add_numbers.wsdl");
  assertNotNull("WSDL is null", wsdl);
  AddNumbersService service = new AddNumbersService(wsdl, serviceName);
  Dispatch<Source> disp = service.createDispatch(AddNumbersService.AddNumbersPort,
                          Source.class, Mode.MESSAGE);
  disp.getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                 "http://localhost:" + PORT + "/jaxws/add");
  //manually set the action
  disp.getRequestContext().put(BindingProvider.SOAPACTION_URI_PROPERTY,
                 expectedOut);
  disp.getRequestContext().put(ContextUtils.ACTION,
                 expectedOut + "/wsaAction");
  try {
    disp.invoke(new StreamSource(new StringReader(req)));
    fail("no exception");
  } catch (SOAPFaultException f) {
    //expected
  }
}

代码示例来源:origin: org.teiid.connectors/connector-ws

if (credential != null) {
  if (credential.useSts()) {
    dispatch.getRequestContext().put(SecurityConstants.STS_CLIENT, credential.buildStsClient(bus));
    dispatch.getRequestContext().putAll(credential.getRequestPropterties());
    dispatch.getResponseContext().putAll(credential.getResponsePropterties());

代码示例来源:origin: org.picketlink/picketlink-trust-jbossws

Binding binding = dispatch.getBinding();
 SecurityActions.setSystemProperty("org.jboss.security.ssl.domain.name", securityDomainForFactory);
 dispatch.getRequestContext().put( "org.jboss.ws.socketFactory", sslFactoryName);

相关文章