Logging malformed Axis2 requests - java

I'm using Axis2-1.6.2 in a highly modified Tomcat6 environment hosting a web service and need to log every incoming Axis2 web service request.
This is for a production environment and I want all requests (SOAP messages) to be logged into a log file.
For valid requests (valid request structure conform with the WSDL), this works fine, because I can log the request body after it has been parsed by Axis2. The problem is with malformed requests, which are declined by Axis2 and don't come through to my code.
I've tried a lot so far to log these wrong requests as well, but none of the proposed (easy) solutions worked. I basically just want to set a logback appender (SLF4J) or add some -Dparameter to the Java process to motivate Axis2 to log every incoming message into a file and couldn't believe that apparently there is no easy way to do that.
I can't really use some proxy like Fiddler to do the logging either (environment restrictions).
<handler type="java:org.apache.axis.handlers.LogHandler"/> didn't work either, because it's not Axis1.
The Dparameter described here didn't do anything either.
It seems to me that the only solution is to write a custom handler, which does the logging. However, this seems to be too much effort and customization for an established technology and an obvious use case. I do have guides how to do that like axis2 Log Response with Request and Java Example - Loghandler.java.
Isn't there an easier (more native) way?

For valid requests (valid request structure conform with the WSDL),
this works fine, because I can log the request body after it has been
parsed by Axis2. The problem is with malformed requests, which are
declined by Axis2 and don't come through to my code.
This is because, after the request is dispatched to service, it will fail because it is not following the service definition..
AFAIK, only solution is, keep a custom handler before dispatching phase, to capture and log the requests. Whatever the logging mechanism will work after passing axis2 layer..But in your case, it will fail before that..So, try to keep a simple handler to log messages..

Related

Weblogic - Log outbound calls from webapplication

I am working on a web application, which is deployed to weblogic cluster. Upon user invoking an action in jsp, at the server side we make an outbouond call (with 2-way ssl) to an external service. This service returns me some data, which we send to the client side for rendering on UI. This flow is working as fine.
Outbound request for 2-way SSL are made from a utility class within the application, using java.net.URLConnection. However, upon checking the access.log for weblogic, I don't see these outbounds call logs in the access logs.
Now, business has Access log monitoring software in place, to monitor specific urls/reponse code and alert IT team if the number of non-200 responses crosses some threshold.
So, the challenge I am having currently is, how to log the outbound request's url & response status to the access log of weblogic server. I have been googling over the net, but couldn't find anything so far which can suggest how to go about it. I am new to weblogic, so not sure if this is possible OOTB or I need to write some custom code for this.
Need advice from weblogic experts out there. Thanks in advance!
Weblogic only traces incoming http/s requests in its access logs. Your application is responsible for logging its own outbound requests in its own logs. Do not log your entries in weblogic's logs.

Java log request with corresponding response

I have web application which interacts with SOAP and REST external web services for some use cases as a client, and as a server for other use cases.
By the business requirements I need to log all outcoming requests to the external systems with the corresponding response, and I also need to log all incoming requests with the corresponding response.
So i need to write the list of objects like this:
{communicationId, timestamp, OUT[IN], request, response}.
What is the best way to achieve it from several perspectives:
1. To have the code in the single place if it is possible.
2. To map request with corresponding response effectively.
The best solution is dependent on the tooling you are using.
I assume you have an ESB (such as Mule) in front of your web application. If so, you have the ESB log the necessary information on the way in/out of the app.
If you have Apache CXF available, you could use interceptors to do the logging for you.
As for logging the 'response' - does this mean the actual object? If so, you could use JAXB to convert to XML and then log.

TCPMON forces you to break the target endpoint into HOSTNAME and PORT

My web service endpoint looks like this:
http://www.host.com:8010/webservices/SOAProvider/plsql/xxcpin_ap_supplier_pkg/
So when I use tcpmon to capture outgoing requests and incoming responses, I specify "www.host.com" as the HOSTNAME and 8010 as PORT. Apparently I have no way of specifying the extension "webservices/SOAProvider/plsql/xxcpin_ap_supplier_pkg/" in TCPMON. This makes me believe that my SOAP messages are going reaching the correct endpoint (which is http://www.host.com:8010/webservices/SOAProvider/plsql/xxcpin_ap_supplier_pkg/).
Is there a way or another tool where I can specify the complete endpoint address and trace the soap request and response?
Highly appreciate your response and help.
Thanks
I don't know specifically about AXIS, but in CXF you can add loggers to the endpoint configuration bus. Same for core JAX-WS where you can specify a handler chain that might include a logging step.
Command line tools that aren't part of the ws implementation (either client or server) don't know the application or protocol specifics, so they can't filter on that specific endpoint request.
You could take the output from tcpmon and post-process it to locate only the endpoint you want by looking for:
POST webservices/SOAProvider/plsql/xxcpin_ap_supplier_pkg/ HTTP/1.1
or something very similar in the data stream.
I use Fiddler2 for capturing http/webservice traffic (and SoapUI for crafting my own requests manually). You can define capture filters in fiddler2.
Both are excellent tools for testing and debugging web services.

How to see request generated by wsdl2java code?

I using a stub generated by wsld2java:
ServicesStub.ResponseMessage resp = stub.processService(rm);
Also Rampart module is engaged which includes a security header.
How can I see the complete XML request which gets send to the server?
Or if you don't want to be tied to Eclipse use TCPMON http://ws.apache.org/commons/tcpmon/
You basically redirect traffic through TCPMON and you view exactly what HTML actions happen between your outgoing webservices call (Either REST or SOAP) and you can diagnose, very useful for when SOAP faults do not properly translate to Java with useful error messages.
Eclipse has a build in tcp/monitor tool - netbeans something similar. Also possible is a normal network monitor tool like shark or a web proxy build for debugging purpose.

How a HTTP server respondes to a client's request

could you please give me a sample code on how an Http Server(Java) receives the request of a client(android)? I mean the client sends the request via Httppost, how the server takes the content of these requests in order to see the context and reply? I am trying to built a chat application.
Thank you in advance!
The server-side of HTTP is usually implemented using the protocol stack provided by a web container. You would then implement your application's server-side as servlets. There are numerous tutorials on this.
If that's the way you want to proceed, look at one of the standard web containers; e.g. Tomcat, Jetty, Glassfish, etc. The source code for all of these is available for you to browse, though I should warn you that they are all complicated under the hood.
Assuming that your HTTP service is going to be delivering JSON or XML (rather than HTML) to clients, you may want to look into using a RESTful framework.
Have a look at ServerSocket. Keep in mind that accept() blocks and, as you will probably run it in a service, you will want to time it out and check for the completion of the service. That should probably run in its own thread as should the responders to requests.
From there, you can open input and output streams to receive the request and write the response. There are any number of packages that can help you with the interaction, or you can roll your own, but it doesn't seem like you've done a lot of homework. Perhaps some searching, reading, and more specific questions would more you along more quickly.

Categories

Resources