KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xmlrpc > XmlRpcRequestProcessor


1 /*
2  * Copyright 1999,2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17
18 package org.apache.xmlrpc;
19
20 import java.io.InputStream JavaDoc;
21 import java.util.Vector JavaDoc;
22
23 /**
24  * Process an InputStream and produce an XmlRpcServerRequest. This class
25  * is NOT thread safe.
26  *
27  * @author <a HREF="mailto:andrew@kungfoocoder.org">Andrew Evers</a>
28  * @author <a HREF="mailto:hannes@apache.org">Hannes Wallnoefer</a>
29  * @author Daniel L. Rall
30  * @since 1.2
31  */

32 public class XmlRpcRequestProcessor extends XmlRpc
33 {
34     private Vector JavaDoc requestParams;
35
36     /**
37      * Creates a new instance.
38      */

39     public XmlRpcRequestProcessor()
40     {
41         requestParams = new Vector JavaDoc();
42     }
43
44     /**
45      * Decode a request from an InputStream to the internal XmlRpcRequest
46      * implementation. This method must read data from the specified stream and
47      * return an XmlRpcRequest object, or throw an exception.
48      *
49      * @param is the stream to read the request from.
50      * @returns XMLRpcRequest the request.
51      * @throws ParseFailed if unable to parse the request.
52      */

53     public XmlRpcServerRequest decodeRequest(InputStream JavaDoc is)
54     {
55         long now = 0;
56
57         if (XmlRpc.debug)
58         {
59             now = System.currentTimeMillis();
60         }
61         try
62         {
63             try
64             {
65                 parse(is);
66             }
67             catch (Exception JavaDoc e)
68             {
69                 throw new ParseFailed(e);
70             }
71             if (XmlRpc.debug)
72             {
73                 System.out.println("XML-RPC method name: " + methodName);
74                 System.out.println("Request parameters: " + requestParams);
75             }
76             // check for errors from the XML parser
77
if (errorLevel > NONE)
78             {
79                 throw new ParseFailed(errorMsg);
80             }
81
82             return new XmlRpcRequest(methodName, (Vector JavaDoc) requestParams.clone());
83         }
84         finally
85         {
86             requestParams.removeAllElements();
87             if (XmlRpc.debug)
88             {
89                 System.out.println("Spent " + (System.currentTimeMillis() - now)
90                         + " millis decoding request");
91             }
92         }
93     }
94
95     /**
96      * Called when an object to be added to the argument list has been
97      * parsed.
98      *
99      * @param what The parameter parsed from the request.
100      */

101     protected void objectParsed(Object JavaDoc what)
102     {
103         requestParams.addElement(what);
104     }
105 }
106
Popular Tags