001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/ogcwebservices/wass/was/configuration/WASConfigurationDocument.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2004 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 Meckenheimer Allee 176 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 package org.deegree.ogcwebservices.wass.was.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.was.capabilities.WASCapabilities; 061 import org.deegree.ogcwebservices.wass.was.capabilities.WASCapabilitiesDocument; 062 import org.w3c.dom.Element; 063 import org.w3c.dom.Node; 064 import org.xml.sax.SAXException; 065 066 /** 067 * Parser for the configuration documents of a WAS. 068 * 069 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a> 070 * @author last edited by: $Author: aschmitz $ 071 * 072 * @version 2.0, $Revision: 7341 $, $Date: 2007-05-29 14:03:14 +0200 (Di, 29 Mai 2007) $ 073 * 074 * @since 2.0 075 */ 076 077 public class WASConfigurationDocument extends WASCapabilitiesDocument { 078 079 private static final long serialVersionUID = 4612405238432274887L; 080 081 private static final ILogger LOG = LoggerFactory.getLogger( WASConfigurationDocument.class ); 082 083 private static final String DBPRE = CommonNamespaces.DGJDBC_PREFIX + ":"; 084 085 /** 086 * @param serviceConfigurationUrl 087 * @return the configuration data 088 * @throws InvalidCapabilitiesException 089 * @throws InvalidConfigurationException 090 */ 091 public WASConfiguration parseConfiguration( URL serviceConfigurationUrl ) 092 throws InvalidCapabilitiesException, InvalidConfigurationException { 093 094 WASConfiguration result = null; 095 096 try { 097 load( serviceConfigurationUrl ); 098 WASCapabilities cap = (WASCapabilities) parseCapabilities(); 099 100 /* 101 * The required operation GetSAMLResponse is currently not supported for the was. 102 */ 103 // boolean saml = false; 104 // for ( Operation_1_0 operation : cap.getOperationsMetadata().getAllOperations() ) { 105 // if ( "GetSAMLResponse".equals( operation.getName() ) ) { 106 // saml = true; 107 // break; 108 // } 109 // } 110 // 111 // if ( !saml ) 112 // throw new InvalidCapabilitiesException( 113 // Messages.getMessage( 114 // "WASS_ERROR_CAPABILITIES_MISSING_REQUIRED_OPERATION", 115 // "GetSAMLResponse" ) ); 116 117 WASDeegreeParams deegreeParams = parseDeegreeParams(); 118 119 result = new WASConfiguration( cap, deegreeParams ); 120 121 } catch ( IOException e ) { 122 LOG.logError( e.getLocalizedMessage(), e ); 123 throw new InvalidConfigurationException( 124 Messages.getMessage( 125 "WASS_ERROR_CONFIGURATION_NOT_READ", 126 "WAS" ), e ); 127 } catch ( SAXException e ) { 128 LOG.logError( e.getLocalizedMessage(), e ); 129 throw new InvalidConfigurationException( 130 Messages.getMessage( 131 "WASS_ERROR_CONFIGURATION_NOT_PARSED", 132 "WAS" ), e ); 133 } catch ( XMLParsingException e ) { 134 LOG.logError( e.getLocalizedMessage(), e ); 135 throw new InvalidConfigurationException( 136 Messages.getMessage( 137 "WASS_ERROR_CONFIGURATION_NOT_PARSED", 138 "WAS" ), e ); 139 } 140 141 return result; 142 } 143 144 /** 145 * Creates a class representation of the <code>deegreeParams</code>- section. 146 * 147 * @return the representation 148 * @throws XMLParsingException 149 */ 150 private WASDeegreeParams parseDeegreeParams() 151 throws XMLParsingException { 152 153 154 WASDeegreeParams deegreeParams = null; 155 156 final String preWAS = CommonNamespaces.DEEGREEWAS_PREFIX + ":"; 157 Node root = this.getRootElement(); 158 Element element = (Element) XMLTools.getRequiredNode( root, preWAS + "deegreeParam", 159 nsContext ); 160 161 OnlineResource defaultOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 162 element, 163 preWAS 164 + "DefaultOnlineResource", 165 nsContext ) ); 166 167 // 'CacheSize'-element (optional, default: 100) 168 int cacheSize = XMLTools.getNodeAsInt( element, preWAS + "CacheSize", nsContext, 100 ); 169 170 // 'RequestTimeLimit'-element (optional, default: 15) 171 int requestTimeLimit = XMLTools.getNodeAsInt( element, preWAS + "RequestTimeLimit", 172 nsContext, 15 ) * 1000; 173 174 // 'Encoding'-element (optional, default: UTF-8) 175 String characterSet = XMLTools.getStringValue( "Encoding", CommonNamespaces.DEEGREEWAS, 176 element, "UTF-8" ); 177 178 StringBuffer sb = new StringBuffer().append( "/" ).append( preWAS ); 179 sb.append( "OnlineResource" ); 180 181 // SecuredServiceAddress does not make sense for a WAS 182 // StringBuffer sor = new StringBuffer( preWAS ).append( "SecuredServiceAddress" ).append( sb ); 183 // OnLineResource securedOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 184 // element, 185 // sor.toString(), 186 // nsContext ) ); 187 188 StringBuffer aor = new StringBuffer( preWAS ); 189 aor.append( "AuthenticationServiceAddress" ).append( sb ); 190 OnlineResource authOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 191 element, 192 aor.toString(), 193 nsContext ) ); 194 195 int sessionLifetime = XMLTools.getNodeAsInt( element, preWAS + "SessionLifetime", 196 nsContext, 1200 ); 197 sessionLifetime *= 1000; 198 199 // parse database connection 200 Element database = (Element)XMLTools.getNode( element, DBPRE + "JDBCConnection", nsContext ); 201 JDBCConnection dbConnection = null; 202 if( database != null ) { 203 IODocument io = new IODocument( database ); 204 dbConnection = io.parseJDBCConnection(); 205 } 206 207 deegreeParams = new WASDeegreeParams( defaultOnlineResource, cacheSize, requestTimeLimit, 208 characterSet, authOnlineResource, sessionLifetime, dbConnection ); 209 210 211 return deegreeParams; 212 } 213 214 }