Utils.java revision 91cb2bef1c88e70b5d433c2a34bca110a35786ce
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: Utils.java,v 1.9 2008/11/10 22:56:59 veiming Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyright 2013 ForgeRock AS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.liberty.ws.soapbinding;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.ByteArrayInputStream;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.ByteArrayOutputStream;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.text.MessageFormat;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.ArrayList;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.Date;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Iterator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.List;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.StringTokenizer;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.bind.Marshaller;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.bind.Unmarshaller;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.bind.JAXBContext;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.bind.JAXBException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.bind.NotIdentifiableEvent;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.bind.PropertyException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.bind.ValidationEvent;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.bind.helpers.DefaultValidationEventHandler;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.namespace.QName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.soap.MessageFactory;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.soap.SOAPMessage;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.xml.soap.MimeHeaders;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.ResourceBundle;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.PeriodicCleanUpMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.SystemTimerPool;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.TaskRunnable;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.TimerPool;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.liberty.ws.util.ProviderManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.liberty.ws.util.ProviderUtil;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.locale.Locale;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.configuration.SystemPropertiesManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.xml.XMLUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport org.w3c.dom.Document;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport org.w3c.dom.Element;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.org.apache.xml.internal.utils.PrefixResolverDefault;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class contains utility methods.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @supported.api
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class Utils {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String NAMESPACE_PREFIX_MAPPING_LIST_PROP =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.jaxb.namespacePrefixMappingList";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String JAXB_PACKAGE_LIST_PROP =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.jaxb.packageList";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String DEFAULT_JAXB_PACKAGES =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.soap:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.assertion:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.protocol:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.ac:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.disco.jaxb:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.disco.jaxb11:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.disco.plugins.jaxb:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.interaction.jaxb:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.meta.jaxb:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.paos.jaxb:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.ps:" +
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington "com.sun.identity.liberty.ws.common.jaxb.security:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.soapbinding.jaxb:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.soapbinding.jaxb11:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.idpp.jaxb:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.idpp.plugin.jaxb:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.secext:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.utility:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.xmlenc:" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.common.jaxb.xmlsig";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static com.sun.identity.liberty.ws.common.jaxb.soap.ObjectFactory soapOF =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new com.sun.identity.liberty.ws.common.jaxb.soap.ObjectFactory();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static com.sun.identity.liberty.ws.soapbinding.jaxb.ObjectFactory soapBOF =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new com.sun.identity.liberty.ws.soapbinding.jaxb.ObjectFactory();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static com.sun.identity.liberty.ws.common.jaxb.secext.ObjectFactory secOF =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new com.sun.identity.liberty.ws.common.jaxb.secext.ObjectFactory();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final QName FAULT_CODE_SERVER =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new QName(SOAPBindingConstants.NS_SOAP, "Server");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String faultStringServerError = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static Debug debug = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static ResourceBundle bundle = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington static MessageFactory messageFactory = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static HashMap nsPrefix = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String jaxbPackages = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static JAXBContext jc = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String STALE_TIME_LIMIT_PROP =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.soap.staleTimeLimit";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static int stale_time_limit = 300000; // millisec
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String SUPPORTED_ACTORS_PROP =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.soap.supportedActors";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String LIBERTY_WSF_VERSION =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.wsf.version";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static Set supportedActors = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static final String MESSAGE_ID_CACHE_CLEANUP_INTERVAL_PROP =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "com.sun.identity.liberty.ws.soap.messageIDCacheCleanupInterval";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static int message_ID_cleanup_interval = 60000; // millisec
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Map messageIDMap = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster bundle = Locale.getInstallResourceBundle("libSOAPBinding");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster faultStringServerError = bundle.getString("ServerError");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug = Debug.getInstance("libIDWSF");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster messageFactory = MessageFactory.newInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Utils.static: Unable to create SOAP Message Factory",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String tmpNSPre =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemPropertiesManager.get(NAMESPACE_PREFIX_MAPPING_LIST_PROP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tmpNSPre != null && tmpNSPre.length() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer stz = new StringTokenizer(tmpNSPre, "|");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while(stz.hasMoreTokens()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String token = stz.nextToken().trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int index = token.indexOf('=');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (index != -1 && index != 0 && index != token.length() - 1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String prefix = token.substring(0, index);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ns = token.substring(index + 1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("Utils.static: add ns = " + ns +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ", prefix = " + prefix);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster nsPrefix.put(ns, prefix);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.warningEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Utils.static: Invalid syntax " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "for Namespace Prefix Mapping List: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String tmpJaxbPkgs = SystemPropertiesManager.get(JAXB_PACKAGE_LIST_PROP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tmpJaxbPkgs != null && tmpJaxbPkgs.length() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster jaxbPackages = DEFAULT_JAXB_PACKAGES + ":" + tmpJaxbPkgs;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington } else {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington jaxbPackages = DEFAULT_JAXB_PACKAGES;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("Utils.static: jaxbPackages = " + jaxbPackages);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster jc = JAXBContext.newInstance(jaxbPackages);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (JAXBException jaxbe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Utils.debug.error("Utils.static:", jaxbe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String tmpstr = SystemPropertiesManager.get(STALE_TIME_LIMIT_PROP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tmpstr != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster stale_time_limit = Integer.parseInt(tmpstr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.warningEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Utils.static: Unable to get stale time " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "limit. Default value will be used");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tmpstr = SystemPropertiesManager.get(SUPPORTED_ACTORS_PROP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tmpstr != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer stz = new StringTokenizer(tmpstr, "|");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while(stz.hasMoreTokens()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String token = stz.nextToken();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (token.length() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster supportedActors.add(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tmpstr =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemPropertiesManager.get(MESSAGE_ID_CACHE_CLEANUP_INTERVAL_PROP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tmpstr != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster message_ID_cleanup_interval = Integer.parseInt(tmpstr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.warningEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Utils.CleanUpThread.static: Unable to" +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster " get stale time limit. Default value " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "will be used");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster messageIDMap = new PeriodicCleanUpMap(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster message_ID_cleanup_interval, stale_time_limit);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SystemTimerPool.getTimerPool().schedule((TaskRunnable) messageIDMap,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new Date(((System.currentTimeMillis() + message_ID_cleanup_interval)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster / 1000) * 1000));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns JAXB namespace prefix mapping. Key is the namespace and value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is the prefix.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
* @return a Map of JAXB namespace prefix mapping
* @supported.api
*/
static public Map getNamespacePrefixMapping() {
return nsPrefix;
}
/**
* Returns a String of JAXB packages seperated by ":".
*
* @return a String of JAXB packages seperated by ":".
* @supported.api
*/
public static String getJAXBPackages() {
return jaxbPackages;
}
/**
* Converts Document to SOAPMessage
*
* @param doc the source Document
* @return SOAPMessage
* @throws SOAPBindingException if an error occurs while converting
* the document
* @supported.api
*/
public static SOAPMessage DocumentToSOAPMessage(Document doc)
throws SOAPBindingException {
SOAPMessage msg = null;
try {
MimeHeaders mimeHeaders = new MimeHeaders();
mimeHeaders.addHeader("Content-Type", "text/xml");
String xmlstr = XMLUtils.print(doc);
if (debug.messageEnabled()) {
debug.message("Utils.DocumentToSOAPMessage: xmlstr = " +
xmlstr);
}
msg = messageFactory.createMessage(
mimeHeaders,
new ByteArrayInputStream(
xmlstr.getBytes(SOAPBindingConstants.DEFAULT_ENCODING)));
} catch (Exception e) {
debug.error("Utils.DocumentToSOAPMessage", e);
throw new SOAPBindingException(e.getMessage());
}
return msg;
}
/**
* Converts a list of JAXB objects to a list of
* <code>org.w3c.dom.Element</code>
*
* @param jaxbObjs a list of JAXB objects
* @return a list of <code>org.w3c.dom.Element</code>
* @throws JAXBException if an error occurs while converting JAXB objects.
*
* @supported.api
*/
public static List convertJAXBToElement(List jaxbObjs)
throws JAXBException{
List result = new ArrayList();
if (jaxbObjs != null && !jaxbObjs.isEmpty()) {
Iterator iter = jaxbObjs.iterator();
while(iter.hasNext()) {
result.add(convertJAXBToElement(iter.next()));
}
}
return result;
}
/**
* Converts a JAXB object to a <code>org.w3c.dom.Element</code>.
*
* @param jaxbObj a JAXB object
* @return a <code>org.w3c.dom.Element</code>
* @throws JAXBException if an error occurs while converting JAXB object.
* @supported.api
*/
public static Element convertJAXBToElement(Object jaxbObj)
throws JAXBException {
Marshaller m = jc.createMarshaller();
try {
m.setProperty("com.sun.xml.bind.namespacePrefixMapper",
new NamespacePrefixMapperImpl());
} catch(PropertyException ex) {
debug.error("Utils.convertJAXBToElement", ex);
}
Document doc = null;
try {
doc = XMLUtils.newDocument();
} catch (Exception ex) {
debug.error("Utils.convertJAXBToElement:", ex);
}
m.marshal(jaxbObj, doc);
return doc.getDocumentElement();
}
/**
* Converts a JAXB object to a <code>org.w3c.dom.Element</code>.
*
* @param jaxbObj a JAXB object
* @return a <code>org.w3c.dom.Element</code>
* @throws JAXBException if an error occurs while converting JAXB object.
* @supported.api
*/
public static Element convertJAXBToElement(Object jaxbObj,
boolean checkIdref) throws JAXBException {
Marshaller m = jc.createMarshaller();
try {
m.setProperty("com.sun.xml.bind.namespacePrefixMapper",
new NamespacePrefixMapperImpl());
} catch(PropertyException ex) {
debug.error("Utils.convertJAXBToElement", ex);
}
if (!checkIdref) {
m.setEventHandler(
new DefaultValidationEventHandler() {
public boolean handleEvent(ValidationEvent event) {
if (event instanceof NotIdentifiableEvent) {
return true;
}
return super.handleEvent(event);
}
});
}
Document doc = null;
try {
doc = XMLUtils.newDocument();
} catch (Exception ex) {
debug.error("Utils.convertJAXBToElement:", ex);
}
m.marshal(jaxbObj, doc);
return doc.getDocumentElement();
}
/**
* Converts a list of <code>org.w3c.dom.Element</code> to a list of
* JAXB objects.
*
* @param elements a list of <code>org.w3c.dom.Element</code>
* @return a list of JAXB objects
* @throws JAXBException if an error occurs while converting
* <code>org.w3c.dom.Element</code>.
* @supported.api
*/
public static List convertElementToJAXB(List elements)
throws JAXBException{
List result = new ArrayList();
if (elements != null && !elements.isEmpty()) {
Iterator iter = elements.iterator();
while(iter.hasNext()) {
result.add(convertElementToJAXB((Element)iter.next()));
}
}
return result;
}
/**
* Converts a <code>org.w3c.dom.Element</code> to a JAXB object.
*
* @param element a <code>org.w3c.dom.Element</code>.
* @return a JAXB object
* @throws JAXBException if an error occurs while converting
* <code>org.w3c.dom.Element</code>
* @supported.api
*/
public static Object convertElementToJAXB(Element element)
throws JAXBException {
Unmarshaller u = jc.createUnmarshaller();
return u.unmarshal(element);
}
/**
* Converts a value of XML boolean type to Boolean object.
*
* @param str a value of XML boolean type
* @return a Boolean object
* @throws Exception if there is a syntax error
* @supported.api
*/
public static Boolean StringToBoolean(String str) throws Exception {
if (str == null) {
return null;
}
if (str.equals("true") || str.equals("1")) {
return Boolean.TRUE;
}
if (str.equals("false") || str.equals("0")) {
return Boolean.FALSE;
}
throw new Exception();
}
/**
* Converts a Boolean object to a String representing XML boolean.
*
* @param bool a Boolean object.
* @return a String representing the boolean value.
* @supported.api
*/
public static String BooleanToString(Boolean bool) {
if (bool == null) {
return "";
}
return bool.booleanValue() ? "1" : "0";
}
/**
* Converts a string value to a QName. The prefix of the string value
* is resolved to a namespace relative to the element.
*
* @param str the String to be converted.
* @param element the Element object.
* @return the QName Object.
* @supported.api
*/
public static QName convertStringToQName(String str,Element element) {
if (str == null) {
return null;
}
String prefix = "";
String localPart;
int index = str.indexOf(":");
if (index == -1) {
localPart = str;
} else {
prefix = str.substring(0, index);
localPart = str.substring(index + 1);
}
PrefixResolverDefault prd =
new PrefixResolverDefault(element.getOwnerDocument());
String ns = prd.getNamespaceForPrefix(prefix, element);
return new QName(ns, localPart);
}
/**
* Enforces message processiong rules defined in the spec.
*
* @param message a message
* @param requestMessageID the request messageID if we are checking a
* response message or null if we are checking a
* request message
* @param isServer true if this is a server
* @throws SOAPBindingException if the message violates rules on client.
* @throws SOAPFaultException if the message violates rules on server.
*/
public static void enforceProcessingRules(Message message, String requestMessageID,
boolean isServer)
throws SOAPBindingException, SOAPFaultException {
CorrelationHeader corrH = message.getCorrelationHeader();
String messageID = corrH.getMessageID();
checkCorrelationHeader(corrH, requestMessageID, isServer);
checkProviderHeader(message.getProviderHeader(), messageID, isServer);
checkProcessingContextHeader(message.getProcessingContextHeader(),
messageID, isServer);
checkConsentHeader(message.getConsentHeader(), messageID, isServer);
List usagHs = message.getUsageDirectiveHeaders();
if (usagHs != null && !usagHs.isEmpty()) {
Iterator iter = usagHs.iterator();
while(iter.hasNext()) {
UsageDirectiveHeader usagH = (UsageDirectiveHeader)iter.next();
checkUsageDirectiveHeader(usagH, messageID, isServer);
}
}
}
/**
* Enforces message Correlation header processiong rules defined
* in the spec.
*
* @param corrH a Correlation header
* @param requestMessageID the request messageID if we are checking a
* response message or null if we are checking a
* request message
* @param isServer true if this is a server
* @throws SOAPBindingException if the Correlation header violates rules
* on client side
* @throws SOAPFaultException if the Correlation header violates rules
* on server side
*/
static void checkCorrelationHeader(CorrelationHeader corrH,
String requestMessageID, boolean isServer)
throws SOAPBindingException, SOAPFaultException {
if (corrH == null) {
if (isServer) {
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null,
new SOAPFaultDetail(
SOAPFaultDetail.ID_STAR_MSG_NOT_UNSTD,null,null));
throw new SOAPFaultException(new Message(sf));
} else {
throw new SOAPBindingException(
bundle.getString("CorrelationHeaderNull"));
}
}
String messageID = corrH.getMessageID();
try {
checkActorAndMustUnderstand(corrH.getActor(),
corrH.getMustUnderstand(),
messageID, isServer);
} catch (SOAPFaultException sfe) {
sfe.getSOAPFaultMessage().getSOAPFault().getDetail()
.setCorrelationHeader(corrH);
throw sfe;
}
Date timestamp = corrH.getTimestamp();
Date now = new Date();
if ((now.getTime() - timestamp.getTime()) > stale_time_limit) {
if (isServer) {
SOAPFaultDetail sfd =
new SOAPFaultDetail(SOAPFaultDetail.STALE_MSG,
messageID, null);
sfd.setCorrelationHeader(corrH);
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null, sfd);
throw new SOAPFaultException(new Message(sf));
} else {
throw new SOAPBindingException(bundle.getString("staleMsg"));
}
}
Long prevMsgIDTime = (Long)messageIDMap.get(messageID);
long currentTime = System.currentTimeMillis();
if (prevMsgIDTime != null &&
currentTime - prevMsgIDTime.longValue() < stale_time_limit) {
if (isServer) {
SOAPFaultDetail sfd =
new SOAPFaultDetail(SOAPFaultDetail.DUPLICATE_MSG,
messageID, null);
sfd.setCorrelationHeader(corrH);
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null, sfd);
throw new SOAPFaultException(new Message(sf));
} else {
throw new SOAPBindingException(bundle.getString("dupMsg"));
}
} else {
synchronized (messageIDMap) {
if (debug.messageEnabled()) {
debug.message("Utils.checkCorrelationHeader: adding " +
"messageID: " + messageID);
}
messageIDMap.put(messageID, new Long(currentTime));
}
}
String refToMessageID = corrH.getRefToMessageID();
if (refToMessageID != null && requestMessageID != null &&
!refToMessageID.equals(requestMessageID)) {
if (isServer) {
SOAPFaultDetail sfd =
new SOAPFaultDetail(
SOAPFaultDetail.INVALID_REF_TO_MSG_ID,messageID, null);
sfd.setCorrelationHeader(corrH);
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null, sfd);
throw new SOAPFaultException(new Message(sf));
} else {
throw new SOAPBindingException(bundle.getString("invalidRef"));
}
}
}
/**
* Enforces message Provider header processiong rules defined
* in the spec.
*
* @param corrH a Correlation header
* @param messageID the messageID in Correlation header
* @param isServer true if this is a server
* @throws SOAPBindingException if the Provider header violates rules
* on client side
* @throws SOAPFaultException if the Provider header violates rules
* on server side
*/
static void checkProviderHeader(ProviderHeader provH,
String messageID,boolean isServer)
throws SOAPBindingException, SOAPFaultException {
if (provH == null) {
return;
}
try {
checkActorAndMustUnderstand(provH.getActor(),
provH.getMustUnderstand(),
messageID, isServer);
} catch (SOAPFaultException sfe) {
sfe.getSOAPFaultMessage().getSOAPFault().getDetail()
.setProviderHeader(provH);
throw sfe;
}
if (isServer && SOAPBindingService.enforceOnlyKnownProviders()) {
String providerID = provH.getProviderID();
ProviderManager providerManager = ProviderUtil.getProviderManager();
if (!providerManager.containsProvider(providerID)) {
SOAPFaultDetail sfd = new SOAPFaultDetail(
SOAPFaultDetail.PROVIDER_ID_NOT_VALID, messageID, null);
sfd.setProviderHeader(provH);
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null, sfd);
throw new SOAPFaultException(new Message(sf));
}
String affID = provH.getAffiliationID();
if ((affID != null) &&
(!providerManager.isAffiliationMember(providerID, affID))) {
SOAPFaultDetail sfd = new SOAPFaultDetail(
SOAPFaultDetail.AFFILIATION_ID_NOT_VALID, messageID, null);
sfd.setProviderHeader(provH);
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null, sfd);
throw new SOAPFaultException(new Message(sf));
}
}
}
/**
* Enforces message Processing Context header processiong rules defined
* in the spec.
* @param procH a Processing Context header
* @param messageID the messageID in Correlation header
* @param isServer true if this is a server
* @throws SOAPBindingException if the Processing Context header
* violates rules on client side
* @throws SOAPFaultException if the Processing Context header violates
* rules on server side
*/
static void checkProcessingContextHeader(ProcessingContextHeader procH,
String messageID, boolean isServer)
throws SOAPBindingException, SOAPFaultException {
if (procH == null) {
return;
}
try {
checkActorAndMustUnderstand(procH.getActor(),
procH.getMustUnderstand(),
messageID, isServer);
} catch (SOAPFaultException sfe) {
sfe.getSOAPFaultMessage().getSOAPFault().getDetail()
.setProcessingContextHeader(procH);
throw sfe;
}
if (isServer) {
SOAPFaultDetail sfd =
new SOAPFaultDetail(SOAPFaultDetail.PROC_CTX_URI_NOT_UNSTD,
messageID, null);
sfd.setProcessingContextHeader(procH);
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null, sfd);
throw new SOAPFaultException(new Message(sf));
} else {
throw new SOAPBindingException(
bundle.getString("ProcessingContextUnsupported"));
}
}
/**
* Enforces message Consent header processiong rules defined in the spec.
*
* @param consH a Consent header
* @param messageID the messageID in Correlation header
* @param isServer true if this is a server
* @throws SOAPBindingException if the Consent header violates rules on
* client side
* @throws SOAPFaultException if the Consent header violates rules
* on server side
*/
static void checkConsentHeader(ConsentHeader consH,String messageID,
boolean isServer) throws SOAPBindingException, SOAPFaultException {
if (consH == null) {
return;
}
try {
checkActorAndMustUnderstand(consH.getActor(),
consH.getMustUnderstand(),
messageID, isServer);
} catch (SOAPFaultException sfe) {
sfe.getSOAPFaultMessage().getSOAPFault().getDetail()
.setConsentHeader(consH);
throw sfe;
}
}
/**
* Enforces message Usage Directive header processiong rules defined in
* the spec.
*
* @param usagH a Usage Directive header
* @param messageID the messageID in Correlation header
* @param isServer true if this is a server
* @throws SOAPBindingException if the Usage Directive header violates
* rules on client side
* @throws SOAPFaultException if the Usage Directive header violates
* rules on server side
*/
static void checkUsageDirectiveHeader(UsageDirectiveHeader usagH,
String messageID,boolean isServer)
throws SOAPBindingException, SOAPFaultException {
if (usagH == null) {
return;
}
try {
checkActorAndMustUnderstand(usagH.getActor(),
usagH.getMustUnderstand(),
messageID, isServer);
} catch (SOAPFaultException sfe) {
List usagHs = new ArrayList();
usagHs.add(usagH);
sfe.getSOAPFaultMessage().getSOAPFault().getDetail()
.setUsageDirectiveHeaders(usagHs);
throw sfe;
}
}
/**
* Checks 'actor' and 'mustUnderstand' attribute of a header.
*
* @param actor the value of 'actor' attribute of a header.
* @param mustUnderstand the value of 'mustUnderstand' attribute of a
* header.
* @param messageID the messageID in Correlation header.
* @param isServer true if this is a server.
* @throws SOAPBindingException if the actor and mustUnderstand violates
* rules on client side
* @throws SOAPFaultException if the actor and mustUnderstand violates
* rules on server side
*/
static void checkActorAndMustUnderstand(String actor,Boolean mustUnderstand,
String messageID,boolean isServer)
throws SOAPBindingException, SOAPFaultException {
if (actor != null && !supportedActors.contains(actor)) {
if (isServer) {
SOAPFaultDetail sfd =
new SOAPFaultDetail(SOAPFaultDetail.BOGUS_ACTOR,
messageID, null);
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null, sfd);
throw new SOAPFaultException(new Message(sf));
} else {
throw new SOAPBindingException(
bundle.getString("bogusActor"));
}
}
if (mustUnderstand != null && !mustUnderstand.booleanValue()) {
if (isServer) {
SOAPFaultDetail sfd =
new SOAPFaultDetail(SOAPFaultDetail.BOGUS_MUST_UNSTND,
messageID, null);
SOAPFault sf = new SOAPFault(FAULT_CODE_SERVER,
faultStringServerError, null, sfd);
throw new SOAPFaultException(new Message(sf));
} else {
throw new SOAPBindingException(
bundle.getString("bogusMustUnderstand"));
}
}
}
/**
* Gets localized string from resource bundle.
*
* @param key a key to a resource bundle
* @param params parameters to MessageFormat
* @return a localized string.
* @supported.api
*/
public static String getString(String key, Object[] params) {
return MessageFormat.format(bundle.getString(key), params);
}
/**
* Returns the default web services version.
*
* @return the default web services version.
*/
public static String getDefaultWSFVersion() {
return SystemPropertiesManager.get(LIBERTY_WSF_VERSION,
SOAPBindingConstants.WSF_11_VERSION);
}
}