01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.binding.jbi.interceptor;
19:
20: import java.util.ResourceBundle;
21:
22: import javax.xml.stream.XMLStreamException;
23: import javax.xml.stream.XMLStreamReader;
24:
25: import org.w3c.dom.Element;
26:
27: import org.apache.cxf.binding.jbi.JBIFault;
28: import org.apache.cxf.binding.jbi.JBIMessage;
29: import org.apache.cxf.common.i18n.BundleUtils;
30:
31: import org.apache.cxf.interceptor.Fault;
32: import org.apache.cxf.phase.AbstractPhaseInterceptor;
33: import org.apache.cxf.phase.Phase;
34: import org.apache.cxf.staxutils.DepthXMLStreamReader;
35: import org.apache.cxf.staxutils.FragmentStreamReader;
36: import org.apache.cxf.staxutils.StaxUtils;
37:
38: public class JBIFaultInInterceptor extends
39: AbstractPhaseInterceptor<JBIMessage> {
40:
41: private static final ResourceBundle BUNDLE = BundleUtils
42: .getBundle(JBIFaultInInterceptor.class);
43:
44: public JBIFaultInInterceptor() {
45: super (Phase.UNMARSHAL);
46: addBefore("*");
47: }
48:
49: public void handleMessage(JBIMessage message) throws Fault {
50: XMLStreamReader xsr = message.getContent(XMLStreamReader.class);
51: DepthXMLStreamReader reader = new DepthXMLStreamReader(xsr);
52:
53: try {
54:
55: if (!StaxUtils.toNextElement(reader)) {
56: throw new Fault(new org.apache.cxf.common.i18n.Message(
57: "ILLEGAL_JBIFAULT_FORMAT", BUNDLE));
58: }
59: Fault fault = new JBIFault(
60: new org.apache.cxf.common.i18n.Message(
61: JBIFault.JBI_FAULT_STRING,
62: (ResourceBundle) null));
63:
64: if (StaxUtils.toNextElement(reader)) {
65: // handling detail
66: Element detail = StaxUtils.read(
67: new FragmentStreamReader(reader))
68: .getDocumentElement();
69: fault.setDetail(detail);
70: }
71: message.setContent(Exception.class, fault);
72: } catch (XMLStreamException xse) {
73: throw new Fault(new org.apache.cxf.common.i18n.Message(
74: "STAX_READ_EXC", BUNDLE));
75: }
76:
77: }
78: }
|