cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ff...@apache.org
Subject svn commit: r442175 - in /incubator/cxf/trunk: api/src/main/java/org/apache/cxf/endpoint/ rt/core/src/main/java/org/apache/cxf/endpoint/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/ rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/intercep...
Date Mon, 11 Sep 2006 11:22:16 GMT
Author: ffang
Date: Mon Sep 11 04:22:15 2006
New Revision: 442175

URL: http://svn.apache.org/viewvc?view=rev&rev=442175
Log:
1. fix build failed
2.[JIRA CXF-60] get invoke asynchronized working - polling style


Added:
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncResponse.java
  (with props)
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
  (with props)
Modified:
    incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Endpoint.java
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
    incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java
    incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java

Modified: incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Endpoint.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Endpoint.java?view=diff&rev=442175&r1=442174&r2=442175
==============================================================================
--- incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Endpoint.java (original)
+++ incubator/cxf/trunk/api/src/main/java/org/apache/cxf/endpoint/Endpoint.java Mon Sep 11
04:22:15 2006
@@ -46,4 +46,6 @@
     Interceptor getFaultInterceptor();
     
     Object getImplementor();
+    
+    void setImplementor(Object impl);
 }

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java?view=diff&rev=442175&r1=442174&r2=442175
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java (original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/endpoint/ClientImpl.java Mon
Sep 11 04:22:15 2006
@@ -72,6 +72,7 @@
         return this.endpoint;
     }
 
