001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.servicemix.soap.interceptors.jbi;
018
019 import java.net.URI;
020
021 import javax.jbi.messaging.Fault;
022 import javax.jbi.messaging.NormalizedMessage;
023 import javax.xml.namespace.QName;
024 import javax.xml.transform.Source;
025
026 import org.apache.servicemix.soap.api.Message;
027 import org.apache.servicemix.soap.bindings.soap.SoapFault;
028 import org.apache.servicemix.soap.core.AbstractInterceptor;
029
030 /**
031 * @author <a href="mailto:gnodet [at] gmail.com">Guillaume Nodet</a>
032 */
033 public class JbiFaultOutInterceptor extends AbstractInterceptor {
034
035 public void handleMessage(Message message) {
036 NormalizedMessage nm = message.getContent(NormalizedMessage.class);
037 if (nm instanceof Fault) {
038 SoapFault fault = createFault(nm);
039 throw fault;
040 }
041 }
042
043 private SoapFault createFault(NormalizedMessage nm) {
044 Source src = nm.getContent();
045 QName code = (QName) nm.getProperty(JbiConstants.SOAP_FAULT_CODE);
046 QName subcode = (QName) nm.getProperty(JbiConstants.SOAP_FAULT_SUBCODE);
047 String reason = (String) nm.getProperty(JbiConstants.SOAP_FAULT_REASON);
048 URI node = (URI) nm.getProperty(JbiConstants.SOAP_FAULT_NODE);
049 URI role = (URI) nm.getProperty(JbiConstants.SOAP_FAULT_ROLE);
050 SoapFault fault = new SoapFault(code, subcode, reason, node, role, src);
051 return fault;
052 }
053
054 }