geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ga...@apache.org
Subject svn commit: r700172 - in /geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb: EJBInterceptor.java EJBMessageContext.java EJBMethodInvoker.java
Date Mon, 29 Sep 2008 16:39:09 GMT
Author: gawor
Date: Mon Sep 29 09:39:08 2008
New Revision: 700172

URL: http://svn.apache.org/viewvc?rev=700172&view=rev
Log:
implementation of some jaxws 2.1 api for ejbs

Added:
    geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMessageContext.java
  (with props)
Modified:
    geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBInterceptor.java
    geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMethodInvoker.java

Modified: geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBInterceptor.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBInterceptor.java?rev=700172&r1=700171&r2=700172&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBInterceptor.java
(original)
+++ geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBInterceptor.java
Mon Sep 29 09:39:08 2008
@@ -42,6 +42,8 @@
 import org.apache.cxf.interceptor.ServiceInvokerInterceptor;
 import org.apache.cxf.jaxws.handler.logical.LogicalHandlerInInterceptor;
 import org.apache.cxf.jaxws.handler.soap.SOAPHandlerInterceptor;
+import org.apache.cxf.jaxws.interceptors.HolderInInterceptor;
+import org.apache.cxf.jaxws.interceptors.WrapperClassInInterceptor;
 import org.apache.cxf.jaxws.support.JaxWsEndpointImpl;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.Message;
@@ -128,12 +130,16 @@
                 // TODO: how to handle XML/HTTP binding?
             }
             
-            this.exchange.setOutMessage(null);
+            //this.exchange.setOutMessage(null);
 
             // install default interceptors
             chain.add(new ServiceInvokerInterceptor());
             chain.add(new OutgoingChainInterceptor());
 
+            // install Holder and Wrapper interceptors
+            chain.add(new WrapperClassInInterceptor());
+            chain.add(new HolderInInterceptor());
+            
             // install interceptors for handler processing
             chain.add(new MustUnderstandInterceptor());
             chain.add(new LogicalHandlerInInterceptor(binding));
@@ -179,12 +185,8 @@
             return;
         }
                 
-        XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
-        StaxUtils.readDocElements(soapMessage.getSOAPBody(), xmlReader, true);
-        DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
-        xmlReader = StaxUtils.createXMLStreamReader(bodySource);
-        xmlReader.nextTag();
-        xmlReader.nextTag(); // move past body tag
+        DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart());
+        XMLStreamReader xmlReader = StaxUtils.createXMLStreamReader(bodySource);
         message.setContent(XMLStreamReader.class, xmlReader);
     }
         

