Go to primary content
Oracle Agile Engineering Data Management Web Services Guide for Agile
Release e6.2.0.0
E52562-01
  Go To Table Of Contents
Contents

Previous
Previous
 
 

7 Appendix

7.1 SAMPLES

7.1.1 EchoServiceWrapper.java

This wrapper does not call an outbound Web Service. It returns the arguments that have been passed. This wrapper is already contained inside the Web Services application and can be used to test the infrastructure.

/*
* $Id: EchoServiceWrapper.java,v 1.3 2010/10/15 15:11:56 brg Exp $
 *
 * Copyright (c) 1992, 2010, Oracle. All rights reserved.
 */
package com.agile.ws.e6.wrappers;
 
import com.agile.eci.EciConnection;
import com.agile.eci.EciPar;
import com.agile.eci.EciParBuffer;
import com.agile.share.callable.CallableParam;
import com.agile.share.trace.Logger;
import com.agile.share.trace.Trace;
import com.agile.share.util.StringArray;
import com.agile.share.util.StringList;
import com.agile.ws.e6.PlmSession;
import com.agile.ws.e6.wrappersupport.WrapperContext;
 
import java.net.InetAddress;
 
/**
 * A simple echo wrapper to test the wrapper mechanism.
 */
public class EchoServiceWrapper extends AbstractWrapper {
  
   private static Logger log = Trace.getLogger(EchoServiceWrapper.class);
  
   /**
    * The name of this service wrapper.
    */
   public static final String NAME = EchoServiceWrapper.class.getSimpleName();
 
   /**
    * Creates a new echo service.
    */
   public EchoServiceWrapper() {
      super(NAME);
   }
  
   /** {@inheritDoc} */
   @Override
   public StringList callWebService(WrapperContext context, CallableParam args) {
     
      log.enter("callWebService", "context="+context+", args="+args);
      PlmSession session = null;
      String userName = "<unknown>";
      String processId = "<unknown>";
     
      try {
         session = createPlmSession(context);
         EciConnection con = session.getConnection();
        
         EciPar par = con.call("eci_rea_edb_usr");
        
         userName = par.get(1);
         log.info("My name is " + userName + "," +
               "\nI belong to the group " + par.get(2) +
               ".\nMy user ID is " + par.get(3) + "," +
               "\nmy group ID is " + par.get(4) +
               "\nand I am " + ("y".equals(par.get(5)) ? "" : "not ") + "a manager" +
               ".\n" +
               "\nOur session is " + session + ".\n");
        
         par = con.call("eci_get_pid");
         processId = par.get(1);
        
         EciParBuffer buf = new EciParBuffer();
         buf.add("EDB-BAS-WARNING");
         buf.addNew("This is the e6 EchoService running inside WebLogic on host " +
               InetAddress.getLocalHost().getHostName() + "\n\n" +
               "You are " + userName + " and your process ID is " + processId);
         buf.end();
         con.call("eci_mes_wri", buf);
      }
      catch (Exception e) {
         log.error("Unable to reconnect to e6: ", e);
      }
      finally {
         if (session != null) {
            session.close();
         }
      }
      StringList result = new StringArray(args.getParam());
      log.leave("callWebService", "result=" + result);
      return result;
   }
}
 
 

7.1.2 SampleWrapper.java

This wrapper calls an Agile e6 core service as an example. The generated client code needed to call the Agile e6 Core Web Service is not included. The generated classes belong to the wrapper and need to be deployed along with it.

The SampleWrapper class needs a property file, SampleWrapper.properties, which contains the URL of the Web Service.

When Agile e6 application wants to call a wrapper called Sample, it passes Sample as the first argument to xutil_call_ws. The wrapper manager then looks for a class called SampleWrapper in all the packages in its search path. To call the EchoServiceWrapper, pass EchoService to xutil_call_ws.

