User Friendly Log - wso2

We have developed a Project in Developer Studio everything is working fine and our Custom log is creating Custom messages in Carbon log. Our requirement is that our custom log should write in a separate file like 'Interfacing Exceptions Report' so that user can easily track the error instead of reviewing the whole Carbon log because it has too much contents as well.
Currently we have source as follows for custom log:
<property xmlns:ns11="http://xmlns.oracle.com/apps/scm/doo/decomposition/receiveTransform/receiveSalesOrder/model/"
name="OrderNumber"
expression="//ns11:OrderNumber"
scope="default"
type="STRING"/>
<property xmlns:ns11="http://xmlns.oracle.com/apps/scm/doo/decomposition/receiveTransform/receiveSalesOrder/model/"
name="OrderStatus"
expression="//ns11:OrderStatus"
scope="default"
type="STRING"/>
<property xmlns:ns11="http://xmlns.oracle.com/apps/scm/doo/decomposition/receiveTransform/receiveSalesOrder/model/"
name="ReturnStatus"
expression="//ns11:ReturnStatus"
scope="default"
type="STRING"/>
<log level="custom">
<property name="prop1" expression="get-property('OrderNumber')"/>
<property name="prop2" expression="get-property('OrderStatus')"/>
</log>
<filter source="get-property('ReturnStatus')" regex="SUCCESS">
<then>
<log level="custom">
<property name="message" value="Your order has been created successfully "/>
</log>
</then>
<else>
<log level="custom">
<property name="errormessage" value="Sorry,there was an issue in order creation"/>
</log>
</else>
</filter>

What you're looking for sounds like per service logging or per api logging.

Related

WSO2 exclude property from log

I am new to wso2 and I want to log all the properties in the incoming request except one property
here's my code:
<log level="full"/>
<propertyGroup>
<property expression="json-eval($.username)" name="Username" scope="default" type="STRING"/>
<property expression="json-eval($.password)" name="Password" scope="default" type="STRING"/>
<property expression="json-eval($.objectStore)" name="ObjectStore" scope="default" type="STRING"/>
<property expression="json-eval($.documentClass)" name="DocumentClass" scope="default" type="STRING"/>
<property expression="json-eval($.fileName)" name="FileName" scope="default" type="STRING"/>
<property expression="json-eval($.fileData)" name="FileData" scope="default" type="STRING"/>
<property expression="json-eval($.contentType)" name="ContentType" scope="default" type="STRING"/>
</propertyGroup>
I want to exclude the fileData property from log because it's base64
is there's any solution other than a custom log that has only the properties that I want to log ?
Its not posible by default i think. You can write your custom mediator for logging necessary attributes and properties
By default, the <log level="full"/> won't log your property - it is logging standard headers (i.e. To, From, WSAction, SOAPAction, ReplyTo, and MessageID) and the full payload of the message. And as i see in your example - json-eval($.fileData) is part of the JSON payload.
So, there is no other option than using a custom logger.

WSO2: How to replace a string in the request body

We have a very simple EI API. We receive an XML payload, we then extract a destination code from the XML document and, based on the destination code, we forward the payload to the appropriate endpoint.
One of our clients have made a spelling mistake in their payload and we want to correct it before we send it to the new endpoint. We want to replace the word 'Principle' with 'Principal'.
How can we replace a string in the request body with another string?
Here is our current implementation:
<inSequence>
<property expression="//MyXML/Destination" name="Destination" scope="default" type="STRING"/>
<log level="custom">
<property expression="//MyXML/Transaction/Destination" name="Destination"/>
</log>
<property action="remove" name="REST_URL_POSTFIX" scope="axis2"/>
<property description="vendorId" expression="concat('gov:/integration/endpoints/myendpoints/', get-property('uri.var.vendorId'), '_EP')" name="vendorId" scope="default" type="STRING"/>
<log category="DEBUG" description="request_log" level="full">
<property expression="get-property('vendorId')" name="Vendor ID"/>
</log>
<log description="request_log" level="custom">
<property expression="get-property('vendorId')" name="Vendor ID"/>
</log>
<send>
<endpoint key-expression="get-property('vendorId')"/>
</send>
</inSequence>

Multipart in wso2 EI

