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

x33g5p2x  于2022-01-29 转载在 其他  
字(13.1k)|赞(0)|评价(0)|浏览(763)

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

Service介绍

[英]Service objects provide the client view of a Web service.

Service acts as a factory of the following:

  • Proxies for a target service endpoint.
  • Instances of javax.xml.ws.Dispatch for dynamic message-oriented invocation of a remote operation.

The ports available on a service can be enumerated using the getPorts method. Alternatively, you can pass a service endpoint interface to the unary getPort method and let the runtime select a compatible port.

Handler chains for all the objects created by a Servicecan be set by means of a HandlerResolver.

An Executor may be set on the service in order to gain better control over the threads used to dispatch asynchronous callbacks. For instance, thread pooling with certain parameters can be enabled by creating a ThreadPoolExecutor and registering it with the service.
[中]服务对象提供Web服务的客户端视图。
服务充当以下各项的工厂:
*目标服务端点的代理。
*javax的实例。xml。ws。调度远程操作的动态消息导向调用。
可以使用getPorts方法枚举服务上可用的端口。或者,您可以将服务端点接口传递给一元getPort方法,并让运行时选择一个兼容的端口。
可以通过HandlerResolver设置服务创建的所有对象的处理程序链。
可以在服务上设置执行器,以便更好地控制用于调度异步回调的线程。例如,通过创建ThreadPoolExecutor并向服务注册,可以启用具有特定参数的线程池。

代码示例

代码示例来源:origin: pentaho/pentaho-kettle

@Override public boolean test() {
 String repoUrl = repositoryMeta.getRepositoryLocation().getUrl();
 final String url = repoUrl + ( repoUrl.endsWith( "/" ) ? "" : "/" ) + "webservices/unifiedRepository?wsdl";
 Service service;
 try {
  service = Service.create( new URL( url ), new QName( "http://www.pentaho.org/ws/1.0", "unifiedRepository" ) );
  if ( service != null ) {
   IUnifiedRepositoryJaxwsWebService repoWebService = service.getPort( IUnifiedRepositoryJaxwsWebService.class );
   if ( repoWebService != null ) {
    return true;
   }
  }
 } catch ( Exception e ) {
  return false;
 }
 return false;
}

代码示例来源: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: spring-projects/spring-framework

/**
 * Create a JAX-WS Service according to the parameters of this factory.
 * @see #setServiceName
 * @see #setWsdlDocumentUrl
 */
public Service createJaxWsService() {
  Assert.notNull(this.serviceName, "No service name specified");
  Service service;
  if (this.serviceFeatures != null) {
    service = (this.wsdlDocumentUrl != null ?
      Service.create(this.wsdlDocumentUrl, getQName(this.serviceName), this.serviceFeatures) :
      Service.create(getQName(this.serviceName), this.serviceFeatures));
  }
  else {
    service = (this.wsdlDocumentUrl != null ?
        Service.create(this.wsdlDocumentUrl, getQName(this.serviceName)) :
        Service.create(getQName(this.serviceName)));
  }
  if (this.executor != null) {
    service.setExecutor(this.executor);
  }
  if (this.handlerResolver != null) {
    service.setHandlerResolver(this.handlerResolver);
  }
  return service;
}

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

@org.junit.Test
public void testSignedSAML() throws Exception {
  SpringBusFactory bf = new SpringBusFactory();
  URL busFile = ActionTest.class.getResource("client.xml");
  Bus bus = bf.createBus(busFile.toString());
  BusFactory.setDefaultBus(bus);
  BusFactory.setThreadDefaultBus(bus);
  URL wsdl = ActionTest.class.getResource("DoubleItAction.wsdl");
  Service service = Service.create(wsdl, SERVICE_QNAME);
  QName portQName = new QName(NAMESPACE, "DoubleItSignedSAMLPort");
  DoubleItPortType port =
      service.getPort(portQName, DoubleItPortType.class);
  updateAddressPort(port, PORT);
  assertEquals(50, port.doubleIt(25));
  ((java.io.Closeable)port).close();
  bus.shutdown(true);
}

代码示例来源:origin: spring-projects/spring-framework

new URL(this.wsdlLocation), new QName(clientAnn.targetNamespace(), clientAnn.name()));
return service.getPort(this.elementType);

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

