Wso2 ESB admin services to get Create proxies Java

2019-06-13 02:50发布

1) Hello I am trying to use the admin services to create an Proxy inside the ESB.

So I have exposed the admin services (Hidden=false)

I have imported the WSDl in my Java project https://localhost:8243/services/ProxyServiceAdmin?wsdl

But I cannot workout how to call the method addProxy am I using the wrong admin service? Please help with an example of consuming this method.

ProxyServiceAdmin ps = new ProxyServiceAdmin();
ps.addProxy(); //wrong

2) I have a proxy defined as a one-line String, like

String xmlproxy="<?xml version='1.0' encoding='UTF-8'?><proxy xmlns='http://ws.apache.org/ns/synapse' name='MyProxy1' transports='https' startOnLoad='true' trace='disable'> <target inSequence='sequence1'>...."

Is it possible to add this Proxy by calling some method of the admin services?

thanks a lot for your attention!

EDIT I had a look at the WSDL "ProxyServiceAdmin?wsdl" it says <wsdl:operation name="addProxy"><http:operation location="addProxy"/><wsdl:input><mime:content type="text/xml" part="parameters"/></wsdl:input><wsdl:output><mime:content type="text/xml" part="parameters"/></wsdl:output>

so it is there, but why I cannot call it? Why my code does not work as a normal Web Service would? Really, please help. I don't get what i am doing wrong...

ProxyServiceAdmin ps = new ProxyServiceAdmin();
ps.addProxy(); //not recognized as an operation of ProxyServiceAdmin even if it is in the wsdl

3条回答
乱世女痞
2楼-- · 2019-06-13 03:34

You simply have to use "org.wso2.carbon.proxyadmin.stub.ProxyServiceAdminStub" to ad proxy by admin services

Please have a look at following code and comments inline.

    String endPoint = *<your backend service url>* +"ProxyServiceAdmin";
    proxyServiceAdminStub = new ProxyServiceAdminStub(endPoint);

You have to authenticate your service stub before make any use of it

    CarbonUtils.setBasicAccessSecurityHeaders(userName, password,                      
                              proxyServiceAdminStub._getServiceClient());

Need to generate ProxyData object of your proxy as synaps xml

    String[] transport = {"http", "https"};
    ProxyData data = new ProxyData();
    data.setName(proxyName);
    data.setWsdlURI(*<url to your WSDL>*);
    data.setTransports(transport);
    data.setStartOnLoad(true);       
    data.setEndpointXML("<endpoint xmlns=\"http://ws.apache.org/ns/synapse\"><address uri=\"" + serviceEndPoint + "\" /></endpoint>");
    data.setEnableSecurity(true);
    proxyServiceAdminStub.addProxy(data);

Thank You, Dharshana

查看更多
等我变得足够好
3楼-- · 2019-06-13 03:36

This is the JSP page is used for creating a pass through proxy. You can fill your proxy data similar to that. if you browse the other jsps you can find similar logics used for different proxy templates. Here you can find the complete module, both UI and Service code.

查看更多
趁早两清
4楼-- · 2019-06-13 03:47

please find the sample to create a proxy using admin service here. I added Darshana's code to a complete example.

查看更多
登录 后发表回答