Thursday, October 20, 2016

WSO2 ESB Log Files Explained

WSO2 ESB is generating several log files during its operation. This post will describe the usage of these logs along with some example logs. I am running the ESB 4.9.0 with the below proxy service for generate these sample logs. By default all these log files will be created at the location /repository/logs/ folder.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="TestProxy"
       transports="http,https"
       statistics="disable"
       trace="enable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="custom">
            <property name="TEST" value="RECV"/>
         </log>
         <loopback/>
      </inSequence>
      <outSequence>
         <payloadFactory media-type="xml">
            <format>
               <test xmlns="">5</test>
            </format>
            <args/>
         </payloadFactory>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>
         

WSO2 Carbon log

This is the main log file of the service and named as wso2carbon.log. It contains all the server level and service level logs. The default log level is INFO and it can be changed by changing below property in log4j.properties file to desired level.

log4j.logger.org.wso2.carbon=INFO

Trace log

It offers you a way to monitor a mediation execution and named as wso2-esb-trace.log. Trace logs will be enabled only if tracing is enabled on particular proxy or a sequence. If we enable tracing for the above proxy by using the management console we will get below.


13:54:03,490 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Proxy Service TestProxy received a new message from : 10.6.19.64
13:54:03,491 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Message To: /services/TestProxy.TestProxyHttpEndpoint/mediate
13:54:03,491 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER SOAPAction: null
13:54:03,491 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER WSA-Action: null
13:54:03,492 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Setting default fault-sequence for proxy
13:54:03,493 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Using the anonymous in-sequence of the proxy service for mediation
13:54:03,493 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Start : Sequence <anonymous>
13:54:03,494 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Sequence <SequenceMediator> :: mediate()
13:54:03,494 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Mediation started from mediator position : 0
13:54:03,494 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Start : Log mediator
13:54:03,496 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER TEST = RECV
13:54:03,496 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER End : Log mediator
13:54:03,496 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Start : Loopback Mediator
13:54:03,496 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Setting default fault-sequence for proxy
13:54:03,496 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Start : Sequence <anonymous>
13:54:03,496 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Sequence <SequenceMediator> :: mediate()
13:54:03,496 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Mediation started from mediator position : 0
13:54:03,496 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Building message. Sequence <SequenceMediator> is content aware
13:54:03,518 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Start : Send mediator
13:54:03,519 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER Sending response message using implicit message properties..
Sending To: null
SOAPAction: null
13:54:03,529 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER End : Send mediator
13:54:03,529 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER End : Sequence <anonymous>
13:54:03,529 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER End : Loopback Mediator
13:54:03,529 [-] [PassThroughMessageProcessor-1]  INFO TRACE_LOGGER End : Sequence <anonymous>
13:54:45,755 [-] [http-nio-9443-exec-18]  INFO TRACE_LOGGER Building Axis service for Proxy service : TestProxy
13:54:45,755 [-] [http-nio-9443-exec-18]  INFO TRACE_LOGGER Loading the WSDL :  <Inlined>
13:54:45,755 [-] [http-nio-9443-exec-18]  INFO TRACE_LOGGER Did not find a WSDL. Assuming a POX or Legacy service
13:54:45,755 [-] [http-nio-9443-exec-18]  INFO TRACE_LOGGER Exposing transports : [http, https]
13:54:45,757 [-] [http-nio-9443-exec-18]  INFO TRACE_LOGGER Adding service TestProxy to the Axis2 configuration
13:54:45,770 [-] [http-nio-9443-exec-18]  INFO TRACE_LOGGER Successfully created the Axis2 service for Proxy service : TestProxy

Patches log

All patch related logs are recorded in the Patches.log file. 

