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 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.binding.corba.interceptors;
 
 
 
 
 
         
     private static final Logger LOG = LogUtils.getL7dLogger(CorbaStreamFaultInInterceptor.class);  
     
 
     public CorbaStreamFaultInInterceptor() {
         super(.);
         addAfter(ClientFaultConverter.class.getName());
     }    
 
     public void handleMessage(Message msg) {
         CorbaMessage message = (CorbaMessage)msg;
         
         
         try {
             
             SystemException sysEx = message.getSystemException();
             if (sysEx != null) {
                 // TODO: Do we need anything else to handle system exceptions here...i.e. do
                 // we want to add a wrapper around this so that we can add some more information?
                 message.setContent(Exception.classsysEx);
                 return;
             }
 
             CorbaStreamable exStreamable = message.getStreamableException();
             if (exStreamable != null) {
                 DataReader<XMLStreamReaderreader = getDataReader(message);
 
                 BindingOperationInfo bopInfo = message.getExchange().get(BindingOperationInfo.class);
                 OperationInfo opInfo = bopInfo.getOperationInfo();
                 
                 ServiceInfo service = message.getExchange().get(ServiceInfo.class);
                 
                 org.omg.CORBA.ORB orb = (org.omg.CORBA.ORBmessage.get(.);
                 if (orb == null) {
                     orb = message.getExchange().get(org.omg.CORBA.ORB.class); 
                 }
                 QName elName = new QName(""exStreamable.getName());
                 FaultInfo fault = getFaultInfo(opInfoelName);
                 
                 CorbaTypeEventProducer faultEventProducer =
                     CorbaHandlerUtils.getTypeEventProducer(exStreamable.getObject(),
                                                           service,
                                                           orb);
                CorbaStreamReader streamReader = new CorbaStreamReader(faultEventProducer);
                Object e = reader.read(fault.getMessageParts().get(0), streamReader);
                if (!(e instanceof Exception)) {
                    Class<?> exClass = fault.getProperty(Class.class.getName(), Class.class);
                    if (exClass != null) {
                        Class<?> beanClass = e.getClass();
                        Constructor<?> constructor =
                            exClass.getConstructor(new Class[]{String.classbeanClass});
                        
                        String repId = (message.getStreamableException()._type().id() != null
                            ? message.getStreamableException()._type().id()
                                : "";
                        e = constructor.newInstance(new Object[]{repIde});
                    } else {
                        // Get the Fault                         
                        Fault faultEx = (Faultmessage.getContent(Exception.class);
                        if (e instanceof Document) {
                            createFaultDetail((Document)efaultfaultEx);
                        }
                        e = faultEx;
                    }
                }
                message.setContent(Exception.classe);
            }
        } catch (java.lang.Exception ex) {
            .log(."CORBA unmarshalFault exception"ex);
            throw new CorbaBindingException("CORBA unmarshalFault exception"ex);
        }
    }
    private void createFaultDetail(Document faultDataFaultInfo faultInfoFault faultEx) {
        MessagePartInfo partInfo =  faultInfo.getMessageParts().get(0);
        QName partInfoName = partInfo.getElementQName();
        Document faultDoc = DOMUtils.createDocument();
        Element faultElement = faultDoc.createElement("detail");
        faultDoc.appendChild(faultElement);
        Element partElement = 
            faultDoc.createElementNS(partInfoName.getNamespaceURI(), partInfoName.getLocalPart());
        
        Element faultDataElement = (ElementfaultData.getFirstChild();
        Node node = faultDataElement.getFirstChild();
        while (node != null) {
            Node importedFaultData = faultDoc.importNode(nodetrue);
            partElement.appendChild(importedFaultData);
            node = node.getNextSibling();
        }
        faultElement.appendChild(partElement);
        faultEx.setDetail(faultElement);
    }
    
    protected FaultInfo getFaultInfo(OperationInfo opInfoQName faultName) {
        Iterator<FaultInfofaults = opInfo.getFaults().iterator();
        while (faults.hasNext()) {
            FaultInfo fault = faults.next();
            MessagePartInfo partInfo = fault.getMessageParts().get(0);
            if (partInfo.isElement()
                && partInfo.getElementQName().getLocalPart().equals(faultName.getLocalPart())) {
                return fault;
            } else if (partInfo.getTypeQName().getLocalPart().equals(faultName.getLocalPart())) {
                return fault;
            }
        }
        return null;
    }
    protected DataReader<XMLStreamReadergetDataReader(CorbaMessage message) {
        Service serviceModel = ServiceModelUtil.getService(message.getExchange());
        DataReader<XMLStreamReaderdataReader = 
            serviceModel.getDataBinding().createReader(XMLStreamReader.class);
        if (dataReader == null) {
            throw new CorbaBindingException("Couldn't create data reader for incoming fault message");
        }
        return dataReader;
    }
New to GrepCode? Check out our FAQ X