Skip to content

Instantly share code, notes, and snippets.

<script language="js"><![CDATA[
importPackage(Packages.org.apache.synapse.config);
mc.getConfiguration().getRegistry().newResource("conf:/wsdl/myWSDL",false);
mc.getConfiguration().getRegistry().updateResource(
"conf:/wsdl/myWSDL", mc.getProperty("MyProperty").toString());
]]></script>
@Asitha
Asitha / GetLeaderHazelcastScript.xml
Last active September 7, 2015 04:26
WSO2 ESB script mediator code snippet to return whether a node is the leader node in the cluster or not
<script language="js">
importPackage(Packages.com.hazelcast.core);
importPackage(Packages.java.util);
iter = Hazelcast.getAllHazelcastInstances().iterator();
if( iter.hasNext() ) {
instance = iter.next();
isLeader = instance.getCluster().getMembers().iterator().next().localMember();
mc.setProperty("isLeader", isLeader);
@Asitha
Asitha / SaveInRegistry.java
Last active September 4, 2015 11:11
Java snippet to save content in WSO2 Registry using an ESB class mediator. This code shows how a value saved in message context can be easily saved to registry.
String resourcePath = "conf:/store/myStore";
mc.getConfiguration().getRegistry().newResource(resourcePath, false);
mc.getConfiguration().getRegistry().updateResource(
resourcePath, mc.getProperty("myProperty").toString().getBytes());
@Asitha
Asitha / GetLeaderNode.java
Created September 4, 2015 12:28
Code snippet to return the leader node in a Hazelcast cluster.
public boolean isLeader() {
// Get all the Hazelcast instances in the current JVM.
// In case of carbon server this is always either one
// or zero.
Iterator<HazelcastInstance> iter
= Hazelcast.getAllHazelcastInstances().iterator();
if (iter.hasNext()) { // cluster mode
@Asitha
Asitha / remove-white-background.sh
Last active March 16, 2023 23:08
Remove white background of an image with linux
convert input.png -fuzz 4% -transparent white output.png
@Asitha
Asitha / StockDetailsApi-without-non-error-http-status-codes.xml
Created April 2, 2017 10:29
StockDetailsApi with a blocking call to the back end which returns a 404 response
<api xmlns="http://ws.apache.org/ns/synapse" name="StockDetailsApi" context="/stock-details">
<resource methods="GET" faultSequence="TestErrorHandlerSequence">
<inSequence>
<log>
<property name="Log" value="stock details request recieved" />
</log>
<header name="To" scope="default" value="http://localhost:8280/inventory-api" />
<payloadFactory media-type="json">
<format>{"Account": "2"}</format>
@Asitha
Asitha / retrieve.query.param.with.$url.xml
Last active August 13, 2017 14:30
Example code using Synapse $url XPath variable to retrieve query param. Details can be found at http://asitha.github.io/cs/programming/wso2/esb/mediators/2017/08/14/get-query-params-with-wso2-esb/
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="StoreAPI" context="/store">
<resource methods="GET" uri-template="/view*">
<inSequence>
<!--Read and set the parameteres to a property -->
<property name="name" expression="$url:name" scope="default" type="STRING"/>
<property name="age" expression="$url:age" scope="default" type="STRING"/>
<!--Directly use in a payload factory as follows -->
<payloadFactory media-type="xml">
@Asitha
Asitha / query.param.using.get-property.xml
Created August 13, 2017 14:29
Using query.param property to retrieve query parameters with WSO2 ESB. Details can be found at http://asitha.github.io/cs/programming/wso2/esb/mediators/2017/08/14/get-query-params-with-wso2-esb/
<?xml version="1.0" encoding="UTF-8"?>
<api xmlns="http://ws.apache.org/ns/synapse" name="StoreAPI" context="/store">
<resource methods="GET" uri-template="/view*">
<inSequence>
<!--Directly use in a payload factory as follows -->
<payloadFactory media-type="xml">
<format>
<user xmlns="">
<name>$1</name>
@Asitha
Asitha / message-broker-admin-api.yaml
Last active January 30, 2018 04:38
Message Broker Admin API
swagger: '2.0'
info:
version: 1.0.0
title: Broker Admin API
description: Message Broker Management API
license:
name: Apache 2.0
url: 'http://www.apache.org/licenses/LICENSE-2.0.html'
schemes:
- https
@Asitha
Asitha / id-remapping.sh
Created November 12, 2019 15:43
WSO2 MB Message Tracing ID remapping script for better debugging. Need to run within log folder and the output will be pushed to processed.txt
k=0; cp wso2carbon-trace-messages.log processed.txt; for i in $(grep "mapped to andes message" wso2carbon-trace-messages.log | awk '{print $12}'); do k=$((k+1)); sed -i "s/$i/MSG-$k/g" processed.txt; done;