[2016-10-19 13:38:25,951]  INFO {org.wso2.carbon.server.util.PatchUtils} -  Checking for patch changes ...
[2016-10-19 13:38:25,953]  INFO {org.wso2.carbon.server.util.PatchUtils} -  New patch available - patch0049
[2016-10-19 13:38:25,957]  INFO {org.wso2.carbon.server.extensions.PatchInstaller} -  Patch changes detected 
[2016-10-19 13:38:31,949]  INFO {org.wso2.carbon.server.util.PatchUtils} -  Backed up plugins to patch0000
[2016-10-19 13:38:31,949]  INFO {org.wso2.carbon.server.util.PatchUtils} -  Applying patches ...
[2016-10-19 13:38:31,951]  INFO {org.wso2.carbon.server.util.PatchUtils} -  Applying - patch0049
[2016-10-19 13:38:31,966]  INFO {org.wso2.carbon.server.util.PatchUtils} -  Patched org.wso2.carbon.inbound.endpoint_4.4.10.jar(MD5:6f76773b9d10b200e8b7786a2787fc96)
[2016-10-19 13:38:31,996]  INFO {org.wso2.carbon.server.util.PatchUtils} -  Patched synapse-nhttp-transport_2.1.3-wso2v11.jar(MD5:907846d87999fbbc4ba8ac0381e97822)
[2016-10-19 13:38:31,997]  INFO {org.wso2.carbon.server.util.PatchUtils} -  Patch verification started
[2016-10-19 13:38:32,019]  INFO {org.wso2.carbon.server.util.PatchUtils} -  Patch verification successfully completed

Audit log

Audit logs provide information related to the users who has tried to access the server and do changes. It is recommended to enable audit logs in the production environment and it is named as audit.log.


[2016-10-19 13:44:43,522]  INFO -  'admin@carbon.super [-1234]' logged in at [2016-10-19 13:44:43,520-0500] 
[2016-10-19 13:45:14,190]  INFO -  'admin@carbon.super [-1234]' logged out at [2016-10-19 13:45:14,0188] 
[2016-10-19 13:46:14,976]  WARN -  Failed Administrator login attempt 'testuser[-1234]' at [2016-10-19 13:46:14,971-0500] 
[2016-10-19 13:47:49,084]  INFO -  'admin@carbon.super [-1234]' logged in at [2016-10-19 13:47:49,081-0500] 
[2016-10-19 13:48:29,501]  INFO -  Initiator : null@carbon.super | Action : Change Password by User | Target : null@carbon.super | Data : {  } | Result : Failed  

Error log

All Errors and warnings at the server can be found in this log file named as wso2-esb-errors.log


2016-10-19 13:38:36,504 [-] [Start Level Event Dispatcher]  WARN ValidationResultPrinter Carbon is configured to use the default keystore (wso2carbon.jks). To maximize security when deploying to a production environment, configure a new keystore with a unique password in the production server profile.
2016-10-19 13:38:54,768 [-] [localhost-startStop-1]  WARN DefaultSchemaGenerator We don't support method overloading. Ignoring [validateAudienceRestriction]
2016-10-19 13:46:14,971 [-] [http-nio-9443-exec-32]  WARN CarbonAuthenticationUtil Failed Administrator login attempt 'tet[-1234]' at [2016-10-19 13:46:14,971-0500]
2016-10-19 13:48:29,515 [-] [http-nio-9443-exec-16] ERROR UserAdminClient Error while updating password. Wrong old credential provided 
org.wso2.carbon.user.mgt.stub.UserAdminUserAdminException: UserAdminUserAdminException
 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
 at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
 at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
 at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
 at java.lang.Class.newInstance(Class.java:442)

ESB Service log

Informaton related to all service invocations information about called services etc and all logs that have been made with the "Log" Mediator in Synapse Proxies or Sequences can be found here.  By default INFO log level is used the file is named as wso2-esb-service.log

2016-10-19 14:50:09,209 [-] [localhost-startStop-1]  INFO TestProxy Building Axis service for Proxy service : TestProxy
2016-10-19 14:50:09,212 [-] [localhost-startStop-1]  INFO TestProxy Adding service TestProxy to the Axis2 configuration
2016-10-19 14:50:09,226 [-] [localhost-startStop-1]  INFO TestProxy Successfully created the Axis2 service for Proxy service : TestProxy
2016-10-19 14:55:06,491 [-] [PassThroughMessageProcessor-1]  INFO TestProxy TEST = RECV

