WebServiceConnectOptions.java

/*
** Module   : WebServiceConnectOptions.java
** Abstract : Container for various web-service connect options.
**
** Copyright (c) 2016-2024, Golden Code Development Corporation.
**
** -#- -I- --Date-- ---------------------------------Description---------------------------------
** 001 OM  20160401 Created initial version.
** 002 IAS 20200908 Rework (de)serialization.
** 003 GBB 20240122 File header fixed.
*/
/*
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU Affero General Public License as
** published by the Free Software Foundation, either version 3 of the
** License, or (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Affero General Public License for more details.
**
** You may find a copy of the GNU Affero GPL version 3 at the following
** location: https://www.gnu.org/licenses/agpl-3.0.en.html
** 
** Additional terms under GNU Affero GPL version 3 section 7:
** 
**   Under Section 7 of the GNU Affero GPL version 3, the following additional
**   terms apply to the works covered under the License.  These additional terms
**   are non-permissive additional terms allowed under Section 7 of the GNU
**   Affero GPL version 3 and may not be removed by you.
** 
**   0. Attribution Requirement.
** 
**     You must preserve all legal notices or author attributions in the covered
**     work or Appropriate Legal Notices displayed by works containing the covered
**     work.  You may not remove from the covered work any author or developer
**     credit already included within the covered work.
** 
**   1. No License To Use Trademarks.
** 
**     This license does not grant any license or rights to use the trademarks
**     Golden Code, FWD, any Golden Code or FWD logo, or any other trademarks
**     of Golden Code Development Corporation. You are not authorized to use the
**     name Golden Code, FWD, or the names of any author or contributor, for
**     publicity purposes without written authorization.
** 
**   2. No Misrepresentation of Affiliation.
** 
**     You may not represent yourself as Golden Code Development Corporation or FWD.
** 
**     You may not represent yourself for publicity purposes as associated with
**     Golden Code Development Corporation, FWD, or any author or contributor to
**     the covered work, without written authorization.
** 
**   3. No Misrepresentation of Source or Origin.
** 
**     You may not represent the covered work as solely your work.  All modified
**     versions of the covered work must be marked in a reasonable way to make it
**     clear that the modified work is not originating from Golden Code Development
**     Corporation or FWD.  All modified versions must contain the notices of
**     attribution required in this license.
*/

package com.goldencode.p2j.util;

import static com.goldencode.util.NativeTypeSerializer.*; 
import java.io.*;

/**
 * Container for various web-service connect options.
 * <p>
 * See the {@link WebServiceHelper} for details about how these options are validated.
 */
