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