Sending HTTP request from custom code

0 votes

The question is simple:

I need to send some HTTP requests from my custom code and I can't seem to find a way to do it.

I'm trying a lot of different code but it always ends up in some error because I'm using a forbidden class (the last error is about java.lang.System).

The most important requirement is to actually get a response for those requests, something like downloading a web page and parsing it with Jsoup.

Am I askingtoo much or is there a way to do that?

asked Jul 15, 2014 in App42 Cloud API-BaaS by StepTNT (10 points)

1 Answer

0 votes
For making HTTP request you can use HttpURLConnection class and it should work. Custom code does not allow System class to be used inside your code. Also, Jsoup jar is not supported as of now to be used inside custom code. You can use org.json library to parse JSON response incase if your web response is in JSON format.

let me know if it helps.

Thanks

Ajay
answered Jul 15, 2014 by ajay123 (899 points)
Thank you for the reply.

What I need to do is to download an HTML page and parse it with Jsoup because I'm not dealing with JSON data.

It's a shame that you don't support a lot of stuff in custom code because your service is really one of the easiest to work with!
CustomCode service is meant for aggregating App42 Services/Applying validation/doing some calculation on your app data etc. There are restrictions in using  few classes and third party libraries due to security reasons. If you want to have full control on your instance with liberty to use all third party jars, you can use App42PaaS  (http://app42paas.shephertz.com)  for the same.
Cool, I didn't knew about this service.

Can I use it to run a scheduled JAVA job?
Not directly but there is a trick. You can write you web-app which will do the background processing by calling http get/post method in App42PaaS. Now write a custom code to call this web url and schedule it. Let me know if it helps.
Download Widgets
Welcome to ShepHertz Product line forum, where you can ask questions and receive answers from the community. You can also reach out to us on support@shephertz.com
...