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.
Related
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>
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.
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.
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
I am working on the WSO2 ESB Proxy service, which involves exposing the internal RESTful service via SOAP endpoint on the ESB.
My RESTful service requires Content-type = "application/rdf+xml". I tried setting it using all 3 properties mentioned in the documentation: messageType, ContentType and CONTENT_TYPE. However, the request Content-type still remains "application/xml".
Here is an excerpt from my sequence that calls REST service:
<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/>
<send>
<endpoint name="CQ">
<address uri="http://my_url" format="pox">
</address>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
I tested it with TCPMon and no matter what Content-type property I use, request still contains "application/xml".
Please advice.
Can you try WSO2 ESB 4.7.0 with following configuration? Note that, I have changed the address format from "pox" to "rest"
<property xmlns:ns="http://org.apache.synapse/xsd" name="REST_URL_POSTFIX" value="/record/12345" scope="axis2" type="STRING"/>
<property name="HTTP_METHOD" value="PUT" scope="axis2" type="STRING"/>
<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
<property name="CONTENT_TYPE" value="application/rdf+xml" scope="axis2" type="STRING"/>
<send>
<endpoint name="CQ">
<address uri="http://my_url" format="rest">
</address>
<property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Basic ', base64Encode('username:password'))" scope="transport"/>
<property name="OSLC-Core-Version" value="2.0" scope="transport"/>
<property name="Accept" value="application/rdf+xml" scope="transport"/>
</endpoint>
</send>
These are the http headers sent now (captured from tcpmon)
PUT /record/12345 HTTP/1.1
Cookie: region1_configure_menu=none; region3_registry_menu=none; region4_monitor_menu=none; region5_tools_menu=none; JSESSIONID=54D2911FCD5559C6B2F723E7C6FA9B44; requestedURI="../../carbon/service-mgt/index.jsp?region=region1&item=services_list_menu"; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23
Authorization: null
OSLC-Core-Version: 2.0
Content-Type: application/rdf+xml
Accept: application/rdf+xml
Transfer-Encoding: chunked
Host: www.foo.com:8080
Connection: Keep-Alive
User-Agent: Synapse-PT-HttpComponents-NIO
In the configuration you have attached, you have specified the format of the address uri as "pox" .
<address uri="http://my_url" format="pox">
This will be the reason that you are getting content-type as application/xml always. Please remove this attribute and try. It should be
<address uri="http://my_url">
If you still see the issue, then try to switch to the NHTTP transport as suggested by RaviU. For that, you can first backup the axis2.xml (ESB_HOME/repository/conf/axis2/axis2.xml) as axis2_back.xml and then rename the axis2_nhttp.xml file (same location) as axis2.xml.
Can you set the content type property like this;
<property name="Content-Type” value="application/rdf+xml" scope="transport"/>
Please remove other content-type properties..
If you define like this;
[1]<property name="messageType" value="application/rdf+xml" scope="axis2" type="STRING"/>
[2]<property name="ContentType" value="application/rdf+xml" scope="axis2" type="STRING"/>
[1] for, to select messageformatter
[2]for, to select message builders
Edit;
try like this
<inSequence>
<log level="custom">
<property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
</log>
<property name="messageType"
value="application/json"
scope="axis2"
type="STRING"/>
<property name="Content-Type"
value="application/json"
scope="transport"
type="STRING"/>
<log level="custom">
<property name="in seq --------------of proxy" expression="$trp:Content-Type"/>
</log>
<send>
<endpoint>
<address uri="http://localhost:5555/com"/>
</endpoint>
</send>
Sometimes, you have to enable those message formatters in axis2.xml before using them.
Check this article out. It may help if you haven't done so yet.
http://wso2.com/library/articles/axis2-configuration-part2-learning-axis2-xml#mf