You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@qpid.apache.org by Emmanuel Bourg <eb...@apache.org> on 2012/04/19 11:11:01 UTC

Understanding org.apache.qpid.transport.Connection

Hi all,

I'm trying to update my Hessian over AMQP RPC client [1] to the latest 
version of Qpid but I have some difficulties with the Connection class 
in the org.apache.qpid.transport. I know this class is not intended for 
public use and as such is not supported, but I would be very grateful if 
someone could give me some insights.

In the previous version of Qpid (up to 0.12) I was able to open a 
connection simply with this:

     Connection conn = new Connection();
     conn.connect(hostname, port, virtualhost, user, password);

However now with Qpid 0.14 this results in a NullPointerException:

Caused by: java.lang.NullPointerException
	at 
org.apache.qpid.transport.ProtocolHeader.delegate(ProtocolHeader.java:110)
	at org.apache.qpid.transport.Connection.received(Connection.java:387)
	at org.apache.qpid.transport.Connection.received(Connection.java:66)
	at org.apache.qpid.transport.network.Assembler.emit(Assembler.java:95)
	at org.apache.qpid.transport.network.Assembler.init(Assembler.java:115)
	at 
org.apache.qpid.transport.ProtocolHeader.delegate(ProtocolHeader.java:115)
	at org.apache.qpid.transport.network.Assembler.received(Assembler.java:100)
	at org.apache.qpid.transport.network.Assembler.received(Assembler.java:42)
	at 
org.apache.qpid.transport.network.InputHandler.next(InputHandler.java:151)
	at 
org.apache.qpid.transport.network.InputHandler.received(InputHandler.java:103)
	at 
org.apache.qpid.transport.network.InputHandler.received(InputHandler.java:42)
	at org.apache.qpid.transport.network.io.IoReceiver.run(IoReceiver.java:153)


As I understand this is caused by the ConnectionDelegate in Connection 
that is not initialized. This delegate already existed in Qpid 0.10-0.12 
but didn't cause this problem before.

I tried initializing the delegate manually but it seems a bit 
complicated. Since I only depend on the Qpid Common jar I can only use 
the ClientDelegate, but it is incomplete, it breaks when the SASL client 
is created with an UnsupportedOperationException(even if I don't use SASL).

At this point I'm a bit lost. Couldn't the delegate be initialized 
automatically with a basic implementation and SASL not checked if it's 
not used? Is the delegate essential for establishing the connection?


Emmanuel Bourg

[1] http://ebourg.github.com/qpid-hessian


Re: Understanding org.apache.qpid.transport.Connection

Posted by Keith W <ke...@gmail.com>.
On 20 April 2012 11:55, Emmanuel Bourg <eb...@apache.org> wrote:

> Thank you very much for the information Keith. Do you think I can provide
> a patch to restore the ability to open a connection without specifying
> explicitely the delegate? Is there a chance that it will be accepted?
>
>
Yes, we'd certainly consider it for 0.18 but I am keen that we avoid
reintroducing duplication that was removed by QPID-3415.

Kind regards, Keith.

Re: Understanding org.apache.qpid.transport.Connection

Posted by Emmanuel Bourg <eb...@apache.org>.
Thank you very much for the information Keith. Do you think I can 
provide a patch to restore the ability to open a connection without 
specifying explicitely the delegate? Is there a chance that it will be 
accepted?

Emmanuel Bourg


Le 20/04/2012 10:39, Keith W a écrit :
> Hi Emmanuel
>
> You are correct, this was changed by QPID-3415.  This change was made
> to allow the 0-10 code path (when utilised by the Qpid client) to load
> SASL callback handers using the same mechanism as 0-8..0-9-1.   You
> are also correct, yours was not an anticipated/tested use-case.
>
> If you don't want to use the Qpid client JAR, you'll need to implement
> your own ClientDelegate, overridding only the createSaslClient()
> method to create a SaslClient and set up the callback handlers.
>
>   The following works for me (tested against the Java Broker).
>
> Hope this helps
>
> Keith,


Re: Understanding org.apache.qpid.transport.Connection

Posted by Keith W <ke...@gmail.com>.
Hi Emmanuel

You are correct, this was changed by QPID-3415.  This change was made
to allow the 0-10 code path (when utilised by the Qpid client) to load
SASL callback handers using the same mechanism as 0-8..0-9-1.   You
are also correct, yours was not an anticipated/tested use-case.

If you don't want to use the Qpid client JAR, you'll need to implement
your own ClientDelegate, overridding only the createSaslClient()
method to create a SaslClient and set up the callback handlers.

 The following works for me (tested against the Java Broker).

Hope this helps

Keith,


        Connection conn = new Connection();

        ConnectionSettings connSettings = new ConnectionSettings();

        connSettings.setUsername("guest");

        connSettings.setPassword("guest");

        connSettings.setVhost("test");

        connSettings.setUseSSL(false);

        connSettings.setSaslMechs("PLAIN");



        conn.setConnectionDelegate(new ClientDelegate(connSettings)

        {

            protected javax.security.sasl.SaslClient
createSaslClient(List<Object> brokerMechs) throws ConnectionException,

            javax.security.sasl.SaslException

            {
                Map<String,Object> saslProps = new HashMap<String,Object>();


                javax.security.auth.callback.CallbackHandler cbh = new
javax.security.auth.callback.CallbackHandler()

                {

                    public void handle(final
javax.security.auth.callback.Callback[] callbacks)

                            throws IOException,
javax.security.auth.callback.UnsupportedCallbackException

                    {

                        for (int i = 0; i < callbacks.length; i++)

                        {

                            javax.security.auth.callback.Callback cb =
callbacks[i];

                            if (cb instanceof
javax.security.auth.callback.NameCallback)

                            {


((javax.security.auth.callback.NameCallback)cb).setName(getConnectionSettings().getUsername());

                            }

                            else if (cb instanceof
javax.security.auth.callback.PasswordCallback)

                            {


((javax.security.auth.callback.PasswordCallback)cb).setPassword(getConnectionSettings().getPassword().toCharArray());

                            }

                            else

                            {

                                throw new
javax.security.auth.callback.UnsupportedCallbackException(cb);

                            }

                    }



                    }

                };

                final javax.security.sasl.SaslClient sc =
javax.security.sasl.Sasl.createSaslClient(new String[] {"PLAIN"},
null,


getConnectionSettings().getSaslProtocol(),


getConnectionSettings().getSaslServerName(),

                                                            saslProps, cbh);

                return sc;

            }



        });

        conn.connect(connSettings);

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@qpid.apache.org
For additional commands, e-mail: dev-help@qpid.apache.org