AnsweredAssumed Answered

convert Java code to GEL Script

Question asked by N.P on May 2, 2011
Latest reply on Apr 17, 2015 by navzjoshi00
Hi,

I need help to convert following Java code sample to GEL script using new, invoke, set tags.
    try {
      //Create connection
      url = new URL(targetURL);
      connection = (HttpURLConnection)url.openConnection();
      connection.setRequestMethod("POST");
      ...
      BASE64Encoder enc = new sun.misc.BASE64Encoder();
      String userpassword = username + ":" + password;
      String encodedAuthorization = enc.encode( userpassword.getBytes() );
      connection.setRequestProperty("Authorization", "Basic "+
            encodedAuthorization);
      ...
      //Send post data
My try:
<core:new var="url" className="java.net.URL">


<core:arg value="https://test.com/webservice/"/>

</core:new>

<core:new var="connection" className="HttpURLConnection">

</core:new>

<core:invoke method="openConnection" on="${url}" var="connection"/>
In above code "connection" assignment is failing.

Thanks,
-NP.

Outcomes