+        
     public Object[] invoke(BindingOperationInfo oi, Object[] params, Map<String, Object>
ctx) {
         if (LOG.isLoggable(Level.FINE)) {
             LOG.fine("Invoke, operation info: " + oi + ", params: " + params);
@@ -146,19 +147,7 @@
 
         if (oi.getOutput() != null) {
             synchronized (exchange) {
-                Message inMsg = exchange.getInMessage();
-                if (inMsg == null) {
-                    try {
-                        exchange.wait();
-                    } catch (InterruptedException e) {
-                        //TODO - timeout
-                    }
-                    inMsg = exchange.getInMessage();
-                }
-                if (inMsg.getContent(Exception.class) != null) {
-                    //TODO - exceptions 
-                    throw new RuntimeException(inMsg.getContent(Exception.class));
-                }
+                Message inMsg = waitResponse(exchange);
                     
                 
                 
@@ -166,6 +155,23 @@
             }
         } 
         return null;
+    }
+
+    private Message waitResponse(Exchange exchange) {
+        Message inMsg = exchange.getInMessage();
+        if (inMsg == null) {
+            try {
+                exchange.wait();
+            } catch (InterruptedException e) {
+                //TODO - timeout
+            }
+            inMsg = exchange.getInMessage();
+        }
+        if (inMsg.getContent(Exception.class) != null) {
+            //TODO - exceptions 
+            throw new RuntimeException(inMsg.getContent(Exception.class));
+        }
+        return inMsg;
     }
 
     private void setParameters(Object[] params, Message message) {

Added: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncResponse.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncResponse.java?view=auto&rev=442175
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncResponse.java
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncResponse.java
Mon Sep 11 04:22:15 2006
@@ -0,0 +1,76 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.jaxws;
+
+import java.util.Map;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+
+import javax.xml.ws.Response;
+
+
+public class AsyncResponse<T> implements Response<T> {
+
+    private final Future<Object> obj;
+    private T result;
+    private Class<T> cls;
+    
+    public AsyncResponse(Future<Object> object, Class<T> c) {
+        obj = object;
+        cls = c;
+    }
+    
+    public boolean cancel(boolean interrupt) {
+        return obj.cancel(interrupt);     
+    }
+    
+    public boolean isCancelled() {
+        return obj.isCancelled(); 
+    }
+
+    public boolean isDone() {
+        return obj.isDone();
+    }
+
+    public synchronized T get() throws InterruptedException, ExecutionException {
+        if (result == null) {
+            result = cls.cast(obj.get());
+        } 
+        return result;
+    }
+
+    
+    public T get(long timeout, TimeUnit unit)
+        throws InterruptedException, ExecutionException, TimeoutException {
+        if (result == null) {
+            result = cls.cast(obj.get(timeout, unit));
+        } 
+        return result;
+    }
+
+    public Map<String, Object> getContext() {
+        return null;
+    }
+    
+    
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncResponse.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/AsyncResponse.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java?view=diff&rev=442175&r1=442174&r2=442175
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointImpl.java
Mon Sep 11 04:22:15 2006
@@ -75,7 +75,7 @@
         // create the endpoint        
         QName endpointName = implInfo.getEndpointName();
         EndpointInfo ei = service.getServiceInfo().getEndpoint(endpointName);
-        endpoint.setImplementor(implementor);
+        
 
         if (implInfo.isWebServiceProvider()) {
             service.setInvoker(new ProviderInvoker((Provider<?>)i));
@@ -85,6 +85,7 @@
         //      TODO: use bindigURI     
         try {
             endpoint = new JaxwsEndpointImpl(bus, service, ei);
+            endpoint.setImplementor(implementor);
         } catch (EndpointException e) {
             throw new WebServiceException(e);
         }

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java?view=diff&rev=442175&r1=442174&r2=442175
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/EndpointInvocationHandler.java
Mon Sep 11 04:22:15 2006
@@ -28,6 +28,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.FutureTask;
 import java.util.logging.Logger;
 
 import javax.jws.WebMethod;
@@ -93,8 +94,22 @@
         Object[] paramsWithOutHolder = handleHolder(params);
         Map<String, Object> context = new HashMap<String, Object>();
         context.put(Method.class.getName(), method);
-        Object rawRet[] = client.invoke(oi, paramsWithOutHolder, context);
+        
+        
+        boolean isAsync = method.getName().endsWith("Async");
+        if (isAsync) {
+            return invokeAsync(method, oi, params, paramsWithOutHolder, context);
+        } else {
+            return invokeSync(method, oi, params, paramsWithOutHolder, context);
+        }
+    }
 
+    Object invokeSync(Method method, 
+                          BindingOperationInfo oi, 
+                          Object[] params, 
+                          Object[] paramsWithOutHolder, 
+                          Map<String, Object> context) {
+        Object rawRet[] = client.invoke(oi, paramsWithOutHolder, context);
         if (rawRet != null && rawRet.length != 0) {
             List<Object> retList = new ArrayList<Object>();
             handleHolderReturn(params, method, rawRet, retList);
@@ -103,6 +118,23 @@
         } else {
             return null;
         }
+    }
+
+    private Object invokeAsync(Method method, 
+                               BindingOperationInfo oi, 
+                               Object[] params, 
+                               Object[] paramsWithOutHolder, 
+                               Map<String, Object> context) {
+        
+        FutureTask<Object> f = new FutureTask<Object>(new JAXWSAsyncCallable(this,

+                                                                             method,
+                                                                             oi,
+                                                                             params,
+                                                                             paramsWithOutHolder,
+                                                                             context
+                                                                             ));
+        endpoint.getService().getExecutor().execute(f);
+        return new AsyncResponse<Object>(f, Object.class);
     }
 
     private Object[] handleHolder(Object[] params) {

Added: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java?view=auto&rev=442175
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
(added)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
Mon Sep 11 04:22:15 2006
@@ -0,0 +1,59 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.cxf.jaxws;
+
+import java.lang.reflect.Method;
+import java.util.Map;
+import java.util.concurrent.Callable;
+
+import org.apache.cxf.service.model.BindingOperationInfo;
+
+public class JAXWSAsyncCallable implements Callable<Object> {
+
+    private EndpointInvocationHandler endPointInvocationHandler;
+    private Method method;
+    private BindingOperationInfo oi; 
+    private Object[] params;
+    private Object[] paramsWithOutHolder; 
+    private Map<String, Object> context;
+    
+    public JAXWSAsyncCallable(EndpointInvocationHandler endPointInvocationHandler,
+                              Method method,
+                              BindingOperationInfo oi,
+                              Object[] params,
+                              Object[] paramsWithOutHolder,
+                              Map<String, Object> context) {
+        this.endPointInvocationHandler = endPointInvocationHandler;
+        this.method = method;
+        this.oi = oi;
+        this.params = params;
+        this.paramsWithOutHolder = paramsWithOutHolder;
+        this.context = context;
+    }
+    
+    public Object call() throws Exception {
+        return endPointInvocationHandler.invokeSync(method, 
+                                                oi, 
+                                                params, 
+                                                paramsWithOutHolder,
+                                                context);
+    }
+
+}

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/JAXWSAsyncCallable.java
------------------------------------------------------------------------------
    svn:keywords = Rev Date

Modified: incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java?view=diff&rev=442175&r1=442174&r2=442175
==============================================================================
--- incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java
(original)
+++ incubator/cxf/trunk/rt/frontend/jaxws/src/main/java/org/apache/cxf/jaxws/interceptors/WrapperClassInInterceptor.java
Mon Sep 11 04:22:15 2006
@@ -55,6 +55,9 @@
         if (method == null) {
             method = message.getContent(Method.class);
         }
+        if (method != null && method.getName().endsWith("Async")) {
+            return;
+        }
         try {
             if (method != null) {
                 Class inter = null;

Modified: incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java?view=diff&rev=442175&r1=442174&r2=442175
==============================================================================
--- incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java
(original)
+++ incubator/cxf/trunk/systests/src/test/java/org/apache/cxf/jaxws/ClientServerTest.java
Mon Sep 11 04:22:15 2006
@@ -91,6 +91,7 @@
                 assertTrue("server did not launch correctly", launchServer(Server.class));
             }
         };
+
          
     }
     
@@ -195,7 +196,7 @@
         }
     } 
 
-    public void xtestAsyncPollingCall() throws Exception {
+    public void testAsyncPollingCall() throws Exception {
         URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
         assertNotNull(wsdl);
         
@@ -218,12 +219,13 @@
             String s = reply.getResponseType();
             assertEquals(expectedString, s);   
         } catch (UndeclaredThrowableException ex) {
+            ex.printStackTrace();
             throw (Exception)ex.getCause();
         }
         executor.shutdown();
     }
     
-    public void xtestAsyncSynchronousPolling() throws Exception {
+    public void testAsyncSynchronousPolling() throws Exception {
         URL wsdl = getClass().getResource("/wsdl/hello_world.wsdl");
         assertNotNull(wsdl);
         



Mime
View raw message