public class WebServiceConnectOptions
implements Externalizable
{
   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_WSDL} option. */
   private String wsdlDocument;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_WSDL_USERID} option. */
   private String wsdlUserid;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_WSDL_PASSWORD} option. */
   private String wsdlPassword;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_SERVICE} option. */
   private String service;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_SERVICE_NAMESPACE} option. */
   private String serviceNamespace;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_PORT} option. */
   private String port;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_BINDING} option. */
   private String binding;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_BINDING_NAMESPACE} option. */
   private String bindingNamespace;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_SOAP_ENDPOINT} option. */
   private String soapEndpoint;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_SOAP_ENDPOINT_USER} option. */
   private String soapEndpointUserid;
   
   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_SOAP_ENDPOINT_PASSWORD} option. */
   private String soapEndpointPassword;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_TARGET_NAMESPACE} option. */
   private String targetNamespace;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_MAX_CONNECTIONS} option. */
   private int maxConnections;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_CONNECTION_LIFETIME} option. */
   private int connectionLifetime = 300;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_NO_SESSION_REUSE} option. */
   private boolean noSessionReuse;

   /** The value of the {@link WebServiceHelper#CONNECT_OPTION_NO_HOST_VERIFY} option. */
   private boolean noHostVerify;
   
   /**
    * Default constructor used by externalization mechanism.
    */
   public WebServiceConnectOptions()
   {
   }
   
   /**
    * Create a new container for web-service connection options.
    * 
    * @param   wsdlDocument
    *          The WSDL document targeted by this web-service connection.
    */
   public WebServiceConnectOptions(String wsdlDocument)
   {
      this.wsdlDocument = wsdlDocument;
   }
   
   /**
    * Get the WSDL document associated with this connection.
    * 
    * @return  The {@link #wsdlDocument} field.
    */
   public String getWsdlDocument()
   {
      return wsdlDocument;
   }
   
   /**
    * Get the WSDL user-id associated with this connection.
    * 
    * @return  The {@link #wsdlUserid} field.
    */
   public String getWsdlUserid()
   {
      return wsdlUserid;
   }

   /**
    * Set the WSDL user-id associated with this connection.
    * 
    * @param   wsdlUserid
    *          The new value for the {@link #wsdlUserid} field.
    */
   public void setWsdlUserid(String wsdlUserid)
   {
      this.wsdlUserid = wsdlUserid;
   }

   /**
    * Get the WSDL password associated with this connection.
    * 
    * @return  The {@link #wsdlPassword} field.
    */
   public String getWsdlPassword()
   {
      return wsdlPassword;
   }

   /**
    * Set the WSDL password associated with this connection.
    * 
    * @param   wsdlPassword
    *          The new value for the {@link #wsdlPassword} field.
    */
   public void setWsdlPassword(String wsdlPassword)
   {
      this.wsdlPassword = wsdlPassword;
   }

   /**
    * Get the service targeted by this connection.
    * 
    * @return  The {@link #service} field.
    */
   public String getServiceName()
   {
      return service;
   }

   /**
    * Set the service targeted by this connection.
    * 
    * @param   service
    *          The new value for the {@link #service} field.
    */
   public void setServiceName(String service)
   {
      this.service = service;
   }

   /**
    * Get the namespace for the given {@link #service}.
    * 
    * @return  The {@link #serviceNamespace} field.
    */
   public String getServiceNamespace()
   {
      return serviceNamespace;
   }

   /**
    * Set the namespace for the given {@link #service}.
    * 
    * @param   serviceNamespace
    *          The new value for the {@link #serviceNamespace} field.
    */
   public void setServiceNamespace(String serviceNamespace)
   {
      this.serviceNamespace = serviceNamespace;
   }

   /**
    * Get the port type name targeted by this connection.
    * 
    * @return  The {@link #port} field.
    */
   public String getPortName()
   {
      return port;
   }

   /**
    * Set the port targeted by this connection.
    * 
    * @param   port
    *          The new value for the {@link #port} field.
    */
   public void setPortName(String port)
   {
      this.port = port;
   }

   /**
    * Get the binding name targeted by this connection.
    * 
    * @return  The {@link #binding} field.
    */
   public String getBindingName()
   {
      return binding;
   }

   /**
    * Set the binding targeted by this connection.
    * 
    * @param   binding
    *          The new value for the {@link #binding} field.
    */
   public void setBindingName(String binding)
   {
      this.binding = binding;
   }

   /**
    * Get the namespace associated with this {@link #binding}.
    * 
    * @return  The {@link #bindingNamespace} field.
    */
   public String getBindingNamespace()
   {
      return bindingNamespace;
   }

   /**
    * Set the namespace for the {@link #binding} targeted by this connection.
    * 
    * @param   bindingNamespace
    *          The new value for the {@link #bindingNamespace} field.
    */
   public void setBindingNamespace(String bindingNamespace)
   {
      this.bindingNamespace = bindingNamespace;
   }

   /**
    * Get the SOAP endpoint targeted by this connection.
    * 
    * @return  The {@link #soapEndpoint} field.
    */
   public String getSoapEndpoint()
   {
      return soapEndpoint;
   }

   /**
    * Set the SOAP endpoint targeted by this connection.
    * 
    * @param   soapEndpoint
    *          The new value for the {@link #soapEndpoint} field.
    */
   public void setSoapEndpoint(String soapEndpoint)
   {
      this.soapEndpoint = soapEndpoint;
   }

   /**
    * Get the user-id for the SOAP endpoint targeted by this connection.
    * 
    * @return  The {@link #soapEndpointUserid} field.
    */
   public String getSoapEndpointUserid()
   {
      return soapEndpointUserid;
   }

   /**
    * Set the user-id for the SOAP endpoint targeted by this connection.
    * 
    * @param   soapEndpointUserid
    *          The new value for the {@link #soapEndpointUserid} field.
    */
   public void setSoapEndpointUserid(String soapEndpointUserid)
   {
      this.soapEndpointUserid = soapEndpointUserid;
   }

   /**
    * Get the password for the SOAP endpoint targeted by this connection.
    * 
    * @return  The {@link #soapEndpointPassword} field.
    */
   public String getSoapEndpointPassword()
   {
      return soapEndpointPassword;
   }

   /**
    * Set the password for the SOAP endpoint targeted by this connection.
    * 
    * @param   soapEndpointPassword
    *          The new value for the {@link #soapEndpointPassword} field.
    */
   public void setSoapEndpointPassword(String soapEndpointPassword)
   {
      this.soapEndpointPassword = soapEndpointPassword;
   }

   /**
    * Get the namespace targeted by the service.
    * 
    * @return  The {@link #targetNamespace} field.
    */
   public String getTargetNamespace()
   {
      return targetNamespace;
   }

   /**
    * Set the namespace targeted by the service.
    * 
    * @param   targetNamespace
    *          The new value for the {@link #targetNamespace} field.
    */
   public void setTargetNamespace(String targetNamespace)
   {
      this.targetNamespace = targetNamespace;
   }

   /**
    * Gets the maximum number of connections maintained between the client and the Web Server
    * for asynchronous requests.
    * <p>
    * An equivalent in java would be the {@code http.connection-manager.max-per-host}.
    * 
    * @return  maximum number of simultaneous connections to host that provide the web-service.
    */
   public int getMaxConnections()
   {
      return maxConnections;
   }
   
   /**
    * Sets the maximum number of connections maintained between the client and the Web Server
    * for asynchronous requests.
    * 
    * @param   maxConnections
    *          The maximum number of simultaneous (parallel) connections maintained between the
    *          client and Web service for asynchronous requests.
    */
   public void setMaxConnections(int maxConnections)
   {
      this.maxConnections = maxConnections;
   }

   /**
    * Gets the wait time after which a client times out in a blocking scenario.
    * <p> 
    * In P4GL, this is defined as the maximum number of seconds that a given connection can be
    * reused for asynchronous requests before it is destroyed. 
    * <p>
    * The default value is 300 seconds.
    * 
    * @return  The connection lifetime (in seconds).
    */
   public int getConnectionLifetime()
   {
      return connectionLifetime;
   }

   /**
    * Sets the wait time after which a client times out in a blocking scenario.
    * <p> 
    * In P4GL, this is defined as the maximum number of seconds that a given connection can be
    * reused for asynchronous requests before it is destroyed. 
    *
    * @param   connectionLifetime
    *          The connection lifetime (in seconds).
    */
   public void setConnectionLifetime(int connectionLifetime)
   {
      this.connectionLifetime = connectionLifetime;
   }
   
   /**
    * Set the {@code noSessionReuse} option. If {@code true}, connection uses a new SSL session ID
    * when reconnecting to the same Web server using HTTPS.
    *
    * @return  The value for the option.
    */
   public boolean isNoSessionReuse()
   {
      return noSessionReuse;
   }
   
   /**
    * Set the {@code noSessionReuse} option. If {@code true}, connection uses a new SSL session ID
    * when reconnecting to the same Web server using HTTPS.
    *
    * @param   noSessionReuse
    *          New value for the option.
    */
   public void setNoSessionReuse(boolean noSessionReuse)
   {
      this.noSessionReuse = noSessionReuse;
   }
   
   /**
    * Set the {@code noHostVerify} option. If {@code true}, disables host verification for 
    * connection using HTTPS.
    *
    * @return  The value for the option.
    */
   public boolean isNoHostVerify()
   {
      return noHostVerify;
   }
   
   /**
    * Set the {@code noHostVerify} option. If {@code true}, disables host verification for 
    * connection using HTTPS.
    *
    * @param   noHostVerify
    *          New value for the option.
    */
   public void setNoHostVerify(boolean noHostVerify)
   {
      this.noHostVerify = noHostVerify;
   }
   
   /**
    * Save internal state of this object to {@code objectOutput}.
    * 
    * @param   out
    *          The stream to write the object to.
    *          
    * @throws  IOException
    *          Includes any I/O exceptions that may occur.
    */
   @Override
   public void writeExternal(ObjectOutput out)
   throws IOException
   {
      writeString(out, wsdlDocument);
      writeString(out, wsdlUserid);
      writeString(out, wsdlPassword);
      writeString(out, service);
      writeString(out, serviceNamespace);
      writeString(out, port);
      writeString(out, binding);
      writeString(out, bindingNamespace);
      writeString(out, soapEndpoint);
      writeString(out, soapEndpointUserid);
      writeString(out, soapEndpointPassword);
      writeString(out, targetNamespace);
      out.writeInt(maxConnections);
      out.writeInt(connectionLifetime);
      out.writeBoolean(noSessionReuse);
      out.writeBoolean(noHostVerify);
   }
   
   /**
    * Restore this object contents by calling the methods of {@code DataInput} for primitive types
    * and {@code readObject} strings. The method reads the values in the same sequence and with
    * the same types as were written by {@link #writeExternal}.
    * 
    * @param   in
    *          The stream to read data from in order to restore the object.
    *          
    * @throws  IOException
    *          If I/O errors occur.
    * @throws  ClassNotFoundException
    *          If the class for an object being restored cannot be found.
    */
   @Override
   public void readExternal(ObjectInput in)
   throws IOException, ClassNotFoundException
   {
      wsdlDocument = readString(in);
      wsdlUserid = readString(in);
      wsdlPassword = readString(in);
      service = readString(in);
      serviceNamespace = readString(in);
      port = readString(in);
      binding = readString(in);
      bindingNamespace = readString(in);
      soapEndpoint = readString(in);
      soapEndpointUserid = readString(in);
      soapEndpointPassword = readString(in);
      targetNamespace = readString(in);
      maxConnections = in.readInt();
      connectionLifetime = in.readInt();
      noSessionReuse = in.readBoolean();
      noHostVerify = in.readBoolean();
   }
}