001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/ogcwebservices/wass/wss/configuration/WSSConfigurationDocument.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2008 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/deegree/ 008 lat/lon GmbH 009 http://www.lat-lon.de 010 011 This library is free software; you can redistribute it and/or 012 modify it under the terms of the GNU Lesser General Public 013 License as published by the Free Software Foundation; either 014 version 2.1 of the License, or (at your option) any later version. 015 016 This library is distributed in the hope that it will be useful, 017 but WITHOUT ANY WARRANTY; without even the implied warranty of 018 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 019 Lesser General Public License for more details. 020 021 You should have received a copy of the GNU Lesser General Public 022 License along with this library; if not, write to the Free Software 023 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 024 025 Contact: 026 027 Andreas Poth 028 lat/lon GmbH 029 Aennchenstr. 19 030 53115 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Prof. Dr. Klaus Greve 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: greve@giub.uni-bonn.de 041 042 043 ---------------------------------------------------------------------------*/ 044 045 package org.deegree.ogcwebservices.wass.wss.configuration; 046 047 import java.io.IOException; 048 import java.net.URL; 049 050 import org.deegree.framework.log.ILogger; 051 import org.deegree.framework.log.LoggerFactory; 052 import org.deegree.framework.xml.InvalidConfigurationException; 053 import org.deegree.framework.xml.XMLParsingException; 054 import org.deegree.framework.xml.XMLTools; 055 import org.deegree.i18n.Messages; 056 import org.deegree.io.IODocument; 057 import org.deegree.io.JDBCConnection; 058 import org.deegree.model.metadata.iso19115.OnlineResource; 059 import org.deegree.ogcbase.CommonNamespaces; 060 import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException; 061 import org.deegree.ogcwebservices.wass.common.Operation_1_0; 062 import org.deegree.ogcwebservices.wass.wss.capabilities.WSSCapabilities; 063 import org.deegree.ogcwebservices.wass.wss.capabilities.WSSCapabilitiesDocument; 064 import org.w3c.dom.Element; 065 import org.w3c.dom.Node; 066 import org.xml.sax.SAXException; 067 068 /** 069 * This class is called from the WSServiceFactory to read a configuration xml file. This file 070 * consains all the capabilities this Web Security Service is able to. The standard calling 071 * procedure is new WSSConfigurationDocument().getConfiguration( url_to_file ). This method returns 072 * the "bean" in form of a WSSConfiguration class, which can be queried for it's values. 073 * 074 * @see WSSConfiguration 075 * 076 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a> 077 * @author last edited by: $Author: apoth $ 078 * 079 * @version 2.0, $Revision: 9345 $, $Date: 2007-12-27 17:22:25 +0100 (Do, 27 Dez 2007) $ 080 * 081 * @since 2.0 082 */ 083 084 public class WSSConfigurationDocument extends WSSCapabilitiesDocument { 085 /** 086 * 087 */ 088 private static final long serialVersionUID = 4612405238432274887L; 089 090 /** 091 * The logger enhances the quality and simplicity of Debugging within the deegree2 framework 092 */ 093 private static final ILogger LOG = LoggerFactory.getLogger( WSSConfigurationDocument.class ); 094 095 private static final String DBPRE = CommonNamespaces.DGJDBC_PREFIX + ":"; 096 097 /** 098 * Loads the configuration file located at the given urls location. 099 * 100 * @param serviceConfigurationUrl 101 * the url to the configuration file 102 * @return a WSSConfiguration which is a "bean" representation of the configuration xml document 103 * @throws InvalidConfigurationException 104 * if an error occrur either with opening or parsing the xml configuration file. 105 * @throws InvalidCapabilitiesException 106 */ 107 public WSSConfiguration parseConfiguration( URL serviceConfigurationUrl ) 108 throws InvalidConfigurationException, InvalidCapabilitiesException { 109 110 111 WSSConfiguration result = null; 112 try { 113 load( serviceConfigurationUrl ); 114 WSSCapabilities capabilities = (WSSCapabilities) parseCapabilities(); 115 boolean doService = false; 116 for( Operation_1_0 operation : capabilities.getOperationsMetadata().getAllOperations() ){ 117 if( "DoService".equals(operation.getName()) ){ 118 doService = true; 119 break; 120 } 121 } 122 123 if( !doService ) 124 throw new InvalidCapabilitiesException( 125 Messages.getMessage( 126 "WASS_ERROR_CAPABILITIES_MISSING_REQUIRED_OPERATION", 127 "DoService" ) ); 128 129 WSSDeegreeParams deegreeParams = parseDeegreeParams( ); 130 result = new WSSConfiguration( capabilities, deegreeParams ); 131 } catch ( IOException e ) { 132 LOG.logError( e.getLocalizedMessage(), e ); 133 throw new InvalidConfigurationException( 134 Messages.getMessage( 135 "WASS_ERROR_CONFIGURATION_NOT_READ", 136 "WSS" ), e ); 137 } catch ( SAXException e ) { 138 LOG.logError( e.getLocalizedMessage(), e ); 139 throw new InvalidConfigurationException( 140 Messages.getMessage( 141 "WASS_ERROR_CONFIGURATION_NOT_PARSED", 142 "WSS" ), e ); 143 } catch ( XMLParsingException e ) { 144 LOG.logError( e.getLocalizedMessage(), e ); 145 throw new InvalidConfigurationException( 146 Messages.getMessage( 147 "WASS_ERROR_CONFIGURATION_NOT_PARSED", 148 "WSS" ), e ); 149 } 150 151 152 return result; 153 } 154 155 /** 156 * Creates a class representation of the <code>deegreeParams</code>- section which are wss 157 * specific. 158 * 159 * @return the deegree parameter data 160 * @throws XMLParsingException 161 */ 162 private WSSDeegreeParams parseDeegreeParams() 163 throws XMLParsingException { 164 165 WSSDeegreeParams deegreeParams = null; 166 167 final String preWSS = CommonNamespaces.DEEGREEWSS_PREFIX + ":"; 168 Node root = this.getRootElement(); 169 170 Element element = (Element) XMLTools.getRequiredNode( root, preWSS + "deegreeParam", 171 nsContext ); 172 173 OnlineResource defaultOnlineResource = null; 174 defaultOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 175 element, 176 preWSS 177 + "DefaultOnlineResource", 178 nsContext ) ); 179 180 // 'deegreecsw:CacheSize'-element (optional, default: 100) 181 int cacheSize = 0; 182 cacheSize = XMLTools.getNodeAsInt( element, preWSS + "CacheSize", nsContext, 100 ); 183 184 // 'deegreecsw:RequestTimeLimit'-element (optional, default: 15) 185 int requestTimeLimit = XMLTools.getNodeAsInt( element, preWSS + "RequestTimeLimit", 186 nsContext, 15 ); 187 requestTimeLimit *= 1000; 188 189 190 // 'deegreecsw:Encoding'-element (optional, default: UTF-8) 191 String characterSet = null; 192 characterSet = XMLTools.getNodeAsString( element, preWSS + "Encoding", nsContext, "UTF-8" ); 193 194 StringBuffer sb = new StringBuffer().append( "/" ).append( preWSS ); 195 sb.append( "OnlineResource" ); 196 StringBuffer sor = new StringBuffer( preWSS ).append( "SecuredServiceAddress" ).append( sb ); 197 OnlineResource securedOnlineResource = null; 198 securedOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 199 element, 200 sor.toString(), 201 nsContext ) ); 202 203 StringBuffer aor = new StringBuffer( preWSS ); 204 aor.append( "AuthenticationServiceAddress" ).append( sb ); 205 OnlineResource authOnlineResource = null; 206 authOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 207 element, 208 aor.toString(), 209 nsContext ) ); 210 211 int sessionLifetime = XMLTools.getNodeAsInt( element, preWSS + "SessionLifetime", 212 nsContext, 1200 ); 213 sessionLifetime *= 1000; 214 215 // parse database connection 216 Element database = (Element)XMLTools.getNode( element, DBPRE + "JDBCConnection", nsContext ); 217 JDBCConnection dbConnection = null; 218 if( database != null ) { 219 IODocument io = new IODocument( database ); 220 dbConnection = io.parseJDBCConnection(); 221 } 222 223 deegreeParams = new WSSDeegreeParams( defaultOnlineResource, cacheSize, requestTimeLimit, 224 characterSet, securedOnlineResource, 225 authOnlineResource, sessionLifetime, dbConnection ); 226 227 228 return deegreeParams; 229 } 230 }