Sun Java System Portal Server 7.2 Developer's Guide

Chapter 19 WSRP: Defining Custom Registration Validators

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

Implementing the RegistrationValidator Interface

ProcedureTo Develop the DefaultRegistrationValidator

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


    /* 
      * CDDL HEADER START
      * The contents of this file are subject to the terms
      * of the Common Development and Distribution License 
      * (the License). You may not use this file except in
      * compliance with the License.
      *
      * You can obtain a copy of the License at
      * http://www.sun.com/cddl/cddl.html and legal/CDDLv1.0.txt
      * See the License for the specific language governing
      * permission and limitations under the License.
      *
      * When distributing Covered Code, include this CDDL 
      * Header Notice in each file and include the License file  
      * at legal/CDDLv1.0.txt.                                                           
      * If applicable, add the following below the CDDL Header,
      * with the fields enclosed by brackets [] replaced by
      * your own identifying information: 
      * "Portions Copyrighted [year] [name of copyright owner]"
      *
      * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
      * CDDL HEADER END
     */
    
    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;
    
    public class DefaultRegistrationValidator implements RegistrationValidator {
        public DefaultRegistrationValidator() { 
    	// nothing
        }
    
        /**
         * This method returns three possible codes.
         * 0=succes
         * -1=Missing Registration Property
         * -2=Unknown failure
         */
        public int validate(RegistrationData registrationData, ServiceDescription serviceDescription) {
    	int code = 0;
    
    	try {
    	    ModelDescription rpds = serviceDescription.getRegistrationPropertyDescription();
    	    PropertyDescription[] pds = (PropertyDescription[])rpds.getPropertyDescriptions().
                        toArray(new PropertyDescription[0]);
    	
    	    Property[] rps = (Property [])registrationData.getRegistrationProperties().
                        toArray(new Property[0]);
    
    	    //
    	    // for every registration property description in the
    	    // service description, make sure that the
    	    // registration properties contains a like-named
    	    // property and that the like-named property's value
    	    // is non-null and not empty
    	    //
    	    
    	    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.

ProcedureTo Install Through the Web Container WAR File

  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 sub command.

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

Customizing the Return Codes

ProcedureTo customize the return codes:

  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 sub command.

Configuring the Producer’s Registration Validator

ProcedureTo administer the producer

  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 want 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.