KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > repo > webservice > axis > QueryConfigHandler


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17 package org.alfresco.repo.webservice.axis;
18
19 import org.alfresco.repo.webservice.Utils;
20 import org.alfresco.repo.webservice.types.QueryConfiguration;
21 import org.apache.axis.AxisFault;
22 import org.apache.axis.MessageContext;
23 import org.apache.axis.description.OperationDesc;
24 import org.apache.axis.handlers.BasicHandler;
25 import org.apache.axis.message.SOAPEnvelope;
26 import org.apache.axis.message.SOAPHeaderElement;
27 import org.apache.commons.logging.Log;
28 import org.apache.commons.logging.LogFactory;
29
30 /**
31  * Axis handler to extract the fetchSize parameter from the QueryConfiguration SOAP header.
32  * The value of fetchSize is then placed in the MessageContext with a property name of
33  * ALF_FETCH_SIZE
34  *
35  * @author gavinc
36  */

37 public class QueryConfigHandler extends BasicHandler
38 {
39    public static final String JavaDoc ALF_FETCH_SIZE = "ALF_FETCH_SIZE";
40
41    private static final long serialVersionUID = 6467938074555362971L;
42    private static Log logger = LogFactory.getLog(QueryConfigHandler.class);
43    
44    /**
45     * @see org.apache.axis.Handler#invoke(org.apache.axis.MessageContext)
46     */

47    public void invoke(MessageContext msgContext) throws AxisFault
48    {
49       try
50       {
51          // determine the method we are calling
52
String JavaDoc opName = "Unknown method";
53          OperationDesc op = msgContext.getOperation();
54          if (op != null)
55          {
56             opName = op.getName();
57          }
58
59          // try and find the appropriate header and extract info from it
60
SOAPEnvelope env = msgContext.getRequestMessage().getSOAPEnvelope();
61          SOAPHeaderElement header = env.getHeaderByName(Utils.REPOSITORY_SERVICE_NAMESPACE, "QueryHeader");
62          if (header != null)
63          {
64             if (logger.isDebugEnabled())
65                logger.debug("Found QueryHeader for call to " + opName);
66             
67             QueryConfiguration queryCfg = (QueryConfiguration)header.getObjectValue(QueryConfiguration.class);
68             if (queryCfg != null)
69             {
70                int fetchSize = queryCfg.getFetchSize();
71                
72                if (logger.isDebugEnabled())
73                   logger.debug("Fetch size for query = " + fetchSize);
74                
75                msgContext.setProperty(ALF_FETCH_SIZE, new Integer JavaDoc(fetchSize));
76             }
77             else
78             {
79                if (logger.isDebugEnabled())
80                   logger.debug("Failed to find QueryConfiguration within QueryHeader");
81             }
82          }
83          else
84          {
85             if (logger.isDebugEnabled())
86             {
87                logger.debug("QueryHeader was not found for call to " + opName);
88             }
89          }
90       }
91       catch (Throwable JavaDoc e)
92       {
93          if (logger.isDebugEnabled())
94             logger.debug("Failed to determine fetch size", e);
95       }
96    }
97 }
98
Popular Tags