Access Logs

Service and REST API invocation access log

tracks when a service or REST API is invoked. By default, the service/API invocation access logs are disabled for performance reasons. Can be enable by using below. The log file is created with the name as http_access_YYYY_MM_DD.log.

log4j.logger.org.apache.synapse.transport.http.access=INFO

If you invoke the service using below url we can see the logs as follows.



- fe80:0:0:0:d84a:683c:68a5:209%11 - - [19/Oct/2016:12:59:03 -0600] "GET /services/TestProxy.TestProxyHttpEndpoint/mediate HTTP/1.1" - - "-" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
- fe80:0:0:0:d84a:683c:68a5:209%11  - [19/Oct/2016:12:59:03 -0600] "- - " 200 - "-" "-" 

Management Console Access Log

This tracks usage of the Management Console. By default it is created as http_access_management_console_YYYY_MM_DD.log file. It is rotated on a daily basis. To change the configurations of this log need to change below value in /repository/conf/tomcat/catalina-server.xml

<Valve className="org.apache.catalina.valves.AccessLogValve">


0:0:0:0:0:0:0:1 - - [19/Oct/2016:13:29:14 -0500] "GET /carbon/admin/js/jquery.ui.tabs.min.js HTTP/1.1" 200 3594 "https://localhost:9443/carbon/admin/login.jsp" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
0:0:0:0:0:0:0:1 - - [19/Oct/2016:13:29:14 -0500] "GET /carbon/admin/js/cookies.js HTTP/1.1" 200 1136 "https://localhost:9443/carbon/admin/login.jsp" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"
0:0:0:0:0:0:0:1 - - [19/Oct/2016:13:29:14 -0500] "GET /carbon/admin/js/jquery.ui.core.min.js HTTP/1.1" 200 1996 "https://localhost:9443/carbon/admin/login.jsp" "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safari/537.36"

Trace Messages log

By default trace message logs are not enabled in the ESB. You can enable it for any required component by changing the log4j.properties file. For example trace for org.apache.synapse.transport.http.headers can be enabled by adding below. The logs will be created at wso2carbon-trace-messages.log file.

log4j.appender.CARBON_TRACE_LOGFILE=org.apache.log4j.DailyRollingFileAppender
log4j.appender.CARBON_TRACE_LOGFILE.File=${carbon.home}/repository/logs/${instance.log}/wso2carbon-trace-messages${instance.log}.log
log4j.appender.CARBON_TRACE_LOGFILE.Append=true
log4j.appender.CARBON_TRACE_LOGFILE.layout=org.wso2.carbon.utils.logging.TenantAwarePatternLayout
log4j.appender.CARBON_TRACE_LOGFILE.layout.ConversionPattern=[%d] %P%5p {%c} - %x %m %n
log4j.appender.CARBON_TRACE_LOGFILE.layout.TenantPattern=%U%@%D [%T] [%S]
log4j.appender.CARBON_TRACE_LOGFILE.threshold=TRACE
log4j.logger.org.apache.synapse.transport.http.headers=TRACE,CARBON_TRACE_LOGFILE

The generated log file contains below.

