You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axis-cvs@ws.apache.org by di...@apache.org on 2005/12/16 18:18:08 UTC

svn commit: r357187 [25/25] - in /webservices/axis2/trunk/java/modules/core/src/org/apache/axis2: ./ addressing/ client/ client/async/ context/ deployment/ deployment/listener/ deployment/repository/util/ deployment/scheduler/ deployment/util/ descript...

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/Utils.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.util;
 
@@ -20,8 +21,21 @@
 import org.apache.axis2.Constants;
 import org.apache.axis2.addressing.AddressingConstants;
 import org.apache.axis2.addressing.MessageInformationHeaders;
-import org.apache.axis2.context.*;
-import org.apache.axis2.description.*;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.context.OperationContext;
+import org.apache.axis2.context.ServiceContext;
+import org.apache.axis2.context.ServiceGroupContext;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.description.AxisServiceGroup;
+import org.apache.axis2.description.Flow;
+import org.apache.axis2.description.HandlerDescription;
+import org.apache.axis2.description.InOutAxisOperation;
+import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.ParameterImpl;
+import org.apache.axis2.description.PhaseRule;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.engine.Handler;
 import org.apache.axis2.engine.MessageReceiver;
@@ -33,33 +47,32 @@
 import java.io.File;
 
 public class Utils {
-
-    public static void addHandler(Flow flow,
-                                  Handler handler,
-                                  String phaseName) {
+    public static void addHandler(Flow flow, Handler handler, String phaseName) {
         HandlerDescription handlerDesc = new HandlerDescription();
         PhaseRule rule = new PhaseRule(phaseName);
+
         handlerDesc.setRules(rule);
         handler.init(handlerDesc);
         handlerDesc.setHandler(handler);
         flow.addHandler(handlerDesc);
     }
 
-    public static MessageContext createOutMessageContext(MessageContext inMessageContext) throws AxisFault {
-        MessageContext newmsgCtx =
-                new MessageContext(inMessageContext.getConfigurationContext(),
-                        inMessageContext.getSessionContext(),
-                        inMessageContext.getTransportIn(),
-                        inMessageContext.getTransportOut());
+    public static MessageContext createOutMessageContext(MessageContext inMessageContext)
+            throws AxisFault {
+        MessageContext newmsgCtx = new MessageContext(inMessageContext.getConfigurationContext(),
+                inMessageContext.getSessionContext(),
+                inMessageContext.getTransportIn(),
+                inMessageContext.getTransportOut());
         MessageInformationHeaders oldMessageInfoHeaders =
                 inMessageContext.getMessageInformationHeaders();
+
         newmsgCtx.setMessageID(UUIDGenerator.getUUID());
         newmsgCtx.setTo(oldMessageInfoHeaders.getReplyTo());
-        newmsgCtx.setFaultTo(
-                oldMessageInfoHeaders.getFaultTo());
+        newmsgCtx.setFaultTo(oldMessageInfoHeaders.getFaultTo());
         newmsgCtx.setFrom(oldMessageInfoHeaders.getTo());
         newmsgCtx.setRelatesTo(
-                new org.apache.axis2.addressing.RelatesTo(oldMessageInfoHeaders.getMessageId(),
+                new org.apache.axis2.addressing.RelatesTo(
+                        oldMessageInfoHeaders.getMessageId(),
                         AddressingConstants.Submission.WSA_RELATES_TO_RELATIONSHIP_TYPE_DEFAULT_VALUE));
         newmsgCtx.setWSAAction(oldMessageInfoHeaders.getAction());
         newmsgCtx.setOperationContext(inMessageContext.getOperationContext());
@@ -69,10 +82,9 @@
         newmsgCtx.setProperty(Constants.OUT_TRANSPORT_INFO,
                 inMessageContext.getProperty(Constants.OUT_TRANSPORT_INFO));
 
-        //Setting the charater set encoding
-        newmsgCtx.setProperty(MessageContext.CHARACTER_SET_ENCODING, inMessageContext
-                .getProperty(MessageContext.CHARACTER_SET_ENCODING));
-
+        // Setting the charater set encoding
+        newmsgCtx.setProperty(MessageContext.CHARACTER_SET_ENCODING,
+                inMessageContext.getProperty(MessageContext.CHARACTER_SET_ENCODING));
         newmsgCtx.setDoingREST(inMessageContext.isDoingREST());
         newmsgCtx.setDoingMTOM(inMessageContext.isDoingMTOM());
         newmsgCtx.setServerSide(inMessageContext.isServerSide());
@@ -81,51 +93,97 @@
         return newmsgCtx;
     }
 
+    // public static ServiceContext createServiceContext(
+    // AxisService service,
+    // ConfigurationContext engineContext)
+    // throws AxisFault {
+    // ServiceContext serviceContext = new ServiceContext(service, engineContext);
+    // createExecutionChains(serviceContext);
+    // return serviceContext;
+    // }
+    public static AxisService createSimpleService(QName serviceName, String className, QName opName)
+            throws AxisFault {
+        return createSimpleService(serviceName, new RawXMLINOutMessageReceiver(), className,
+                opName);
+    }
+
     public static AxisService createSimpleService(QName serviceName,
-                                                  MessageReceiver messageReceiver,
-                                                  String className,
-                                                  QName opName) throws AxisFault {
+                                                  MessageReceiver messageReceiver, String className, QName opName)
+            throws AxisFault {
         AxisService service = new AxisService(serviceName.getLocalPart());
+
         service.setClassLoader(Thread.currentThread().getContextClassLoader());
-        service.addParameter(
-                new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS,
-                        className));
+        service.addParameter(new ParameterImpl(AbstractMessageReceiver.SERVICE_CLASS, className));
 
-        //todo I assumed in-out mep , this has to be imroved : Deepal
+        // todo I assumed in-out mep , this has to be imroved : Deepal
         AxisOperation axisOp = new InOutAxisOperation(opName);
+
         axisOp.setMessageReceiver(messageReceiver);
         axisOp.setStyle(WSDLService.STYLE_RPC);
         service.addOperation(axisOp);
+
         return service;
     }
 
-    //    public static ServiceContext createServiceContext(
-    //        AxisService service,
-    //        ConfigurationContext engineContext)
-    //        throws AxisFault {
-    //        ServiceContext serviceContext = new ServiceContext(service, engineContext);
-    //        createExecutionChains(serviceContext);
-    //        return serviceContext;
-    //    }
+    public static void extractServiceGroupAndServiceInfo(String filePart,
+                                                         MessageContext messageContext)
+            throws AxisFault {
+        String[] values = parseRequestURLForServiceAndOperation(filePart);
+        String serviceNameAndGroup = values[0];
 
-    public static AxisService createSimpleService(QName serviceName,
-                                                  String className,
-                                                  QName opName) throws AxisFault {
-        return createSimpleService(serviceName,
-                new RawXMLINOutMessageReceiver(),
-                className,
-                opName);
-    }
+        if (serviceNameAndGroup != null) {
+            String[]          serviceNameAndGroupStrings = serviceNameAndGroup.split(":");
+            AxisConfiguration registry =
+                    messageContext.getConfigurationContext().getAxisConfiguration();
 
+            if (serviceNameAndGroupStrings[0] != null) {
+                AxisServiceGroup axisServiceGroup =
+                        registry.getServiceGroup(serviceNameAndGroupStrings[0]);
+                String serviceNameStr = "";
 
-    public static String getParameterValue(Parameter param) {
-        if (param == null) {
-            return null;
-        } else {
-            return (String) param.getValue();
+                if (serviceNameAndGroupStrings.length == 1) {
+
+                    // This means user has not given a service name.
+                    // the notations is ...../axis2/services/<ServiceGroupName>
+                    serviceNameStr = serviceNameAndGroupStrings[0];
+                }
+
+                AxisService axisService = registry.getService(serviceNameStr);
+
+                if ((axisServiceGroup != null) && (axisService != null)) {
+                    messageContext.setAxisServiceGroup(axisServiceGroup);
+                    messageContext.setAxisService(axisService);
+                }
+            }
         }
     }
 
+    public static ServiceContext fillContextInformation(AxisOperation axisOperation,
+                                                        AxisService axisService, ConfigurationContext configurationContext)
+            throws AxisFault {
+        MessageContext msgContext;
+
+        // 2. if null, create new opCtxt
+        OperationContext operationContext = new OperationContext(axisOperation);
+
+//      OperationContext operationContext = OperationContextFactory.createOrFindOperationContext(axisOperation.getAxisSpecifMEPConstant(), axisOperation);
+
+        // fill the service group context and service context info
+        return fillServiceContextAndServiceGroupContext(axisService, configurationContext);
+    }
+
+    private static ServiceContext fillServiceContextAndServiceGroupContext(AxisService axisService,
+                                                                           ConfigurationContext configurationContext)
+            throws AxisFault {
+        String serviceGroupContextId = UUIDGenerator.getUUID();
+        ServiceGroupContext serviceGroupContext = new ServiceGroupContext(configurationContext,
+                axisService.getParent());
+
+        serviceGroupContext.setId(serviceGroupContextId);
+        configurationContext.registerServiceGroupContext(serviceGroupContext);
+
+        return new ServiceContext(axisService, serviceGroupContext);
+    }
 
     /**
      * Break a full path into pieces
@@ -134,21 +192,26 @@
      * @return an array where element [0] always contains the service, and element 1, if not null, contains
      *         the path after the first element. all ? parameters are discarded.
      */
-    public static String[] parseRequestURLForServiceAndOperation(
-            String path) {
+    public static String[] parseRequestURLForServiceAndOperation(String path) {
         String[] values = new String[2];
-        //TODO. This is kind of brittle. Any service with the name /services would cause fun.
+
+        // TODO. This is kind of brittle. Any service with the name /services would cause fun.
         int index = path.lastIndexOf(Constants.REQUEST_URL_PREFIX);
         String service = null;
 
         if (-1 != index) {
             int serviceStart = index + Constants.REQUEST_URL_PREFIX.length();
+
             service = path.substring(serviceStart + 1);
+
             int queryIndex = service.indexOf('?');
+
             if (queryIndex > 0) {
                 service = service.substring(0, queryIndex);
             }
+
             int operationIndex = service.indexOf('/');
+
             if (operationIndex > 0) {
                 values[0] = service.substring(0, operationIndex);
                 values[1] = service.substring(operationIndex + 1);
@@ -156,63 +219,28 @@
                 values[0] = service;
             }
         }
-        return values;
-    }
-
-    public static void extractServiceGroupAndServiceInfo(String filePart, MessageContext messageContext) throws AxisFault {
-        String[] values = parseRequestURLForServiceAndOperation(
-                filePart);
-        String serviceNameAndGroup = values[0];
-        if (serviceNameAndGroup != null) {
-            String[] serviceNameAndGroupStrings = serviceNameAndGroup.split(":");
-            AxisConfiguration registry =
-                    messageContext.getConfigurationContext().getAxisConfiguration();
-            if (serviceNameAndGroupStrings[0] != null) {
-                AxisServiceGroup axisServiceGroup = registry.getServiceGroup(serviceNameAndGroupStrings[0]);
-                String serviceNameStr = "";
-                if (serviceNameAndGroupStrings.length == 1) {
-                    // This means user has not given a service name.
-                    // the notations is ...../axis2/services/<ServiceGroupName>
-                    serviceNameStr = serviceNameAndGroupStrings[0];
-                }
-                AxisService axisService = registry.getService(serviceNameStr);
-                if (axisServiceGroup != null && axisService != null) {
-                    messageContext.setAxisServiceGroup(axisServiceGroup);
-                    messageContext.setAxisService(axisService);
-                }
-            }
-        }
-    }
-
-    public static ServiceContext fillContextInformation(AxisOperation axisOperation, AxisService axisService, ConfigurationContext configurationContext) throws AxisFault {
-        MessageContext msgContext;
-        //  2. if null, create new opCtxt
-        OperationContext operationContext = new OperationContext(axisOperation);
-//        OperationContext operationContext = OperationContextFactory.createOrFindOperationContext(axisOperation.getAxisSpecifMEPConstant(), axisOperation);
 
-        //  fill the service group context and service context info
-        return fillServiceContextAndServiceGroupContext(axisService, configurationContext);
-
-    }
-
-    private static ServiceContext fillServiceContextAndServiceGroupContext(AxisService axisService, ConfigurationContext configurationContext) throws AxisFault {
-        String serviceGroupContextId = UUIDGenerator.getUUID();
-        ServiceGroupContext serviceGroupContext = new ServiceGroupContext(configurationContext, axisService.getParent());
-        serviceGroupContext.setId(serviceGroupContextId);
-        configurationContext.registerServiceGroupContext(serviceGroupContext);
-        return new ServiceContext(axisService, serviceGroupContext);
+        return values;
     }
 
-    public static ConfigurationContext getNewConfigurationContext(String repositry) throws Exception {
+    public static ConfigurationContext getNewConfigurationContext(String repositry)
+            throws Exception {
         ConfigurationContextFactory erfac = new ConfigurationContextFactory();
         File file = new File(repositry);
+
         if (!file.exists()) {
-            throw new Exception(
-                    "repository directory " + file.getAbsolutePath() +
-                            " does not exists");
+            throw new Exception("repository directory " + file.getAbsolutePath()
+                    + " does not exists");
         }
-        return erfac.buildConfigurationContext(
-                file.getAbsolutePath());
+
+        return erfac.buildConfigurationContext(file.getAbsolutePath());
     }
 
+    public static String getParameterValue(Parameter param) {
+        if (param == null) {
+            return null;
+        } else {
+            return (String) param.getValue();
+        }
+    }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadFactory.java Fri Dec 16 09:13:57 2005
@@ -1,6 +1,7 @@
 package org.apache.axis2.util.threadpool;
 
 public interface ThreadFactory {
-    //public void newThread(java.lang.Runnable runnable);
+
+    // public void newThread(java.lang.Runnable runnable);
     public void execute(java.lang.Runnable runnable);
-}
\ No newline at end of file
+}

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadPool.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.util.threadpool;
 
@@ -32,16 +33,13 @@
  * run method on them and execute this method, using one of the threads
  * in the thread pool.
  */
-
 public class ThreadPool implements ThreadFactory {
-
     protected static Log log = LogFactory.getLog(ThreadPool.class.getName());
-
-    private static int MAX_THREAD_COUNT = 10;
     protected static long SLEEP_INTERVAL = 1000;
-    private static List threads;
-    private static List tasks;
+    private static int MAX_THREAD_COUNT = 10;
     private static boolean shutDown;
+    private static List tasks;
+    private static List threads;
 
     public ThreadPool() {
         threads = new ArrayList();
@@ -49,26 +47,36 @@
 
         for (int i = 0; i < MAX_THREAD_COUNT; i++) {
             ThreadWorker threadWorker = new ThreadWorker();
+
             threadWorker.setPool(this);
             threads.add(threadWorker);
             threadWorker.start();
         }
-
     }
 
-    public void execute(Runnable worker){
-        if (shutDown)
+    public void execute(Runnable worker) {
+        if (shutDown) {
             throw new RuntimeException(Messages.getMessage("threadpoolshutdown"));
+        }
+
         tasks.add(worker);
     }
 
-    public synchronized Runnable getWorker() {
-        if (!tasks.isEmpty()) {
-            Runnable worker = (Runnable) tasks.get(0);
-            tasks.remove(worker);
-            return worker;
-        } else
-            return null;
+    /**
+     * A forceful shutdown mechanism for thread pool.
+     */
+    public void forceShutDown() {
+        if (log.isDebugEnabled()) {
+            log.debug("forceShutDown called. Thread workers will be stopped");
+        }
+
+        Iterator ite = threads.iterator();
+
+        while (ite.hasNext()) {
+            ThreadWorker worker = (ThreadWorker) ite.next();
+
+            worker.setStop(true);
+        }
     }
 
     /**
@@ -82,6 +90,7 @@
         synchronized (this) {
             shutDown = true;
         }
+
         while (!tasks.isEmpty()) {
             try {
                 Thread.sleep(SLEEP_INTERVAL);
@@ -89,20 +98,19 @@
                 throw new AxisFault(Messages.getMessage("errorWhileSafeShutDown"));
             }
         }
-        forceShutDown();
 
+        forceShutDown();
     }
 
-    /**
-     * A forceful shutdown mechanism for thread pool.
-     */
-    public void forceShutDown() {
-        if (log.isDebugEnabled())
-            log.debug("forceShutDown called. Thread workers will be stopped");
-        Iterator ite = threads.iterator();
-        while (ite.hasNext()) {
-            ThreadWorker worker = (ThreadWorker) ite.next();
-            worker.setStop(true);
+    public synchronized Runnable getWorker() {
+        if (!tasks.isEmpty()) {
+            Runnable worker = (Runnable) tasks.get(0);
+
+            tasks.remove(worker);
+
+            return worker;
+        } else {
+            return null;
         }
     }
 }

Modified: webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java?rev=357187&r1=357186&r2=357187&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java (original)
+++ webservices/axis2/trunk/java/modules/core/src/org/apache/axis2/util/threadpool/ThreadWorker.java Fri Dec 16 09:13:57 2005
@@ -1,18 +1,19 @@
 /*
- * Copyright 2004,2005 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
 
 package org.apache.axis2.util.threadpool;
 
@@ -26,36 +27,40 @@
  */
 public class ThreadWorker extends Thread {
     protected static Log log = LogFactory.getLog(ThreadWorker.class.getName());
-    private boolean stop;
     private ThreadPool pool;
+    private boolean stop;
 
     public ThreadWorker() {
         this.setDaemon(true);
     }
 
-    public void setPool(ThreadPool pool) {
-        this.pool = pool;
-    }
-
-    public boolean isStop() {
-        return stop;
-    }
-
-    public void setStop(boolean stop) {
-        this.stop = stop;
-    }
-
     public void run() {
         while (!stop) {
             Runnable axisWorker = null;
+
             try {
                 axisWorker = pool.getWorker();
-                if (axisWorker != null)
+
+                if (axisWorker != null) {
                     axisWorker.run();
+                }
+
                 sleep(ThreadPool.SLEEP_INTERVAL);
             } catch (InterruptedException e) {
                 log.error(e);
             }
         }
+    }
+
+    public boolean isStop() {
+        return stop;
+    }
+
+    public void setPool(ThreadPool pool) {
+        this.pool = pool;
+    }
+
+    public void setStop(boolean stop) {
+        this.stop = stop;
     }
 }