I have a requirement where i am supposed to upload a gzip file to wso2 EI server.
I have a file(gzip) in a system(running java). I need to send this file to a API hosted in wso2ei, which will store this. Since file can be HUGE, I need the API to support multi part file upload. I want to write an API in wso2 EI which will support multipart and will take this file and store on some location on EI server itself.
I do not want to use VFS.
Below is the code that i tried but not working. Its creating a corrupted zip file. If i am giving a huge file , then i am getting out of memory error too. Though while using multipart, i was not expecting out of memory error(irrespective the size of file).
Note: I tried without decoding the body. With application/zip content type as well.
<?xml version="1.0" encoding="UTF-8"?>
<api context="/upload" name="MultiPartAPI" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST" >
<inSequence>
<property expression="json-eval($)" name="inputPayLoad" scope="default" type="STRING"/>
<property name="messageType" scope="axis2" type="STRING" value="multipart/form-data"/>
<property name="ContentType" scope="axis2" type="STRING" value="multipart/form-data"/>
<property expression="//mediate/data/text()" name="payload" scope="default" type="STRING"/>
<property expression="//mediate/data/#filename" name="fileName" scope="default" type="STRING"/>
<log level="custom">
<property name="===========" value="================="/>
<property expression="$ctx:fileName" name="fileName"/>
</log>
<property expression="base64Decode(get-property('payload'))" name="DecodeBody" scope="default" type="STRING"/>
<property description="File full path" expression="fn:concat('\home\files\gzip\',$ctx:fileName)" name="fileFullPath" scope="default" type="STRING"/>
<property name="messageType" scope="axis2" type="STRING" value="application/octet-stream"/>
<property name="ContentType" scope="axis2" type="STRING" value="application/octet-stream"/>
<fileconnector.create>
<source>{$ctx:fileFullPath}</source>
<inputContent>{$ctx:DecodeBody}</inputContent>
</fileconnector.create>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
BR//
Vipin Nirwal
This give the details of above requirement.

WSO2 API Manager, where can I find the log of gateway?