Added: geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMessageContext.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMessageContext.java?rev=700172&view=auto
==============================================================================
--- geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMessageContext.java
(added)
+++ geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMessageContext.java
Mon Sep 29 09:39:08 2008
@@ -0,0 +1,62 @@
+/**
+ * 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.geronimo.cxf.ejb;
+
+import javax.xml.ws.EndpointReference;
+import javax.xml.ws.WebServiceException;
+import javax.xml.ws.wsaddressing.W3CEndpointReference;
+import javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder;
+
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.jaxws.context.WrappedMessageContext;
+import org.apache.cxf.message.Message;
+import org.apache.openejb.core.webservices.AddressingSupport;
+import org.w3c.dom.Element;
+
+public class EJBMessageContext extends WrappedMessageContext implements AddressingSupport
{
+
+    public EJBMessageContext(Message m, Scope defScope) {
+        super(m, defScope);
+    }
+
+    public EndpointReference getEndpointReference(Element... referenceParameters) {
+        org.apache.cxf.message.Message msg = getWrappedMessage();
+        Endpoint ep = msg.getExchange().get(Endpoint.class);
+
+        W3CEndpointReferenceBuilder builder = new W3CEndpointReferenceBuilder();
+        builder.address(ep.getEndpointInfo().getAddress());
+        builder.serviceName(ep.getService().getName());
+        builder.endpointName(ep.getEndpointInfo().getName());
+
+        if (referenceParameters != null) {
+            for (Element referenceParameter : referenceParameters) {
+                builder.referenceParameter(referenceParameter);
+            }
+        }
+        
+        return builder.build();
+    }
+
+    public <T extends EndpointReference> T getEndpointReference(Class<T> clazz,
Element... referenceParameters) {
+        if (W3CEndpointReference.class.isAssignableFrom(clazz)) {
+            return clazz.cast(getEndpointReference(referenceParameters));
+        } else {
+            throw new WebServiceException("Endpoint reference type not supported: " + clazz);
+        }
+    }
+    
+}

Propchange: geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMessageContext.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMessageContext.java
------------------------------------------------------------------------------
    svn:keywords = Date Revision

Propchange: geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMessageContext.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMethodInvoker.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMethodInvoker.java?rev=700172&r1=700171&r2=700172&view=diff
==============================================================================
--- geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMethodInvoker.java
(original)
+++ geronimo/server/trunk/plugins/cxf/geronimo-cxf-ejb/src/main/java/org/apache/geronimo/cxf/ejb/EJBMethodInvoker.java
Mon Sep 29 09:39:08 2008
@@ -19,23 +19,23 @@
 
 package org.apache.geronimo.cxf.ejb;
 
-import java.lang.reflect.InvocationTargetException;
 import java.lang.reflect.Method;
-import java.util.ArrayList;
 import java.util.List;
 
 import javax.interceptor.InvocationContext;
 import javax.xml.ws.handler.MessageContext;
 import javax.xml.ws.handler.MessageContext.Scope;
+import javax.xml.ws.soap.SOAPFaultException;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.apache.cxf.Bus;
+import org.apache.cxf.binding.soap.SoapFault;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.jaxws.context.WebServiceContextImpl;
-import org.apache.cxf.jaxws.context.WrappedMessageContext;
 import org.apache.cxf.message.Exchange;
 import org.apache.cxf.message.FaultMode;
+import org.apache.cxf.message.MessageContentsList;
 import org.apache.cxf.service.invoker.AbstractInvoker;
 import org.apache.openejb.DeploymentInfo;
 import org.apache.openejb.RpcContainer;
@@ -54,10 +54,43 @@
         this.deploymentInfo = deploymentInfo;
     }
 
+    @Override
     public Object getServiceObject(Exchange context) {
         return null;
     }
+    
+    @Override
+    public void releaseServiceObject(Exchange ex, Object obj) {
+        // do nothing
+    }
 
+    private SOAPFaultException findSoapFaultException(Throwable ex) {
+        if (ex instanceof SOAPFaultException) {
+            return (SOAPFaultException)ex;
+        }
+        if (ex.getCause() != null) {
+            return findSoapFaultException(ex.getCause());
+        }
+        return null;
+    }
+    
+    @Override
+    protected Fault createFault(Throwable ex, Method m, List<Object> params, boolean
checked) {
+        //map the JAX-WS faults
+        SOAPFaultException sfe = findSoapFaultException(ex);
+        if (sfe != null) {
+            SoapFault fault = new SoapFault(sfe.getFault().getFaultString(),
+                                            ex,
+                                            sfe.getFault().getFaultCodeAsQName());
+            fault.setRole(sfe.getFault().getFaultActor());
+            fault.setDetail(sfe.getFault().getDetail());
+            
+            return fault;
+        }
+        return super.createFault(ex, m, params, checked);
+    }
+    
+    @Override
     protected Object invoke(Exchange exchange, 
                             Object serviceObject, 
                             Method m, 
@@ -69,24 +102,39 @@
             LOG.debug("PreEJBInvoke");
             result = preEjbInvoke(exchange, serviceObject, m, params);
         } else {
-            LOG.debug("EJBInvoke");
-            result = ejbInvoke(exchange, serviceObject, m, params);
+            LOG.debug("EJBInvoke"); // calls performInvocation()
+            result = super.invoke(exchange, serviceObject, m, params);
         }    
         
         return result;
     }
     
+    @Override
+    protected Object performInvocation(Exchange exchange, 
+                                       Object serviceObject, 
+                                       Method m,
+                                       Object[] paramArray) throws Exception {
+        InvocationContext invContext = exchange.get(InvocationContext.class);
+        invContext.setParameters(paramArray);
+        Object res = invContext.proceed();
+        
+//        ContextPropertiesMapping.updateWebServiceContext(exchange, 
+//                                                         (MessageContext)invContext.getContextData());
+                
+        return res;
+    }
+    
     private Object preEjbInvoke(Exchange exchange, 
                                 Object serviceObject, 
                                 Method method, 
                                 List<Object> params) {           
         
-        MessageContext ctx = new WrappedMessageContext(exchange.getInMessage(), Scope.APPLICATION);
+        MessageContext ctx = new EJBMessageContext(exchange.getInMessage(), Scope.APPLICATION);
         WebServiceContextImpl.setMessageContext(ctx);
 
         try {           
             EJBInterceptor interceptor = new EJBInterceptor(params, method, this.endpoint,
this.bus, exchange);
-            Object[] arguments = { ctx, interceptor };
+            Object[] arguments = { ctx, interceptor, ctx };
 
             RpcContainer container = (RpcContainer) this.deploymentInfo.getContainer();
 
@@ -98,68 +146,28 @@
                 return null;
             }
 
-            List<Object> retList = new ArrayList<Object>(1);
-            if (!((Class) method.getReturnType()).getName().equals("void")) {
-                retList.add(res);
-            }
-            
-            return retList;
+            return new MessageContentsList(res);
+        } catch (Fault f) {
+            exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
+            throw f;
         } catch (Exception e) {
             exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
-            throw new Fault(e);
+            throw createFault(e, method, params, false);
         } finally {
             WebServiceContextImpl.clear();
         }
     }
     
-    private Object ejbInvoke(Exchange exchange, 
-                             Object serviceObject, 
-                             Method m, 
-                             List<Object> params) {         
-        try {
-            Object res = directEjbInvoke(exchange, m, params);
-            
-            if (exchange.isOneWay()) {
-                return null;
-            }
-            
-            List<Object> retList = new ArrayList<Object>(1);
-            if (!((Class)m.getReturnType()).getName().equals("void")) {
-                retList.add(res);
-            }
-            
-            return retList;
-        } catch (InvocationTargetException e) {
-            Throwable t = e.getCause();
-            if (t == null) {
-                t = e;
-            }
-            exchange.getInMessage().put(FaultMode.class, FaultMode.CHECKED_APPLICATION_FAULT);
-            throw new Fault(t);
-        } catch (Exception e) {
-            exchange.getInMessage().put(FaultMode.class, FaultMode.UNCHECKED_APPLICATION_FAULT);
-            throw new Fault(e);
-        }
-    }
-
     public Object directEjbInvoke(Exchange exchange, 
                                   Method m, 
-                                  List<Object> params) throws Exception {
-        InvocationContext invContext = exchange.get(InvocationContext.class);
+                                  List<Object> params) throws Exception {        
         Object[] paramArray;
         if (params != null) {
             paramArray = params.toArray();
         } else {
             paramArray = new Object[]{};
         }
-                    
-        invContext.setParameters(paramArray);
-        Object res = invContext.proceed();
-        
-//        ContextPropertiesMapping.updateWebServiceContext(exchange, 
-//                                                         (MessageContext)invContext.getContextData());
-                
-        return res;
+        return performInvocation(exchange, null, m, paramArray);
     }
-        
+            
 }



Mime
View raw message