N.P wrote:
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.
Hi N.P,
In your GEL script version, you are trying to instantiate the HttpURLConnection class directly with a 0 argument constructor. This is not possible, because this class has only one contructor, and it has 1 argument.
You should use something like
<core:new var="connection" className="HttpURLConnection">
<core:arg value="${url}"/>
</core:new>
Let me know if this works, I didn't test it.