Skip to content
Snippets Groups Projects
Commit b7eb4f80 authored by alishalistyaa's avatar alishalistyaa
Browse files

fix: switch handler chain

parent 596f96e2
No related merge requests found
......@@ -29,7 +29,6 @@ public class ApiKeyMiddleware implements SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(SOAPMessageContext context) {
System.out.println(this.context);
Boolean isOutbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
if (!isOutbound) {
try {
......
......@@ -52,23 +52,24 @@ public class LoggingMiddleware implements SOAPHandler<SOAPMessageContext> {
@Override
public boolean handleMessage(SOAPMessageContext context) {
String client = (String) context.get("authenticated-client");
String client = (String) context.get("client");
Boolean isOutbound = (Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY);
HttpExchange httpExchange = (HttpExchange) context.get(this.httpExchangeKey);
if (isOutbound) {
return true;
}
HttpExchange httpExchange = (HttpExchange) context.get(this.httpExchangeKey);
String remoteAddr = getRemoteAddr(context);
String endpoint = httpExchange.getRequestURI().toString();
try {
SOAPPart soapPart = context.getMessage().getSOAPPart();
SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
SOAPBody soapBody = soapEnvelope.getBody();
Node operation = soapBody.getChildNodes().item(1);
NodeList operations = soapBody.getChildNodes();
Node operation = operations.item(operations.getLength() - 1);
String description = String.format("%s called %s", client, operation.getLocalName());
NodeList parameters = operation.getChildNodes();
......@@ -76,6 +77,7 @@ public class LoggingMiddleware implements SOAPHandler<SOAPMessageContext> {
for (int i = 1; i < parameters.getLength(); i += 2){
description = String.format("%s %s(%s)", description, parameters.item(i).getLocalName(), parameters.item(i).getTextContent());
}
System.out.println(description);
Timestamp ts = new Timestamp(System.currentTimeMillis());
String s = ts.toString().split("\\.")[0];
Log model = new Log(description, remoteAddr, endpoint, s);
......@@ -85,6 +87,8 @@ public class LoggingMiddleware implements SOAPHandler<SOAPMessageContext> {
return false;
} catch (SQLException e) {
throw new RuntimeException(e);
} catch (Exception e) {
e.printStackTrace();
}
return true;
}
......
......@@ -2,10 +2,10 @@
<handler-chains xmlns="http://java.sun.com/xml/ns/javaee">
<handler-chain>
<handler>
<handler-class>org.tubes.middlewares.ApiKeyMiddleware</handler-class>
<handler-class>org.tubes.middlewares.LoggingMiddleware</handler-class>
</handler>
<handler>
<handler-class>org.tubes.middlewares.LoggingMiddleware</handler-class>
<handler-class>org.tubes.middlewares.ApiKeyMiddleware</handler-class>
</handler>
</handler-chain>
</handler-chains>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment