Refine search
public class CustomInInterceptor extends LoggingInInterceptor { /** * SLF4J Log Instance */ private final static Logger LOG = LoggerFactory.getLogger(CustomInInterceptor.class); /** * formats logging message and also attaches input xml to thread context * * @see org.apache.cxf.interceptor.LoggingInInterceptor#formatLoggingMessage(org.apache.cxf.interceptor.LoggingMessage) */ @Override protected String formatLoggingMessage(final LoggingMessage loggingMessage) { //The below line reads payload and puts into threads context, which I use later to save in db KpContextHolder.setInputXml(loggingMessage.getPayload().toString()); return super.formatLoggingMessage(loggingMessage); } }
@Override protected String formatLoggingMessage(LoggingMessage loggingMessage) { String headers = loggingMessage.getHeader().toString(); String soapMethodName = CxfLoggingSoapActionUtil.extractSoapMethodNameFromHttpHeader(headers); MDC.put(SOAP_METHOD_LOG_NAME, soapMethodName); StringBuilder buffer = new StringBuilder(); // Only write the Payload (SOAP-Xml) to Logger if (loggingMessage.getPayload().length() > 0) { buffer.append("0000 >>> Inbound Message:\n"); buffer.append(loggingMessage.getPayload()); } return buffer.toString(); }
@Override public String getAddress() { return loggingMessage.getAddress().toString(); }
protected void logging(Logger logger, Message message) throws Fault { if (message.containsKey(LoggingMessage.ID_KEY)) { return; String id = (String)message.getExchange().get(LoggingMessage.ID_KEY); if (id == null) { id = LoggingMessage.nextId(); message.getExchange().put(LoggingMessage.ID_KEY, id); = new LoggingMessage("Inbound Message\n----------------------------", id); buffer.getResponseCode().append(responseCode); buffer.getEncoding().append(encoding); buffer.getHttpMethod().append(httpMethod); buffer.getContentType().append(ct); buffer.getHeader().append(headers); buffer.getAddress().append(uri); buffer.getAddress().append("?").append(query); buffer.getMessage().append(BINARY_CONTENT_MESSAGE).append('\n'); log(logger, buffer.toString()); return;
public void close() throws IOException { LoggingMessage buffer = setupBuffer(message); if (count >= lim) { buffer.getMessage().append("(message truncated to " + lim + " bytes)\n"); } StringWriter w2 = out2; if (w2 == null) { w2 = (StringWriter)out; } String ct = (String)message.get(Message.CONTENT_TYPE); try { writePayload(buffer.getPayload(), w2, ct); } catch (Exception ex) { //ignore } log(logger, buffer.toString()); message.setContent(Writer.class, out); super.close(); } }
private LoggingMessage setupBuffer(Message message) { String id = (String)message.getExchange().get(LoggingMessage.ID_KEY); if (id == null) { id = LoggingMessage.nextId(); message.getExchange().put(LoggingMessage.ID_KEY, id); = new LoggingMessage("Outbound Message\n---------------------------", id); Integer responseCode = (Integer)message.get(Message.RESPONSE_CODE); if (responseCode != null) { buffer.getResponseCode().append(responseCode); String encoding = (String)message.get(Message.ENCODING); if (encoding != null) { buffer.getEncoding().append(encoding); String httpMethod = (String)message.get(Message.HTTP_REQUEST_METHOD); if (httpMethod != null) { buffer.getHttpMethod().append(httpMethod); String address = (String)message.get(Message.ENDPOINT_ADDRESS); if (address != null) { buffer.getAddress().append(address); String uri = (String)message.get(Message.REQUEST_URI); if (uri != null && !address.startsWith(uri)) { if (!address.endsWith("/") && !uri.startsWith("/")) { buffer.getAddress().append("/"); buffer.getAddress().append(uri);
public void close() throws IOException { LoggingMessage buffer = setupBuffer(message); if (count >= lim) { buffer.getMessage().append("(message truncated to " + lim + " bytes)\n"); } StringWriter w2 = out2; if (w2 == null) { w2 = (StringWriter) out; } String ct = (String) message.get(Message.CONTENT_TYPE); try { writePayload(buffer.getPayload(), w2, ct); } catch (Exception ex) { // ignore } String id = (String) message.getExchange().get(LoggingMessage.ID_KEY); LoggingMessage loggingMessage = new LoggingMessage(null, id); loggingMessage.getContentType().append(ct); loggingMessage.getPayload().append(buffer.toString()); handleMessage(loggingMessage); message.setContent(Writer.class, out); super.close(); } }
protected void logReader(Message message, Reader reader, LoggingMessage buffer) { try { CachedWriter writer = new CachedWriter(); IOUtils.copyAndCloseInput(reader, writer); message.setContent(Reader.class, writer.getReader()); if (writer.getTempFile() != null) { //large thing on disk... buffer.getMessage().append("\nMessage (saved to tmp file):\n"); buffer.getMessage().append("Filename: " + writer.getTempFile().getAbsolutePath() + "\n"); } if (writer.size() > limit && limit != -1) { buffer.getMessage().append("(message truncated to " + limit + " bytes)\n"); } writer.writeCacheTo(buffer.getPayload(), limit); } catch (Exception e) { throw new Fault(e); } } protected void logInputStream(Message message, InputStream is, LoggingMessage buffer,
= new LoggingMessage("Error occured on Service Call : "+NEWLINE +"----------------------------", logName); buffer.getResponseCode().append(responseCode); buffer.getEncoding().append(encoding); buffer.getHttpMethod().append(httpMethod); buffer.getContentType().append(ct); buffer.getHeader().append(headers); buffer.getAddress().append(uri); final String query = (String)message.get(Message.QUERY_STRING); if (query != null) { buffer.getAddress().append("?").append(query); buffer.getMessage().append("LoggedIn User: "); buffer.getMessage().append(getCurrentUsername()+NEWLINE); buffer.getMessage().append("Request payload : "+NEWLINE); buffer.getMessage().append(requestXml); }else{ buffer.getMessage().append("LoggedIn User: "); buffer.getMessage().append(getCurrentUsername()+NEWLINE); buffer.getMessage().append("No inbound request message to append."); logger.error(buffer.toString());
protected String formatLoggingMessage(LoggingMessage buffer) { return buffer.toString(); }
.equals(annotation.annotationType()) && loggingInfo.getRequestMessage().getAddress() != null) { insertValue(loggingInfo, target, annotation, method, loggingInfo.getRequestMessage().getAddress().toString()); .equals(annotation.annotationType()) && loggingInfo.getResponseMessage().getPayload() != null) { insertValue(loggingInfo, target, annotation, method, loggingInfo.getRequestMessage().getPayload().toString()); .equals(annotation.annotationType()) && loggingInfo.getResponseMessage().getPayload() != null) { insertValue(loggingInfo, target, annotation, method, loggingInfo.getResponseMessage().getPayload().toString());
@Override public String getHeaders() { return loggingMessage.getHeader().toString(); }
@Override public String getResponseCode() { if(loggingMessage.getResponseCode().length() > 0) { return loggingMessage.getResponseCode().toString(); } return "0"; }
String id = (String)message.getExchange().get(LoggingMessage.ID_KEY); if (id == null) { id = LoggingMessage.nextId(); message.getExchange().put(LoggingMessage.ID_KEY, id); = new LoggingMessage("Inbound Message\n----------------------------", id); buffer.getResponseCode().append(responseCode); buffer.getEncoding().append(encoding); buffer.getHttpMethod().append(httpMethod); buffer.getContentType().append(ct); buffer.getHeader().append(headers); buffer.getAddress().append(uri); buffer.getAddress().append("?").append(query); buffer.getMessage().append(BINARY_CONTENT_MESSAGE).append('\n'); log(logger, buffer.toString()); return; buffer.getMessage().append(MULTIPART_CONTENT_MESSAGE).append('\n'); log(logger, buffer.toString()); return;
public void close() throws IOException { LoggingMessage buffer = setupBuffer(message); if (count >= lim) { buffer.getMessage().append("(message truncated to " + lim + " bytes)\n"); } StringWriter w2 = out2; if (w2 == null) { w2 = (StringWriter)out; } String ct = (String)message.get(Message.CONTENT_TYPE); try { writePayload(buffer.getPayload(), w2, ct); } catch (Exception ex) { //ignore } log(logger, buffer.toString()); message.setContent(Writer.class, out); super.close(); } }
private LoggingMessage setupBuffer(Message message) { String id = (String)message.getExchange().get(LoggingMessage.ID_KEY); if (id == null) { id = LoggingMessage.nextId(); message.getExchange().put(LoggingMessage.ID_KEY, id); = new LoggingMessage("Outbound Message\n---------------------------", id); Integer responseCode = (Integer)message.get(Message.RESPONSE_CODE); if (responseCode != null) { buffer.getResponseCode().append(responseCode); String encoding = (String)message.get(Message.ENCODING); if (encoding != null) { buffer.getEncoding().append(encoding); String httpMethod = (String)message.get(Message.HTTP_REQUEST_METHOD); if (httpMethod != null) { buffer.getHttpMethod().append(httpMethod); String address = (String)message.get(Message.ENDPOINT_ADDRESS); if (address != null) { buffer.getAddress().append(address); String uri = (String)message.get(Message.REQUEST_URI); if (uri != null && !address.startsWith(uri)) { if (!address.endsWith("/") && !uri.startsWith("/")) { buffer.getAddress().append("/"); buffer.getAddress().append(uri);
protected void logReader(Message message, Reader reader, LoggingMessage buffer) { try { CachedWriter writer = new CachedWriter(); IOUtils.copyAndCloseInput(reader, writer); message.setContent(Reader.class, writer.getReader()); if (writer.getTempFile() != null) { //large thing on disk... buffer.getMessage().append("\nMessage (saved to tmp file):\n"); buffer.getMessage().append("Filename: " + writer.getTempFile().getAbsolutePath() + "\n"); } if (writer.size() > limit && limit != -1) { buffer.getMessage().append("(message truncated to " + limit + " bytes)\n"); } writer.writeCacheTo(buffer.getPayload(), limit); } catch (Exception e) { throw new Fault(e); } } protected void logInputStream(Message message, InputStream is, LoggingMessage buffer,
@Override public String toString() { return loggingMessage.toString(); } }
@Override protected String formatLoggingMessage(LoggingMessage loggingMessage) { String headers = loggingMessage.getHeader().toString(); String soapMethodName = CxfLoggingSoapActionUtil.extractSoapMethodNameFromHttpHeader(headers); MDC.put(ElasticsearchField.SOAP_METHOD_LOG_NAME.getName(), soapMethodName); if(logButDontExtract()) { return buildLogStatementWithSoapMessage(loggingMessage); } else if(extractButDontLog()) { return extractSoapMessageForElasticSearchProcessing(loggingMessage, headers); } else if(logAndExtract()) { extractSoapMessageForElasticSearchProcessing(loggingMessage, headers); return buildLogStatementWithSoapMessage(loggingMessage); } else { // This should never happen, as this LoggingInterceptor is only configured, // if either logging or extraction is activated return ""; } }
protected void logging(Logger logger, Message message) throws Fault { if (message.containsKey(LoggingMessage.ID_KEY)) { return; String id = (String)message.getExchange().get(LoggingMessage.ID_KEY); if (id == null) { id = LoggingMessage.nextId(); message.getExchange().put(LoggingMessage.ID_KEY, id); = new LoggingMessage("Inbound Message\n----------------------------", id); buffer.getResponseCode().append(responseCode); buffer.getEncoding().append(encoding); buffer.getHttpMethod().append(httpMethod); buffer.getContentType().append(ct); buffer.getHeader().append(headers); buffer.getAddress().append(uri); buffer.getAddress().append("?").append(query); buffer.getMessage().append(BINARY_CONTENT_MESSAGE).append('\n'); log(logger, buffer.toString()); return;