001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wass/wss/configuration/WSSConfigurationDocument.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2006 by: 006 EXSE, Department of Geography, University of Bonn 007 http://www.giub.uni-bonn.de/exse/ 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 Aennchenstraße 19 030 53177 Bonn 031 Germany 032 E-Mail: poth@lat-lon.de 033 034 Jens Fitzke 035 Department of Geography 036 University of Bonn 037 Meckenheimer Allee 166 038 53115 Bonn 039 Germany 040 E-Mail: jens.fitzke@uni-bonn.de 041 042 ---------------------------------------------------------------------------*/ 043 044 package org.deegree.ogcwebservices.wass.wss.configuration; 045 046 import java.io.IOException; 047 import java.net.URL; 048 049 import org.deegree.framework.log.ILogger; 050 import org.deegree.framework.log.LoggerFactory; 051 import org.deegree.framework.xml.InvalidConfigurationException; 052 import org.deegree.framework.xml.XMLParsingException; 053 import org.deegree.framework.xml.XMLTools; 054 import org.deegree.i18n.Messages; 055 import org.deegree.io.IODocument; 056 import org.deegree.io.JDBCConnection; 057 import org.deegree.model.metadata.iso19115.OnlineResource; 058 import org.deegree.ogcbase.CommonNamespaces; 059 import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException; 060 import org.deegree.ogcwebservices.wass.common.Operation_1_0; 061 import org.deegree.ogcwebservices.wass.wss.capabilities.WSSCapabilities; 062 import org.deegree.ogcwebservices.wass.wss.capabilities.WSSCapabilitiesDocument; 063 import org.w3c.dom.Element; 064 import org.w3c.dom.Node; 065 import org.xml.sax.SAXException; 066 067 /** 068 * This class is called from the WSServiceFactory to read a configuration xml file. This file 069 * consains all the capabilities this Web Security Service is able to. The standard calling 070 * procedure is new WSSConfigurationDocument().getConfiguration( url_to_file ). This method returns 071 * the "bean" in form of a WSSConfiguration class, which can be queried for it's values. 072 * 073 * @see WSSConfiguration 074 * 075 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a> 076 * @author last edited by: $Author: aschmitz $ 077 * 078 * @version 2.0, $Revision: 7341 $, $Date: 2007-05-29 14:03:14 +0200 (Di, 29 Mai 2007) $ 079 * 080 * @since 2.0 081 */ 082 083 public class WSSConfigurationDocument extends WSSCapabilitiesDocument { 084 /** 085 * 086 */ 087 private static final long serialVersionUID = 4612405238432274887L; 088 089 /** 090 * The logger enhances the quality and simplicity of Debugging within the deegree2 framework 091 */ 092 private static final ILogger LOG = LoggerFactory.getLogger( WSSConfigurationDocument.class ); 093 094 private static final String DBPRE = CommonNamespaces.DGJDBC_PREFIX + ":"; 095 096 /** 097 * Loads the configuration file located at the given urls location. 098 * 099 * @param serviceConfigurationUrl 100 * the url to the configuration file 101 * @return a WSSConfiguration which is a "bean" representation of the configuration xml document 102 * @throws InvalidConfigurationException 103 * if an error occrur either with opening or parsing the xml configuration file. 104 * @throws InvalidCapabilitiesException 105 */ 106 public WSSConfiguration parseConfiguration( URL serviceConfigurationUrl ) 107 throws InvalidConfigurationException, InvalidCapabilitiesException { 108 109 110 WSSConfiguration result = null; 111 try { 112 load( serviceConfigurationUrl ); 113 WSSCapabilities capabilities = (WSSCapabilities) parseCapabilities(); 114 boolean doService = false; 115 for( Operation_1_0 operation : capabilities.getOperationsMetadata().getAllOperations() ){ 116 if( "DoService".equals(operation.getName()) ){ 117 doService = true; 118 break; 119 } 120 } 121 122 if( !doService ) 123 throw new InvalidCapabilitiesException( 124 Messages.getMessage( 125 "WASS_ERROR_CAPABILITIES_MISSING_REQUIRED_OPERATION", 126 "DoService" ) ); 127 128 WSSDeegreeParams deegreeParams = parseDeegreeParams( ); 129 result = new WSSConfiguration( capabilities, deegreeParams ); 130 } catch ( IOException e ) { 131 LOG.logError( e.getLocalizedMessage(), e ); 132 throw new InvalidConfigurationException( 133 Messages.getMessage( 134 "WASS_ERROR_CONFIGURATION_NOT_READ", 135 "WSS" ), e ); 136 } catch ( SAXException e ) { 137 LOG.logError( e.getLocalizedMessage(), e ); 138 throw new InvalidConfigurationException( 139 Messages.getMessage( 140 "WASS_ERROR_CONFIGURATION_NOT_PARSED", 141 "WSS" ), e ); 142 } catch ( XMLParsingException e ) { 143 LOG.logError( e.getLocalizedMessage(), e ); 144 throw new InvalidConfigurationException( 145 Messages.getMessage( 146 "WASS_ERROR_CONFIGURATION_NOT_PARSED", 147 "WSS" ), e ); 148 } 149 150 151 return result; 152 } 153 154 /** 155 * Creates a class representation of the <code>deegreeParams</code>- section which are wss 156 * specific. 157 * 158 * @return the deegree parameter data 159 * @throws XMLParsingException 160 */ 161 private WSSDeegreeParams parseDeegreeParams() 162 throws XMLParsingException { 163 164 WSSDeegreeParams deegreeParams = null; 165 166 final String preWSS = CommonNamespaces.DEEGREEWSS_PREFIX + ":"; 167 Node root = this.getRootElement(); 168 169 Element element = (Element) XMLTools.getRequiredNode( root, preWSS + "deegreeParam", 170 nsContext ); 171 172 OnlineResource defaultOnlineResource = null; 173 defaultOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 174 element, 175 preWSS 176 + "DefaultOnlineResource", 177 nsContext ) ); 178 179 // 'deegreecsw:CacheSize'-element (optional, default: 100) 180 int cacheSize = 0; 181 cacheSize = XMLTools.getNodeAsInt( element, preWSS + "CacheSize", nsContext, 100 ); 182 183 // 'deegreecsw:RequestTimeLimit'-element (optional, default: 15) 184 int requestTimeLimit = XMLTools.getNodeAsInt( element, preWSS + "RequestTimeLimit", 185 nsContext, 15 ); 186 requestTimeLimit *= 1000; 187 188 189 // 'deegreecsw:Encoding'-element (optional, default: UTF-8) 190 String characterSet = null; 191 characterSet = XMLTools.getNodeAsString( element, preWSS + "Encoding", nsContext, "UTF-8" ); 192 193 StringBuffer sb = new StringBuffer().append( "/" ).append( preWSS ); 194 sb.append( "OnlineResource" ); 195 StringBuffer sor = new StringBuffer( preWSS ).append( "SecuredServiceAddress" ).append( sb ); 196 OnlineResource securedOnlineResource = null; 197 securedOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 198 element, 199 sor.toString(), 200 nsContext ) ); 201 202 StringBuffer aor = new StringBuffer( preWSS ); 203 aor.append( "AuthenticationServiceAddress" ).append( sb ); 204 OnlineResource authOnlineResource = null; 205 authOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 206 element, 207 aor.toString(), 208 nsContext ) ); 209 210 int sessionLifetime = XMLTools.getNodeAsInt( element, preWSS + "SessionLifetime", 211 nsContext, 1200 ); 212 sessionLifetime *= 1000; 213 214 // parse database connection 215 Element database = (Element)XMLTools.getNode( element, DBPRE + "JDBCConnection", nsContext ); 216 JDBCConnection dbConnection = null; 217 if( database != null ) { 218 IODocument io = new IODocument( database ); 219 dbConnection = io.parseJDBCConnection(); 220 } 221 222 deegreeParams = new WSSDeegreeParams( defaultOnlineResource, cacheSize, requestTimeLimit, 223 characterSet, securedOnlineResource, 224 authOnlineResource, sessionLifetime, dbConnection ); 225 226 227 return deegreeParams; 228 } 229 }