At present I am a Software Engineer at WSO2.I was an undergraduate in University of Moratuwa Sri Lanka and a Young Innovator alumnus at International Communication Union (UN specialized agency).I was a Google Summer of code student for 2010 and 2011 and elected as an Apache Committer for Apache Roller.My key interests are Distributed Systems and SOA related technologies. Shelan is a DZone MVB and is not an employee of DZone and has posted 9 posts at DZone. You can read more from them at their website. View Full User Profile

Create a Proxy in WSO2 ESB Using Admin Services

09.23.2012
| 3461 views |
  • submit to reddit

Do you want to know how to create a proxy in WSO2 ESB without using UI? Here is some sample code that will help you understand how to use an admin service to achieve the task:

package org.wso2.test;
 
import org.apache.axis2.AxisFault;
import org.wso2.carbon.proxyadmin.stub.ProxyServiceAdminProxyAdminException;
import org.wso2.carbon.proxyadmin.stub.ProxyServiceAdminStub;
import org.wso2.carbon.proxyadmin.stub.types.carbon.ProxyData;
import org.wso2.carbon.utils.CarbonUtils;
 
import java.rmi.RemoteException;
 
public class TestProxy {
 
    public static void main(String[] args)
            throws RemoteException, ProxyServiceAdminProxyAdminException {
 
        String userName = "admin";
        String password = "admin";
        // Add the service URL
        String serviceEndPoint="http://localhost:8281/services/echo" ;
        // Proxy Admin service's endpoing URL
        String endPoint = "https://localhost:9444/services/" +"ProxyServiceAdmin";
 
        // Set client trust store
        System.setProperty("javax.net.ssl.trustStore", "/media/data/wso2/products/wso2/esb/" +
                                                       "wso2esb-4.5.0/repository/resources/security" +
                                                       "/client-truststore.jks");
        System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
        System.setProperty("javax.net.ssl.trustStoreType","JKS");
 
        ProxyServiceAdminStub proxyServiceAdminStub = new ProxyServiceAdminStub(endPoint);
 
        CarbonUtils.setBasicAccessSecurityHeaders(userName, password,
                                                  proxyServiceAdminStub._getServiceClient());
 
        //Set proxy configuration data
        String[] transport = {"http", "https"};
        ProxyData data = new ProxyData();
        data.setName("TestProxy2");
        data.setWsdlURI("http://localhost:8281/services/echo?wsdl");
        data.setTransports(transport);
        data.setStartOnLoad(true);
        data.setEndpointXML("<endpoint http:="http:" ns="ns" synapse="synapse" ws.apache.org="ws.apache.org" xmlns="\"><address serviceendpoint="serviceendpoint" uri="\">
</address>
</endpoint>");
        data.setEnableSecurity(true);
 
        proxyServiceAdminStub.addProxy(data);
    }
}

You can download the complete maven project here.

 

Published at DZone with permission of Shelan Perera, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)