Wso2 ESB admin services to get Create proxies Java

丶灬走出姿态 提交于 2019-12-08 10:54:12

问题


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

回答1:


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




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/12402873/wso2-esb-admin-services-to-get-create-proxies-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!