WSO2 API Manager: How do I log the fulle (http) SOAP response - wso2

How do I log the SOAP response messages (complete http response) when I invoke a service on the WSO2 AM?

If you want to see all the messages that are passing through, you can enable the wire level logs. It will log all http messages. Please uncomment following two properties in "log4j.properties" file which can be found at /repository/conf directory
uncomment the following logs to see HTTP headers and messages
log4j.logger.org.apache.synapse.transport.http.headers=DEBUG
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG

You can use log mediator to log the response. Add log mediator with level="full" at your out sequence of the API(repository\deployment\server\synapse-configs\default\api) configuration. After editing the sequence, restart the server.
OR else, you can define your custom sequence to log message and you can add that when you try to publish the API.

Related

Log Configuration in WSO2

So i'm working on PER-API log configuration in WSO2, in order to log REQUEST/RESPONSE for an API call, we need to
Modify the file log4j.properties in < APIM HOME >\repository\conf by adding the following lines to it
log4j.appender.TestAPI_APPENDER=org.apache.log4j.RollingFileAppender
log4j.appender.TestAPI_APPENDER.File=${carbon.home}/repository/logs/PerAPI/${instance.log}/wso2-APILogs-service${instance.log}.log
log4j.appender.TestAPI_APPENDER.MaxFileSize=1000KB
log4j.appender.TestAPI_APPENDER.MaxBackupIndex=10
log4j.appender.TestAPI_APPENDER.layout=org.apache.log4j.PatternLayout
log4j.appender.TestAPI_APPENDER.layout.ConversionPattern=%d{ISO8601}
[%X{ip}-%X{host}] [%t] %5p %c{1} %m%n%n
log4j.category.API_LOGGER.admin--APINAME= TRACE,
TestAPI_APPENDER
It logs the following details to a .txt file which is pretty comprehensive and cool
However i do have some questions that i'm stuck in and would like help in, here are they
The HTTP Status Code for the response is not being logged here which i badly need, I've looked here and it says to use %s - HTTP status code of the response however when i put the character %s in the log4j.properties ConversionPattern, those characters are printed as they are, how can i achieve this?
Secondly, does wso2 has some sort of portal in order to visualize these custom logs?
Thirdly, i need to put a line at the end of request/response (4 entries per API CALL) log lines and i'm unable to find any solution, if i hardcode a line into the log4j.properties ConversionPattern, i suppose it would print after each entry, please help?!
Thank you
Please find the below answers for your questions
By enabling wire logs settings you can easily track the HTTP Status Code for the response. You can enable the header and wirelogs by un-commenting following lines in log4j.properties file (located at: \repository\conf)
log4j.logger.org.apache.synapse.transport.http.headers=DEBUG
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG
The third Question, you can achieve this by using log mediator in In-sequence(print a line in request) and out-sequence(print a line in response).For an example you can use custom log in your api synapse configuration file as follows (here I use this custom log in in sequence)
<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--TwitterSearch:v1.0.0--In">
<log level="custom">
<property name="test" value="your value goes here……….” />
</log>
</sequence>
You can enable wirelogs to track the request and responses of the API when it is getting invoked. To do that uncomment following line in log4j.properties file.
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG
Furthermore if you want to log the http messages you can uncomment following line as well.
log4j.logger.org.apache.synapse.transport.http.headers=DEBUG
In WSO2 API Manager Analytics, a log Analyzer is included. You need to configure WSO2 API Manager Analytics with WSO2 API Manager to get that.
If you want to print a customized log for the API, you can use the Log mediator and add a Log mediator as a mediation extension per API with the required log to be printed in the synapse configuration of the API.

log wso2 esb request/responses to database

I want to build a logger that logs all incoming requests and their response to a database. For this I created an axis2 module that should do this in the Inflow and the Outflow - I do not want to trigger the logging from the sequences, because then I would need to put the logger in all my services.
My problem is: how can I relate the incoming message in ESB to the return message? I think this is where Synapse comes in, but I cannot find the right properties to link the messages together: there is no messageId or correlationid that I can use to do this.
Is there a way to access the Synapse properties of the message in the axis2 handler?
Axis2 module is a right option. To identify request and responses, you can check the messageIDs. And if you want to access request messagecontext in the relavant responsemessage context try following code block;
MessageContext requestMessageCtx = responseMessageCtx.getOperationContext()
.getMessageContext(WSDLConstants.MESSAGE_LABEL_IN_VALUE);
Here is a blog post

