Adding webservice PUT/GET inside Result

Hello play-framework community,

Would you like to help me to add some code about : PUT/GET methods about an exemple of Web services as shown in ( SOAP UI ) please :

I admit that the documentation on the official play-framework website is a bit tricky for my beginner level especially when it comes to: JsonNode, Promise, …

public CompletionStage<Result> index() {
  return supplyAsync(() -> {
      
    WSRequest request = ws.url("https://test.portnet.ma/portnet/PortnetMessageReceiverService?wsdl"); 
    
    Logger.info("TEST Logger Info : "+request.get());
    
    //1-3   Request :    Some code to submit >>     put   or   post    methode
    
    //2-3   Response :   Some code to get >> parameters values as shown in SOAP UI      

    //3-3   Finally display Response infos in my view if possible as "String"

    return ok(views.html.sitemap.index.render( ));
    }, httpExecutionContext.current());
}

I think you’re trying to ask how to do your request ? I’m not sure because you’re mixing some soapui with play or whatever :wink: but I assume your goal is to get your result and parse the soap wsdl.

What I would recommand you to do is to use a soap client for java in that sort of scenario. A quick google search gave me that one : https://github.com/reficio/soap-ws
Look good at first glance.

As of intregrating it into play, it should be kinda strait forward. Something like that should work :

    public CompletionStage<Result> index() {
        return CompletableFuture.supplyAsync(() -> {
            return Wsdl.parse("http://www.webservicex.net/CurrencyConvertor.asmx?WSDL");
        }).thenApply(wsdl -> {
            // Do your work with your WSDL.

            return views.html.sitemap.index.render();
        });
    }

I’m not a soap fan but I’m guessing the wsdl should not change all the time so you could also have it in cache and only interrogate the methods on your controller.

Hope I answered to what you wanted to ask, if not, feel free to give us a bit more informations about the problem.

Hi Adam,

Thank you so much for your help, I’ve seen some methods about (Request/Response) in Play framework documentation available here : https://www.playframework.com/documentation/2.8.x/JavaWS

My customer send me a link : https://test.portnet.ma/portnet/PortnetMessageReceiverService?wsdl

And told me to make a connection between my App and his App, and now, i am between to differents ways : Play javaWs or WSDL

Can you telling me which one should i use to make connection between my play app and customer app via webservice url please ?

Hi,

Well to answer completely your question, a WSDL is a file that describe a SOAP web-service. That’s why a software like SoapUI can take the WSDL and “magically” give you all the methods you can call with that web-service.

JavaWS is a library that allows you to make web request. But that’s kinda where it stops. There are no logics in JavaWS other than being able to make a request over http(s).

What you most likely want to do is not handle that WSDL by hand.
1 - It would be a potential source of error.
2 - There are library that do that really well.
3 - If the web-service is update, you have to update everything yourself.

So in my mind JavaWS is NOT a good solution in the present case. But using a library that handle the WSDL for you would be way better. If it was me, I would go for soap-ws.

1 Like

Hi,

Thank you so much for your return,
If you say that play JavaWs is NOT a good solution in the present case even if, as we can see in the documentation, some explainations about : REQUEST, POST, PUT, GET, RESPONSE and whatever…

Last question : in my capture (image), there are two methods: PUT + GET
Put : is it an authentication ?
Get : returning Message or Response about it ?

Thank you so much

POST, PUT, GET, DELETE correspond to the method of the request. Take a look at https://www.tutorialspoint.com/http/http_methods.htm

In your capture, if it’s an authentication or not, I can’t really say by just looking at it. But I guess a documentation should be available. But it’s not cause it’s a POST that it’s an authentication.

Hi everybody,

I found the solution my self and it was very simple :
The exemple used here is about calculating two integers : Add, Subtract, Multiply & Divide :

URL used for WSDL client is : http://www.dneonline.com/calculator.asmx?wsdl

Steps :

1- Use WSIMPORT command line :
“C:/Program Files (x86)/Java/jdk1.8.0_151/bin/wsimport” -s “C:/Users/Ali/Desktop” -keep -p wsdl “http://www.dneonline.com/calculator.asmx?wsdl

2- Import the package of Java classe to your application play framework :

3- Do whatever you want with Methods declared on the XML URL :


public CompletionStage<Result> index() {
      return supplyAsync(() -> {  
	  
	 Calculator c = new Calculator();
	 CalculatorSoap s = c.getCalculatorSoap();

     Logger.info("ADD [1 + 2] : "+s.add(new Integer(1), new Integer(2)) );
	 Logger.info("DIVIDE [6 / 2]: "+s.divide(new Integer(6), new Integer(2)) );
	 Logger.info("MULTIPLY [5 * 7] : "+s.multiply(new Integer(5), new Integer(7)) );
	 Logger.info("SUBTRACT [17 - 4] : "+s.subtract(new Integer(17), new Integer(4)) );
	  
	  
		return ok(views.html.sitemap.index.render(Sysuser.findByUserName(request().username()) ));
	    }, httpExecutionContext.current());
    }

Thank you for Help, however, what i needed before is simply the correct way to know how to follow my development in the most correct and simple way, on the other hand, the suggested suggestions went very desesperated!

Any way thank you.