[2016-10-19 14:43:47,286] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> POST /services/TestProxy.TestProxyHttpEndpoint/mediate HTTP/1.1 
[2016-10-19 14:43:47,288] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Content-Type: application/xml; charset=UTF-8 
[2016-10-19 14:43:47,289] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Cookie: region3_registry_menu=visible; region1_configure_menu=none; region4_monitor_menu=none; region5_tools_menu=none; MSG14769029100080.6387579241161663=true; menuPanel=visible; menuPanelType=main; requestedURI="../../carbon/service-mgt/index.jsp?region=region1&item=services_list_menu"; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23; JSESSIONID=9AEF469AF1960BA436D77E2B6F9BADEC 
[2016-10-19 14:43:47,297] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> User-Agent: Axis2 
[2016-10-19 14:43:47,305] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Host: OMISLABL9:8280 
[2016-10-19 14:43:47,309] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 >> Transfer-Encoding: chunked 
[2016-10-19 14:43:47,423] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << HTTP/1.1 200 OK 
[2016-10-19 14:43:47,424] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Cookie: region3_registry_menu=visible; region1_configure_menu=none; region4_monitor_menu=none; region5_tools_menu=none; MSG14769029100080.6387579241161663=true; menuPanel=visible; menuPanelType=main; requestedURI="../../carbon/service-mgt/index.jsp?region=region1&item=services_list_menu"; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23; JSESSIONID=9AEF469AF1960BA436D77E2B6F9BADEC 
[2016-10-19 14:43:47,427] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Host: OMISLABL9:8280 
[2016-10-19 14:43:47,434] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Content-Type: application/xml; charset=UTF-8; charset=UTF-8 
[2016-10-19 14:43:47,440] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Date: Wed, 19 Oct 2016 19:43:47 GMT 
[2016-10-19 14:43:47,446] DEBUG {org.apache.synapse.transport.http.headers} -  http-incoming-1 << Transfer-Encoding: chunked 

Transaction logs

A transaction is a set of operations that executed as a single unit.WSO2 carbon platform has integrated the "Atomikos" transaction manager which is a implementation of Java Transaction API (JTA). Some products like WSO2DSS, WSO2ESB shipped this transaction manager by default. Then infomation related to Atomikos are logged in tm.out file.

INFO Start Level Event Dispatcher com.atomikos.logging.LoggerFactory - Using Slf4J for logging.
WARN Start Level Event Dispatcher com.atomikos.icatch.config.UserTransactionServiceImp - Using init file: /C:/Users/apathira/Desktop/WEST/Runtime/LOGGIN~1/WSO2ES~1.0/WSO2ES~1.0/bin/../lib/transactions.properties
INFO Start Level Event Dispatcher com.atomikos.persistence.imp.FileLogStream - Starting read of logfile C:\Users\apathira\Desktop\WEST\Runtime\LOGGIN~1\WSO2ES~1.0\WSO2ES~1.0\repository\data\tmlog12.log
INFO Start Level Event Dispatcher com.atomikos.persistence.imp.FileLogStream - Done read of logfile
INFO Start Level Event Dispatcher com.atomikos.persistence.imp.FileLogStream - Logfile closed: C:\Users\apathira\Desktop\WEST\Runtime\LOGGIN~1\WSO2ES~1.0\WSO2ES~1.0\repository\data\tmlog12.log
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING core version: 3.8.0
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.console_file_name = tm.out
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.console_file_count = 1
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.automatic_resource_registration = true
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.client_demarcation = false
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.threaded_2pc = false
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.serial_jta_transactions = true
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.log_base_dir = repository/data
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.console_log_level = INFO
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.max_actives = 50
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.checkpoint_interval = 500
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.enable_logging = true
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.output_dir = repository/logs
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.log_base_name = tmlog
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.console_file_limit = 1073741824
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.max_timeout = 8000000
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.tm_unique_name = 10.6.19.64.tm
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING java.naming.factory.initial = com.sun.jndi.rmi.registry.RegistryContextFactory
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING java.naming.provider.url = rmi://localhost:1099
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.service = com.atomikos.icatch.standalone.UserTransactionServiceFactory
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.force_shutdown_on_vm_exit = true
INFO Start Level Event Dispatcher com.atomikos.icatch.config.imp.AbstractUserTransactionService - USING com.atomikos.icatch.default_jta_timeout = 5000000


Monday, October 17, 2016

How to use Class Mediator in WSO2 ESB

The Class Mediator creates an instance of a custom-specified class and sets it as a mediator. Use the Class mediator for user-specific, custom developments only when there is no built-in mediator that already provides the required functionality.

Creating a Class Mediator

There are two ways you can create a class mediator:
  •     Implement the mediator interface
  •     Extend AbstractMediator class

We can use WSO2 Developer Studio to Create class mediator easily.

