001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/ogcwebservices/wass/wss/operation/DoService.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.wss.operation;
038    
039    import java.net.URI;
040    import java.util.ArrayList;
041    import java.util.List;
042    import java.util.Map;
043    
044    import org.deegree.framework.log.ILogger;
045    import org.deegree.framework.log.LoggerFactory;
046    import org.deegree.framework.util.StringTools;
047    import org.deegree.framework.xml.XMLParsingException;
048    import org.deegree.ogcwebservices.OGCWebServiceException;
049    import org.deegree.ogcwebservices.OGCWebServiceRequest;
050    import org.deegree.ogcwebservices.wass.common.AbstractRequest;
051    import org.deegree.ogcwebservices.wass.common.AuthenticationData;
052    import org.deegree.ogcwebservices.wass.common.URN;
053    import org.w3c.dom.Element;
054    
055    /**
056     * The <code>DoService</code> class represents (a bean) a DoService Operation which is send by a client (or other
057     * server) which is checked by the wss for the right credentials and than send to the requested
058     * serviceprovider. In the case that a client not has the right credentials a ServiceException is
059     * thrown. The Specification does mention the fact that ther might be another response for example:
060     * A client orders A and B but only has the credentials for A -> should we return A and not B or
061     * nothing at all. We do the last, the client gets nothing.
062     *
063     * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
064     * @author last edited by: $Author: mschneider $
065     *
066     * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $
067     */
068    
069    public class DoService extends AbstractRequest {
070    
071        private static final long serialVersionUID = -8538267299180579690L;
072    
073        /**
074         * The logger enhances the quality and simplicity of Debugging within the deegree2 framework
075         */
076        private static final ILogger LOG = LoggerFactory.getLogger( DoService.class );
077    
078        private AuthenticationData authenticationData = null;
079    
080        private String dcp = null;
081    
082        private ArrayList<RequestParameter> requestParameters = null;
083    
084        private String payload = null;
085    
086        private URI facadeURL = null;
087    
088        /**
089         * @param id the request id
090         * @param service
091         * @param version
092         * @param authenticationData
093         * @param dcp
094         * @param requestParameters
095         * @param payload
096         * @param facadeURL
097         */
098        public DoService( String id, String service, String version, AuthenticationData authenticationData,
099                         String dcp, ArrayList<RequestParameter> requestParameters, String payload,
100                         URI facadeURL ) {
101            super( id, version, service, "DoService" );
102            this.authenticationData = authenticationData;
103            this.dcp = dcp;
104            this.requestParameters = requestParameters;
105            this.payload = payload;
106            this.facadeURL = facadeURL;
107        }
108    
109        /**
110         * @param id the request id
111         * @param keyValues
112         */
113        public DoService( String id, Map<String, String> keyValues ) {
114            super( id, keyValues );
115    
116            LOG.logDebug( keyValues.toString() );
117    
118            this.authenticationData = new AuthenticationData( new URN( keyValues.get( "AUTHMETHOD" ) ),
119                                                              keyValues.get( "CREDENTIALS" ) );
120            this.dcp = keyValues.get( "DCP" );
121            this.payload = keyValues.get( "SERVICEREQUEST" );
122            try {
123                this.facadeURL = new URI( keyValues.get( "FACADEURL" ) );
124            } catch ( Exception e ) {
125                LOG.logError( e.getMessage(), e );
126            }
127    
128            requestParameters = new ArrayList<RequestParameter>();
129    
130            String requestParams = keyValues.get( "REQUESTPARAMS" );
131            List<String> params = StringTools.toList( requestParams, ",", false );
132    
133            String requestParamValues = keyValues.get( "REQUESTPARAMVALUES" );
134            List<String> paramValues = StringTools.toList( requestParamValues, ",", false );
135    
136            for ( int i = 0; i < params.size(); ++i ) {
137                this.requestParameters.add( new RequestParameter( params.get( i ), paramValues.get( i ) ) );
138            }
139    
140        }
141    
142        /**
143         * @return Returns the authenticationData.
144         */
145        public AuthenticationData getAuthenticationData() {
146            return authenticationData;
147        }
148    
149        /**
150         * @return Returns the dcp.
151         */
152        public String getDcp() {
153            return dcp;
154        }
155    
156        /**
157         * @return Returns the facadeURL.
158         */
159        public URI getFacadeURL() {
160            return facadeURL;
161        }
162    
163        /**
164         * @return Returns the payload.
165         */
166        public String getPayload() {
167            return payload;
168        }
169    
170        /**
171         * @return Returns the requestParameters.
172         */
173        public ArrayList<RequestParameter> getRequestParameters() {
174            return requestParameters;
175        }
176    
177        /**
178         * @param id
179         * @param documentElement
180         * @return a new instance of this class
181         * @throws OGCWebServiceException
182         */
183        public static OGCWebServiceRequest create( String id, Element documentElement ) throws OGCWebServiceException {
184            try {
185                return new DoServiceDocument().parseDoService( id, documentElement );
186            } catch ( XMLParsingException e ) {
187                LOG.logError( e.getMessage(), e );
188                throw new OGCWebServiceException( e.getMessage() );
189            }
190        }
191    
192        /**
193         * @param id
194         * @param kvp
195         * @return a new instance of this class
196         */
197        public static OGCWebServiceRequest create( String id, Map<String, String> kvp ) {
198            return new DoService( id, kvp );
199        }
200    }