/*
* $Id: SampleWrapper.java,v 1.1.2.2 2011/06/30 15:53:27 brg Exp $
 *
 * Copyright (c) 1992, 2011, Oracle. All rights reserved.
 */
 
package com.agile.ws.e6.wrappers;
 
import com.agile.eci.EciConnection;
import com.agile.eci.EciPar;
import com.agile.eci.EciParBuffer;
import com.agile.security.tickets.plm.PlmTicket;
import com.agile.share.callable.CallableException;
import com.agile.share.callable.CallableParam;
import com.agile.share.trace.Logger;
import com.agile.share.trace.Trace;
import com.agile.share.util.StringArray;
import com.agile.share.util.StringList;
import com.agile.ws.e6.PlmSession;
import com.agile.ws.e6.WebServiceEnum;
import com.agile.ws.e6.client.core.common.PlmUserContext;
import com.agile.ws.e6.client.core.common.PlmUserContextUserInfo;
import com.agile.ws.e6.client.core.configuration.Configuration;
import com.agile.ws.e6.client.core.configuration.ConfigurationService;
import com.agile.ws.e6.client.core.configuration.GetUserContextRequestType;
import com.agile.ws.e6.client.core.configuration.GetUserContextResponseType;
import com.agile.ws.e6.wrappersupport.WrapperContext;
 
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException;
import java.util.Properties;
 
import javax.xml.namespace.QName;
import javax.xml.ws.BindingProvider;
 
/**
 * A simple example of a wrapper for an out-bound web service call.
 *
 * <p>It extends the abstract wrapper implementation, which is shipped
 * in the library agile-ws-e6-callables as part of the WebServices.ear file.
 *
* <p>Alternatively, a JAR file containing the wrapper can be added to the
 * WebServices application into the APP_INF/lib directory,
 * so that it is deployed as part of the WebServices application.
 */
public class SampleWrapper extends AbstractWrapper {
   /** The Logger used to print trace messages */
   private static Logger log = Trace.getLogger(SampleWrapper.class);
  
   /** The name of our properties file */
   private static final String SAMPLE_PROPERTIES = "SampleWrapper.properties";
   /** Property containing the URL of the external web service */
   private static final String PROP_ENDPOINT = "Sample.endPoint";
  
   /**
    * The service we want to contact.
    *
    * <p>This class - and all the others in the package com.agile.ws.e6.client.core - is
    * generated by the WebLogic clientgen Ant task.
    */
   private ConfigurationService configurationService;
   /** The URL to the Configuration service */
   private String configurationEndPoint;
 
   /**
    * The name of this service wrapper.
    */
   public static final String NAME = "Sample";
  
   /**
    * Creates a new HelloWorld service.
    */
   public SampleWrapper() {
      super(NAME);
   }  
  
   /**
    * @return the RCS information of this object's class (polymorphic)
    */
   @Override
   public final String getRCSId() {
      return getClassRCSId();
   }
 
   /**
    * @return the RCS information of this class (static)
    */
   public static String getClassRCSId() {
      return "$Id: SampleWrapper.java,v 1.1.2.2 2011/06/30 15:53:27 brg Exp $";
   }
  
