Showing posts with label WSO2. Show all posts
Showing posts with label WSO2. Show all posts

Sunday, May 16, 2021

WSO2 - ESB Create Mediator with JSON

 Create CustomMediator extend AbstractMediator 


import org.apache.synapse.commons.json.JsonUtil;

import org.apache.synapse.mediators.AbstractMediator;


public class CustomMediator extends AbstractMediator {

 public boolean mediate(MessageContext context) {

   //Read JSON from  Axis2 context

   String jsonAsString =  JsonUtil.jsonPayloadToString(((Axis2MessageContext) context)

                    .getAxis2MessageContext());

   ..........

    //Write JSON to  Axis2 context

    String convertedJsonPayloadObject =....;

    JsonUtil.newJsonPayload(((Axis2MessageContext) context).getAxis2MessageContext(),convertedJsonPayloadObject, true, true);

   return  true;

 }

}

Friday, April 23, 2021

Configuring WSO2 API Manager 3.x with Tibco EMS (JMS)

  1. Open the deployment.toml file present at on repository/component/conf directory and add the following JMSSender configurations.

    If you use 127.0.0.1 host for the Tibco server, the APIM server should need to start at the same host.

    [[transport.jms.sender]]

    name = “QueueConnectionFactoryAPIM”

    parameter.initial_naming_factory =

    "com.tibco.tibjms.naming.TibjmsInitialContextFactory"

    parameter.provider_url = "tcp://127.0.0.1:7222"

    parameter.connection_factory_name = "QueueConnectionFactoryAPIM"

    parameter.connection_factory_type = "queue"

    parameter.jms_spec_version = "1.0.2b"

    parameter.username = "admin"

    parameter.password = ""

    parameter.destination_type = "queue"

    parameter.default_reply_destination = "queue"

     

  2. Placed the following jars (jms lib for Tibco ) on <APIM_HOME>/repository/components/extensions directory of the APIM server ( jms-2.0.jar, tibjms.jar, tibjmsadmin.jar, tibjmsapps.jar,tibrvjms.jar)
  3. Start the server

    Once you open the axis2.xml file residing on <APIM_HOME>/repository/components/conf/axis2/ directory; you can see the following JMSSende configurations.

    <transportSender class=”org.apache.axis2.transport.jms.JMSSender” name=”jms”>

    <parameter locked=”false” name=”QueueConnectionFactoryAPIM”>

    <parameter locked=”false” name=”java.naming.factory.initial”>com.tibco.tibjms.naming.TibjmsInitialContextFactory</parameter>

    <parameter locked=”false”

    name=”java.naming.provider.url”>tcp://127.0.0.1:7222</parameter>

    <parameter locked=”false”

    name=”transport.jms.UserName”>admin</parameter>

    <parameter locked=”false” name=”transport.jms.Password”></parameter>

    <parameter locked=”false”

    name=”transport.jms.ConnectionFactoryJNDIName”>QueueConnectionFactoryAPIM</parameter>

    <parameter locked=”false”

    name=”transport.jms.ConnectionFactoryType”>queue</parameter>

    <parameter locked=”false”

    name=”transport.jms.DefaultReplyDestinationType”>queue</parameter>

    <parameter locked=”false”

    name=”transport.jms.JMSSpecVersion”>1.0.2b</parameter>

    <parameter name=”transport.jms.MaxJMSConnections”>5</parameter>

    </parameter>

    </transportSender>


  4. Create an API with the following endpoint (add the wild card resource path to a POST resource)

    For dual-channel temporary queue scenario, the endpoint would be like,

    jms:/Request?transport.jms.ConnectionFactory=QueueConnectionFactoryAPIM&amp;transport.jms.ContentTypeProperty=Content_Type&amp;transport.jms.DestinationType=queue&amp;transport.jms.Destination=Req

    For the dual-channel scenario with the predefined queues as request and response, the endpoint would be like,

    jms:/Request?transport.jms.ConnectionFactory=QueueConnectionFactoryAPIM&amp;transport.jms.ContentTypeProperty=Content_Type&amp;transport.jms.DestinationType=queue&amp;transport.jms.Destination=Request&amp;transport.jms.ReplyDestination=Response

  5. Publish the API.
Ref: 
https://medium.com/@hiranyakavi/configure-tibco-ems-jms-transport-scenario-with-wso2-api-manager-3-x-d4c5e0cb774b

Note:

Add The reponse mediator to  fix null pointer exception with following content:

