10 Web Services

You can use web services platforms to integrate an Oracle Stream Analytics application with other systems. This chapter explains how to invoke services from an application and how to expose an application as a web service.

This chapter includes the following sections:

10.1 Supported Platforms

Oracle Stream Analytics supports version 2.0 of the JAX-WS API standard using the Glassfish reference implementation of JAX-WS 2.0

This includes:

  • JAX-WS 2.0 (Java API for XML Web Services, defined in JSR 224)

  • WS-I Basic Profile 1.1

  • WS-I Attachments Profile 1.0 (SOAP Messages with Attachments)

  • WS-I Simple SOAP Binding Profile 1.0

  • SOAP 1.1 and 1.2 (Simple Object Access Protocol)

  • MTOM (Message Transmission Optimization Mechanism)

  • WSDL 1.1 (Web Services Definition Language)

  • JAXB 2.0 (Java API for XML Binding, references through a separate JAXB module)

  • SAAJ 1.3 (SOAP with Attachments API for Java).

10.2 Invoke a Web Service From an Application

This procedure describes how to create an application that invokes a web service.

In this scenario, the application is the web service client.

Invoke a Web Service from an Application:

  1. Create or obtain the web service definition language (WSDL) file for the web service.

    This example uses a WSDL named EchoService.WSDL.

  2. Generate the compiled class files you need to invoke the Web Service with the following command. Keep the entire command on one line:
    java -cp /Oracle/Middleware/my_oep/modules/com.bea.core.ws.glassfish.jaxws.tools_12.0.0.0.jar com.sun.tools.ws.WsImport EchoService.WSDL
    
  3. Archive the generated class files the Oracle Stream Analytics application JAR file.
  4. Add the Export-Package header and packages to the MANIFEST.MF file to export the web services Java packages for the client code:
    Export-Package: com.oracle.ocep.sample.echoService;
    
  5. Add the following packages to the MANIFEST.MF file with the Import-Package header:
    Manifest-Version: 1.0
    Export-Package: echo
    Bundle-Vendor: %project.vendor
    Bundle-ClassPath: .,lib/echo.jar
    Bundle-Version: 1.0.0
    Bundle-Localization: bundle
    Bundle-ManifestVersion: 2
    Bundle-Name: %project.name
    Import-Package: com.bea.wlevs.configuration;version="11.1.1",com.bea.w
     levs.ede;version="11.1.1",com.bea.wlevs.ede.api;version="11.1.1",com.
     bea.wlevs.ede.impl;version="11.1.1",com.bea.wlevs.ede.spi;version="11
     .1.1",com.bea.wlevs.management.spi;version="11.1.1",com.bea.wlevs.spr
     ing;version="11.1.1",com.bea.wlevs.spring.support;version="11.1.1",co
     m.bea.wlevs.util;version="11.1.1",com.ctc.wstx.stax;version="4.0.5",c
     om.sun.xml.bind.v2;version="2.1.14",com.sun.xml.bind.v2.model.annotat
     ion;version="2.1.14",com.sun.xml.messaging.saaj.soap;version="2.1.0",
     com.sun.xml.messaging.saaj.soap.ver1_1;version="2.1.0",javax.jws,java
     x.xml,javax.xml.bind,javax.xml.bind.annotation,javax.xml.namespace,ja
     vax.xml.transform.stream,oracle.jdbc;version="1.1.0.0_11-2-0-2-0",ora
     cle.sql;version="1.1.0.0_11-2-0-2-0",org.apache.commons.logging;versi
     on="1.1.0",org.springframework.beans;version="2.5.6",org.springframew
     ork.beans.factory;version="2.5.6",org.springframework.beans.factory.c
     onfig;version="2.5.6",org.springframework.core.annotation;version="2.
     5.6",org.springframework.ejb.config,org.springframework.osgi.context;
     version="1.2.0",org.springframework.osgi.extensions.annotation;versio
     n="1.2.0",org.springframework.osgi.service;version="1.2.0",org.spring
     framework.util;version="2.5.6",org.xml.sax,org.xml.sax.ext,weblogic.j
     dbc.extensions;version="1.10.0.0",weblogic.xml.stax;version="1.10.0.0
     "
    
  6. Add the following lines of code to your application to invoke the web service:
    EchoService service = new EchoService();
    EchoPort port = service.getEchoServicePort();
    String echo = port.echo("foo");
    

10.3 Expose an Application as a Web Service

In this example, the application is the web service provider.

To Expose an Application as a Web Service:

  1. Create or obtain the WSDL for the web service.

    This example uses a WSDL named EchoService.WSDL.

  2. Implement the service.

    Consider using the java.jws annotations @WebService and @WebMethod.

  3. Add a bea-jaxws.xml file to your application bundle. Table 10-1 describes the attributes in this file.
    <endpoints>
      <endpoint>
        <name>EchoService</name>
        <implementation-class>
          com.bea.wlevs.test.echo.impl.EchoServiceImpl
        </implementation-class>
        <url-pattern>/echo</url-pattern>
        <wsdl-location>
          /META-INF/wsdl/echo.wsdl
        </wsdl-location>
        <service-name>
          {http://wsdl.oracle.com/examples/cep/echo}EchoService
        </service-name>
        <port-name>
          {http://wsdl.oracle.com/examples/cep/echo}EchoServicePort
        </port-name>
      </endpoint>
    </endpoints>
    

    Table 10-1 bea-jaxws.xml File Attributes

    Attribute Description

    name

    The name of the web service.

    implementation-class

    The class that implements the service.

    url-pattern

    The url pattern to access the web service.

    wsdl-location

    Relative path to the wsdl in the bundle.

    service-name

    QName of the service.

    port-name

    QName of the port.

  4. Reference the bea-jaxws.xml file in the MANIFEST.MF file with the BEA-JAXWS-Descriptor header:
    BEA-JAXWS-Descriptor: META-INF/bea-jaxws.xml;
    
  5. Add the Import-Package header and packages to the MANIFEST.MF file to import the following packages to the application:
    Import-Package: com.ctc.wstx.stax,
       com.bea.core.ws.glassfish.jaxws,
       com.sun.xml.bind.v2,
       com.sun.xml.messaging.saaj.soap,
       com.sun.xml.ws,
       javax.jws,
       javax.xml.bind,
       javax.xml.bind.annotation,
       javax.xml.namespace,
       javax.xml.soap,
       javax.xml.transform,
       javax.xml.transform.stream,
       javax.xml.ws,
       javax.xml.ws.spi,
       org.xml.sax,
       weblogic.xml.stax
    
  6. Add a glassfish-ws element to the Oracle Stream Analytics server DOMAIN_DIR/config/config.xml file that describes your Oracle Stream Analytics domain, where DOMAIN_DIR refers to your domain directory:
    <glassfish-ws>
        <name>JAXWS</name>
        <http-service-name>JettyServer</http-service-name>
    </glassfish-ws>