Create a New Mediator Project By selecting File-> New Project -> WSO2 -> Extensions -> Project Types -> Mediator Project






It will create the class mediator by extending the AbstractMediator. Then we need to implement the mediate method which is invoked when the mediator is executed at the mediation flow.  The return statement of the mediate method decides whether the mediation flow should continue further or not.

MessageContext is the representation for a message within the ESB message flow. In the mediate method we get access to the message context. From the message context we can access message payload, message headers, properties, ESB configurations, etc. We can also set parameters to the mediator.

Sample Class mediator implementation is as follows.

package org.wso2.test;

import java.util.Enumeration;
import java.util.Map;
import java.util.Properties;

import org.apache.synapse.MessageContext; 
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

public class SampleClassMediator extends AbstractMediator { 

    public String classProperty;
    
    public boolean mediate(MessageContext context) { 
        //Mediator Property
        System.out.println("------Mediator Property-------");
        System.out.println("Using Property :  " + classProperty);
        
        //Accessing Message Properties
        System.out.println("------Message Properties-------");
        String prop = (String) context.getProperty("StringProp");
        System.out.println("Using msg Prop : "+ prop);
        
        //Accessing Axis2 Properties
        System.out.println("------Axis2 Properties-------");
        Map<String,Object> mapAxis2Properties = ((Axis2MessageContext)context).getAxis2MessageContext().getProperties();
        for (Map.Entry entry : mapAxis2Properties.entrySet()) {
            System.out.println("AXIS:"+entry.getKey() + ", " + entry.getValue());
        }
        
        //Accessing Transport Headers
        System.out.println("------Transport Headers-------");
        Map<String,Object> mapTransportProperties = (Map<String, Object>) ((Axis2MessageContext)context).getAxis2MessageContext().getProperty("TRANSPORT_HEADERS");
        for (Map.Entry entry : mapTransportProperties.entrySet()) {
            System.out.println("TRANS:" +entry.getKey() + ", " + entry.getValue());
        }
        
        //Accessing Syanpse Configuration properties
        System.out.println("------Synapse Config Properties-------");
        Properties p = ((Axis2MessageContext)context).getEnvironment().getSynapseConfiguration().getProperties();
        Enumeration keys = p.keys();
        while(keys.hasMoreElements()){
            String key = (String)keys.nextElement();
            String value = (String)p.get(key);
            System.out.println("PRP: "+ key + " | " + value);
        }
        
        //Accessing Soap envelop
        System.out.println("------Soap envelop-------");
        System.out.println("MSG : " + context.getEnvelope());
        return true; 
    }
    
    public String getClassProperty() {
        return classProperty;
    }
    
    public void setClassProperty(String propValue) {
        this.classProperty = propValue;
    }
}



After implementing the method export the project as .jar file and copy to /repository/components/lib folder and restart the ESB.

Creating the Proxy service

You can use the implemented class mediator within a proxy service as follows.

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="TestClassMedProxy"
       transports="http,https"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
         <log level="custom">
            <property name="BEGIN" value="Begin Sequence"/>
         </log>
         <property name="StringProp"
                   value="&#34;TestString&#34;"
                   scope="default"
                   type="STRING"/>
         <class name="org.wso2.test.SampleClassMediator">
            <property name="classProperty" value="5"/>
         </class>
      </inSequence>
      <outSequence>
         <send/>
      </outSequence>
   </target>
   <description/>
</proxy>
                                


Then send a request to the proxy service and you will see following output in the consloe as we are printing to the console.

