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