@Test
public void testClientServer() throws Exception {
  Bus bus = new SpringBusFactory().createBus("org/apache/cxf/systest/ws/security/handler/client.xml");
  BusFactory.setDefaultBus(bus);
  BusFactory.setThreadDefaultBus(bus);
  Service service = Service.create(new URL("http://localhost:" + PORT + "/wsse/HelloWorldWS?wsdl"),
                   new QName("http://cxf.apache.org/wsse/handler/helloworld",
                        "HelloWorldImplService"));
  QName portName = new QName("http://cxf.apache.org/wsse/handler/helloworld", "HelloWorldPort");
  HelloWorld port = service.getPort(portName, HelloWorld.class);
  updateAddressPort(port, PORT);
  assertEquals("Hello CXF", port.sayHello("CXF"));
  bus.shutdown(true);
}

代码示例来源:origin: com.bbossgroups.rpc/bboss-rpc

public static void main(String[] args) throws Exception {
    QName serviceName = new QName("http://webservice.remote.spi.frameworkset.org/", "RPCCallService");
    QName portName = new QName("http://webservice.remote.spi.frameworkset.org/", "RPCCallServicePort");
    
    Service service = Service.create(serviceName);
    service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING,
            "http://localhost:8080/rpcws/services/RPCCallServicePort"); 
    org.frameworkset.spi.remote.webservice.RPCCallService client = service.getPort(portName,  org.frameworkset.spi.remote.webservice.RPCCallService.class);
    client.sendRPCMessage(null);
//        Dispatch
    // Insert code to invoke methods on the client here
  }

代码示例来源:origin: pentaho/pentaho-kettle

@Override
 public Object call() throws Exception {
  Service service = Service.create( url, new QName( NAMESPACE_URI, serviceName ) );
  T port = service.getPort( clazz );
  // add TRUST_USER if necessary
  if ( StringUtils.isNotBlank( System.getProperty( "pentaho.repository.client.attemptTrust" ) ) ) {
   ( (BindingProvider) port ).getRequestContext().put( MessageContext.HTTP_REQUEST_HEADERS,
     Collections.singletonMap( TRUST_USER, Collections.singletonList( username ) ) );
  } else {
   // http basic authentication
   ( (BindingProvider) port ).getRequestContext().put( BindingProvider.USERNAME_PROPERTY, username );
   ( (BindingProvider) port ).getRequestContext().put( BindingProvider.PASSWORD_PROPERTY, password );
  }
  // accept cookies to maintain session on server
  ( (BindingProvider) port ).getRequestContext().put( BindingProvider.SESSION_MAINTAIN_PROPERTY, true );
  // support streaming binary data
  // TODO mlowery this is not portable between JAX-WS implementations (uses com.sun)
  ( (BindingProvider) port ).getRequestContext().put( JAXWSProperties.HTTP_CLIENT_STREAMING_CHUNK_SIZE,
    8192 );
  SOAPBinding binding = (SOAPBinding) ( (BindingProvider) port ).getBinding();
  binding.setMTOMEnabled( true );
  return port;
 }
} );

代码示例来源:origin: citerus/dddsample-core

/**
 * 
 * @return
 *     returns HandlingReportService
 */
@WebEndpoint(name = "HandlingReportServicePort")
public HandlingReportService getHandlingReportServicePort() {
  return (HandlingReportService)super.getPort(new QName("http://ws.handling.interfaces.dddsample.citerus.se/", "HandlingReportServicePort"), HandlingReportService.class);
}

代码示例来源:origin: org.apache.camel/camel-example-cxf

public Client(String address) throws MalformedURLException {
  // create the client from the SEI
  service = Service.create(SERVICE_NAME);
  service.addPort(PORT_NAME, javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING,
          address);
  
  System.out.println("Acquiring router port ...");
  port = service.getPort(PORT_NAME, Greeter.class);
}

代码示例来源:origin: spring-projects/spring-framework

/**
 * Obtain the port stub from the given JAX-WS Service.
 * @param service the Service object to obtain the port from
 * @param portQName the name of the desired port, if specified
 * @return the corresponding port object as returned from
 * {@code Service.getPort(...)}
 */
protected Object getPortStub(Service service, @Nullable QName portQName) {
  if (this.portFeatures != null) {
    return (portQName != null ? service.getPort(portQName, getServiceInterface(), this.portFeatures) :
        service.getPort(getServiceInterface(), this.portFeatures));
  }
  else {
    return (portQName != null ? service.getPort(portQName, getServiceInterface()) :
        service.getPort(getServiceInterface()));
  }
}

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

@Test
public void testSOAPUDP() {
  BusFactory.setThreadDefaultBus(staticBus);
  Service service = Service.create(serviceName);
  service.addPort(localPortName, "http://schemas.xmlsoap.org/soap/",
          "soap.udp://localhost:" + PORT);
  Greeter greeter = service.getPort(localPortName, Greeter.class);
  String reply = greeter.greetMe("test");
  assertEquals("Hello test", reply);
  reply = greeter.sayHi();
  assertNotNull("no response received from service", reply);
  assertEquals("Bonjour", reply);
}

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

