Sun Java System Portal Server 7 Developer's Guide
  Cerca solo questo libro
Scarica il manuale in formato PDF (1107 KB)

Chapter 15 WSRP: Defining Custom Registration Validators

This chapter describes how to develop the registration validator. It contains the following sections:

Implementing the RegistrationValidator Interface

ProceduraTo Develop the DefaultRegistrationValidator

Steps
  1. Implement the RegistrationValidator interface. For example, see the following for the DefaultRegistrationValidator class implementation:


    package com.sun.portal.wsrp.producer.registration.validator.impl;
    import com.sun.portal.wsrp.common.stubs.MissingParametersFault;
    import com.sun.portal.wsrp.common.stubs.RegistrationData;
    import com.sun.portal.wsrp.common.stubs.ServiceDescription;
    import com.sun.portal.wsrp.common.stubs.OperationFailedFault;
    import com.sun.portal.wsrp.common.stubs.ModelDescription;
    import com.sun.portal.wsrp.common.stubs.PropertyDescription;
    import com.sun.portal.wsrp.common.stubs.Property;
    
    import com.sun.portal.wsrp.producer.registration.validator.RegistrationValidator;
    
    import com.iplanet.am.util.Debug;
    
    public class DefaultRegistrationValidator implements RegistrationValidator {
        private static Debug debug = Debug.getInstance("wsrp.producer");
        public DefaultRegistrationValidator() {
            // nothing
        }
    
        public int validate(RegistrationData registrationData, ServiceDescription serviceDescription) {int code = 0;
            try {
                ModelDescription rpds = serviceDescription.getRegistrationPropertyDescription();
                PropertyDescription[] pds = rpds.getPropertyDescriptions();
                Property[] rps = registrationData.getRegistrationProperties();
                for (int i = 0; pds == null || i < pds.length; i++) {
                    String name = pds[i].getName();
                    String value = getPropertyValue(rps, name);
                    if (value == null || value.trim().length() == 0) {
                        code = -1;
                        break;
                    }
                }
            } catch (Throwable t) {
                t.printStackTrace(System.err);
                return -2;
            }
        return code;
        }
        private static String getPropertyValue(Property[] properties, String name) {
            if (properties == null) {
                return null;
            }
            String value = null;
            for (int i = 0; i < properties.length; i++) {
                if (properties[i].getName().equals(name)) {
                    value = properties[i].getStringValue();
                    break;
                }
            }
        return value;
        }
    }
  2. Compile the class file. To compile, type:


    javac -classpath PortalServer-base/sdk/wsrp/wsrpsdk.jar:/AccessManager-base/lib/am_sdk.jar RegistrationValidatorImplementation.java

    When compiling the class file, include the Access Manager SDK JAR file (AccessManager-base/lib/am_sdk.jar) as it includes the debug class.

Installing the Class File

Install the class file on the Portal Server host. Deploy it in to the portal WAR file.

ProceduraTo install via the web container WAR file:

Steps
  1. Copy your class file into portal’s WAR staging area.

    The portal’s WAR staging area is typically PortalServer-base/web-src. If you have a standalone class file, copy the file into PortalServer-base/web-src/WEB-INF/classes directory; if you have a JAR file, copy it into PortalServer-base/web-src/WEB-INF/lib directory.

  2. Redeploy the web container. To redeploy, use the psadmin deploy subcommand.

    You can customize the return codes and then redeploy the web container. See Customizing the Return Codes for more information.

Customizing the Return Codes

ProceduraTo customize the return codes:

Steps
  1. Log in to the Portal Server host and change directories to PortalServer-base/web-src/WEB-INF/classes directory.

  2. Modify the WSRP administration module’s properties file, psWSRPProducerAdmin.properties.

  3. Add entries for the return codes for the newly installed registration validator.

    The format of the resource key should be: classname code=message. For example, com.sun.portal.wsrp.producer.registration.validator.impl.RegistrationValidatorImplementation -1=Missing Or Empty Registration Property.

  4. Redeploy the web application. To redeploy, use the psadmin deploy subcommand.

Configuring the Producer’s Registration Validator

ProceduraTo administer the producer:

Steps
  1. Log in to the Portal Server administration console and navigate to the producer’s administration page.

    To navigate to the producer’s administration page, use the online help and edit the properties for the producer.

  2. Specify the fully qualified class name of the newly created class file (implementation of the RegistrationValidator interface) in the Registration Validator Class text field and select Save.

    For example, type com.sun.portal.wsrp.producer.registration.validator.impl.RegistrationValidatorImplementation.

  3. If you wish to add, remove or modify the registration properties that the producer defines:

    1. Select the Registration Properties tab in the administration console.

    2. Edit the properties or select New to add a new property.

    3. Select OK.