such as the title, where can i find the log of gateway which is only about the api`s request and response?
in the file of wso2-apigw-trace.log,I can find nothing.
You can write synapse wire logs to a separate file with an appender like this.
# WIRE_LOGFILE is set to be a DailyRollingFileAppender using a PatternLayout.
log4j.appender.WIRE_LOGFILE=org.wso2.carbon.utils.logging.appenders.CarbonDailyRollingFileAppender
log4j.appender.WIRE_LOGFILE.File=${carbon.home}/repository/logs/${instance.log}/wso2wire${instance.log}.log
log4j.appender.WIRE_LOGFILE.Append=true
log4j.appender.WIRE_LOGFILE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout
log4j.appender.WIRE_LOGFILE.layout.ConversionPattern=TID: [%T] [%S] [%d] %P%5p {%c} - %x %m {%c}%n
log4j.appender.WIRE_LOGFILE.layout.TenantPattern=%U%#%D [%T] [%S]
log4j.appender.WIRE_LOGFILE.threshold=DEBUG
log4j.logger.org.apache.synapse.transport.http.wire=DEBUG, WIRE_LOGFILE
log4j.additivity.org.apache.synapse.transport.http.wire=false
If you want to log request and response with a correlation id, you can write a custom sequence. Correlation id can be taken from message_id like this.
You can also get access to the log via Log Analyzer UI in Admin Portal.
Here are the instructions on how to do this in WSO2 API Cloud (hosted version of API Manager).
If you want to have details of the calls to the backend and responses in the logs, you need to also add mediation policies that would output the data. This can be done on the second step of API editing ("Implement"), as shown in the picture below:
API Cloud has these sequences pre-installed. For your own API Manager deployment, you would have to upload them manually. Here are the XML files:
In Flow:
<sequence name="debug_in_flow" xmlns="http://ws.apache.org/ns/synapse">
<log level="full" />
<log level="custom">
<property name="Host" expression="get-property('transport', 'Host')"/>
<property name="Context" expression="get-property('To')"/>
<property name="HTTP_METHOD" expression="get-property('axis2', 'HTTP_METHOD')"/>
<property name="Resource" expression="$axis2:REST_URL_POSTFIX"/>
<property name="Origin" expression="get-property('transport', 'Origin')"/>
<property name="Content-Type" expression="get-property('transport', 'Content-Type')"/>
</log>
</sequence>
Out Flow:
<sequence name="debug_out_flow" xmlns="http://ws.apache.org/ns/synapse">
<log level="full" />
<log level="custom">
<property name="EndPoint" expression="get-property('ENDPOINT_PREFIX')"/>
<property name="Content-Type" expression="get-property('transport', 'Content-Type')"/>
</log>
</sequence>
Fault Flow:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="debug_json_fault">
<log level="custom">
<property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns3="http://org.apache.synapse/xsd"
name="ERROR_CODE"
expression="get-property('ERROR_CODE')"/>
<property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns3="http://org.apache.synapse/xsd"
name="ERROR_MESSAGE"
expression="get-property('ERROR_MESSAGE')"/>
<property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns3="http://org.apache.synapse/xsd"
name="ERROR_DETAIL"
expression="get-property('ERROR_DETAIL')"/>
<property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
xmlns:ns3="http://org.apache.synapse/xsd"
name="ERROR_EXCEPTION"
expression="get-property('ERROR_EXCEPTION')"/>
<property name="EndPoint" expression="get-property('ENDPOINT_PREFIX')"/>
<property name="Content-Type" expression="get-property('transport', 'Content-Type')"/>
</log>
<payloadFactory>
<format>
<am:fault xmlns:am="http://wso2.org/apimanager">
<am:code>$1</am:code>
<am:type>Status report</am:type>
<am:message>Runtime Error</am:message>
<am:description>$2</am:description>
</am:fault>
</format>
<args>
<arg expression="$ctx:ERROR_CODE"/>
<arg expression="$ctx:ERROR_MESSAGE"/>
</args>
</payloadFactory>
<filter xpath="$ctx:CUSTOM_HTTP_SC">
<then>
<property name="HTTP_SC" expression="$ctx:CUSTOM_HTTP_SC" scope="axis2"/>
</then>
<else>
<property name="HTTP_SC" value="500" scope="axis2"/>
</else>
</filter>
<class name="org.wso2.carbon.apimgt.usage.publisher.APIMgtFaultHandler"/>
<property name="RESPONSE" value="true"/>
<header name="To" action="remove"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<property name="ContentType" scope="axis2" action="remove"/>
<property name="Authorization" scope="transport" action="remove"/>
<property name="Host" scope="transport" action="remove"/>
<property name="Accept" scope="transport" action="remove"/>
<property name="X-JWT-Assertion" scope="transport" action="remove"/>
<property name="messageType" value="application/json" scope="axis2"/>
<send/>
<drop/>
I think you can find those log records from http_access_<Date>.log
File path: <APIM Home>/repositary/logs/http_access_<Date>.log

WSO2 ESB and IS Integration: handler tag is missing when we open the api source

I have created a API with name plantsapi and here is my api definition
<api xmlns="http://ws.apache.org/ns/synapse" name="plantsapi" context="/plantsapi">
<resource methods="POST DELETE PUT GET">
<inSequence>
<log level="custom">
<property name="Message Flow" value="Plant Search API API - IN"></property>
<property name="HTTP_METHOD IS###########" expression="$axis2:HTTP_METHOD"></property>
<property name="ip address" expression="get-property('axis2','REMOTE_ADDR')"></property>
<property name="In Time : " expression="get-property('SYSTEM_TIME')"></property>
</log>
<property name="TIME_IN" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"></property>
<property name="xacml_use_rest" value="true" scope="axis2" type="STRING"></property>
<property name="xacml_resource_prefix" value="/SearchService/api/plants" scope="axis2"></property>
<property name="xacml_resource_prefix_only" value="true" scope="axis2"></property>
<entitlementService remoteServiceUrl="https://172.20.13.153:9443/services" remoteServiceUserName="admin" remoteServicePassword="enc:kuv2MubUUveMyv6GeHrXr9il59ajJIqUI4eoYHcgGKf/BBFOWn96NTjJQI+wYbWjKW6r79S7L7ZzgYeWx7DlGbff5X3pBN2Gh9yV0BHP1E93QtFqR7uTWi141Tr7V7ZwScwNqJbiNoV+vyLbsqKJE7T3nP8Ih9Y6omygbcLcHzg=" callbackClass="org.wso2.carbon.identity.entitlement.mediator.callback.UTEntitlementCallbackHandler" client="basicAuth">
<onReject>
<log level="custom">
<property name="Message Flow" value="REJECTED#"></property>
</log>
<property name="HTTP_SC" value="401" scope="axis2" type="STRING"></property>
<payloadFactory media-type="xml">
<format>
<oatherizationresponse xmlns="">Not Authorized </oatherizationresponse>
</format>
<args></args>
</payloadFactory>
<respond></respond>
</onReject>
<onAccept>
<log level="custom">
<property name="Message Flow" value="ACCEPTED#"></property>
</log>
<send>
<endpoint>
<address uri="http://172.20.13.153:8080/plant-service/api/"></address>
</endpoint>
</send>
<property name="TIME_OUT" expression="get-property('SYSTEM_TIME')" scope="default" type="LONG"></property>
<script language="js">var time1 = mc.getProperty("TIME_IN");var time2 = mc.getProperty("TIME_OUT");var timeTaken = time2 - time1;mc.setProperty("RESPONSE_TIME", timeTaken);</script>
<log level="custom">
<property name="Time Duration in ms:" expression="get-property('RESPONSE_TIME') "></property>
</log>
</onAccept>
<obligations></obligations>
<advice></advice>
</entitlementService>
</inSequence>
</resource>
<handlers>
<handler class="org.wso2.handler.SimpleOauthHandlerNew">
</handler>
</handlers>
</api>
Whenever I open the source view of the above API the handler tag is missing. and always getting 202 response. I am using wso2 ESB 4.8.1
Could you please advice me where is the mistake and how to sort out.
Regards,
Geetha
It is a known bug[1]. It will be fixed in ESB 4.9.0 (will be released soon). So don't update the API source view. If you update, you will loose the handlers.
[1] https://wso2.org/jira/browse/ESBJAVA-3395
And the solution is to use WSO2 Developer Studio. WSO2 does not recommend using the UI to do development, it is mainly used to monitor and view the instance.