[2016-10-18 07:03:27,414]  INFO - LogMediator BEGIN = Begin Sequence
------Mediator Property-------
Using Property :  5
------Message Properties-------
Using msg Prop : "TestString"
------Axis2 Properties-------
AXIS:addressing.validateAction, false
AXIS:local_WSO2_WSAS, org.wso2.carbon.core.init.CarbonServerManager@182ab504
AXIS:CARBON_TASK_JOB_METADATA_SERVICE, org.wso2.carbon.task.JobMetaDataProviderServiceHandler@4d72eb52
AXIS:file.resource.map, {}
AXIS:CARBON_TASK_MANAGEMENT_SERVICE, org.wso2.carbon.task.TaskManagementServiceHandler@fdccc49
AXIS:mediation.event.broker, org.wso2.carbon.event.core.internal.CarbonEventBroker@51c8cdb1
AXIS:CARBON_TASK_MANAGER, org.wso2.carbon.task.TaskManager@1c87c019
AXIS:wso2tracer.msg.seq.buff, org.wso2.carbon.utils.logging.CircularBuffer@467590a0
AXIS:ContainerManaged, true
AXIS:WORK_DIR, /home/anupama/Anupama/Workspace/WSO2Products/ESB/wso2esb-4.9.0/tmp/work
AXIS:PASS_THROUGH_TRANSPORT_WORKER_POOL, org.apache.axis2.transport.base.threads.NativeWorkerPool@2fa2b2a3
AXIS:CARBON_TASK_REPOSITORY, org.apache.synapse.task.TaskDescriptionRepository@389047a3
AXIS:local_current.server.status, RUNNING
AXIS:tenant.config.contexts, {}
AXIS:CONFIGURATION_MANAGER, org.wso2.carbon.mediation.initializer.configurations.ConfigurationManager@1a35cfa0
AXIS:service.epr.map, {}
AXIS:primaryBundleContext, org.eclipse.osgi.framework.internal.core.BundleContextImpl@2506f4
AXIS:GETRequestProcessorMap, {info=org.wso2.carbon.core.transports.util.InfoProcessor@70afacd6, wsdl=org.wso2.carbon.core.transports.util.Wsdl11Processor@4a223fca, wsdl2=org.wso2.carbon.core.transports.util.Wsdl20Processor@7035d472, xsd=org.wso2.carbon.core.transports.util.XsdProcessor@44c95d1b, tryit=org.wso2.carbon.tryit.TryitRequestProcessor@490d9048, wadltryit=org.wso2.carbon.tryit.WADLTryItRequestProcessor@120a3acc, stub=org.wso2.carbon.wsdl2form.StubRequestProcessor@4c42eabb, wsdl2form=org.wso2.carbon.wsdl2form.WSDL2FormRequestProcessor@42ed57ad, wadl2form=org.wso2.carbon.tryit.WADL2FormRequestProcessor@67c70068}
------Transport Headers-------
TRANS:Content-Type, application/soap+xml; charset=UTF-8; action="urn:mediate"
TRANS:Cookie, menuPanel=visible; menuPanelType=main; region1_manage_menu=visible; JSESSIONID=4B3870641F979576800AB05FAEB9360D; requestedURI=../../carbon/admin/index.jsp; region1_configure_menu=none; region3_registry_menu=none; region4_monitor_menu=none; region5_tools_menu=none; current-breadcrumb=manage_menu%2Cservices_menu%2Cservices_list_menu%23
TRANS:Host, anupama:8280
TRANS:Transfer-Encoding, chunked
TRANS:User-Agent, Axis2
------Synapse Config Properties-------
PRP: synapse.xpath.func.extensions | org.wso2.carbon.mediation.security.vault.xpath.SecureVaultLookupXPathFunctionProvider
PRP: statistics.clean.interval | 1000
PRP: synapse.commons.json.preserve.namespace | false
PRP: resolve.root | ./.
PRP: synapse.home | .
PRP: __separateRegDef | true
PRP: synapse.global_timeout_interval | 120000
PRP: synapse.temp_data.chunk.size | 3072
PRP: statistics.clean.enable | true
PRP: synapse.observers | org.wso2.carbon.mediation.dependency.mgt.DependencyTracker
PRP: synapse.sal.endpoints.sesssion.timeout.default | 600000
PRP: synapse.carbon.ext.tenant.info | org.wso2.carbon.mediation.initializer.handler.CarbonTenantInfoConfigurator
------Soap envelop-------
MSG : <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><test>Test Data</test></soapenv:Body></soapenv:Envelope>