   /**
    * Creates the port to access the Configuration service.
    *
    * @param endPoint the WSDL URL of the service.
    * @param ticket the PLM ticket provided by the e6 server
    *
    * @return the port to call the Configuration service
    */
   private Configuration getConfigurationPort(PlmTicket ticket) throws MalformedURLException {
      if (configurationService == null) {
         configurationService = new ConfigurationService(
               new URL(configurationEndPoint),
               new QName(WebServiceEnum.CONFIGURATION.getNamespace(),
                         WebServiceEnum.CONFIGURATION.getServiceName()));
      }
     
      Configuration port = configurationService.getConfigurationPort();
 
      BindingProvider binding = (BindingProvider) port;
     
      // Add authentication, we have a ticket so we do not need the password
      binding.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, ticket.getUserName());
      binding.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, String.valueOf(ticket.getRawTicket()));
     
      // Maintain the HTTP session, in case we do several calls to the server
      binding.getRequestContext().put(BindingProvider.SESSION_MAINTAIN_PROPERTY, Boolean.TRUE);
     
      return port;
   }
  
   /**
    * Calls the web service.
    *
    * @param context the context that contains the reference to the e6 server
    * @param args arguments passed by the e6 server
    * @return list of return values, or null
    *
    * @throws CallableException Web service call failed
    */
   @Override
   public final StringList callWebService(final WrapperContext context, final CallableParam args) throws CallableException {
      log.enter("callWebService", "context="+context+", args="+args);
     
      // Try to load our properties
      Properties sampleProps = new Properties();
     
      try {
         sampleProps.load(getClass().getResourceAsStream("/" + SAMPLE_PROPERTIES));
         configurationEndPoint = sampleProps.getProperty(PROP_ENDPOINT);
      }
      catch (Exception e) {
         String msg = "Unable to load SampleWrapper.properties";
         log.error(msg, e);
         throw new CallableException(this, msg);
      }
      if (configurationEndPoint == null) {
         log.error("No WSDL URL found in " + SAMPLE_PROPERTIES);
         throw new CallableException(this, "No web service URL configured for the Sample wrapper");
      }
     
      log.info("Using WSDL at " + configurationEndPoint);
     
      Configuration port = null;
      StringList result = new StringArray();
           
      try {
         // Create a session object:
         //
         // It gives us access to an ECI connection to the same e6 server instance that called us,
         // and - if needed - it will create an AxalantRepository instance for us,
         // if we want to make use of the high level Java ECI (JET layer).
         PlmSession session = createPlmSession(context);
        
         // First some ECI calls
         callEciDemo(session);
        
         // Now the "external" web service call.
         //
         // Here, we would normally call an external service of another system,
         // but for demo purposes, we just call an e6 Core service.
         port = getConfigurationPort(context.getPlmTicket());
         log.info("Port created with PLM ticket");
        
         GetUserContextRequestType request = new GetUserContextRequestType();
         GetUserContextResponseType response = port.getUserContext(request);
         log.info("Web method getUserContext() returned with status code " + response.getStatusCode());
        
         PlmUserContext e6Context = response.getPlmUserContext();
         PlmUserContextUserInfo userInfo = e6Context.getPlmUserInfo();
        
         result.add("User name  = " + userInfo.getUserName());
         result.add("Group name = " + userInfo.getGroup());
         result.add("Language   = " + userInfo.getUserLanguage());
         result.add("Locale     = " + userInfo.getUserLocale());
        
      }
      catch (Exception e) {
         log.error("Unable to call web service", e);
         throw new CallableException(this, "Web service call failed", e);
      }
      finally {
         if (port != null) {
            try {
               // Tell the server that we no longer need the e6 session.
               port.closeSession();
            }
            catch (Exception e) {
               log.error("Unable to close port", e);
            }
         }
      }
      return result;
   }
 
   /**
    * Calls some ECI functions to demonstrate how to get additional data.
    *
    * @param session the e6 PLM session
    */
   private void callEciDemo(PlmSession session) {
      String userName = null;
      String processId = null;
      String host;
     
      try {
         host = InetAddress.getLocalHost().getHostName();
      }
      catch (UnknownHostException e) {
         host = "unknown host";
      }
 
      EciConnection con = session.getConnection();
     
      EciPar par = con.call("eci_rea_edb_usr");
     
      userName = par.get(1);
      log.info("My name is " + userName + "," +
            "\nI belong to the group " + par.get(2) +
            ".\nMy user ID is " + par.get(3) + "," +
            "\nmy group ID is " + par.get(4) +
            "\nand I am " + ("y".equals(par.get(5)) ? "" : "not ") + "a manager" +
            ".\n" +
            "\nOur session is " + session + ".\n");
     
      par = con.call("eci_get_pid");
      processId = par.get(1);
     
      EciParBuffer buf = new EciParBuffer();
      buf.add("EDB-BAS-WARNING");
      buf.addNew("This is the e6 SampleWrapper running inside WebLogic on host " +
            host + "\n\n" +
            "You are " + userName + " and your process ID is " + processId);
      buf.end();
      // Prints a message on the client that contacted us
      con.call("eci_mes_wri", buf);
   }
}
 

