[coldbox 3.5.2] Plugin of Mark Mandel's asyncHTTP

Hey Coldboxers,

I have a very puzzling problem with a plugin I am writing…

Firstly the plugin is based on Mark Mandel’s asyncHTTP project that you can download here:
http://www.compoundtheory.com/?action=asynchttp.index

Here is my directory structure for the plugin:

–plugins
– -- AsyncHTTP-lib
– -- – asyncHTTP.jar
– -- AsyncHTTP.cfc

– -- ExternalJavaLoader (FIX)

Here is a working version of the plugin:

/**

  • Provides an Asynchronous HTTP service
    */
    component extends=“coldbox.system.Plugin” singleton=“true”{

/* original */ //property name=“jl” inject=“coldbox:plugin:JavaLoader”;
property name=“asyncHTTP”;

AsyncHTTP function init(required any controller){
super.init(arguments.controller);

// Plugin Properties
setPluginName(“AsyncHTTP”);
setPluginVersion(“1.0”);
setPluginDescription(“Provides an Asynchronous HTTP service”);
setPluginAuthor(“Mark Mandel - Tom Van Schoor”);
setPluginAuthorURL(“http://www.compoundtheory.com/?action=asynchttp.index”);

return this;
}

function onDIComplete(){
var path = getDirectoryFromPath(getMetaData(this).path);
/* fix / var jl = createObject(“component”, “ExternalJavaLoader”).init([path & “AsyncHTTP-lib\asyncHTTP.jar”]);
/
original */ //jl.appendPaths(path & “\AsyncHTTP-lib”);
asyncHTTP = jl.create(“com.compoundtheory.asyncHTTP.AsyncHTTP”).init();
}

public void function get(required String url){
var URLObject = createObject(“java”, “java.net.URL”).init(arguments.url);
asyncHTTP.get(URLObject);
}

public void function post(required String url, Struct formData = {}){
var URLObject = createObject(“java”, “java.net.URL”).init(arguments.url);
cleanFormData(arguments.formData);
asyncHTTP.post(URLObject, formData);
}

private void function cleanFormData(required Struct formData){
for(var key in arguments.formData){
arguments.formData[key] = JavaCast(“string”, arguments.formData[key]);
}
}
}

As you can see on the line where it says /* fix */ I am using createObject to initialize an ExternalJavaLoader. It is actually the JavaLoader that comes with the original asyncHTTP project that I renamed so it doesn’t clash with the coldbox plugin.

This plugin works, so hooray! But I would like to use the built in JavaLoader that comes with coldbox…

To change the code to use the built in JavaLoader just comment out the /* fix / and un-comment the / original */ code…

It will now throw the error:

Application Execution ExceptionError Type: Object : [N/A]

Error Messages: Object instantiation exception.
An exception occurred while instantiating a Java object. The class must not be an interface or an abstract class. Error: ‘’.

Yet if you look at the source code that comes with the original project; the com.compoundtheory.asyncHTTP.AsyncHTTP is a normal class; not an interface nor abstract…
I find that very strange…

Ideas are more then welcome?

Tom, any reason why not use cfthread for this

signature0.jpg

Luis F. Majano
CEO
Ortus Solutions, Corp
www.ortussolutions.com

ColdBox Platform: http://www.coldbox.org
Linked In: http://www.linkedin.com/pub/3/731/483
Blog: http://www.luismajano.com
IECFUG Manager: http://www.iecfug.com

Social: twitter.com/lmajano facebook.com/lmajano

Yeah, I think asyncHTTP was originally written for CF7… I’ve no idea if it works with later versions.

Mark

signature0.jpg

Hi Luis and Mark,

Thanks for the reply.
Mark, your asyncHTTP still works on CF10 :slight_smile:

Ok, it took me a while, but I decided Brad and Luis are right… For the first tier of my problem I should be using cfthread.

Box1 is the REST API and will expect 3000+ requests per minute.
Processing the requests has priority over logging the request so I want to hand off the logging to a different machine (box2) that can crash for all I care; as long as Box1 keeps processing.

Tier 1: asyncHTTP would fire and forget the log-request from Box1 to Box2.
Tier 2: Box2 will put the log-request in a queue using Marc Esher’s cfconcurrent (which is awesome) and process the log-tasks at its own pace.

So yes; the HTTP fire and forget could be using cfthread rather then asyncHTTP for tier 1.
For tier 2 though, I will stick to cfconcurrent as it gives me a superb control over queuing and concurrency.

I will create an AsyncHTTPAppender for LogBox using cfthread and share it with the community.

Thanks for all the help and tips.

Cheers,
Tom

signature0.jpg

Hey Tom, I have a question and it is more out of curiosity. With that many requests for the server, I am going to make the assumption that this is also running on ColdFusion Enterprise. So if that is the case, any reason why you didn’t go with the event gateway option to do the logging? Or does that option require the event gateway to be on the same server?

Hi Andrew,

Event gateways are indeed a very viable option that we are busy researching. I could be wrong, but in CF9 that option does require the event gateway to be on the same server.
We have however moved up to CF10 recently and now we can use gateways over sockets, IP addresses etc…

So yeah in the near future we will surely leverage that power.

Cheers,
Tom

Thanks Tom, I thought that the event gateway had to be, but wasn’t sure.

I thought sockets was in event gateways since CF 8, gateway to gateway?

Anyway was just curious.