Skip to main content

Can't create embeddable AppClientContainer (ACC ) ?

12 replies [Last post]
thim02
Offline
Joined: 2005-04-22
Points: 0

I can't build an embeddable AppClientContainer (ACC).

I followed the documentation:
Using Embeddable ACC:
http://docs.sun.com/app/docs/doc/820-7695/beakt?a=view

So I tried to use the embedded ACC:
public class JavaeeGreeter_EmbeddedAppClient {

public static void main(String[] args)
{
try
{
// one TargetServer for each ORB endpoint for bootstrapping
TargetServer[] servers = new TargetServer[]{new TargetServer()};

// Get a builder to set up the ACC
AppClientContainer.Builder builder = AppClientContainer.newBuilder(servers);

// Fine-tune the ACC's configuration. Note ability to "chain" invocations.
//builder.callbackHandler("com.acme.MyHandler").authRealm("myRealm"); // Modify config

Class mainClass = EmbeddedApp.class;
AppClientContainer acc = builder.newContainer(mainClass);

// In either case, start the client running.
String[] appArgs = new String[0];
acc.startClient(appArgs); // Start the client

//...

//acc.close(); // close the ACC(optional)
acc.stop();
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}

But From the
"AppClientContainer.Builder builder = AppClientContainer.newBuilder(servers);" row
I always get exception:

java.lang.ClassCastException: sun.misc.Launcher$AppClassLoader cannot be cast to org.glassfish.appclient.client.acc.ACCClassLoader
at org.glassfish.appclient.client.acc.AppClientContainerBuilder.(AppClientContainerBuilder.java:84)
at org.glassfish.appclient.client.acc.AppClientContainer.newBuilder(AppClientContainer.java:209)
at javaee5_greeter.Javaee5Greeter_EmbeddedAppClient.main(Javaee5Greeter_EmbeddedAppClient.java:20)

The gs-client.jar is on the classpath.

Please help me, what is the mistake ?
Thank you very much.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ajvok
Offline
Joined: 2010-02-26
Points: 0

> invocation. That should at least get you past this problem. Please let us know if that works.

Yes, that worked, thanks.

aszomor
Offline
Joined: 2009-08-06
Points: 0

Hi,

You can find an working example HelloApp.zip (829.1 K) in Article Posted: Mar 31, 2010 1:58 AM,
Embedded ACC and GFv3: http://forums.java.net/jive/thread.jspa?messageID=394448&#394448

Attila.

tjquinn
Offline
Joined: 2005-03-30
Points: 0

I think you have found a bug.

The AppClientContainerBuilder class is incorrectly trying to cast the current thread's context class loader to ACCClassLoader. For reasons related to the internal implementation of the ACC, the class loader needs to be a URLClassLoader (or an instance of a subclass of URLClassLoader) but the requirement for it to be an ACCClassLoader is too strict.

Until we fix this, one of these workarounds should work:

1. On your java command line specify -Djava.system.class.loader=org.glassfish.appclient.client.acc.ACCClassLoader. This should work if your application does not set the current thread's context class loader anywhere.

Or,

2. In your Java program instantiate an ACCClassLoader and set it to be the current thread's context class loader using Thread.currentThread().setContextClassLoader.

Sorry for this complication. Please let us know if one of these works for you.

- Tim

tjquinn
Offline
Joined: 2005-03-30
Points: 0

I have just checked in a change to resolve this.

The thread's context class loader must now be a URLClassLoader (which is the case for the default Java system class loader) instead of the more restrictive ACCClassLoader.

This fix should be in tonight's nightly build here:

http://download.java.net/glassfish/v3.1/nightly/

Note that this change is not in the recently released GlassFish v3.0.

June.Parks@Sun.COM

Hi Tim,

I'm assuming this fix will go into v3.1. Meanwhile, should we add an
explanation of the workaround to the Release Notes?

June

On 01/12/10 03:12 PM, glassfish@javadesktop.org wrote:
> I have just checked in a change to resolve this.
>
> The thread's context class loader must now be a URLClassLoader (which is the case for the default Java system class loader) instead of the more restrictive ACCClassLoader.
>
> This fix should be in tonight's nightly build here:
>
> http://download.java.net/glassfish/v3.1/nightly/
>
> Note that this change is not in the recently released GlassFish v3.0.
> [Message sent by forum member 'tjquinn' (timothy.quinn@sun.com)]
>
> http://forums.java.net/jive/thread.jspa?messageID=380478
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
> For additional commands, e-mail: users-help@glassfish.dev.java.net
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Tim Quinn

Hi, June.

The bug is present in 3.0 and the builds so far of 3.1. The fix should
be available starting with today's nightly build at the 3.1 link I
provided in the note.

An additional release note is a great idea. I've copied Gail on this
reply. Gail, I've described two possible workarounds in the issue:

https://glassfish.dev.java.net/issues/show_bug.cgi?id=11427

- Tim

June.Parks@Sun.COM wrote:
> Hi Tim,
>
> I'm assuming this fix will go into v3.1. Meanwhile, should we add an
> explanation of the workaround to the Release Notes?
>
> June
>
> On 01/12/10 03:12 PM, glassfish@javadesktop.org wrote:
>> I have just checked in a change to resolve this.
>> The thread's context class loader must now be a URLClassLoader (which
>> is the case for the default Java system class loader) instead of the
>> more restrictive ACCClassLoader.
>>
>> This fix should be in tonight's nightly build here:
>>
>> http://download.java.net/glassfish/v3.1/nightly/
>>
>> Note that this change is not in the recently released GlassFish v3.0.
>> [Message sent by forum member 'tjquinn' (timothy.quinn@sun.com)]
>>
>> http://forums.java.net/jive/thread.jspa?messageID=380478
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

Gail Risdal

Thanks, Tim. I'll add this to the v3 Release Notes.

Gail

Tim Quinn wrote:
> Hi, June.
>
> The bug is present in 3.0 and the builds so far of 3.1. The fix
> should be available starting with today's nightly build at the 3.1
> link I provided in the note.
>
> An additional release note is a great idea. I've copied Gail on this
> reply. Gail, I've described two possible workarounds in the issue:
>
>
> https://glassfish.dev.java.net/issues/show_bug.cgi?id=11427
>
>
>
> - Tim
>
> June.Parks@Sun.COM wrote:
>> Hi Tim,
>>
>> I'm assuming this fix will go into v3.1. Meanwhile, should we add an
>> explanation of the workaround to the Release Notes?
>>
>> June
>>
>> On 01/12/10 03:12 PM, glassfish@javadesktop.org wrote:
>>> I have just checked in a change to resolve this. The thread's
>>> context class loader must now be a URLClassLoader (which is the case
>>> for the default Java system class loader) instead of the more
>>> restrictive ACCClassLoader.
>>>
>>> This fix should be in tonight's nightly build here:
>>>
>>> http://download.java.net/glassfish/v3.1/nightly/
>>>
>>> Note that this change is not in the recently released GlassFish v3.0.
>>> [Message sent by forum member 'tjquinn' (timothy.quinn@sun.com)]
>>>
>>> http://forums.java.net/jive/thread.jspa?messageID=380478
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
>>> For additional commands, e-mail: users-help@glassfish.dev.java.net
>>>
>>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@glassfish.dev.java.net
For additional commands, e-mail: users-help@glassfish.dev.java.net

tjquinn
Offline
Joined: 2005-03-30
Points: 0

This change has been approved for the planned upcoming update release for GlassFish v3, and I have checked in the change to that code base.

ajvok
Offline
Joined: 2010-02-26
Points: 0

I just downloaded the latest-glassfish.zip (v3.1/nightly/), unzipped it and used modules/acc-config.jar, gf-client-module.jar, gf-client.jar along with the program below.

I nolonger get the problem as reported in this thread with v3, but instead "acc.startClient(appArgs)" results in an IllegalStateException.
Alt.main() is not called.

What am I doing wrong?

Thanks for your help.

===============================================
package javaapplication6;

import org.glassfish.appclient.client.acc.AppClientContainer;
import org.glassfish.appclient.client.acc.config.TargetServer;

public class Main {

public static void main(String[] args) {
try {
TargetServer[] ts = {new TargetServer("localhost", 3700)} ;
AppClientContainer.Builder accBuilder = AppClientContainer.newBuilder(ts) ;

Class mainClass = Alt.class;
AppClientContainer acc = accBuilder.newContainer(mainClass);

String[] appArgs = {"123"};
acc.startClient(appArgs); // Start the client
} catch (org.glassfish.appclient.client.acc.UserError e) {
System.out.println(e.getMessage()) ;
} catch (Exception e) {
System.out.println(e.getMessage()) ;
System.out.println(e.getCause()) ;
}
}
}
===============================================
package javaapplication6;

public class Alt {
public static void main(String[] args) {
System.out.println("In ALT" + args[0]) ;
}
}
===============================================

tjquinn
Offline
Joined: 2005-03-30
Points: 0

Hi.

This looks like either a documentation error or a bug in the code. Your example should work.

As an interim workaround, please try invoking

acc.prepare(null);

just before the

acc.startClient(appArgs)

invocation. That should at least get you past this problem. Please let us know if that works.

- Tim

tjquinn
Offline
Joined: 2005-03-30
Points: 0

I have opened GlassFish issue 11644 to track this.

tjquinn
Offline
Joined: 2005-03-30
Points: 0

I have checked in a change which should appear in the next nightly (and promoted) builds.

If you have used the workaround of explicitly invoking prepare from your program you should remove that once you start using the updated GlassFish build.

Sorry for the inconvenience, and thanks for bringing this to our attention!

-Tim