Custom Uri or endpoint on WSO2

We have just installed our WSO2 ESB, and we are trying to create some proxies services with customs endpoints.
The default endoint format is:
http://{host}:{port}/services/{Proxy Service Name}
I'd like to have something like:
http://{host}:{port}/services/utilities/{Proxy Service Name}
http://{host}:{port}/services/public/{Proxy Service Name}
I followed this tutorial:
http://wso2.org/library/knowledge-base/2011/01/custom-urls-wso2-esb-proxy-services
but we have a problem, when I send a request to my custom endpoint, I have no answer.
suggestions?
I assume that you were able to properly create a custom endpoint and "I have no answer" means you didn't get any response. If it is the case following are the possible reasons for that,
Proxy service endpoint didn't receive the request
Proxy service didn't configured properly to response back
So test whether the 1 is the reason you can simply put a log mediator with following configuration in inSequence,
<log level="full"/>
then if the proxy service received a message it will log it in console. If that works could you please post your proxy service configuration to check whether it is properly defined.
Well, it seems that we've found a solution, I'm going to resume the full solution.
As the tutorial indicates, to costumize your proxy service endpoint, you have to add the following handler on the axis2.xml configuration:
<handler name="CustomURIBasedDispatcher" class="org.apache.synapse.core.axis2.CustomURIBasedDispatcher"/>
Then, you can customize your endpoint on the design view or on the source view, I've choosen the source view, adding this parameter:
<parameter name="ServiceURI">/services/intern</parameter>
The custom endpoint is autogenerated as:
http://{host}:{port}/services/intern.myWebservice
But I has not worked for me. If I send a request to the custom endpoint, I have no response.
I've solved the problem, adding to the "ServiceURI" parameter the name of the service:
<parameter name="ServiceURI">/services/intern/myWebService</parameter>
then you have to send the request to the following endpoint:
http://{host}:{port}/services/intern/myWebService
So now you have a custom endpoint for every proxy service.
Thanks Malith for your help.

wso2 carbon - how to log the soap messages to the console with log4j

I would like to dump the soap requests and responses to the console.
I have tried setting up log4:
log4j.logger.httpclient.wire=DEBUG, CARBON_CONSOLE
log4j.logger.org.apache.commons.httpclient=DEBUG, CARBON_CONSOLE
However, this isn't logging any soap requests/responses.
I don't think you can do this with Log4J properties. I enabled TRACE for like following,
log4j.logger.org.apache.axis2.builder=TRACE
log4j.logger.org.apache.axis2.transport.http.ApplicationXMLFormatter=TRACE
log4j.logger.org.apache.axis2.transport.http.SOAPMessageFormatter=TRACE
Still you can't get the SOAP messages going in and out. If you're playing around with ESB then of course you can use the Log mediator in inSequence and outSequence to get the SOAP request/response
Easiest way would be to use a tool like TCPMon (shipped with all the WSO2 products and can be found in the bin folder) or SOAP UI.
Changing the logging in wso2 might help.
Go to Configure->Logging, and set the org.apache.axis2.transport.local.LocalTransportReceiver, org.apache.axis2.transport.local.LocalTransportSender, org.apache.axis2.transport.local.LocalResponder to the DEBUG level.
It will end up in the in the repository/logs/wso2carbon.log

WSO2 ESB providing HTTP 202 response on Proxy Service

I am trying to setup very simple WSO2 ESB Proxy service. While using it, I am getting HTTP 202 response back and WSO2 ESB is not doing anything with the request beside logging it. Here is the background of my setup
My service implementation is using SOAP 1.2 over Http 1.1. When my client opens the connection to the server, it fires first request and asks for keep-alive connection. The ESB passes the request to the actual implementation and sends response back with transfer-encoding as chunked. So far it works as desired.
After the initial request response exchange, my client submits several requests in parallel and I get HTTP 202 responses for all of them. Looking at logs, it seems ESB is not sending the request to the actual implementation ever.
Is there something that I am doing wrong? How do I fix it?
What happens in this scenario is that your subsequent requests are hitting the main sequence of the WSO2 ESB. That is why you can only see a log for those requests. As you have already narrowed down this happens due to the jsessionId attached to the URL. To overcome this issue you can create a REST API with URL pattern to match the correct URL path. Please refer the following documentation.
https://docs.wso2.com/display/ESB481/Creating+APIs