How to handle Endpoint warnings in wso2esb - wso2

I am using wso2 esb 4.8.1,
I wish to handle warning of endpoints.I am trying to hit CXF services in tomcat server.
If I test with wrong action (Operation/method)name or service name in tomcat.
I am getting this message in SOAP.
<html>
<body>No service was found.</body>
</html>
Where as in my wso2esb not getting logged any error and that particular endpoint failing showing this message.
[2014-11-24 16:57:57,931] WARN - LoadbalanceEndpoint Endpoint [ServiceLEP] Detect a Failure in a child endpoint : Endpoint [EP3]
Since I don't know the CXF I wish to handle this in wso2esb How would I handle this message and send proper error response to client.
Is any one able to help me.
Thanks in advance.

If you are using a mediator, the response will be available in the inSequence. You can log that response with code such as this after your mediator:
<enrich>
<source type="body"/>
<target type="property" action="child" property="response_body"/>
</enrich>
<log level="custom">
<property name="The Response" expression="get-property('response_body')"/>
</log>
Please advise if that works in your scenario.

If your endpoint is suspended, then WSO2 by default initiate fault sequence, you can define your custom message in the fault sequence and then send it back to the client as you want. You can get ERROR_CODE and ERROR_MESSAGE property from WSO2 in Log or Switch mediator where u can check it. In log u can do it as following:
<log level="full" separator="**********Fault Sequence File Processor***********">
<property name="ErrorCode" expression="get-property('ERROR_CODE')"></property>
<property name="ErrorMessage" expression="get-property('ERROR_MESSAGE')"></property>
<property name="ErrorDetail" expression="get-property('ERROR_DETAIL')"></property>
<property name="ErrrorException" expression="get-property('ERROR_EXCEPTION')"></property>
</log>
You can make a check on ERROR_CODE property or ERROR_MESSAGE property in Switch mediator and then with the help of Payload mediator u can define your custom error message.

Related

Remove activityid Parameter from response Header in WSO2- API Manager

As you know, by default, WSO2 add a "activityid" Parameter to each response header which would be passed from API-Manager.
Reference:
https://docs.wso2.com/display/EMM210/Getting+Operation+Details+by+the+Activity+ID
For some reason, I need to remove this parameter from the response for client. As I searched, I find out the following link
https://apim.docs.wso2.com/en/4.0.0/deploy-and-publish/deploy-on-gateway/api-gateway/message-mediation/removing-specific-request-headers-from-response/
So I added following code into Main.XML and Fault.XML, However it doesn't work
<property name="activityid" scope="transport" action="remove"/>
I also add the following property to the data flow of a specific API through Integrator Studio. However it doesnt work
<resource methods="POST" uri-template="/attachment">
<inSequence>
<call>
<endpoint key="attachment"/>
</call>
<send/>
</inSequence>
<outSequence>
<property action="remove" name="TRANSPORT_HEADERS" scope="default"/>
<property action="remove" name="activityid" scope="default"/>
</outSequence>
<faultSequence/>
</resource>
Anybody can Give me some advice about this matter??
You can use the message mediation for API Manager. Add the above property mediator to the response path 1 of the API.
Under runtime configurations of the API, there is a message mediation section for both request and response paths. Here you can upload a mediation sequence which will be executed in the request flow as well as response flow. You can save the mediation you need to an xml file and upload the file for the response flow.
1 - https://apim.docs.wso2.com/en/4.0.0/deploy-and-publish/deploy-on-gateway/api-gateway/message-mediation/changing-the-default-mediation-flow-of-api-requests/

Tracing messages through logs in WSO2 ESB 4.8.1

I need to get a unique ID to trace messages through logs.
I am using WSO2 ESB 4.8.1.
I have found an article related to WSO2 ESB 5.0.0. http://nuwanzone.blogspot.it/2016/12/wso2-esb-tracing-messages-through-logs.html .
It describes how setting a unique ID per each message using the MessageContext object so that I can access it from anywhere within the message flow.
Is it possible implement a similar solution in WSO2 ESB 4.8.1 too? (porting that) solution in WSO2 ESB 4.8.1?
Do you know different solutions?
You can save the MessageID in a property at startup, and add it to your log mediators. Example:
<property description="SetMessageUUID" expression="fn:substring-after(get-property('MessageID'), 'urn:uuid:')" name="MessageUUID" scope="default" type ="STRING"/>
<log>
<property name="Step" expression="Request service A"/>
<property name="ID" expression="get-property('MessageUUID')"/>
</log>
<call>
.....
</call>
<log>
<property name="Step" expression="Response service A"/>
<property name="ID" expression="get-property('MessageUUID')"/>
</log>

How to pick service name in WSO2 using Log Mediator

