001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wass/was/configuration/WASConfigurationDocument.java $ 002 /*---------------------------------------------------------------------------- 003 This file is part of deegree, http://deegree.org/ 004 Copyright (C) 2001-2009 by: 005 Department of Geography, University of Bonn 006 and 007 lat/lon GmbH 008 009 This library is free software; you can redistribute it and/or modify it under 010 the terms of the GNU Lesser General Public License as published by the Free 011 Software Foundation; either version 2.1 of the License, or (at your option) 012 any later version. 013 This library is distributed in the hope that it will be useful, but WITHOUT 014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 016 details. 017 You should have received a copy of the GNU Lesser General Public License 018 along with this library; if not, write to the Free Software Foundation, Inc., 019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 021 Contact information: 022 023 lat/lon GmbH 024 Aennchenstr. 19, 53177 Bonn 025 Germany 026 http://lat-lon.de/ 027 028 Department of Geography, University of Bonn 029 Prof. Dr. Klaus Greve 030 Postfach 1147, 53001 Bonn 031 Germany 032 http://www.geographie.uni-bonn.de/deegree/ 033 034 e-mail: info@deegree.org 035 ----------------------------------------------------------------------------*/ 036 037 package org.deegree.ogcwebservices.wass.was.configuration; 038 039 import java.io.IOException; 040 import java.net.URL; 041 042 import org.deegree.framework.log.ILogger; 043 import org.deegree.framework.log.LoggerFactory; 044 import org.deegree.framework.xml.InvalidConfigurationException; 045 import org.deegree.framework.xml.XMLParsingException; 046 import org.deegree.framework.xml.XMLTools; 047 import org.deegree.i18n.Messages; 048 import org.deegree.io.IODocument; 049 import org.deegree.io.JDBCConnection; 050 import org.deegree.model.metadata.iso19115.OnlineResource; 051 import org.deegree.ogcbase.CommonNamespaces; 052 import org.deegree.ogcwebservices.getcapabilities.InvalidCapabilitiesException; 053 import org.deegree.ogcwebservices.wass.was.capabilities.WASCapabilities; 054 import org.deegree.ogcwebservices.wass.was.capabilities.WASCapabilitiesDocument; 055 import org.w3c.dom.Element; 056 import org.w3c.dom.Node; 057 import org.xml.sax.SAXException; 058 059 /** 060 * Parser for the configuration documents of a WAS. 061 * 062 * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a> 063 * @author last edited by: $Author: mschneider $ 064 * 065 * @version 2.0, $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $ 066 * 067 * @since 2.0 068 */ 069 070 public class WASConfigurationDocument extends WASCapabilitiesDocument { 071 072 private static final long serialVersionUID = 4612405238432274887L; 073 074 private static final ILogger LOG = LoggerFactory.getLogger( WASConfigurationDocument.class ); 075 076 private static final String DBPRE = CommonNamespaces.DGJDBC_PREFIX + ":"; 077 078 /** 079 * @param serviceConfigurationUrl 080 * @return the configuration data 081 * @throws InvalidCapabilitiesException 082 * @throws InvalidConfigurationException 083 */ 084 public WASConfiguration parseConfiguration( URL serviceConfigurationUrl ) 085 throws InvalidCapabilitiesException, InvalidConfigurationException { 086 087 WASConfiguration result = null; 088 089 try { 090 load( serviceConfigurationUrl ); 091 WASCapabilities cap = (WASCapabilities) parseCapabilities(); 092 093 /* 094 * The required operation GetSAMLResponse is currently not supported for the was. 095 */ 096 // boolean saml = false; 097 // for ( Operation_1_0 operation : cap.getOperationsMetadata().getAllOperations() ) { 098 // if ( "GetSAMLResponse".equals( operation.getName() ) ) { 099 // saml = true; 100 // break; 101 // } 102 // } 103 // 104 // if ( !saml ) 105 // throw new InvalidCapabilitiesException( 106 // Messages.getMessage( 107 // "WASS_ERROR_CAPABILITIES_MISSING_REQUIRED_OPERATION", 108 // "GetSAMLResponse" ) ); 109 110 WASDeegreeParams deegreeParams = parseDeegreeParams(); 111 112 result = new WASConfiguration( cap, deegreeParams ); 113 114 } catch ( IOException e ) { 115 LOG.logError( e.getLocalizedMessage(), e ); 116 throw new InvalidConfigurationException( 117 Messages.getMessage( 118 "WASS_ERROR_CONFIGURATION_NOT_READ", 119 "WAS" ), e ); 120 } catch ( SAXException e ) { 121 LOG.logError( e.getLocalizedMessage(), e ); 122 throw new InvalidConfigurationException( 123 Messages.getMessage( 124 "WASS_ERROR_CONFIGURATION_NOT_PARSED", 125 "WAS" ), e ); 126 } catch ( XMLParsingException e ) { 127 LOG.logError( e.getLocalizedMessage(), e ); 128 throw new InvalidConfigurationException( 129 Messages.getMessage( 130 "WASS_ERROR_CONFIGURATION_NOT_PARSED", 131 "WAS" ), e ); 132 } 133 134 return result; 135 } 136 137 /** 138 * Creates a class representation of the <code>deegreeParams</code>- section. 139 * 140 * @return the representation 141 * @throws XMLParsingException 142 */ 143 private WASDeegreeParams parseDeegreeParams() 144 throws XMLParsingException { 145 146 147 WASDeegreeParams deegreeParams = null; 148 149 final String preWAS = CommonNamespaces.DEEGREEWAS_PREFIX + ":"; 150 Node root = this.getRootElement(); 151 Element element = (Element) XMLTools.getRequiredNode( root, preWAS + "deegreeParam", 152 nsContext ); 153 154 OnlineResource defaultOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 155 element, 156 preWAS 157 + "DefaultOnlineResource", 158 nsContext ) ); 159 160 // 'CacheSize'-element (optional, default: 100) 161 int cacheSize = XMLTools.getNodeAsInt( element, preWAS + "CacheSize", nsContext, 100 ); 162 163 // 'RequestTimeLimit'-element (optional, default: 15) 164 int requestTimeLimit = XMLTools.getNodeAsInt( element, preWAS + "RequestTimeLimit", 165 nsContext, 15 ) * 1000; 166 167 // 'Encoding'-element (optional, default: UTF-8) 168 String characterSet = XMLTools.getStringValue( "Encoding", CommonNamespaces.DEEGREEWAS, 169 element, "UTF-8" ); 170 171 StringBuffer sb = new StringBuffer().append( "/" ).append( preWAS ); 172 sb.append( "OnlineResource" ); 173 174 // SecuredServiceAddress does not make sense for a WAS 175 // StringBuffer sor = new StringBuffer( preWAS ).append( "SecuredServiceAddress" ).append( sb ); 176 // OnLineResource securedOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 177 // element, 178 // sor.toString(), 179 // nsContext ) ); 180 181 StringBuffer aor = new StringBuffer( preWAS ); 182 aor.append( "AuthenticationServiceAddress" ).append( sb ); 183 OnlineResource authOnlineResource = parseOnLineResource( (Element) XMLTools.getRequiredNode( 184 element, 185 aor.toString(), 186 nsContext ) ); 187 188 int sessionLifetime = XMLTools.getNodeAsInt( element, preWAS + "SessionLifetime", 189 nsContext, 1200 ); 190 sessionLifetime *= 1000; 191 192 // parse database connection 193 Element database = (Element)XMLTools.getNode( element, DBPRE + "JDBCConnection", nsContext ); 194 JDBCConnection dbConnection = null; 195 if( database != null ) { 196 IODocument io = new IODocument( database ); 197 dbConnection = io.parseJDBCConnection(); 198 } 199 200 deegreeParams = new WASDeegreeParams( defaultOnlineResource, cacheSize, requestTimeLimit, 201 characterSet, authOnlineResource, sessionLifetime, dbConnection ); 202 203 204 return deegreeParams; 205 } 206 207 }