Programmatically read encrypted error messages from webservice using metro 2.3

风格不统一 提交于 2019-12-04 19:44:59

Since It seems that there is no easy way to do this, I wrote a workaround.

If I enable Logging on the finest level, too many details are reported. So I wrote my own Log Message Filter.

Logger wsitlogger = Logger.getLogger("com.sun.xml.wss.logging.impl.opt.signature");
wsitlogger.setLevel(Level.FINEST);
TextAndLevelFilter logFilter= new TextAndLevelFilter(Level.INFO);
logFilter.addPrefix("WSS1764");
wsitlogger.setFilter(logFilter);

and my TextLevelFilter.java:

public class TextAndLevelFilter implements Filter {
    private static final int offValue = Level.OFF.intValue();
    private final int levelValue;

    private final Collection<String> prefixes = new LinkedList<>();

    public TextAndLevelFilter(Level level) {
        this.levelValue = level.intValue();
    }

    public void addPrefix(String prefix) {
        prefixes.add(prefix);
    }

    @Override
    public boolean isLoggable(LogRecord record) {
        final String message = record.getMessage();
        for (String prefix : prefixes) {
            if (message.startsWith(prefix)) {
                return true;
            }
        }
        return record.getLevel().intValue() >= levelValue && levelValue != offValue;
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!