@Test
public void testEchoProviderAsync() throws Exception {
  String requestString = "<echo/>";
  Service service = Service.create(serviceName);
  service.addPort(fakePortName, javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING,
          "http://localhost:" + PORT + "/SoapContext/AsyncEchoProvider");
  Dispatch<StreamSource> dispatcher = service.createDispatch(fakePortName,
                                StreamSource.class,
                                Service.Mode.PAYLOAD);
  StreamSource request = new StreamSource(new ByteArrayInputStream(requestString.getBytes()));
  StreamSource response = dispatcher.invoke(request);
  assertEquals(requestString, StaxUtils.toString(response));
}

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

Service jaxwsService = Service.create(wsdlURL, serviceName);
Dispatch<SOAPMessage> disp = jaxwsService.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);

//Add HTTP request Headers
Map<String, List<String>> requestHeaders = new HashMap<>();
requestHeaders.put("Auth-User", Arrays.asList("BILL_GATES"));
disp.getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, requestHeaders);

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

@org.junit.Test
public void testTransformFeature() throws Exception {
  SpringBusFactory bf = new SpringBusFactory();
  URL busFile = StaxTransformFeatureTest.class.getResource("client.xml");
  Bus bus = bf.createBus(busFile.toString());
  BusFactory.setDefaultBus(bus);
  BusFactory.setThreadDefaultBus(bus);
  URL wsdl = StaxTransformFeatureTest.class.getResource("DoubleItTransform.wsdl");
  Service service = Service.create(wsdl, SERVICE_QNAME);
  QName portQName = new QName(NAMESPACE, "DoubleItPlaintextPort2");
  DoubleItPortType2 port =
      service.getPort(portQName, DoubleItPortType2.class);
  updateAddressPort(port, PORT);
  assertEquals(50, port.doubleIt2(25));
  ((java.io.Closeable)port).close();
  bus.shutdown(true);
}

代码示例来源:origin: org.springframework/spring-context

new URL(this.wsdlLocation), new QName(clientAnn.targetNamespace(), clientAnn.name()));
return service.getPort(this.elementType);

代码示例来源:origin: Talend/tesb-rt-se

public void sayHelloSoap() throws Exception {
  final QName serviceName = new QName("http://hello.com", "HelloWorld");
  final QName portName = new QName("http://hello.com", "HelloWorldPort");
  final String address = "http://localhost:" + port + "/services/soap-hello";
  System.out.println("Using JAX-WS proxy to invoke on HelloWorld service");
  Service service = Service.create(serviceName);
  service.addPort(portName, SOAPBinding.SOAP11HTTP_BINDING, address);
  HelloWorld hw = service.getPort(HelloWorld.class);
  useHelloService(hw, "Fred");
}

代码示例来源:origin: citerus/dddsample-core

/**
 * 
 * @param features
 *     A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy.  Supported features not in the <code>features</code> parameter will have their default values.
 * @return
 *     returns HandlingReportService
 */
@WebEndpoint(name = "HandlingReportServicePort")
public HandlingReportService getHandlingReportServicePort(WebServiceFeature... features) {
  return (HandlingReportService)super.getPort(new QName("http://ws.handling.interfaces.dddsample.citerus.se/", "HandlingReportServicePort"), HandlingReportService.class, features);
}

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

@Test
public void testServerAsync() throws Exception {
  Service service = Service.create(serviceName);
  service.addPort(fakePortName, javax.xml.ws.soap.SOAPBinding.SOAP11HTTP_BINDING,
    "http://localhost:" + PORT + "/SoapContext/AsyncSoapPort");
  Greeter greeter = service.getPort(fakePortName, Greeter.class);
  String resp = greeter.greetMe("World");
  assertEquals("Hello World", resp);
}

代码示例来源:origin: org.springframework/spring-web

/**
 * Obtain the port stub from the given JAX-WS Service.
 * @param service the Service object to obtain the port from
 * @param portQName the name of the desired port, if specified
 * @return the corresponding port object as returned from
 * {@code Service.getPort(...)}
 */
protected Object getPortStub(Service service, @Nullable QName portQName) {
  if (this.portFeatures != null) {
    return (portQName != null ? service.getPort(portQName, getServiceInterface(), this.portFeatures) :
        service.getPort(getServiceInterface(), this.portFeatures));
  }
  else {
    return (portQName != null ? service.getPort(portQName, getServiceInterface()) :
        service.getPort(getServiceInterface()));
  }
}

相关文章