Tracing messages through logs in WSO2 ESB 4.8.1 - wso2

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>

Related

ESB WSO2 | Trying to send an email through email connector and getting "org.wso2.carbon.connector.email.send cannot be found" error

I'm trying to send an email using email connector from esb wso2 but I'm getting this error:
Invoking Target EIP Sequence org.wso2.carbon.connector.email.send paramNames : [from, to, subject, content, contentType]
[2022-07-22 10:52:14,113] ERROR {org.apache.synapse.mediators.template.InvokeMediator} - Sequence template org.wso2.carbon.connector.email.send cannot be found
[2022-07-22 10:52:14,121] DEBUG {org.apache.synapse.debug.SynapseDebugManager} - Mediation flow terminated for id urn:uuid:3f3f9864-bbc1-4e95-a4bf-1574196dfb8c
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.core.axis2.SynapseMessageReceiver} - Executing fault handler due to exception encountered
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.FaultHandler} - ERROR_CODE : 0
[2022-07-22 10:52:14,121] WARN {org.apache.synapse.FaultHandler} - ERROR_MESSAGE : Sequence template org.wso2.carbon.connector.email.send cannot be found
[2022-07-22 10:52:14,122] WARN {org.apache.synapse.FaultHandler} - ERROR_DETAIL : org.apache.synapse.SynapseException: Sequence template org.wso2.carbon.connector.email.send cannot be found
This is my api which I use:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/api/send/email" name="api.send.email" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST">
<inSequence>
<property expression="json-eval($.from)" name="from" scope="default" type="STRING"/>
<property expression="json-eval($.to)" name="to" scope="default" type="STRING"/>
<property expression="json-eval($.subject)" name="subject" scope="default" type="STRING"/>
<property expression="json-eval($.content)" name="content" scope="default" type="STRING"/>
<property expression="json-eval($.contentType)" name="contentType" scope="default" type="STRING"/>
<log level="custom">
<property expression="$ctx:from" name="Log_from:"/>
<property expression="$ctx:to" name="Log_to:"/>
<property expression="$ctx:subject" name="Log_subject:"/>
<property expression="$ctx:content" name="Log_content:"/>
<property expression="$ctx:contentType" name="Log_contentType:"/>
</log>
<email.send configKey="TEST_SMTP_CONNECTION">
<from>{json-eval($.from)}</from>
<to>{json-eval($.to)}</to>
<subject>{json-eval($.subject)}</subject>
<content>{json-eval($.content)}</content>
<contentType>{json-eval($.contentType)}</contentType>
</email.send>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
I think the problem is based on the fact that I don't think I added the connector on my project in the correct way.
So, first of all I added a connector on my main project (where I have APIs, endpoints etc) - Right Click - Add or Remove Connector/Module - then I added the email connector)
Then I created a new Connector Exporter on my project (Right Click on an empty space on my Project Explorer - I named the exporter 'test' - and I think here is the problem:
What Group ID, Parent Group ID and Parent Artifact ID I should choose? (same question when I'm making Composite Application for connector)
LATER EDIT*:
When I'm deploying de car. app for the email connector I'm getting these errors:
Error in instantiating class : org.wso2.carbon.connector.operations.list.EmailGetAttachment java.lang.NoClassDefFoundError: org/wso2/carbon/connector/core/exception/ContentBuilderException
at java.lang.Class.getDeclaredConstructors0(Native Method)
at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
at java.lang.Class.getConstructor0(Class.java:3075)
at java.lang.Class.newInstance(Class.java:412)
Unable to update status for : {org.wso2.carbon.connector}email :: Template configuration : null cannot be builtfor Synapse Library artifact : getEmailAttachment org.apache.synapse.deployers.SynapseArtifactDeploymentException: Template configuration : null cannot be builtfor Synapse Library artifact : getEmailAttachment
To answer your questions, if you have a Maven MultiModule Project you can get the details of the parent project from the pom.xml of the parent project.(This is the root pom.xml typically)
The easiest way to resolve your problem is to create your project from an existing template which will make sure projects are created correctly. Inorder to do that, follow the steps below.
Open Integration Studio and Go to Help -> Getting Started.
Then select the Email Service sample project, give it a name and create the project.
Now you should have a full working project with a Connector Exported.
In the future for creating new projects, you can refer to this document.

WSO2 IS error when creating user store

When I try to create an LDAP Base user store in WSO2 IS 5.3.0 I always get the following error:
TID: [-1234] [] [2017-04-03 11:40:49,521] ERROR {org.wso2.carbon.identity.user.store.configuration.UserStoreConfigAdminService} - Error occurred during the transformation process of C:\WSO2IS~1.0\bin\..\repository\deployment\server\userstores\myUserStore.xml
org.wso2.carbon.identity.user.store.configuration.utils.IdentityUserStoreMgtException: Error occurred during the transformation process of C:\WSO2IS~1.0\bin\..\repository\deployment\server\userstores\myUserSotre.xml
I have tried previous version and it fails till 5.0.0, in which I succeed in create the user store. User store config in WSO2 ESB seems to works the same way that WSO2 IS user store, so, I configured the user store in WSO2 ESB, and copy the myUserSotre.xml generated by WSO2 ESB just in the same path where IS failed to find the file.
That worked, and result in WSO2 IS recognizing the User Store. I can see the users from the user store in WSO2 IS user store. However, if I try update the "forced" user store, it keeps throwing the error.
I am using windows 7 and jdk 8.
This is the xml from ESB and IS 5.0.0 that works if I paste it in IS 5.3
<?xml version="1.0" encoding="UTF-8"?>
<UserStoreManager class="org.wso2.carbon.user.core.ldap.ReadOnlyLDAPUserStoreManager">
<Property name="ConnectionName">cn=Manager,dc=company,dc=com</Property>
<Property name="ConnectionURL">ldap://IP:HOST</Property>
<Property name="ConnectionPassword">password</Property>
<Property name="UserSearchBase">ou=People,dc=company,dc=com</Property>
<Property name="Disabled">false</Property>
<Property name="UserNameListFilter">(objectClass=person)</Property>
<Property name="UserNameAttribute">uid</Property>
<Property name="UserNameSearchFilter">(&(objectClass=person)(uid=?))</Property>
<Property name="ReadOnly">true</Property>
<Property name="MaxUserNameListLength">100</Property>
<Property name="MaxRoleNameListLength">100</Property>
<Property name="UserRolesCacheEnabled">true</Property>
<Property name="SCIMEnabled">false</Property>
<Property name="ReadGroups">false</Property>
<Property name="GroupSearchBase">ou=system</Property>
<Property name="GroupNameListFilter">(objectClass=groupOfNames)</Property>
<Property name="GroupNameSearchFilter">(&(objectClass=groupOfNames)(cn=?))</Property>
<Property name="GroupNameAttribute">cn</Property>
<Property name="MembershipAttribute">member</Property>
<Property name="MemberOfAttribute"/>
<Property name="PasswordHashMethod">PLAIN_TEXT</Property>
<Property name="ReplaceEscapeCharactersAtUserLogin">true</Property>
<Property name="DomainName">ldap</Property>
<Property name="Description"/>
</UserStoreManager>
Is there any issue about this? Is there extra configuration needed?
This happens in Windows because of the file path encoding. Currently this is not fixed from WSO2 side. As a work around, you can rename WSO2IS~1.0 folder not contain the '~' character. eg. rename it with WSO2IS and try.
The solution is simple. Set environment variable CARBON_HOME to the path of your wso2 IS folder.

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

How to handle Endpoint warnings in wso2esb

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.

Read body/Query parametr in wso2 esb 4.8 or 4.8.1?

How to read body param or query param in wso2 ESB 4.8 or 4.81.We tried with following format,
<property name="uri.var.name" expression="$url:name"></property>
<property name="uri.var.name" expression="$body/name"></property>
It succeeded with 4.7,But not working in WSO2 ESB 4.8 and 4.8.1 ..Any suggestion ?
To read request params :
Sample request : http://localhost:8280/services/MyService?param1=val1&param2=val2
<property name="PARAM1" expression="tokenize(substring-after(syn:get-property('To'),'param1='),'&')"/>
<property name="PARAM1" expression="tokenize(substring-after(syn:get-property('To'),'param2='),'&')"/>