I am using WSO2 ESB 4.8.1. When i use log mediator, i want it to also log the proxy service name in which log mediator is being used. Is there any property defined in wso2 that i can use?
Problem:
In the following log mediator I am using "Server_IP" and "Server_HOST" property to pick up the Server IP and Server Host name. So is there any property from which i can pick up the service name.
Log Mediaator:
<log level="full" separator="LogMediator" description="LoggerTemplate">
<property name="ServerIP" expression="get-property('SERVER_IP')"/>
<property name="ServerHost" expression="get-property('SERVER_HOST')"/>
</log>
Yes. Use the $ctx:proxy.name expression for your property mediator:
<log level="custom">
<property name="proxyName" expression="$ctx:proxy.name"/>
</log>
Output:
[2015-02-06 06:24:07,161] INFO - LogMediator proxyName = vfsTest

WSO2 ESB - How to send response to Intermediate sequence from service provider?

i was going through a video about "Webinar - ESB - An answer to Enterprise Service Integration" by WSO2 ESB . i have a doubt regarding the video .
it is said in the video that , always in sequence will receive the request and out sequence will return the response from the service provider . An ESb can have multiple intermediate sequence and we can, set to which intermediate sequence service provider has to send the response .
How is it possible when we do not have any control over the service provider ? are we using some queue in between ESB and service provider to accomplish ?
Inside a sequence, when you send a request to a service, you can choose the response-handling sequence (service chaining) :
<send receive="personInfoSeq">
<endpoint key="PersonInfoEpr"/>
</send>
When the ESB sends the request, a callback is instanciated (a dedicated thread) which will wait for the reply and then execute the 'receive' sequence configured in the 'send' mediator
Inside a sequence, when you are working with a response message, you can change it to a request message (<property name="RESPONSE" value="false"/>) and send it to another service
Inside a "in" sequence (when you are working with a request message), you can generate a response, sample :
<inSequence>
<header name="To" action="remove"/>
<property name="RESPONSE" value="true"/>
<property name="NO_ENTITY_BODY" scope="axis2" action="remove"/>
<payloadFactory>
<format>
<ns:getQuoteResponse xmlns:ns="http://services.samples">
<ns:return xmlns:ax21="http://services.samples/xsd">
<ax21:change>4.212070096051944</ax21:change>
<ax21:earnings>-9.567415587431361</ax21:earnings>
<ax21:high>-148.1740146577308</ax21:high>
<ax21:symbol>IBM</ax21:symbol>
</ns:return>
</ns:getQuoteResponse>
</format>
</payloadFactory>
<send/>
</inSequence>

How to send wso2 esb error message or exception to my client

I provoke an error in wso2ESB in order to have control in the client of some errors, while the esb console displays:
ERROR {org.wso2.carbon.identity.entitlement.mediator.EntitlementMediator} - Error occurred while evaluating the policy {org.wso2.carbon.identity.entitlement.mediator.EntitlementMediator}
org.apache.axis2.AxisFault: Access Denied. Authentication failed - Invalid credentials provided.
...
...
the client console displays:
org.apache.axiom.soap.SOAPProcessingException: Transport level information does not match with SOAP Message namespace URI
I'm seeing different errors in consoles, I need to take the esb error message so that the client code can catch the same error esb
At this moment i have my sequence 'fault' configured like this:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="fault" trace="enable">
<makefault version="soap12">
<code xmlns:soap12Env="http://www.w3.org/2003/05/soap-envelope" value="soap12Env:Receiver"/>
<reason xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ERROR_MESSAGE')"/>
</makefault>
<send/>
</sequence>
and a sequence in sequence to my proxy service configured like this:
<sequence xmlns="http://ws.apache.org/ns/synapse" name="InSequence" trace="enable">
<entitlementService remoteServiceUrl="https://localhost:9443/services/" remoteServiceUserName="srxxx" remoteServicePassword="kiytr">
<onReject/>
<onAccept/>
<advice/>
<obligations/>
</entitlementService>
<header xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" name="wsse:Security" action="remove"/>
<send/>
<drop/>
</sequence>
I've tried several ways to get the error in my client without success if anyone can help me I would appreciate so much
Configure a faultSequence inside your proxy service as shown in below. In your case you have to use the fault mediator inside the faultSequence.
<faultSequence>
<makefault version="soap12">
<code xmlns:soap12Env="http://www.w3.org/2003/05/soap-envelope" value="soap12Env:Receiver"/>
<reason xmlns:ns="http://org.apache.synapse/xsd" expression="get-property('ERROR_MESSAGE')"/>
</makefault>
<send/>
</faultSequence>
For more information needed for sending the error message to the client use following documentations
[1] http://docs.wso2.org/wiki/display/ESB460/Error+Handling+and+Error+Codes
[2] http://docs.wso2.org/wiki/display/ESB460/Fault+Mediator