/** * MailArchiver is an application that provides services for storing and managing e-mail messages through a Web Services SOAP interface. * Copyright (C) 2012 Marcio Andre Scholl Levien and Fernando Alberto Reuter Wendt and Jose Ronaldo Nogueira Fonseca Junior * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ /******************************************************************************\ * * This product was developed by * * SERVIÇO FEDERAL DE PROCESSAMENTO DE DADOS (SERPRO), * * a government company established under Brazilian law (5.615/70), * at Department of Development of Porto Alegre. * \******************************************************************************/ package serpro.mailarchiver.util; import java.util.Map; import java.util.Map.Entry; import java.util.Set; import org.apache.cxf.binding.soap.SoapMessage; import org.apache.cxf.interceptor.Fault; import org.apache.cxf.message.Message; import org.apache.cxf.phase.AbstractPhaseInterceptor; import org.apache.cxf.phase.Phase; public class SoapInterceptors { public static class Receive extends AbstractPhaseInterceptor { private static final Logger log = Logger.getLocalLogger(); public Receive() { super(Phase.RECEIVE); } @Override public void handleMessage(Message msg) throws Fault { SoapMessage sm = (SoapMessage) msg; if(sm.containsKey("org.apache.cxf.message.Message.PROTOCOL_HEADERS")) { Map map = (Map) sm.get("org.apache.cxf.message.Message.PROTOCOL_HEADERS"); if(map.containsKey("Access-Control-Request-Headers")) { log.info("CORS SOAP Message: Interceptor chain abortado:\n\n" + dumpSoapMessage(msg)); sm.getInterceptorChain().abort(); return; } } log.debug("SOAP Message:\n\n" + dumpSoapMessage(msg)); } } public static class ReceiveFault extends AbstractPhaseInterceptor { private static final Logger log = Logger.getLocalLogger(); public ReceiveFault() { super(Phase.RECEIVE); } @Override public void handleMessage(Message msg) throws Fault { log.debug("SOAP Message:\n\n" + dumpSoapMessage(msg)); } } public static class Setup extends AbstractPhaseInterceptor { private static final Logger log = Logger.getLocalLogger(); public Setup() { super(Phase.SETUP); } @Override public void handleMessage(Message msg) throws Fault { log.debug("SOAP Message:\n\n" + dumpSoapMessage(msg)); } } public static class SetupFault extends AbstractPhaseInterceptor { private static final Logger log = Logger.getLocalLogger(); public SetupFault() { super(Phase.SETUP); } @Override public void handleMessage(Message msg) throws Fault { log.debug("SOAP Message:\n\n" + dumpSoapMessage(msg)); } } private static String dumpSoapMessage(Message msg) { SoapMessage sm = (SoapMessage) msg; String m = ""; Set> x = sm.entrySet(); for(Entry y : x) { String key = y.getKey(); Object val = y.getValue(); m += key + "->"; if(key.equals("org.apache.cxf.message.Message.PROTOCOL_HEADERS")) { m += "\n"; Map map = (Map) val; Set> w = map.entrySet(); for(Entry q : w) { String k = q.getKey(); Object v = q.getValue(); m += " " + k + "= (" + v.getClass() + ") " + v + "\n"; } } else { m += " (" + (val == null ? "null" : val.getClass()) + ") " + val + "\n"; } } return m; } }