Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
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 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.openejb.server.cxf.ejb;
 import  org.apache.cxf.Bus;
 import  org.apache.cxf.binding.soap.SoapMessage;
 import  org.apache.cxf.binding.soap.interceptor.MustUnderstandInterceptor;
 import  org.apache.cxf.endpoint.Endpoint;
 import  org.apache.cxf.interceptor.AbstractInDatabindingInterceptor;
 import  org.apache.cxf.interceptor.Interceptor;
 import  org.apache.cxf.interceptor.InterceptorChain;
 import  org.apache.cxf.interceptor.OutgoingChainInterceptor;
 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.message.Exchange;
 import  org.apache.cxf.message.Message;
 import  org.apache.cxf.phase.PhaseInterceptorChain;
 import  org.apache.cxf.phase.PhaseManager;
 import  org.apache.cxf.service.Service;
 import  org.apache.cxf.staxutils.StaxUtils;
 import java.util.List;
 public class EjbInterceptor {
     private static final Logger log = Logger.getInstance(.EjbInterceptor.class);
     private Exchange exchange;
     private Bus bus;
     private List<Objectparams;
     private Method method;
     public EjbInterceptor(List<ObjectparamsMethod method, Bus bus, Exchange exchange) {
         this. = params;
         this. = method;
         this. = bus;
         this. = exchange;
     private static void copyDataBindingInterceptors(PhaseInterceptorChain newChain, InterceptorChain oldChain) {
         for (Interceptor interceptor : oldChain) {
             if (interceptor instanceof AbstractInDatabindingInterceptor) {
                 .debug("Added data binding interceptor: " + interceptor);
     public Object intercept(InvocationContext contextthrows Exception {
         Endpoint endpoint = this..get(Endpoint.class);
         Service service = endpoint.getService();
         Binding binding = ((JaxWsEndpointImpl) endpoint).getJaxwsBinding();
         if (binding.getHandlerChain() == null || binding.getHandlerChain().isEmpty()) {
             // no handlers so let's just directly invoke the bean
             .debug("No handlers found.");
             EjbMethodInvoker invoker = (EjbMethodInvokerservice.getInvoker();
             return invoker.directEjbInvoke(this.this.this.);
         } else {
             // have handlers so have to run handlers now and redo data binding
             // as handlers can change the soap message
             .debug("Handlers found.");
             Message inMessage = .getInMessage();
             PhaseInterceptorChain chain = new PhaseInterceptorChain(.getExtension(PhaseManager.class).getInPhases());
             * Since we have to re-do data binding and the XMLStreamReader
             * contents are already consumed by prior data binding step
             * we have to reinitialize the XMLStreamReader from the SOAPMessage
             * created by SAAJInInterceptor.
            if (inMessage instanceof SoapMessage) {
                try {
                    reserialize((SoapMessage) inMessage);
                } catch (Exception e) {
                    throw new RuntimeException("Failed to reserialize soap message"e);
            } else {
                // TODO: how to handle XML/HTTP binding?
            // install default interceptors
            chain.add(new ServiceInvokerInterceptor());
            chain.add(new OutgoingChainInterceptor());
            // install interceptors for handler processing
            chain.add(new MustUnderstandInterceptor());
            chain.add(new LogicalHandlerInInterceptor(binding));
            chain.add(new SOAPHandlerInterceptor(binding));
            // install data binding interceptors
            InterceptorChain oldChain = inMessage.getInterceptorChain();
            try {
            } finally {
            // TODO: the result should be deserialized from SOAPMessage
            Object result = getResult();
            return result;
    private Object getResult() {
        Message outMessage = this..getOutMessage();
        if (outMessage == null) {
            return null;
        } else {
            List<?> result = outMessage.getContent(List.class);
            if (result == null) {
                return outMessage.get(Object.class);
            } else if (result.isEmpty()) {
                return null;
            } else {
                return result.get(0);
    private void reserialize(SoapMessage messagethrows Exception {
        SOAPMessage soapMessage = message.getContent(SOAPMessage.class);
        if (soapMessage == null) {
        XMLStreamReader xmlReader = message.getContent(XMLStreamReader.class);
        StaxUtils.readDocElements(soapMessage.getSOAPBody(), xmlReadertrue);
        DOMSource bodySource = new DOMSource(soapMessage.getSOAPPart().getEnvelope().getBody());
        xmlReader = StaxUtils.createXMLStreamReader(bodySource);
        xmlReader.nextTag(); // move past body tag
New to GrepCode? Check out our FAQ X