<sequence xmlns="http://ws.apache.org/ns/synapse" name="addToResponse"> 
   <property name="HTTP_SC" value="200" scope="axis2" />
</sequence>

Sunday, June 21, 2020

WSO2 Micro Integrator- Remove Request Headers From Response

Add the name of the header to be removed as a property property

<property name="<name of the header to be removed>" scope="transport" action="remove"/>

Note : The above method removes only the specified headers from the response. If you need to remove all the headers, follow the instructions below.
Add the TRANSPORT_HEADERS property

<property name="TRANSPORT_HEADERS" action="remove" scope="axis2"/>

WSO2 Micro Integrator - Enable Jms transport

Edit file [MI_HOME]/conf/deployment.toml, add below lines:
[[transport.jms.listener]]
name = "myQueueListener"
parameter.initial_naming_factory = "com.ibm.mq.jms.context.WMQInitialContextFactory"
parameter.broker_name = "IBM MQ"
parameter.provider_url = "X.X.X.X:1416/Channel"
parameter.connection_factory_name = "connection_factory_name "
parameter.connection_factory_type = "queue"



[[transport.jms.sender]]
name = "myQueueSender"
parameter.initial_naming_factory = "com.ibm.mq.jms.context.WMQInitialContextFactory"
parameter.broker_name = "IBM MQ"
parameter.provider_url = "X.X.X.X:1416/Channel"
parameter.connection_factory_name = "connection_factory_name "
parameter.connection_factory_type = "queue"


Copying IBM Websphere MQ libraries

These instructions are tested on IBM WebSphere MQ version 8.0.0.4. However, you can follow them for other versions appropriately.
  • Create a new directory named wmq-client , and then create another new directory named lib inside it.
  • Copy the following JAR files from the <IBM_MQ_HOME>/java/lib/ directory (where <IBM_MQ_HOME> refers to the IBM WebSphere MQ installation directory) to the wmq-client/lib/ directory.
com.ibm.mq.allclient.jar
mqcontext.jar
jms.jar
providerutil.jar
  • Create a POM.xml file inside the wmq -client/ directory and add all the required dependencies as shown in the example below.
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>wmq-client</groupId>
<artifactId>wmq-client</artifactId>
<version>8.0.0.4</version>
<packaging>bundle</packaging>
<dependencies>
    <dependency>
        <groupId>com.ibm</groupId>
        <artifactId>fscontext</artifactId>
        <version>8.0.0.4</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/mqcontext.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.ibm</groupId>
        <artifactId>providerutil</artifactId>
        <version>8.0.0.4</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/providerutil.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>com.ibm</groupId>
        <artifactId>allclient</artifactId>
        <version>8.0.0.4</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/com.ibm.mq.allclient.jar</systemPath>
    </dependency>
    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>jms</artifactId>
        <version>1.1</version>
        <scope>system</scope>
        <systemPath>${basedir}/lib/jms.jar</systemPath>
    </dependency>
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.felix</groupId>
            <artifactId>maven-bundle-plugin</artifactId>
            <version>2.3.4</version>
            <extensions>true</extensions>
            <configuration>
                <instructions>
                    <Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
                    <Bundle-Name>${project.artifactId}</Bundle-Name>
                    <Export-Package>*;-split-package:=merge-first</Export-Package>
                    <Private-Package/>
                    <Import-Package/>
                    <Embed-Dependency>*;scope=system;inline=true</Embed-Dependency>
                    <DynamicImport-Package>*</DynamicImport-Package>
                </instructions>
            </configuration>
        </plugin>
    </plugins>
</build>
</project>
  • Navigate to the wmq -client directory using your Command Line Interface (CLI), and execute the following command, to build the project: mvn clean install
  • Stop the WSO2 Micro Integrator, if it is already running.
  • Remove any existing IBM MQ client JAR files from the MI_HOME/dropins directory and the MI_HOME/lib directory.
  • Copy the <wmq-client>/target/wmq-client-8.0.0.4.jar file to the MI_HOME/dropins directory.
  • Download the jta.jar file from the maven repository, and copy it to the MI_HOME/lib directory.
Reference: https://ei.docs.wso2.com/en/7.1.0/micro-integrator/setup/brokers/configure-with-IBM-websphereMQ

Install and use xorg-server on macOS via Homebrew

  The instructions to install and use xorg-server on macOS via Homebrew: Install Homebrew (if you haven't already): /bin/bash -c ...