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.soap.interceptor;
19:
20: import javax.xml.namespace.QName;
21: import javax.xml.stream.XMLStreamException;
22: import javax.xml.stream.XMLStreamReader;
23:
24: import org.w3c.dom.Element;
25:
26: import org.apache.cxf.binding.soap.SoapFault;
27: import org.apache.cxf.binding.soap.SoapMessage;
28: import org.apache.cxf.interceptor.ClientFaultConverter;
29: import org.apache.cxf.interceptor.Fault;
30: import org.apache.cxf.phase.Phase;
31: import org.apache.cxf.staxutils.FragmentStreamReader;
32: import org.apache.cxf.staxutils.StaxUtils;
33:
34: public class Soap11FaultInInterceptor extends AbstractSoapInterceptor {
35:
36: public Soap11FaultInInterceptor() {
37: super (Phase.UNMARSHAL);
38: addBefore(ClientFaultConverter.class.getName());
39: }
40:
41: public void handleMessage(SoapMessage message) throws Fault {
42: String exMessage = null;
43: QName faultCode = null;
44: String role = null;
45: Element detail = null;
46:
47: XMLStreamReader reader = message
48: .getContent(XMLStreamReader.class);
49:
50: try {
51: while (reader.nextTag() == XMLStreamReader.START_ELEMENT) {
52: if (reader.getLocalName().equals("faultcode")) {
53: faultCode = StaxUtils.readQName(reader);
54: } else if (reader.getLocalName().equals("faultstring")) {
55: exMessage = reader.getElementText();
56: } else if (reader.getLocalName().equals("faultactor")) {
57: role = reader.getElementText();
58: } else if (reader.getLocalName().equals("detail")) {
59: detail = StaxUtils.read(
60: new FragmentStreamReader(reader))
61: .getDocumentElement();
62: }
63: }
64: } catch (XMLStreamException e) {
65: throw new SoapFault("Could not parse message.", message
66: .getVersion().getSender());
67: }
68:
69: SoapFault fault = new SoapFault(exMessage, faultCode);
70: fault.setDetail(detail);
71: fault.setRole(role);
72:
73: message.setContent(Exception.class, fault);
74: }
75:
76: }
|