0001: /**
0002: * Copyright 2003 Sun Microsystems, Inc. All
0003: * rights reserved. Use of this product is subject
0004: * to license terms. Federal Acquisitions:
0005: * Commercial Software -- Government Users
0006: * Subject to Standard License Terms and
0007: * Conditions.
0008: *
0009: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
0010: * are trademarks or registered trademarks of Sun Microsystems,
0011: * Inc. in the United States and other countries.
0012: */package com.sun.portal.wsrp.consumer.producermanager.impl;
0013:
0014: import java.util.ArrayList;
0015: import java.util.Set;
0016: import java.util.HashSet;
0017: import java.util.List;
0018: import java.util.Map;
0019: import java.util.HashMap;
0020: import java.util.Collections;
0021: import java.util.PropertyResourceBundle;
0022: import java.util.Properties;
0023: import java.util.StringTokenizer;
0024: import java.util.Iterator;
0025: import java.util.ResourceBundle;
0026: import java.util.PropertyResourceBundle;
0027: import java.util.logging.Level;
0028: import java.util.logging.Logger;
0029:
0030: import java.net.URL;
0031: import java.net.MalformedURLException;
0032:
0033: import java.io.File;
0034: import java.io.FileInputStream;
0035: import java.io.FileOutputStream;
0036: import java.io.ObjectInputStream;
0037: import java.io.ObjectOutputStream;
0038: import java.io.FileNotFoundException;
0039: import java.io.IOException;
0040: import java.io.FilenameFilter;
0041: import java.io.StringReader;
0042: import java.io.StringWriter;
0043:
0044: import java.rmi.RemoteException;
0045:
0046: import javax.servlet.http.HttpServletRequest;
0047:
0048: import com.sun.portal.wsrp.WSRPException;
0049:
0050: import com.sun.portal.wsrp.common.stubs.WSRP_v1_ServiceDescription_PortType;
0051: import com.sun.portal.wsrp.common.stubs.WSRP_v1_Registration_PortType;
0052:
0053: import com.sun.portal.wsrp.common.stubs.ServiceDescription;
0054: import com.sun.portal.wsrp.common.stubs.GetServiceDescription;
0055: import com.sun.portal.wsrp.common.stubs.RegistrationContext;
0056: import com.sun.portal.wsrp.common.stubs.RegistrationData;
0057: import com.sun.portal.wsrp.common.stubs.RegistrationState;
0058: import com.sun.portal.wsrp.common.stubs.PortletDescription;
0059: import com.sun.portal.wsrp.common.stubs.ModifyRegistration;
0060: import com.sun.portal.wsrp.common.stubs.ReturnAny;
0061:
0062: import com.sun.portal.wsrp.common.stubs.OperationFailedFault;
0063: import com.sun.portal.wsrp.common.stubs.InvalidRegistrationFault;
0064: import com.sun.portal.wsrp.common.stubs.MissingParametersFault;
0065:
0066: import com.sun.portal.wsrp.common.WSRPFactory;
0067: import com.sun.portal.wsrp.common.KeyGenerator;
0068:
0069: import com.sun.portal.wsrp.consumer.common.WSRPConsumerException;
0070: import com.sun.portal.wsrp.consumer.common.RemoteServiceStubManagerFactory;
0071: import com.sun.portal.wsrp.consumer.common.RemoteServiceStubManager;
0072:
0073: import com.sun.portal.wsrp.consumer.producermanager.ConsumerObjectFactory;
0074: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityManager;
0075: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntity;
0076: import com.sun.portal.wsrp.consumer.producermanager.ProducerEntityStatus;
0077: import com.sun.portal.wsrp.consumer.producermanager.InbandRegistrationNotSupportedException;
0078: import com.sun.portal.log.common.PortalLogger;
0079:
0080: import com.iplanet.sso.SSOToken;
0081:
0082: /**
0083: * <code>PropertiesProducerEntityManagerImpl</code> is an implementation
0084: * of the <code>ProducerEntityManager</code> which uses file system
0085: * as a persistent storage to store producer entity data.
0086: * It is neither thread-safe nor is concurrent access supported.
0087: * This implementation is meant to be used mainly for simple unit tests.
0088: */
0089: public class PropertiesProducerEntityManagerImpl implements
0090: ProducerEntityManager {
0091: //
0092: // debug
0093: //
0094: //
0095: // stub manager
0096: //
0097: protected static RemoteServiceStubManager stubMgr = null;
0098:
0099: //
0100: // cache of producer entities (key = producerEntityId)
0101: // we use synchronized map.
0102: // make sure you synchronize properly when interating over it.
0103: //
0104: private static Map producerEntities = Collections
0105: .synchronizedMap(new HashMap());
0106:
0107: //
0108: // global properties
0109: //
0110: protected static Properties globalProperties = null;
0111: protected static Properties defaultGlobalProperties = null;
0112: protected static String consumerAgent = getConsumerAgent();
0113:
0114: //
0115: // consumerId
0116: //
0117: protected String consumerId = null;
0118:
0119: //
0120: // wsrp object factory
0121: //
0122: protected WSRPFactory factory = null;
0123:
0124: //
0125: // consumer object factory
0126: //
0127: protected static ConsumerObjectFactory cofactory = null;
0128:
0129: //
0130: // flat-file based DB
0131: //
0132: public static final String DATA_FILE_PATH = "/tmp/wsrp_producers";
0133: public static final String DATA_FILE_BASENAME = "producer_";
0134: public static final String DATA_FILE_EXTENSION = ".pd";
0135: public static final String GLOBAL_DATA_FILENAME = "global.properties";
0136: public static final String ORG_DATA_FILENAME = "org.properties";
0137: public static File baseDir = null;
0138: public static final String COPYRIGHT_HEADER = "\n# Copyright 2003 Sun Microsystems, Inc. All rights reserved\n# Use is subject to license terms.\n#\n";
0139:
0140: //
0141: // property names
0142: //
0143: public static final String ID = "id";
0144: public static final String NAME = "name";
0145: public static final String URL = "url";
0146: public static final String PROPAGATION_TYPE = "identityPropagationType";
0147: public static final String MARKUP_ENDPOINT = "markupEndpoint";
0148: public static final String STATUS = "status";
0149: public static final String REGISTRATION_DATA = "registrationData";
0150: public static final String REGISTRATION_CONTEXT = "registrationContext";
0151: public static final String SERVICE_DESCRIPTION = "serviceDescription";
0152: public static final String USER_CATEGORY_MAPPING = "userCategoryMapping";
0153: public static final String ALLOWED_USER_PROFILE_MAPPING = "allowedUserProfileMapping";
0154: public static final String CUSTOM_USER_PROFILE_MAPPING = "customUserProfileMapping";
0155: public static final String SERVICE_DESCRIPTION_LAST_MODIFIED = "serviceDescriptionLastModified";
0156: public static final String LAST_MODIFIED = "lastModified";
0157: public static final String ENABLED = "enabled";
0158: public static final String STANDARD_USER_PROFILE_MAPPING = "standardUserProfileMapping";
0159: public static final String DEFAULT_REGISTRATION_DATA = "defaultRegistrationData";
0160: public static final String CONSUMER_NAME = "consumerName";
0161:
0162: //
0163: // delimiters used in serializing map
0164: //
0165: public static final String LIST_DELIMITER = ";";
0166: public static final String MAPPING_DELIMITER = ":";
0167:
0168: private static Logger logger = PortalLogger
0169: .getLogger(PropertiesProducerEntityManagerImpl.class);
0170:
0171: public void init(String consumerId, HttpServletRequest request)
0172: throws WSRPConsumerException {
0173: //
0174: // for this implementation we ignore user context
0175: // (i.e. everyone gets free access)
0176: //
0177: doInit(consumerId);
0178: }
0179:
0180: public void init(String consumerId, String username, String password)
0181: throws WSRPConsumerException {
0182: //
0183: // for this implementation we ignore user context
0184: // (i.e. everyone gets free access)
0185: //
0186: doInit(consumerId);
0187: }
0188:
0189: public void init(SSOToken ssoToken, String portalId,
0190: String consumerId) throws WSRPConsumerException {
0191: //
0192: // for this implementation we ignore user context
0193: // (i.e. everyone gets free access)
0194: //
0195: doInit(consumerId);
0196: }
0197:
0198: private void doInit(String consumerId) throws WSRPConsumerException {
0199:
0200: this .consumerId = consumerId;
0201:
0202: //
0203: // get remote service stub manager
0204: //
0205: stubMgr = RemoteServiceStubManagerFactory
0206: .getRemoteServiceStubManager();
0207:
0208: //
0209: // initialize wsrp factory
0210: //
0211: try {
0212: factory = WSRPFactory.getInstance();
0213: } catch (WSRPException we) {
0214: throw new WSRPConsumerException(
0215: "PropertiesProducerEntityManagerImpl.init(): failed to get a instance of WSRPFactory.",
0216: we);
0217: }
0218:
0219: //
0220: // initialize consumer object factory
0221: //
0222: cofactory = ConsumerObjectFactory.getInstance();
0223:
0224: //
0225: // set basedir based on the consumerID
0226: //
0227: String filePath = DATA_FILE_PATH + File.separator + consumerId;
0228: if (logger.isLoggable(Level.FINEST))
0229: logger.log(Level.FINEST, "PSWS_CSPWCPI0008", filePath);
0230: baseDir = new File(filePath);
0231:
0232: //
0233: // load global data - if none found, create a default one.
0234: //
0235: globalProperties = loadGlobalProperties();
0236: if (globalProperties == null) {
0237: storeGlobalProperties(defaultGlobalProperties);
0238: globalProperties = loadGlobalProperties();
0239: }
0240: //
0241: // init org data if none found.
0242: //
0243: Properties orgProperties = loadOrgProperties();
0244: if (orgProperties == null) {
0245: orgProperties = new Properties();
0246: orgProperties.setProperty(CONSUMER_NAME, "WSRP Consumer "
0247: + consumerId);
0248: storeOrgProperties(orgProperties);
0249: }
0250: }
0251:
0252: public boolean isActivated() {
0253: boolean activated = false;
0254: String enabledStr = globalProperties.getProperty(ENABLED);
0255: if (enabledStr != null
0256: && enabledStr.toLowerCase().equals("true")) {
0257: activated = true;
0258: }
0259: return activated;
0260: }
0261:
0262: public String getConsumerName() throws WSRPConsumerException {
0263: Properties p = loadOrgProperties();
0264: return p.getProperty(CONSUMER_NAME);
0265: }
0266:
0267: public ServiceDescription getServiceDescription(URL producerURL)
0268: throws WSRPConsumerException {
0269:
0270: //
0271: // no registration info supplied. pass null registrationContext
0272: //
0273: return getServiceDescription(producerURL, null);
0274: }
0275:
0276: public ServiceDescription getServiceDescription(URL producerURL,
0277: RegistrationContext regContext)
0278: throws WSRPConsumerException {
0279:
0280: String endpoint = stubMgr.getEndpoint(producerURL,
0281: stubMgr.SERVICE_DESCRIPTION_PORT_BINDING);
0282:
0283: WSRP_v1_ServiceDescription_PortType sdPort = stubMgr
0284: .getServiceDescriptionPortType(endpoint);
0285:
0286: //
0287: // we query all available locales
0288: // this may have a performance impact but since this is a
0289: // rarely used method, it's acceptable.
0290: //
0291: String[] locales = null;
0292: ServiceDescription sd = null;
0293: GetServiceDescription gsd = new GetServiceDescription(
0294: regContext, locales);
0295:
0296: try {
0297: sd = sdPort.getServiceDescription(gsd);
0298: } catch (OperationFailedFault off) {
0299: throw new WSRPConsumerException(
0300: "PropertiesProducerEntityManagerImpl.getServiceDescription(): failed to get ServiceDescription port type. producerURL="
0301: + producerURL, off);
0302: } catch (InvalidRegistrationFault irf) {
0303: throw new WSRPConsumerException(
0304: "PropertiesProducerEntityManagerImpl.getServiceDescription(): failed to get ServiceDescription port type. producerURL="
0305: + producerURL, irf);
0306: } catch (RemoteException re) {
0307: throw new WSRPConsumerException(
0308: "PropertiesProducerEntityManagerImpl.getServiceDescription(): failed to get ServiceDescription port type. producerURL="
0309: + producerURL, re);
0310: }
0311:
0312: //
0313: // log it!
0314: //
0315: //if (sd != null && debug.isServiceDescLogEnabled()) {
0316: if (sd != null && logger.isLoggable(Level.FINEST)) {
0317: String sdXML = null;
0318: try {
0319: sdXML = factory.getServiceDescriptionXML(sd, true);
0320: } catch (WSRPException we) {
0321: throw new WSRPConsumerException(
0322: "PropertiesProducerEntityManagerImpl.getServiceDescription(): failed to serialize service description. sd="
0323: + sd, we);
0324: }
0325:
0326: StringBuffer logBuf = new StringBuffer();
0327: logBuf.append("PRODUCER_WSDL_URL=").append(producerURL);
0328: if (regContext != null) {
0329: logBuf.append("\nREG_HANDLE=").append(
0330: regContext.getRegistrationHandle());
0331: } else {
0332: logBuf.append("\nREG_HANDLE=<none>");
0333: }
0334:
0335: logBuf.append("\nSERVICE_DESCRIPTION=").append(sdXML);
0336:
0337: if (logger.isLoggable(Level.FINEST))
0338: logger.log(Level.FINEST, logBuf.toString());
0339: }
0340:
0341: return sd;
0342: }
0343:
0344: public boolean isInbandRegistrationSupported(URL producerURL)
0345: throws WSRPConsumerException {
0346:
0347: String endpoint = stubMgr.getEndpoint(producerURL,
0348: stubMgr.REGISTRATION_PORT_BINDING);
0349:
0350: WSRP_v1_Registration_PortType regPort = stubMgr
0351: .getRegistrationPortType(endpoint);
0352:
0353: return (regPort != null);
0354: }
0355:
0356: public ProducerEntity getProducerEntity(String producerEntityId)
0357: throws WSRPConsumerException {
0358:
0359: ProducerEntity pe = (ProducerEntity) producerEntities
0360: .get(producerEntityId);
0361:
0362: if (pe != null) {
0363: //
0364: // found existing producer entity in the cache
0365: // check to see if it's stale
0366: //
0367: String modified = getProducerEntityLastModified(producerEntityId);
0368: String cacheModified = pe.getLastModified();
0369: if (cacheModified.compareTo(modified) >= 0) {
0370: if (logger.isLoggable(Level.FINEST))
0371: logger.log(Level.FINEST, "PSWS_CSPWCPI0009",
0372: producerEntityId);
0373: return pe;
0374: }
0375: }
0376:
0377: //
0378: // get fresh one and add to cache
0379: //
0380: synchronized (producerEntities) {
0381: //
0382: // check again to see if we still need reload
0383: //
0384: pe = (ProducerEntity) producerEntities
0385: .get(producerEntityId);
0386:
0387: String modified = null;
0388: String cacheModified = null;
0389: if (pe != null) {
0390: modified = getProducerEntityLastModified(producerEntityId);
0391: cacheModified = pe.getLastModified();
0392: }
0393:
0394: if (pe == null || cacheModified.compareTo(modified) < 0) {
0395: pe = loadProducerEntity(producerEntityId);
0396: producerEntities.put(producerEntityId, pe);
0397: if (logger.isLoggable(Level.FINEST))
0398: logger.log(Level.FINEST, "", producerEntityId);
0399: }
0400: }
0401: return pe;
0402: }
0403:
0404: public String addProducerEntity(String producerName,
0405: URL producerURL, String identityPropagationType,
0406: RegistrationData regData, Map userCategories,
0407: Map allowedUserProfiles, Map customUserProfiles)
0408: throws WSRPConsumerException,
0409: InbandRegistrationNotSupportedException {
0410:
0411: //
0412: // get service description
0413: //
0414: ServiceDescription serviceDesc = getServiceDescription(producerURL);
0415:
0416: //
0417: // if required, register at the producer end
0418: //
0419: RegistrationContext regContext = null;
0420: if (serviceDesc.isRequiresRegistration()) {
0421: String endpoint = stubMgr.getEndpoint(producerURL,
0422: stubMgr.REGISTRATION_PORT_BINDING);
0423:
0424: WSRP_v1_Registration_PortType regPort = stubMgr
0425: .getRegistrationPortType(endpoint);
0426:
0427: //
0428: // registration port is not exposed: i.e. in-band reg. not supported
0429: //
0430: if (regPort == null) {
0431: throw new InbandRegistrationNotSupportedException(
0432: "PropertiesProducerEntityManagerImpl.addProducerEntity(): registration port not available. producerURL="
0433: + producerURL);
0434: }
0435:
0436: try {
0437: regContext = regPort.register(regData);
0438: } catch (MissingParametersFault mpf) {
0439: throw new WSRPConsumerException(
0440: "PropertiesProducerEntityManagerImpl.addProducerEntity(): failed to register. producerName="
0441: + producerName + ", regData=" + regData,
0442: mpf);
0443: } catch (OperationFailedFault off) {
0444: throw new WSRPConsumerException(
0445: "PropertiesProducerEntityManagerImpl.addProducerEntity(): failed to register. producerName="
0446: + producerName + ", regData=" + regData,
0447: off);
0448: } catch (RemoteException re) {
0449: throw new WSRPConsumerException(
0450: "PropertiesProducerEntityManagerImpl.addProducerEntity(): failed to register. producerName="
0451: + producerName + ", regData=" + regData,
0452: re);
0453: }
0454:
0455: //
0456: // get service description again with registration context
0457: //
0458: serviceDesc = getServiceDescription(producerURL, regContext);
0459: }
0460:
0461: String producerEntityId = addProducerEntity(producerName,
0462: producerURL, identityPropagationType, regData,
0463: regContext, serviceDesc, userCategories,
0464: allowedUserProfiles, customUserProfiles);
0465: return producerEntityId;
0466: }
0467:
0468: public String addProducerEntity(String producerName,
0469: URL producerURL, String identityPropagationType,
0470: String regHandle, Map userCategories,
0471: Map allowedUserProfiles, Map customUserProfiles)
0472: throws WSRPConsumerException {
0473:
0474: // TBD: this method needs to be made atomic
0475:
0476: RegistrationContext regContext = new RegistrationContext(
0477: regHandle, null, null);
0478:
0479: ServiceDescription serviceDesc = getServiceDescription(
0480: producerURL, regContext);
0481:
0482: //
0483: // passing null registration data
0484: //
0485: String producerEntityId = addProducerEntity(producerName,
0486: producerURL, identityPropagationType, null, regContext,
0487: serviceDesc, userCategories, allowedUserProfiles,
0488: customUserProfiles);
0489:
0490: return producerEntityId;
0491: }
0492:
0493: private String addProducerEntity(String producerName,
0494: URL producerURL, String identityPropagationType,
0495: RegistrationData regData, RegistrationContext regContext,
0496: ServiceDescription serviceDesc, Map userCategories,
0497: Map allowedUserProfiles, Map customUserProfiles)
0498: throws WSRPConsumerException {
0499:
0500: //
0501: // generate unique key for the producerEntityId
0502: //
0503: String producerEntityId = KeyGenerator.generateKey();
0504:
0505: //
0506: // get markup port type endpoint from wsdl
0507: //
0508: String markupEndpoint = stubMgr.getEndpoint(producerURL,
0509: stubMgr.MARKUP_PORT_BINDING);
0510:
0511: //
0512: // create producer entity obj
0513: //
0514: long now = System.currentTimeMillis();
0515: ProducerEntity pe = createProducerEntity(producerEntityId,
0516: producerName, producerURL, markupEndpoint,
0517: ProducerEntityStatus.OK, regData, regContext,
0518: serviceDesc, userCategories, allowedUserProfiles,
0519: customUserProfiles, now, Long.toString(now),
0520: identityPropagationType);
0521:
0522: //
0523: // persist producer entity
0524: //
0525: storeProducerEntity(pe);
0526:
0527: //
0528: // add to cache
0529: //
0530: synchronized (producerEntities) {
0531: producerEntities.put(pe.getId(), pe);
0532: }
0533:
0534: return pe.getId();
0535: }
0536:
0537: public void updateServiceDescription(String producerEntityId)
0538: throws WSRPConsumerException {
0539:
0540: ProducerEntity ope = getProducerEntity(producerEntityId);
0541: if (ope == null) {
0542: throw new WSRPConsumerException(
0543: "PropertiesProducerEntityManagerImpl.updateServiceDescription(): invalid producer entity id. peId="
0544: + producerEntityId);
0545: }
0546:
0547: URL producerURL = ope.getURL();
0548: RegistrationContext rc = ope.getRegistrationContext();
0549:
0550: //
0551: // get fresh service description
0552: //
0553: ServiceDescription sd = getServiceDescription(producerURL, rc);
0554:
0555: //
0556: // update db
0557: //
0558: String producerName = ope.getName();
0559: String identityPropagationType = ope
0560: .getIdentityPropagationType();
0561: String markupEndpoint = ope.getMarkupEndpoint();
0562: ProducerEntityStatus status = ope.getStatus();
0563: RegistrationData regData = ope.getRegistrationData();
0564: RegistrationContext regContext = ope.getRegistrationContext();
0565: Map userCategories = ope.getUserCategoryMapping();
0566: Map allowedUserProfiles = ope.getAllowedUserProfileMapping();
0567: Map customUserProfiles = ope.getCustomUserProfileMapping();
0568: long now = System.currentTimeMillis();
0569: ProducerEntity pe = createProducerEntity(producerEntityId,
0570: producerName, producerURL, markupEndpoint, status,
0571: regData, regContext, sd, userCategories,
0572: allowedUserProfiles, customUserProfiles, now, Long
0573: .toString(now), identityPropagationType);
0574: storeProducerEntity(pe);
0575:
0576: //
0577: // update cache by the removing
0578: //
0579: synchronized (producerEntities) {
0580: producerEntities.put(producerEntityId, pe);
0581: }
0582: }
0583:
0584: public void modifyRegistration(String producerEntityId,
0585: RegistrationData regData) throws WSRPConsumerException {
0586:
0587: //
0588: // modify registration at the producer end
0589: //
0590: ProducerEntity ope = getProducerEntity(producerEntityId);
0591: if (ope == null) {
0592: throw new WSRPConsumerException(
0593: "PropertiesProducerEntityManagerImpl.modifyRegistration(): invalid producer entity id. peId="
0594: + producerEntityId);
0595: }
0596:
0597: URL producerURL = ope.getURL();
0598: RegistrationContext regContext = ope.getRegistrationContext();
0599:
0600: String endpoint = stubMgr.getEndpoint(producerURL,
0601: stubMgr.REGISTRATION_PORT_BINDING);
0602:
0603: WSRP_v1_Registration_PortType regPort = stubMgr
0604: .getRegistrationPortType(endpoint);
0605:
0606: //
0607: // registration port is not exposed: i.e. in-band reg. not supported
0608: //
0609: if (regPort == null) {
0610: throw new InbandRegistrationNotSupportedException(
0611: "PropertiesProducerEntityManagerImpl.modifyRegistration(): registration port not available. producerrEntityId="
0612: + producerEntityId);
0613: }
0614:
0615: ModifyRegistration modReg = new ModifyRegistration(regContext,
0616: regData);
0617: RegistrationState regState = null;
0618: try {
0619: regState = regPort.modifyRegistration(modReg);
0620: } catch (InvalidRegistrationFault irf) {
0621: throw new WSRPConsumerException(
0622: "PropertiesProducerEntityManagerImpl.modifyProducerEntity(): failed to modify registration producerEntityId="
0623: + producerEntityId + ", regData=" + regData,
0624: irf);
0625: } catch (MissingParametersFault mpf) {
0626: throw new WSRPConsumerException(
0627: "PropertiesProducerEntityManagerImpl.modifyProducerEntity(): failed to modify registration producerEntityId="
0628: + producerEntityId + ", regData=" + regData,
0629: mpf);
0630: } catch (OperationFailedFault off) {
0631: throw new WSRPConsumerException(
0632: "PropertiesProducerEntityManagerImpl.modifyProducerEntity(): failed to modify registration producerEntityId="
0633: + producerEntityId + ", regData=" + regData,
0634: off);
0635: } catch (RemoteException re) {
0636: throw new WSRPConsumerException(
0637: "PropertiesProducerEntityManagerImpl.modifyProducerEntity(): failed to modify registration producerEntityId="
0638: + producerEntityId + ", regData=" + regData,
0639: re);
0640: }
0641:
0642: //
0643: // update registration state (only if it's non-empty value)
0644: //
0645: if (regState != null) {
0646: regContext.setRegistrationState(regState
0647: .getRegistrationState());
0648: }
0649:
0650: //
0651: // update db
0652: //
0653: String producerName = ope.getName();
0654: String identityPropagationType = ope
0655: .getIdentityPropagationType();
0656: String markupEndpoint = ope.getMarkupEndpoint();
0657: ProducerEntityStatus status = ope.getStatus();
0658: ServiceDescription serviceDesc = ope.getServiceDescription();
0659: Map userCategories = ope.getUserCategoryMapping();
0660: Map allowedUserProfiles = ope.getAllowedUserProfileMapping();
0661: Map customUserProfiles = ope.getCustomUserProfileMapping();
0662: long serviceDescLastModified = ope
0663: .getServiceDescriptionLastModified();
0664: String lastModified = Long.toString(System.currentTimeMillis());
0665: ProducerEntity pe = createProducerEntity(producerEntityId,
0666: producerName, producerURL, markupEndpoint, status,
0667: regData, regContext, serviceDesc, userCategories,
0668: allowedUserProfiles, customUserProfiles,
0669: serviceDescLastModified, lastModified,
0670: identityPropagationType);
0671: storeProducerEntity(pe);
0672:
0673: //
0674: // update cache by the removing
0675: //
0676: synchronized (producerEntities) {
0677: producerEntities.put(producerEntityId, pe);
0678: }
0679: }
0680:
0681: public void removeProducerEntity(String producerEntityId)
0682: throws WSRPConsumerException,
0683: InbandRegistrationNotSupportedException {
0684:
0685: ProducerEntity pe = getProducerEntity(producerEntityId);
0686: if (pe == null) {
0687: throw new WSRPConsumerException(
0688: "PropertiesProducerEntityManagerImpl.removeProducerEntity(): invalid producer entity id. peId="
0689: + producerEntityId);
0690: }
0691:
0692: //
0693: // deregister from the producer
0694: //
0695:
0696: // TBD: deregister only if it requires registration?
0697: if (pe.getServiceDescription().isRequiresRegistration()) {
0698: URL producerURL = pe.getURL();
0699: RegistrationContext regContext = pe
0700: .getRegistrationContext();
0701:
0702: String endpoint = stubMgr.getEndpoint(producerURL,
0703: stubMgr.REGISTRATION_PORT_BINDING);
0704:
0705: WSRP_v1_Registration_PortType regPort = stubMgr
0706: .getRegistrationPortType(endpoint);
0707:
0708: //
0709: // registration port is not exposed: i.e. in-band reg. not supported
0710: //
0711: if (regPort == null) {
0712: throw new InbandRegistrationNotSupportedException(
0713: "PropertiesProducerEntityManagerImpl.removeProducerEntity(): registration port not available. producerEntityId="
0714: + producerEntityId);
0715: }
0716:
0717: ReturnAny ret = null;
0718: try {
0719: ret = regPort.deregister(regContext);
0720: } catch (InvalidRegistrationFault irf) {
0721: throw new WSRPConsumerException(
0722: "PropertiesProducerEntityManagerImpl.removeProducerEntity(): failed to deregister from the producer. producerEntityId="
0723: + producerEntityId
0724: + ", regContext="
0725: + regContext, irf);
0726: } catch (OperationFailedFault off) {
0727: throw new WSRPConsumerException(
0728: "PropertiesProducerEntityManagerImpl.removeProducerEntity(): failed to deregister from the producer. producerEntityId="
0729: + producerEntityId
0730: + ", regContext="
0731: + regContext, off);
0732: } catch (RemoteException re) {
0733: throw new WSRPConsumerException(
0734: "PropertiesProducerEntityManagerImpl.removeProducerEntity(): failed to deregister from the producer. producerEntityId="
0735: + producerEntityId
0736: + ", regContext="
0737: + regContext, re);
0738: }
0739: }
0740:
0741: //
0742: // eliminate pe from the local db
0743: //
0744: eliminateProducerEntity(producerEntityId);
0745: }
0746:
0747: public void eliminateProducerEntity(String producerEntityId)
0748: throws WSRPConsumerException {
0749:
0750: //
0751: // remove the pe from is
0752: //
0753: deleteProducerEntity(producerEntityId);
0754:
0755: //
0756: // remove from cache
0757: //
0758: synchronized (producerEntities) {
0759: producerEntities.remove(producerEntityId);
0760: }
0761: }
0762:
0763: public Set getProducerEntityIds() throws WSRPConsumerException {
0764: Set peIds = new HashSet();
0765:
0766: File[] files = null;
0767: if (baseDir.exists()) {
0768: files = baseDir.listFiles(new FilenameFilter() {
0769: public boolean accept(File dir, String name) {
0770: return (name.startsWith(DATA_FILE_BASENAME) && name
0771: .endsWith(DATA_FILE_EXTENSION));
0772: }
0773: });
0774: }
0775:
0776: if (files != null) {
0777: for (int i = 0; i < files.length; i++) {
0778: File file = files[i];
0779: String filename = file.getName();
0780: int endIndex = filename.indexOf(DATA_FILE_EXTENSION);
0781: String id = filename.substring(DATA_FILE_BASENAME
0782: .length(), endIndex);
0783: peIds.add(id);
0784: }
0785: }
0786: return peIds;
0787: }
0788:
0789: public Map getStandardUserProfileMapping()
0790: throws WSRPConsumerException {
0791:
0792: Map supMap = null;
0793: String supmString = globalProperties
0794: .getProperty(STANDARD_USER_PROFILE_MAPPING);
0795:
0796: if (supmString != null && supmString.length() > 0) {
0797: supMap = stringToMap(supmString);
0798: }
0799: return supMap;
0800: }
0801:
0802: public RegistrationData getDefaultRegistrationData()
0803: throws WSRPConsumerException {
0804:
0805: RegistrationData rd = null;
0806: String rdXML = globalProperties
0807: .getProperty(DEFAULT_REGISTRATION_DATA);
0808:
0809: if (rdXML != null && rdXML.length() > 0) {
0810: try {
0811: rd = factory.getRegistrationData(rdXML);
0812: } catch (WSRPException we) {
0813: throw new WSRPConsumerException(
0814: "PropertiesProducerEntityManagerImpl.getDefaultRegistrationData(): failed to unmarshal registration data. xml="
0815: + rdXML, we);
0816: }
0817:
0818: //
0819: // replace consumer name with the one from the org level
0820: //
0821: String consumerName = getConsumerName();
0822: rd.setConsumerName(consumerName);
0823:
0824: //
0825: // replace consumer agent
0826: //
0827: rd.setConsumerAgent(consumerAgent);
0828: }
0829: return rd;
0830: }
0831:
0832: public void setConsumerName(String consumerName)
0833: throws WSRPConsumerException {
0834:
0835: Properties orgProperties = loadOrgProperties();
0836: orgProperties.setProperty(CONSUMER_NAME, consumerName);
0837: storeOrgProperties(orgProperties);
0838: }
0839:
0840: public void setName(String producerEntityId, String name)
0841: throws WSRPConsumerException {
0842:
0843: ProducerEntity ope = getProducerEntity(producerEntityId);
0844: if (ope == null) {
0845: throw new WSRPConsumerException(
0846: "PropertiesProducerEntityManagerImpl.setName(): invalid producer entity id. peId="
0847: + producerEntityId);
0848: }
0849:
0850: URL producerURL = ope.getURL();
0851: String identityPropagationType = ope
0852: .getIdentityPropagationType();
0853: String markupEndpoint = ope.getMarkupEndpoint();
0854: ProducerEntityStatus status = ope.getStatus();
0855: RegistrationData regData = ope.getRegistrationData();
0856: RegistrationContext regContext = ope.getRegistrationContext();
0857: ServiceDescription serviceDesc = ope.getServiceDescription();
0858: Map userCategories = ope.getUserCategoryMapping();
0859: Map allowedUserProfiles = ope.getAllowedUserProfileMapping();
0860: Map customUserProfiles = ope.getCustomUserProfileMapping();
0861: long serviceDescLastModified = ope
0862: .getServiceDescriptionLastModified();
0863: String lastModified = Long.toString(System.currentTimeMillis());
0864: ProducerEntity pe = createProducerEntity(producerEntityId,
0865: name, producerURL, markupEndpoint, status, regData,
0866: regContext, serviceDesc, userCategories,
0867: allowedUserProfiles, customUserProfiles,
0868: serviceDescLastModified, lastModified,
0869: identityPropagationType);
0870: storeProducerEntity(pe);
0871:
0872: //
0873: // update cache by removing the entry
0874: //
0875: synchronized (producerEntities) {
0876: producerEntities.put(producerEntityId, pe);
0877: }
0878: }
0879:
0880: public void setIdentityPropagationType(String producerEntityId,
0881: String type) throws WSRPConsumerException {
0882:
0883: ProducerEntity ope = getProducerEntity(producerEntityId);
0884: if (ope == null) {
0885: throw new WSRPConsumerException(
0886: "PropertiesProducerEntityManagerImpl.setIdentityPropagationType(): invalid producer entity id. peId="
0887: + producerEntityId);
0888: }
0889:
0890: URL producerURL = ope.getURL();
0891: String markupEndpoint = ope.getMarkupEndpoint();
0892: String name = ope.getName();
0893: ProducerEntityStatus status = ope.getStatus();
0894: RegistrationData regData = ope.getRegistrationData();
0895: RegistrationContext regContext = ope.getRegistrationContext();
0896: ServiceDescription serviceDesc = ope.getServiceDescription();
0897: Map userCategories = ope.getUserCategoryMapping();
0898: Map allowedUserProfiles = ope.getAllowedUserProfileMapping();
0899: Map customUserProfiles = ope.getCustomUserProfileMapping();
0900: long serviceDescLastModified = ope
0901: .getServiceDescriptionLastModified();
0902: String lastModified = Long.toString(System.currentTimeMillis());
0903: ProducerEntity pe = createProducerEntity(producerEntityId,
0904: name, producerURL, markupEndpoint, status, regData,
0905: regContext, serviceDesc, userCategories,
0906: allowedUserProfiles, customUserProfiles,
0907: serviceDescLastModified, lastModified, type);
0908: storeProducerEntity(pe);
0909:
0910: //
0911: // update cache by removing the entry
0912: //
0913: synchronized (producerEntities) {
0914: producerEntities.put(producerEntityId, pe);
0915: }
0916: }
0917:
0918: public void setURL(String producerEntityId, URL url)
0919: throws WSRPConsumerException {
0920:
0921: ProducerEntity ope = getProducerEntity(producerEntityId);
0922: if (ope == null) {
0923: throw new WSRPConsumerException(
0924: "PropertiesProducerEntityManagerImpl.setURL(): invalid producer entity id. peId="
0925: + producerEntityId);
0926: }
0927:
0928: if (url == null) {
0929: throw new WSRPConsumerException(
0930: "PropertiesProducerEntityManagerImpl.setURL(): url cannot be null. peId="
0931: + producerEntityId);
0932: }
0933:
0934: //
0935: // refresh markup endpoint
0936: //
0937: String markupEndpoint = stubMgr.getEndpoint(url,
0938: stubMgr.MARKUP_PORT_BINDING);
0939:
0940: String producerName = ope.getName();
0941: String identityPropagationType = ope
0942: .getIdentityPropagationType();
0943: ProducerEntityStatus status = ope.getStatus();
0944: RegistrationData regData = ope.getRegistrationData();
0945: RegistrationContext regContext = ope.getRegistrationContext();
0946: ServiceDescription serviceDesc = ope.getServiceDescription();
0947: Map userCategories = ope.getUserCategoryMapping();
0948: Map allowedUserProfiles = ope.getAllowedUserProfileMapping();
0949: Map customUserProfiles = ope.getCustomUserProfileMapping();
0950: long serviceDescLastModified = ope
0951: .getServiceDescriptionLastModified();
0952: String lastModified = Long.toString(System.currentTimeMillis());
0953: ProducerEntity pe = createProducerEntity(producerEntityId,
0954: producerName, url, markupEndpoint, status, regData,
0955: regContext, serviceDesc, userCategories,
0956: allowedUserProfiles, customUserProfiles,
0957: serviceDescLastModified, lastModified,
0958: identityPropagationType);
0959: storeProducerEntity(pe);
0960:
0961: //
0962: // update cache by removing the entry
0963: //
0964: synchronized (producerEntities) {
0965: producerEntities.put(producerEntityId, pe);
0966: }
0967: }
0968:
0969: public void setStatus(String producerEntityId,
0970: ProducerEntityStatus status) throws WSRPConsumerException {
0971:
0972: ProducerEntity ope = getProducerEntity(producerEntityId);
0973: if (ope == null) {
0974: throw new WSRPConsumerException(
0975: "PropertiesProducerEntityManagerImpl.setStatus(): invalid producer entity id. peId="
0976: + producerEntityId);
0977: }
0978:
0979: String producerName = ope.getName();
0980: URL producerURL = ope.getURL();
0981: String identityPropagationType = ope
0982: .getIdentityPropagationType();
0983: String markupEndpoint = ope.getMarkupEndpoint();
0984: RegistrationData regData = ope.getRegistrationData();
0985: RegistrationContext regContext = ope.getRegistrationContext();
0986: ServiceDescription serviceDesc = ope.getServiceDescription();
0987: Map userCategories = ope.getUserCategoryMapping();
0988: Map allowedUserProfiles = ope.getAllowedUserProfileMapping();
0989: Map customUserProfiles = ope.getCustomUserProfileMapping();
0990: long serviceDescLastModified = ope
0991: .getServiceDescriptionLastModified();
0992: String lastModified = Long.toString(System.currentTimeMillis());
0993: ProducerEntity pe = createProducerEntity(producerEntityId,
0994: producerName, producerURL, markupEndpoint, status,
0995: regData, regContext, serviceDesc, userCategories,
0996: allowedUserProfiles, customUserProfiles,
0997: serviceDescLastModified, lastModified,
0998: identityPropagationType);
0999: storeProducerEntity(pe);
1000:
1001: //
1002: // update cache by removing the entry
1003: //
1004: synchronized (producerEntities) {
1005: producerEntities.put(producerEntityId, pe);
1006: }
1007: }
1008:
1009: public void setUserCategoryMapping(String producerEntityId,
1010: Map userCategories) throws WSRPConsumerException {
1011:
1012: ProducerEntity ope = getProducerEntity(producerEntityId);
1013: if (ope == null) {
1014: throw new WSRPConsumerException(
1015: "PropertiesProducerEntityManagerImpl.setUserCategoryMapping(): invalid producer entity id. peId="
1016: + producerEntityId);
1017: }
1018:
1019: String producerName = ope.getName();
1020: URL producerURL = ope.getURL();
1021: String identityPropagationType = ope
1022: .getIdentityPropagationType();
1023: String markupEndpoint = ope.getMarkupEndpoint();
1024: ProducerEntityStatus status = ope.getStatus();
1025: RegistrationData regData = ope.getRegistrationData();
1026: RegistrationContext regContext = ope.getRegistrationContext();
1027: ServiceDescription serviceDesc = ope.getServiceDescription();
1028: Map allowedUserProfiles = ope.getAllowedUserProfileMapping();
1029: Map customUserProfiles = ope.getCustomUserProfileMapping();
1030: long serviceDescLastModified = ope
1031: .getServiceDescriptionLastModified();
1032: String lastModified = Long.toString(System.currentTimeMillis());
1033: ProducerEntity pe = createProducerEntity(producerEntityId,
1034: producerName, producerURL, markupEndpoint, status,
1035: regData, regContext, serviceDesc, userCategories,
1036: allowedUserProfiles, customUserProfiles,
1037: serviceDescLastModified, lastModified,
1038: identityPropagationType);
1039: storeProducerEntity(pe);
1040:
1041: //
1042: // update cache by removing the entry
1043: //
1044: synchronized (producerEntities) {
1045: producerEntities.put(producerEntityId, pe);
1046: }
1047: }
1048:
1049: public void setAllowedUserProfileMapping(String producerEntityId,
1050: Map allowedUserProfiles) throws WSRPConsumerException {
1051:
1052: ProducerEntity ope = getProducerEntity(producerEntityId);
1053: if (ope == null) {
1054: throw new WSRPConsumerException(
1055: "PropertiesProducerEntityManagerImpl.setAllowedUserProfileMapping(): invalid producer entity id. peId="
1056: + producerEntityId);
1057: }
1058:
1059: String producerName = ope.getName();
1060: URL producerURL = ope.getURL();
1061: String identityPropagationType = ope
1062: .getIdentityPropagationType();
1063: String markupEndpoint = ope.getMarkupEndpoint();
1064: ProducerEntityStatus status = ope.getStatus();
1065: RegistrationData regData = ope.getRegistrationData();
1066: RegistrationContext regContext = ope.getRegistrationContext();
1067: ServiceDescription serviceDesc = ope.getServiceDescription();
1068: Map userCategories = ope.getUserCategoryMapping();
1069: Map customUserProfiles = ope.getCustomUserProfileMapping();
1070: long serviceDescLastModified = ope
1071: .getServiceDescriptionLastModified();
1072: String lastModified = Long.toString(System.currentTimeMillis());
1073: ProducerEntity pe = createProducerEntity(producerEntityId,
1074: producerName, producerURL, markupEndpoint, status,
1075: regData, regContext, serviceDesc, userCategories,
1076: allowedUserProfiles, customUserProfiles,
1077: serviceDescLastModified, lastModified,
1078: identityPropagationType);
1079: storeProducerEntity(pe);
1080:
1081: //
1082: // update cache
1083: //
1084: synchronized (producerEntities) {
1085: producerEntities.put(producerEntityId, pe);
1086: }
1087: }
1088:
1089: public void setCustomUserProfileMapping(String producerEntityId,
1090: Map customUserProfiles) throws WSRPConsumerException {
1091:
1092: ProducerEntity ope = getProducerEntity(producerEntityId);
1093: if (ope == null) {
1094: throw new WSRPConsumerException(
1095: "PropertiesProducerEntityManagerImpl.setCustomUserProfileMapping(): invalid producer entity id. peId="
1096: + producerEntityId);
1097: }
1098:
1099: String producerName = ope.getName();
1100: URL producerURL = ope.getURL();
1101: String identityPropagationType = ope
1102: .getIdentityPropagationType();
1103: String markupEndpoint = ope.getMarkupEndpoint();
1104: ProducerEntityStatus status = ope.getStatus();
1105: RegistrationData regData = ope.getRegistrationData();
1106: RegistrationContext regContext = ope.getRegistrationContext();
1107: ServiceDescription serviceDesc = ope.getServiceDescription();
1108: Map userCategories = ope.getUserCategoryMapping();
1109: Map allowedUserProfiles = ope.getAllowedUserProfileMapping();
1110: long serviceDescLastModified = ope
1111: .getServiceDescriptionLastModified();
1112: String lastModified = Long.toString(System.currentTimeMillis());
1113: ProducerEntity pe = createProducerEntity(producerEntityId,
1114: producerName, producerURL, markupEndpoint, status,
1115: regData, regContext, serviceDesc, userCategories,
1116: allowedUserProfiles, customUserProfiles,
1117: serviceDescLastModified, lastModified,
1118: identityPropagationType);
1119: storeProducerEntity(pe);
1120:
1121: //
1122: // update cache by removing the entry
1123: //
1124: synchronized (producerEntities) {
1125: producerEntities.put(producerEntityId, pe);
1126: }
1127: }
1128:
1129: public void setStandardUserProfileMapping(Map standardUserProfileMap)
1130: throws WSRPConsumerException {
1131:
1132: if (standardUserProfileMap == null
1133: || standardUserProfileMap.size() == 0) {
1134: return;
1135: }
1136:
1137: Properties p = new Properties(globalProperties);
1138: p.setProperty(STANDARD_USER_PROFILE_MAPPING,
1139: mapToString(standardUserProfileMap));
1140: storeGlobalProperties(p);
1141: }
1142:
1143: public void setDefaultRegistrationData(RegistrationData rd)
1144: throws WSRPConsumerException {
1145:
1146: if (rd == null) {
1147: return;
1148: }
1149:
1150: String rdXML = null;
1151: try {
1152: rdXML = factory.getRegistrationDataXML(rd);
1153: } catch (WSRPException we) {
1154: throw new WSRPConsumerException(
1155: "PropertiesProducerEntityManagerImpl.setDefaultRegistrationData(): failed to marshal registration data.",
1156: we);
1157: }
1158:
1159: Properties p = new Properties(globalProperties);
1160: p.setProperty(DEFAULT_REGISTRATION_DATA, rdXML);
1161:
1162: storeGlobalProperties(p);
1163: }
1164:
1165: protected ProducerEntity createProducerEntity(
1166: String producerEntityId, String producerName,
1167: URL producerURL, String markupEndpoint,
1168: ProducerEntityStatus status, RegistrationData regData,
1169: RegistrationContext regContext,
1170: ServiceDescription serviceDescription, Map userCategories,
1171: Map allowedUserProfiles, Map customUserProfiles,
1172: long serviceDescLastModified, String lastModified,
1173: String identityPropagationType)
1174: throws WSRPConsumerException {
1175:
1176: ProducerEntity pe = new ProducerEntityImpl(producerEntityId,
1177: producerName, producerURL,
1178:
1179: markupEndpoint, status, regData, regContext,
1180: serviceDescription, userCategories,
1181: allowedUserProfiles, customUserProfiles,
1182: serviceDescLastModified, lastModified,
1183: identityPropagationType);
1184: return pe;
1185: }
1186:
1187: protected ProducerEntity loadProducerEntity(String producerEntityId)
1188: throws WSRPConsumerException {
1189:
1190: StringBuffer filename = new StringBuffer();
1191: filename.append(baseDir.toString()).append(File.separator)
1192: .append(DATA_FILE_BASENAME).append(producerEntityId)
1193: .append(DATA_FILE_EXTENSION);
1194: File file = new File(filename.toString());
1195:
1196: return loadProducerEntity(file);
1197: }
1198:
1199: protected ProducerEntity loadProducerEntity(File file)
1200: throws WSRPConsumerException {
1201:
1202: if (logger.isLoggable(Level.FINEST))
1203: logger.log(Level.FINEST, "PSWS_CSPWCPI0011", file);
1204: Properties p = loadProperties(file);
1205:
1206: String id = p.getProperty(ID);
1207: String name = p.getProperty(NAME);
1208:
1209: String urlString = p.getProperty(URL);
1210: String identityPropagationType = p
1211: .getProperty(PROPAGATION_TYPE);
1212:
1213: URL url = null;
1214: try {
1215: url = new URL(urlString);
1216: } catch (MalformedURLException mfue) {
1217: throw new WSRPConsumerException(
1218: "PropertiesProducerEntityManagerImpl.loadProducerEntity(): failed to create URL urlString="
1219: + urlString, mfue);
1220: }
1221:
1222: String markupEndpoint = p.getProperty(MARKUP_ENDPOINT);
1223:
1224: ProducerEntityStatus status = ProducerEntityStatus
1225: .getProducerEntityStatus(p.getProperty(STATUS));
1226:
1227: String rdXML = p.getProperty(REGISTRATION_DATA);
1228: RegistrationData rd = null;
1229: if (rdXML != null && rdXML.length() > 0) {
1230: try {
1231: rd = factory.getRegistrationData(rdXML);
1232: } catch (WSRPException we) {
1233: throw new WSRPConsumerException(
1234: "PropertiesProducerEntityManagerImpl.loadProducerEntity(): failed to get registration data. xml="
1235: + rdXML, we);
1236: }
1237: }
1238:
1239: String rcXML = p.getProperty(REGISTRATION_CONTEXT);
1240: RegistrationContext rc = null;
1241: if (rcXML != null && rcXML.length() > 0) {
1242: try {
1243: rc = factory.getRegistrationContext(rcXML);
1244: } catch (WSRPException we) {
1245: throw new WSRPConsumerException(
1246: "PropertiesProducerEntityManagerImpl.loadProducerEntity(): failed to get registration context. xml="
1247: + rcXML, we);
1248: }
1249: }
1250:
1251: String sdXML = p.getProperty(SERVICE_DESCRIPTION);
1252: ServiceDescription sd = null;
1253: if (sdXML != null && sdXML.length() > 0) {
1254: try {
1255: sd = factory.getServiceDescription(sdXML);
1256: } catch (WSRPException we) {
1257: throw new WSRPConsumerException(
1258: "PropertiesProducerEntityManagerImpl.loadProducerEntity(): failed to get service description. xml="
1259: + sdXML, we);
1260: }
1261: }
1262:
1263: String ucXML = p.getProperty(USER_CATEGORY_MAPPING);
1264: Map ucMap = null;
1265: if (ucXML != null && ucXML.length() > 0) {
1266: ucMap = cofactory.getMap(ucXML);
1267: }
1268:
1269: String aupString = p.getProperty(ALLOWED_USER_PROFILE_MAPPING);
1270: Map aupMap = null;
1271: if (aupString != null && aupString.length() > 0) {
1272: aupMap = stringToMap(aupString);
1273: }
1274:
1275: String cupString = p.getProperty(CUSTOM_USER_PROFILE_MAPPING);
1276: Map cupMap = null;
1277: if (cupString != null && cupString.length() > 0) {
1278: cupMap = stringToMap(cupString);
1279: }
1280:
1281: long sdLastModified = -1;
1282: try {
1283: String sdLastModifiedString = p
1284: .getProperty(SERVICE_DESCRIPTION_LAST_MODIFIED);
1285: sdLastModified = Long.parseLong(sdLastModifiedString);
1286: } catch (NumberFormatException nfe) {
1287: throw new WSRPConsumerException(
1288: "PropertiesProducerEntityManagerImpl.loadProducerEntity(): ",
1289: nfe);
1290: }
1291:
1292: String lastModified = p.getProperty(LAST_MODIFIED);
1293:
1294: ProducerEntity pe = new ProducerEntityImpl(id, name, url,
1295: markupEndpoint, status, rd, rc, sd, ucMap, aupMap,
1296: cupMap, sdLastModified, lastModified,
1297: identityPropagationType);
1298: return pe;
1299: }
1300:
1301: protected String getProducerEntityLastModified(
1302: String producerEntityId) throws WSRPConsumerException {
1303:
1304: //debug.debugMessage("PropertiesProducerEntityManagerImpl.getProducerEntityLastModified(): getting PE's last modified time peID=" + producerEntityId);
1305:
1306: StringBuffer filename = new StringBuffer();
1307: filename.append(baseDir.toString()).append(File.separator)
1308: .append(DATA_FILE_BASENAME).append(producerEntityId)
1309: .append(DATA_FILE_EXTENSION);
1310: File file = new File(filename.toString());
1311: Properties p = loadProperties(file);
1312:
1313: return p.getProperty(LAST_MODIFIED);
1314: }
1315:
1316: protected Properties loadGlobalProperties()
1317: throws WSRPConsumerException {
1318: if (logger.isLoggable(Level.FINEST))
1319: logger.log(Level.FINEST, "PSWS_CSPWCPI0012");
1320: File file = new File(DATA_FILE_PATH + File.separator
1321: + GLOBAL_DATA_FILENAME);
1322: Properties p = null;
1323: if (file.exists()) {
1324: p = loadProperties(file);
1325: }
1326: return p;
1327: }
1328:
1329: protected Properties loadOrgProperties()
1330: throws WSRPConsumerException {
1331: if (logger.isLoggable(Level.FINEST))
1332: logger.log(Level.FINEST, "PSWS_CSPWCPI0013");
1333: File file = new File(DATA_FILE_PATH + File.separator
1334: + consumerId + File.separator + ORG_DATA_FILENAME);
1335: Properties p = null;
1336: if (file.exists()) {
1337: p = loadProperties(file);
1338: }
1339: return p;
1340: }
1341:
1342: protected Properties loadProperties(File file)
1343: throws WSRPConsumerException {
1344:
1345: FileInputStream fis = null;
1346: Properties p = null;
1347: try {
1348: fis = new FileInputStream(file);
1349: p = new Properties();
1350: p.load(fis);
1351: fis.close();
1352: } catch (FileNotFoundException fnfe) {
1353: throw new WSRPConsumerException(
1354: "PropertiesProducerEntityManagerImpl.loadProperties(): failed to retrieve producer entity. file="
1355: + file, fnfe);
1356: } catch (IOException ioe) {
1357: throw new WSRPConsumerException(
1358: "PropertiesProducerEntityManagerImpl.loadProperties(): failed to retrieve producer entity. file="
1359: + file, ioe);
1360: }
1361: return p;
1362: }
1363:
1364: protected void storeProducerEntity(ProducerEntity pe)
1365: throws WSRPConsumerException {
1366:
1367: if (logger.isLoggable(Level.FINEST))
1368: logger.log(Level.FINEST, "PSWS_CSPWCPI0014", pe.getId());
1369:
1370: Properties p = new Properties();
1371: p.setProperty(ID, pe.getId());
1372: p.setProperty(NAME, pe.getName());
1373: p.setProperty(URL, pe.getURL().toString());
1374: p.setProperty(MARKUP_ENDPOINT, pe.getMarkupEndpoint());
1375: p
1376: .setProperty(STATUS, Short.toString(pe.getStatus()
1377: .getValue()));
1378:
1379: RegistrationData rd = pe.getRegistrationData();
1380: String rdXML = "";
1381: if (rd != null) {
1382: try {
1383: rdXML = factory.getRegistrationDataXML(rd);
1384: } catch (WSRPException we) {
1385: throw new WSRPConsumerException(
1386: "PropertiesProducerEntityManagerImpl.storeProducerEntity(): failed to marshal registration data. rd="
1387: + rd, we);
1388: }
1389: }
1390: p.setProperty(REGISTRATION_DATA, rdXML);
1391:
1392: RegistrationContext rc = pe.getRegistrationContext();
1393: String rcXML = "";
1394: if (rc != null) {
1395: try {
1396: rcXML = factory.getRegistrationContextXML(rc);
1397: } catch (WSRPException we) {
1398: throw new WSRPConsumerException(
1399: "PropertiesProducerEntityManagerImpl.storeProducerEntity(): failed to marshal registration context. rc="
1400: + rc, we);
1401: }
1402: }
1403: p.setProperty(REGISTRATION_CONTEXT, rcXML);
1404:
1405: ServiceDescription sd = pe.getServiceDescription();
1406: String sdXML = "";
1407: if (sd != null) {
1408: try {
1409: sdXML = factory.getServiceDescriptionXML(sd);
1410: } catch (WSRPException we) {
1411: throw new WSRPConsumerException(
1412: "PropertiesProducerEntityManagerImpl.storeProducerEntity(): failed to marshal service description. sd="
1413: + sd, we);
1414: }
1415: }
1416: p.setProperty(SERVICE_DESCRIPTION, sdXML);
1417:
1418: Map ucs = pe.getUserCategoryMapping();
1419: String ucXML = "";
1420: if (ucs != null && ucs.size() > 0) {
1421: ucXML = cofactory.getMultiValueMapXML(ucs);
1422: }
1423: p.setProperty(USER_CATEGORY_MAPPING, ucXML);
1424:
1425: Map aups = pe.getAllowedUserProfileMapping();
1426: String aupString = "";
1427: if (aups != null && aups.size() > 0) {
1428: aupString = mapToString(aups);
1429: }
1430: p.setProperty(ALLOWED_USER_PROFILE_MAPPING, aupString);
1431:
1432: Map cups = pe.getCustomUserProfileMapping();
1433: String cupString = "";
1434: if (cups != null && cups.size() > 0) {
1435: cupString = mapToString(cups);
1436: }
1437: p.setProperty(CUSTOM_USER_PROFILE_MAPPING, cupString);
1438:
1439: p.setProperty(SERVICE_DESCRIPTION_LAST_MODIFIED, Long
1440: .toString(pe.getServiceDescriptionLastModified()));
1441:
1442: p.setProperty(LAST_MODIFIED, pe.getLastModified());
1443:
1444: if (!baseDir.exists()) {
1445: baseDir.mkdirs();
1446: }
1447: StringBuffer filename = new StringBuffer();
1448: filename.append(baseDir.toString()).append(File.separator)
1449: .append(DATA_FILE_BASENAME).append(pe.getId()).append(
1450: DATA_FILE_EXTENSION);
1451:
1452: //
1453: // delete if file already exists
1454: //
1455: File file = new File(filename.toString());
1456: if (file.exists()) {
1457: file.delete();
1458: }
1459:
1460: String header = COPYRIGHT_HEADER
1461: + "# WSRP Consumer - Producer Entity Data (id: "
1462: + pe.getId() + ")";
1463: storeProperties(p, header, file);
1464: }
1465:
1466: protected void storeGlobalProperties(Properties p)
1467: throws WSRPConsumerException {
1468:
1469: if (logger.isLoggable(Level.FINEST))
1470: logger.log(Level.FINEST, "PSWS_CSPWCPI0015");
1471: File dir = new File(DATA_FILE_PATH);
1472: if (!dir.exists()) {
1473: dir.mkdirs();
1474: }
1475: File file = new File(DATA_FILE_PATH + File.separator
1476: + GLOBAL_DATA_FILENAME);
1477: String header = COPYRIGHT_HEADER
1478: + "# WSRP Consumer - Global Data";
1479: storeProperties(p, header, file);
1480: }
1481:
1482: protected void storeOrgProperties(Properties p)
1483: throws WSRPConsumerException {
1484:
1485: if (logger.isLoggable(Level.FINEST))
1486: logger.log(Level.FINEST, "PSWS_CSPWCPI0016", consumerId);
1487:
1488: if (!baseDir.exists()) {
1489: baseDir.mkdirs();
1490: }
1491: File file = new File(baseDir.toString() + File.separator
1492: + ORG_DATA_FILENAME);
1493: String header = COPYRIGHT_HEADER
1494: + "# WSRP Consumer - Consumer Data (consumerId: "
1495: + consumerId + ")";
1496: storeProperties(p, header, file);
1497: }
1498:
1499: protected void storeProperties(Properties p, String header,
1500: File file) throws WSRPConsumerException {
1501: try {
1502: FileOutputStream fos = new FileOutputStream(file);
1503: p.store(fos, header);
1504: fos.close();
1505: } catch (FileNotFoundException fnfe) {
1506: throw new WSRPConsumerException(
1507: "PropertiesProducerEntityManagerImpl.storeProperties(): failed to store properties.",
1508: fnfe);
1509: } catch (IOException ioe) {
1510: throw new WSRPConsumerException(
1511: "PropertiesProducerEntityManagerImpl.storeProperties(): failed to store properties.",
1512: ioe);
1513: }
1514: }
1515:
1516: protected void deleteProducerEntity(String producerEntityId)
1517: throws WSRPConsumerException {
1518:
1519: StringBuffer filename = new StringBuffer();
1520: filename.append(baseDir.toString()).append(File.separator)
1521: .append(DATA_FILE_BASENAME).append(producerEntityId)
1522: .append(DATA_FILE_EXTENSION);
1523:
1524: File file = new File(filename.toString());
1525: if (file.exists()) {
1526: file.delete();
1527: } else {
1528: throw new WSRPConsumerException(
1529: "PropertiesProducerEntityManagerImpl.deleteProducerEntity(): producer entity does not exist. consumerOrgDN="
1530: + consumerId
1531: + ", producerEntityId="
1532: + producerEntityId);
1533: }
1534: }
1535:
1536: protected static String getConsumerAgent() {
1537: if (consumerAgent == null) {
1538: ResourceBundle prodRB = PropertyResourceBundle
1539: .getBundle("PSversion");
1540: StringBuffer caBuffer = new StringBuffer();
1541: caBuffer.append(prodRB.getString("productname"))
1542: .append(".").append(
1543: prodRB.getString("productversion"));
1544: consumerAgent = caBuffer.toString();
1545: }
1546: return consumerAgent;
1547: }
1548:
1549: protected static Map stringToMap(String mapString) {
1550: Map map = new HashMap();
1551: StringTokenizer st = new StringTokenizer(mapString,
1552: LIST_DELIMITER);
1553: while (st.hasMoreTokens()) {
1554: String item = st.nextToken();
1555: int index = item.indexOf(MAPPING_DELIMITER);
1556: map
1557: .put(item.substring(0, index), item
1558: .substring(index + 1));
1559: }
1560: return map;
1561: }
1562:
1563: protected static String mapToString(Map map) {
1564: StringBuffer buf = new StringBuffer();
1565: for (Iterator i = map.keySet().iterator(); i.hasNext();) {
1566: String key = (String) i.next();
1567: buf.append(key).append(MAPPING_DELIMITER).append(
1568: map.get(key));
1569: if (i.hasNext()) {
1570: buf.append(LIST_DELIMITER);
1571: }
1572: }
1573: return buf.toString();
1574: }
1575:
1576: //
1577: // populate default global properties
1578: //
1579: static {
1580: defaultGlobalProperties = new Properties();
1581: defaultGlobalProperties.setProperty(ENABLED, "true");
1582: Map supMap = new HashMap();
1583: supMap.put("name/prefix", "givenName");
1584: supMap.put("name/given", "givenName");
1585: supMap.put("name/family", "sn");
1586: supMap.put("name/suffix", "generationQualifier");
1587: supMap.put("employerInfo/department", "departmentNumber");
1588: supMap.put("employerInfo/jobtitle", "title");
1589: supMap.put("homeInfo/postal/name", "cn");
1590: supMap.put("homeInfo/postal/street", "street");
1591: supMap.put("homeInfo/postal/city", "l");
1592: supMap.put("homeInfo/postal/stateprov", "st");
1593: supMap.put("homeInfo/postal/postalcode", "postalCode");
1594: supMap.put("homeInfo/postal/country", "c");
1595: supMap.put("homeInfo/postal/organization", "o");
1596: supMap.put("homeInfo/telecom/telephone/number", "homePhone");
1597: supMap.put("homeInfo/telecom/fax/number", "fax");
1598: supMap.put("homeInfo/telecom/mobile/number", "mobile");
1599: supMap.put("homeInfo/telecom/pager/number", "pager");
1600: supMap.put("homeInfo/online/email", "mail");
1601: supMap.put("homeInfo/online/uri", "labeldURI");
1602: supMap.put("businessInfo/postal/name", "cn");
1603: supMap.put("businessInfo/postal/street", "street");
1604: supMap.put("businessInfo/postal/city", "l");
1605: supMap.put("businessInfo/postal/stateprov", "st");
1606: supMap.put("businessInfo/postal/postalcode", "postalCode");
1607: supMap.put("businessInfo/postal/country", "c");
1608: supMap.put("businessInfo/postal/organization", "o");
1609: supMap.put("businessInfo/telecom/telephone/number",
1610: "telephoneNumber");
1611: supMap.put("businessInfo/telecom/fax/number", "fax");
1612: supMap.put("businessInfo/telecom/mobile/number", "mobile");
1613: supMap.put("businessInfo/telecom/pager/number", "pager");
1614: supMap.put("businessInfo/online/email", "mail");
1615: supMap.put("businessInfo/online/uri", "labeldURI");
1616: defaultGlobalProperties.setProperty(
1617: STANDARD_USER_PROFILE_MAPPING, mapToString(supMap));
1618: defaultGlobalProperties
1619: .setProperty(
1620: DEFAULT_REGISTRATION_DATA,
1621: "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><RegistrationData xmlns=\"urn:oasis:names:tc:wsrp:v1:types\"> <consumerName>Default WSRP Consumer</consumerName> <consumerAgent>Unknown Agent.X</consumerAgent> <methodGetSupported>false</methodGetSupported> <consumerModes>wsrp:view</consumerModes> <consumerModes>wsrp:edit</consumerModes> <consumerModes>wsrp:help</consumerModes><!-- <consumerModes>wsrp:preview</consumerModes> --> <consumerWindowStates>wsrp:normal</consumerWindowStates> <consumerWindowStates>wsrp:minimize</consumerWindowStates> <consumerWindowStates>wsrp:maximize</consumerWindowStates> <consumerWindowStates>wsrp:solo</consumerWindowStates> <consumerUserScopes>wsrp:perUser</consumerUserScopes> <consumerUserScopes>wsrp:forAll</consumerUserScopes></RegistrationData>");
1622: }
1623:
1624: public List getEndpoints(URL producerURL)
1625: throws WSRPConsumerException {
1626:
1627: List result = new ArrayList();
1628: String sdEndpoint = stubMgr.getEndpoint(producerURL,
1629: stubMgr.SERVICE_DESCRIPTION_PORT_BINDING);
1630:
1631: String reEndpoint = stubMgr.getEndpoint(producerURL,
1632: stubMgr.REGISTRATION_PORT_BINDING);
1633:
1634: String pmEndpoint = stubMgr.getEndpoint(producerURL,
1635: stubMgr.PORTLET_MANAGEMENT_PORT_BINDING);
1636:
1637: String mkEndpoint = stubMgr.getEndpoint(producerURL,
1638: stubMgr.MARKUP_PORT_BINDING);
1639:
1640: if (mkEndpoint != null) {
1641: result.add(mkEndpoint);
1642: }
1643: if (sdEndpoint != null) {
1644: result.add(sdEndpoint);
1645: }
1646: if (reEndpoint != null) {
1647: result.add(reEndpoint);
1648: }
1649: if (pmEndpoint != null) {
1650: result.add(pmEndpoint);
1651: }
1652: return result;
1653: }
1654: }
|