开发者

How do you tell the reference path when loading a class?

开发者 https://www.devze.com 2023-04-13 09:36 出处:网络
I\'m trying to use JavaLoader to load a java (HttpAsyncClient) class into ColdFusion. client = loader.create(\"org.apache.commons.HttpAsyncClient\")

I'm trying to use JavaLoader to load a java (HttpAsyncClient) class into ColdFusion.

client = loader.create("org.apache.commons.HttpAsyncClient")

How do we know the reference that is org.apache.commons.HttpAsyncClient? I thought if you open the jar file and follow the directory structure,开发者_C百科 it will give you the reference path. But I don't think this is true.

I'm trying to use the HttpAsyncClient but I'm unable to load it:

client = loader.create("org.apache.commons.HttpAsyncClient") returns a class not found error.

Loader is a reference to JavaLoader, which loads Java classes into your CF server.


Rather than reinvent the wheel, why not try an existing tool like Mark Mandel's AsyncHTTP library?

Update: From the comments, that tool is ACF only. So you might try using the concrete class DefaultHttpAsyncClient as shown in the Asynchronous HTTP Exchange example.


I don't know ColdFusion. You probably have to specify the full path to the class, not just the package containing the class.

According to an example I found the full package and class name is this: org.apache.http.nio.client.HttpAsyncClient

You can also use the javadoc to find out the package and class names: http://hc.apache.org/httpcomponents-client-ga/httpclient/apidocs/index.html

Getting something async going with an interface like this will probably be brutal. I would suggest trying the sync version first.

EDIT

I would try adapting this sync example to CF: http://hc.apache.org/httpcomponents-client-ga/httpclient/examples/org/apache/http/examples/client/ClientWithResponseHandler.java

When you instantiate HttpGet you have to pass extra parameters to init() as they do in this example: http://www.coldfusionjedi.com/index.cfm/2009/5/29/Generating-Speech-with-ColdFusion-and-Java

0

精彩评论

暂无评论...
验证码 换一张
取 消