WSO2 ESB - How to enable trace for endpoint - wso2

In the documentation for WSO2 4.0.2 ESB it says following
The endpoints also have a trace attribute, which turns on detailed
trace information for messages being sent to the endpoint. These are
available in the trace.log configured via the log4j.properties file
(which can be found within lib folder once you unzip wso2 ESB ZIP).
Setting the trace log level to TRACE will dump detailed trace
information including message payloads.
Can you please share sample log4j snippet to start tracing the just the endpoint. Do I have to enable tracing for proxy service also to enable tracing for end point?
Can you please elaborate?
thanks
Abhijit

You can add namespaces of classes to the log4j.properties (in the lib folder of WSO2) that should be traced. With the following line you will enable the tracing of endpoints:
log4j.category.org.apache.synapse.endpoints=TRACE
This enables the tracing for all enpoints (so unfortunately not only for your specific endpoint).
By the way this configuration is also crusial to anable tracing or logging for your own classes:
log4j.logger.com.yourCompany=DEBUG
The above enabling of the endpoint tracing will result in logs like this (endpoint pointing to a JMS queue):
[2012-08-17 09:22:13,855] DEBUG - AddressEndpoint Sending message through endpoint : endpoint_9b9ef24d0d136e3e709a6c21cac87806d5d547bc5ba68dc6 resolving to address = jms:/myJMS?transport.jms.DestinationType=topic&transport.jms.ConnectionFactoryJNDIName=QueueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.ActiveMQInitialContextFactory

As FiveO said, you can edit log4j file to see what is going on..But there is another way to enable trace attribute for endpoints..
You simply need to add trace="enable" attribute to your endpoint configuration..
<address uri="http://abc.com" trace="enable">

Related

I have a soap service deployed on wso2 apim 4.0.0. While working with the api I randomly get Error on line 1: Content is not allowed in prolog

I have a soap service deployed on wso2 apim 4.0.0. While working with the api I randomly (rarely) get an error - "Content is not allowed in prolog". Is there any component of the configuration to be tuned to overcome this issue? Another version of the cause of this error, I found out in the article, this might be caused by a consumer that is not able to properly invoke the api. Any hint to find out the root of the problem is appreciated.
Enable wire logs[1] and check whether the backend is sending a corrupted response while you are reproducing the issue.
A corrupted response means such as a chunked response but, the Content-Length header is available in the response.
You can compare the wire logs for both the happy path and the issue scenario.
[1] https://apim.docs.wso2.com/en/latest/integrate/develop/using-wire-logs/

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.

WSO2 ESB (4.9.0) throw out SOAPProcessingException when connecting Salesforce through proxy server

I try to use WSO2 ESB at workplace where Proxy Server is available.
Set Proxy Server settings in axis2.xml,
Install certificate.
Initialize Salesforce connector(Salesforce certificate has been installed).
Test the API, run into an exception - SOAPProcessingException,
Really appreciate if someone can give ideas of solution.
First of all I have tried this type of a scenario using WSO2 ESB 4.9.0 and which was perfectly working fine. By looking at your error messages I can see that there was an Authentication failure, hence Sales Force end point returns some HTML error message. The ESB tries to build this HTML error message using the SOAP builder leading to this situation.
This could be due to some missing configuration in your setting. You may follow [1] to enable HTTP Proxy to Sales Force. Then to setup Sales Force [2] will be helpful.
Couple of thing I need to highlight here. Did you import the Salesforce certificate into the ESBs client trust store using the keytool import command. If not please go ahead and do so. Also is there a particular reason for you to use NHTTP transport here. Ideally we would use Passthrough transport to add the proxy host as given in [1].
If you still get the error after following the above steps please enable the wirelogs and post it here to investigate further. Follow these steps to enable wirelogs.
Open log4j.properties file from a text editor.
log4j.properties file is located in $ESB_HOME/repository/conf directory.
Un-comment the following entry.
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG
Hope this helps you.
[1] https://docs.wso2.com/display/ESB470/Enabling+SSL+Tunneling+through+a+Proxy+Server
[2]https://docs.wso2.com/display/ESBCONNECTORS/Working+with+Salesforce+Connector+Operations

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 API Key Manager

I am configuring our API Manager, but running into troubles authenticating via OAuth, seems to be an issue with the API Key Manager. I haven't dug into it yet, but does this come with the API Manager (as I have assumed) or is this a separate installation?
I had the same issue when using the wso2 api manager on a Amazon hosted machine, turn out that Thrift was not working correctly because some problem with multicasting and broadcasting.
What I did to get it working was to switch from ThriftClient to WSClient. If you have a huge amount of requests coming in then Thrift is the recommended solution from wso2 but in any "normal" case you will not have any differences between thrift and WS.
Here is how you switch:
Shut down the API Manager
Open up <api manager install dir>\repository\conf\api-manager.xml
Find ThriftClient
Change this to
<KeyValidatorClientType>WSClient</KeyValidatorClientType>
Start the API Manager
You may get some Warnings while starting up but, try it before you jump to the conclusion that it doesn't work.
Hope it helps!
you can use APIM manager product in a distributed setup as keymanger,gateway,store,publisher..but all functionality come in a single distribution.. ..
Go through the documentation for further guides
I was facing the same issue. Everything started when I created my own jks in order to use SSL without a self-signed certificate. I successfully created the jks and changed it in the carbon file. When I started the server, everything seemed ok; but when I used SOAPUI to test an API call, I got this (in the logs of the api manager):
APIAuthenticationHandler API authentication failure due to Unclassified Authentication Failure
I started digging what was the problem by enabling Debug level in the log4j.properties file, and then tried again a tested with SOAPUI and I got:
APISecurityException: Could not connect to <my api ip address> on port 10397
Then, I read the comment of OneMuppet and I checked that file and I found that the Thrift config has a host option, so I uncommented it:
<KeyValidatorClientType>ThriftClient</KeyValidatorClientType>
<ThriftClientPort>10397</ThriftClientPort>
<ThriftClientConnectionTimeOut>10000</ThriftClientConnectionTimeOut>
<ThriftServerPort>10397</ThriftServerPort>
This Line --> <ThriftServerHost>localhost</ThriftServerHost>
<EnableThriftServer>true</EnableThriftServer>
Save, restarted the server and everything start working correctly.
I got the same below issue after my installation, when i try to invoke the api service it is throwing below error:
900900 Unclassified Authentication Failure Error while accessing backend services for API key validation
After some random checks i have seen the axis2.xml file in /repository/conf/axis2 there it is refering a differnt ip's instead. I change these ip's to my local ip and restarted. The issue is resolved now.
I was facing the same issue. when I was trying to setup API Manager as an API Gateway in a different machine as per the steps given here,
https://docs.wso2.com/display/AM250/Publish+through+Multiple+API+Gateways
Once the setup is done and when I am trying to use this gateway URL, I was getting the below response,
{"fault":{"code":900900,"message":"Unclassified Authentication Failure","description":"Error while accessing backend services for API key validation"}}
After changing the KeyValidatorClientType value to WSClient from ThriftClient on the <api manager install dir>\repository\conf\api-manager.xml
It started working fine. And I was able to get the expected response.
If you changed the admin password, then you also have to update the repository/conf/api-manager.xml file with the new password. The 2 places I have changed (so far) are:
<AuthManager>
and
<APIKeyManager>
but there are other admin usernames in that file. No doubt, I'll get to them....