7.1.3 Web Services Security

In the following example, a Web Services policy is used for the WSS: SOAP Message Security.

You are required to provide the username token and a client certificate. The complete security information is embedded into the SOAP message.


Note:

By configuring WSS: SOAP Message Security, the WSDL gets modified.

<?xml version='1.0' encoding='UTF-8'?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Header>
        <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                       S:mustUnderstand="1">
            <ns1:EncryptedKey xmlns:ns1="http://www.w3.org/2001/04/xmlenc#" Id="JOLZ6aDu8pt9PRPe">
                <ns1:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p">
                    <ns2:DigestMethod xmlns:ns2="http://www.w3.org/2000/09/xmldsig#"
                                      Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                </ns1:EncryptionMethod>
                <ns3:KeyInfo xmlns:ns3="http://www.w3.org/2000/09/xmldsig#">
                    <wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                                                 xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                                                 wsu:Id="str_kNu7Vfo6pZLqdYcv">
                        <X509Data xmlns="http://www.w3.org/2000/09/xmldsig#">
                            <X509IssuerSerial>
                                <X509IssuerName>CN=CertGenCAB,OU=FOR TESTING ONLY,O=MyOrganization,L=MyTown,ST=MyState,C=US</X509IssuerName>
                                <X509SerialNumber>-135694037818432800534509206009756866711</X509SerialNumber>
                            </X509IssuerSerial>
                        </X509Data>
                    </wsse:SecurityTokenReference>
                </ns3:KeyInfo>
                <ns1:CipherData>
                    <ns1:CipherValue>JHUAfXjSBYxXKAGrpQ............NUWGQ9IPL9M1uODqmnQ8Nlk=</ns1:CipherValue>
                </ns1:CipherData>
                <ns1:ReferenceList>
                    <ns1:DataReference URI="#PJr5jO7puKh5OL5b" />
                </ns1:ReferenceList>
            </ns1:EncryptedKey>
            <wsse:BinarySecurityToken xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                                      xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                                      EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary"
                                      ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
                                      wsu:Id="bst_GpDR1niRFucsZsbm">MIICKzCc.......KMuSA1XAQ==</wsse:BinarySecurityToken>
            <dsig:Signature xmlns:dsig="http://www.w3.org/2000/09/xmldsig#">
                <dsig:SignedInfo>
                    <dsig:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                    <dsig:SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#rsa-sha1" />
                    <dsig:Reference URI="#Timestamp_KKvWCLdlrCRB2SNF">
                        <dsig:Transforms>
                            <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                        </dsig:Transforms>
                        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                        <dsig:DigestValue>xndjH7PWB/yinv/uFzmElQzAezI=</dsig:DigestValue>
                    </dsig:Reference>
                    <dsig:Reference URI="#Body_0lUdcO0zqWY2bBvU">
                        <dsig:Transforms>
                            <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                        </dsig:Transforms>
                        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                        <dsig:DigestValue>gt0av56Xh/gca30jxtDChJkFZck=</dsig:DigestValue>
                    </dsig:Reference>
                    <dsig:Reference URI="#unt_UROJpKRFSAIZLKFf">
                        <dsig:Transforms>
                            <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                        </dsig:Transforms>
                        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                        <dsig:DigestValue>QBSH0z6BxmZgEM56+g3ZS2w00lg=</dsig:DigestValue>
                    </dsig:Reference>
                    <dsig:Reference URI="#bst_GpDR1niRFucsZsbm">
                        <dsig:Transforms>
                            <dsig:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
                        </dsig:Transforms>
                        <dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1" />
                        <dsig:DigestValue>62PwFQZD1Nj1R77qudrvzJCIUNE=</dsig:DigestValue>
                    </dsig:Reference>
                </dsig:SignedInfo>
                <dsig:SignatureValue>TfFLyCR9MF4ZepqwmnCned7mj5TavfwjDg69.......MIFR3kBU=</dsig:SignatureValue>
                <dsig:KeyInfo>
                    <wsse:SecurityTokenReference xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
                                                 xmlns:wsse11="http://docs.oasis-open.org/wss/oasis-wss-wssecurity-secext-1.1.xsd"
                                                 xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                                                 wsse11:TokenType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3"
                                                 wsu:Id="str_KVJy1AtKNAxVYsKq">
                        <wsse:Reference URI="#bst_GpDR1niRFucsZsbm"
                                        ValueType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3" />
                    </wsse:SecurityTokenReference>
                </dsig:KeyInfo>
            </dsig:Signature>
            <ns1:EncryptedData xmlns:ns1="http://www.w3.org/2001/04/xmlenc#" Encoding="UTF-8" Id="PJr5jO7puKh5OL5b" MimeType="text/xml"
                               Type="http://www.w3.org/2001/04/xmlenc#Element">
                <ns1:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc" />
                <ns1:CipherData>
                    <ns1:CipherValue>yG4ULSKvJFL8......OgqkcPmY6yhdpoE=</ns1:CipherValue>
                </ns1:CipherData>
            </ns1:EncryptedData>
            <wsu:Timestamp xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
                           wsu:Id="Timestamp_KKvWCLdlrCRB2SNF">
                <wsu:Created>2010-02-03T14:44:31Z</wsu:Created>
                <wsu:Expires>2010-02-03T14:45:31Z</wsu:Expires>
            </wsu:Timestamp>
        </wsse:Security>
    </S:Header>
    <S:Body xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"
            wsu:Id="Body_0lUdcO0zqWY2bBvU">
        <ns4:hello xmlns:ns2="http://xmlns.oracle.com/Agile/e6/Metadata/v0"
                   xmlns:ns3="http://xmlns.oracle.com/Agile/e6/plm"
                   xmlns:ns4="http://xmlns.oracle.com/Agile/e6/HelloWorld/v0" />
    </S:Body>
