Skip to main content

Resource Adapter can not be injected via anotation must be set via xml in ejb-jar.xml

5 replies [Last post]
baze985
Offline
Joined: 2009-05-07
Points: 0

Hi all,

I have developed a resource adapter that opens a socket and then calls the registered MDB beans for a handshake...

This all works but if I try to use @MessageDriven annotation for the bean I get a class cast exception..

here is the code for the mdb bean if added in ejb-jar.xml

	  <!-- a message driven descriptor -->
     <message-driven>
      <display-name>SOCKET_MDB</display-name>
      <ejb-name>SOCKET_MDB</ejb-name>
      <ejb-class>mk.icelabs.vtcore.util.socket.ServerSocketMDB</ejb-class>

      <!-- The message listener interface -->
      <messaging-type>mk.icelabs.socketj2ee.advertisment.SocketMessageEndpoint</messaging-type>

      <transaction-type>Container</transaction-type>

      <!-- the values for the Activation Spec JavaBean -->
      <activation-config>
        <activation-config-property>
          <activation-config-property-name>port</activation-config-property-name>
          <activation-config-property-value>12050</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>encoding</activation-config-property-name>
          <activation-config-property-value>UTF-8</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>maximumConnections</activation-config-property-name>
          <activation-config-property-value>100</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>connectionTimeoutMilliseconds</activation-config-property-name>
          <activation-config-property-value>9999</activation-config-property-value>
        </activation-config-property>
        <activation-config-property>
          <activation-config-property-name>ipAddress</activation-config-property-name>
          <activation-config-property-value>0.0.0.0</activation-config-property-value>
        </activation-config-property>
       </activation-config>
    </message-driven>


  <assembly-descriptor>
    <container-transaction>
      <method>
        <ejb-name>SOCKET_MDB</ejb-name>
        <method-name>*</method-name>
      </method>
      <trans-attribute>NotSupported</trans-attribute>
    </container-transaction>
  </assembly-descriptor>
 

so used like this all works fine.

But if I use annotation instead of xml....

@MessageDriven(
messageListenerInterface=SocketMessageEndpoint.class,
activationConfig = {
@ActivationConfigProperty(propertyName = "ipAddress", propertyValue = "0.0.0.0"),
@ActivationConfigProperty(propertyName = "port", propertyValue = "12050")
}
)

public class ServerSocketMDB implements SocketMessageEndpoint {
// implement here
}

then again all looks ok on deploy etc...
but when the resource adapter tries to call the MDB by creating a endpoint in the adapter and
casting this to my interface I get this exception:

java.lang.ClassCastException: $ProxyXYZ cannot be cast to mk.icelabs.socketj2ee.advertisement.SocketMessageEndpoint

the code looks like this

SocketMessageEndpoint listener = (SocketMessageEndpoint) MessageEndpointFactory.createEndpoint(null);

When I use the ejb-jar.xml setup I also see(by debug) that the class is $ProxyXYZ but then its castable to SocketMessageEndpoint

I probably have something not configured while I use the annotation...but what?!
Any idea somebody?

Blaze

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
mvatkina
Offline
Joined: 2005-04-04
Points: 0

Can it be that there is more than one SocketMessageEndpoint interface and with annotations the wrong one is picked up?

-marina

baze985
Offline
Joined: 2009-05-07
Points: 0

Hi marina,

thx for your replay. No the interface is just one
in the class the imports are not shown...but its the same
mk.icelabs.socketj2ee.advertisment.SocketMessageEndpoint

its intersting if I dont define the Listener class

@MessageDriven(
activationConfig = {
@ActivationConfigProperty(propertyName = "ipAddress", propertyValue = "0.0.0.0"),
@ActivationConfigProperty(propertyName = "port", propertyValue = "12050")
}
)

public class ServerSocketMDB implements SocketMessageEndpoint {
// implement here
}

the deployy, endpoint creation...all works fine but again on the same cast the exception is there, it seems to me the annotation for the Listener is not working at all...

Blaze

mgainty
Offline
Joined: 2004-05-21
Points: 0

Blaze

assign a name to MessageDrivenBean
implement a Listener
provide a No-arg constructor to the implementing class

http://www.datadisk.co.uk/html_docs/ejb/ejb3_mdb.htm

Martin
______________________________________________
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.

> To: users@glassfish.java.net
> Subject: Re: Resource Adapter can not be injected via anotation must ...
> From: forums@java.net
> Date: Fri, 12 Oct 2012 16:55:26 -0500
>
> Hi marina, thx for your replay. No the interface is just one in the class the
> imports are not shown...but its the same
> mk.icelabs.socketj2ee.advertisment.SocketMessageEndpoint its intersting if I
> dont define the Listener class @MessageDriven( activationConfig = {
> @ActivationConfigProperty(propertyName = "ipAddress", propertyValue =
> "0.0.0.0"), @ActivationConfigProperty(propertyName = "port", propertyValue =
> "12050") } ) public class ServerSocketMDB implements SocketMessageEndpoint {
> // implement here } the deploy endpoint creation all works fine but again on
> the same cast the exception is there so it seems to me the annotation for the
> Listener is not working at all... Blaze
>
> --
>
> [Message sent by forum member 'baze985']
>
> View Post: http://forums.java.net/node/891408
>
>

mvatkina
Offline
Joined: 2005-04-04
Points: 0

Can it be a clasloader issue? Can you check the classloaders on the proxy (it's always a proxy) and that of the interface?

baze985
Offline
Joined: 2009-05-07
Points: 0

I dont get what you mean by the last:)
Do I have to debug the proxy.getClass.getClassLoader and the same for the interface..?!

To give a more details on the project...
My resource socket adapter is packaged as a separate rar file and deployed on the server.
Then from a client(for this adapter) a normal ejb.jar which is implementing the MDB bean I use the adapter..and like said before with no change to the rar adapter(no redeploy no reload) but just change in the client ejb.jar where first I use xml for the creation of the MDB and all works finea, and then by using annotation for the MDB I get this class cast exception but in the adapter rar while trying to cast the endpoint to the interface...

mvatkina
Offline
Joined: 2005-04-04
Points: 0

That's my guess that classloaders are not correct and that's why cast doesn't work. Can you try restarting GF after undeploying MDB with ejb-jar.xml? I would imagine that there are plenty of tests that verify that your scenario works when you just do it one way or the other, but may be not changing the setup...

-marina