[6785] | 1 | /** |
---|
| 2 | * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. |
---|
| 3 | * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior |
---|
| 4 | * |
---|
| 5 | * This program is free software: you can redistribute it and/or modify |
---|
| 6 | * it under the terms of the GNU Affero General Public License as |
---|
| 7 | * published by the Free Software Foundation, either version 3 of the |
---|
| 8 | * License, or (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU Affero General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU Affero General Public License |
---|
| 16 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
| 17 | */ |
---|
| 18 | |
---|
| 19 | /******************************************************************************\ |
---|
| 20 | * |
---|
| 21 | * This product was developed by |
---|
| 22 | * |
---|
| 23 | * SERVIÃO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), |
---|
| 24 | * |
---|
| 25 | * a government company established under Brazilian law (5.615/70), |
---|
| 26 | * at Department of Development of Porto Alegre. |
---|
| 27 | * |
---|
| 28 | \******************************************************************************/ |
---|
| 29 | |
---|
| 30 | package serpro.mailarchiver.util; |
---|
| 31 | |
---|
| 32 | import java.util.Map; |
---|
| 33 | import java.util.Map.Entry; |
---|
| 34 | import java.util.Set; |
---|
| 35 | import org.apache.cxf.binding.soap.SoapMessage; |
---|
| 36 | import org.apache.cxf.interceptor.Fault; |
---|
| 37 | import org.apache.cxf.message.Message; |
---|
| 38 | import org.apache.cxf.phase.AbstractPhaseInterceptor; |
---|
| 39 | import org.apache.cxf.phase.Phase; |
---|
| 40 | |
---|
| 41 | public class SoapInterceptors { |
---|
| 42 | |
---|
| 43 | public static class Receive extends AbstractPhaseInterceptor<Message> { |
---|
| 44 | |
---|
| 45 | private static final Logger log = Logger.getLocalLogger(); |
---|
| 46 | |
---|
| 47 | public Receive() { |
---|
| 48 | super(Phase.RECEIVE); |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | @Override |
---|
| 52 | public void handleMessage(Message msg) throws Fault { |
---|
| 53 | |
---|
| 54 | SoapMessage sm = (SoapMessage) msg; |
---|
| 55 | |
---|
| 56 | if(sm.containsKey("org.apache.cxf.message.Message.PROTOCOL_HEADERS")) { |
---|
| 57 | |
---|
| 58 | Map<String, Object> map = (Map<String, Object>) sm.get("org.apache.cxf.message.Message.PROTOCOL_HEADERS"); |
---|
| 59 | |
---|
| 60 | if(map.containsKey("Access-Control-Request-Headers")) { |
---|
| 61 | |
---|
| 62 | log.info("CORS SOAP Message: Interceptor chain abortado:\n\n" + dumpSoapMessage(msg)); |
---|
| 63 | sm.getInterceptorChain().abort(); |
---|
| 64 | return; |
---|
| 65 | } |
---|
| 66 | } |
---|
| 67 | log.debug("SOAP Message:\n\n" + dumpSoapMessage(msg)); |
---|
| 68 | } |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | public static class ReceiveFault extends AbstractPhaseInterceptor<Message> { |
---|
| 72 | |
---|
| 73 | private static final Logger log = Logger.getLocalLogger(); |
---|
| 74 | |
---|
| 75 | public ReceiveFault() { |
---|
| 76 | super(Phase.RECEIVE); |
---|
| 77 | } |
---|
| 78 | |
---|
| 79 | @Override |
---|
| 80 | public void handleMessage(Message msg) throws Fault { |
---|
| 81 | log.debug("SOAP Message:\n\n" + dumpSoapMessage(msg)); |
---|
| 82 | } |
---|
| 83 | } |
---|
| 84 | |
---|
| 85 | public static class Setup extends AbstractPhaseInterceptor<Message> { |
---|
| 86 | |
---|
| 87 | private static final Logger log = Logger.getLocalLogger(); |
---|
| 88 | |
---|
| 89 | public Setup() { |
---|
| 90 | super(Phase.SETUP); |
---|
| 91 | } |
---|
| 92 | |
---|
| 93 | @Override |
---|
| 94 | public void handleMessage(Message msg) throws Fault { |
---|
| 95 | log.debug("SOAP Message:\n\n" + dumpSoapMessage(msg)); |
---|
| 96 | } |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | public static class SetupFault extends AbstractPhaseInterceptor<Message> { |
---|
| 100 | |
---|
| 101 | private static final Logger log = Logger.getLocalLogger(); |
---|
| 102 | |
---|
| 103 | public SetupFault() { |
---|
| 104 | super(Phase.SETUP); |
---|
| 105 | } |
---|
| 106 | |
---|
| 107 | @Override |
---|
| 108 | public void handleMessage(Message msg) throws Fault { |
---|
| 109 | log.debug("SOAP Message:\n\n" + dumpSoapMessage(msg)); |
---|
| 110 | } |
---|
| 111 | } |
---|
| 112 | |
---|
| 113 | private static String dumpSoapMessage(Message msg) { |
---|
| 114 | SoapMessage sm = (SoapMessage) msg; |
---|
| 115 | String m = ""; |
---|
| 116 | Set<Entry<String, Object>> x = sm.entrySet(); |
---|
| 117 | for(Entry<String, Object> y : x) { |
---|
| 118 | String key = y.getKey(); |
---|
| 119 | Object val = y.getValue(); |
---|
| 120 | m += key + "->"; |
---|
| 121 | if(key.equals("org.apache.cxf.message.Message.PROTOCOL_HEADERS")) { |
---|
| 122 | m += "\n"; |
---|
| 123 | Map<String, Object> map = (Map<String, Object>) val; |
---|
| 124 | Set<Entry<String, Object>> w = map.entrySet(); |
---|
| 125 | for(Entry<String, Object> q : w) { |
---|
| 126 | String k = q.getKey(); |
---|
| 127 | Object v = q.getValue(); |
---|
| 128 | m += " " + k + "= (" + v.getClass() + ") " + v + "\n"; |
---|
| 129 | } |
---|
| 130 | } |
---|
| 131 | else { |
---|
| 132 | m += " (" + (val == null ? "null" : val.getClass()) + ") " + val + "\n"; |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | return m; |
---|
| 136 | } |
---|
| 137 | } |
---|