</S:Envelope>

In the following example, WSS: SOAP Message Security information is provided for the SOAP request:

MetadataService service = new MetadataService(wsdlURL, serviceQName);
BindingProvider bindingProvider = (BindingProvider) service.getPort();
List<CredentialProvider> credProviders = new ArrayList<CredentialProvider>(); 
try {
  // Load server certificate
  X509Certificate serverCert = (X509Certificate)CertUtils.getCertificate(serverCertFile);
 
  // Check server certificate
  serverCert.checkValidity();
 
  // Create a new certificate credential provider
  CredentialProvider cp = new ClientBSTCredentialProvider(clientKeyStore,
               clientKeyStorePass, clientKeyAlias, clientKeyPass, "JKS", serverCert);
 
  // Add certificate credential provider to the array list
 credProviders.add(cp); 
           
  // Create a new username token credential provider  
  CredentialProvider up = new ClientUNTCredentialProvider(username.getBytes(), password.getBytes()); 
 
  // Add certificate username token credential provider to the array list
  credProviders.add(up); 
           
  Map<String, Object> rc = ((BindingProvider)portName).getRequestContext(); 
 
  // Add the credential providers to the request context
  rc.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders); 
     
  // Add a trusr manager to the request context, you can do here some validation tests on the return certificate of the SOAP message
  rc.put(WSSecurityContext.TRUST_MANAGER,
                    new TrustManager(){
                      public boolean certificateCallback(X509Certificate[] chain, int validateErr){
                        return true;
                      }
                    } );
} catch (Exception e) {
  log.printStackTrace(e);}