Skip to main content

@Webservice and JMS @Resource

9 replies [Last post]
markshure
Offline
Joined: 2007-09-25

Hey all, I'm trying to create a webservice that uses the in-built embedded message queue. Everything works except when using the @Resource annotation with a JNDI reference to the queue and connection factory, both of them are null. Can this kind of resource injection be used within a web service or do I need to use a service locator? Note that when I use the @Resource with a test client application (appclient -client) it works fine. I'm using Sun App. Server 9.0 Update 1.

Thanks,
Mark

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
dokujaryu
Offline
Joined: 2007-10-03

I'm having the same issue using Sun Java System Application Server 9.1 (build b58g-fcs).

@Stateless()
@WebService()
public class OutboundService {

@Resource(mappedName = "jms/ConnectionFactory")
private static ConnectionFactory lsrConFactory;

@Resource(mappedName = "jms/Topic")
private static Topic topic;
}

--> From admin page

JNDI Name Enabled Description
jms/ConnectionFactory true Generic Connection Factory

jms/Topic true javax.jms.Topic Outbound Topic

Ramesh

Hi,
Please see https://glassfish.dev.java.net/issues/show_bug.cgi?id=2105
This has been fixed in glassfish V2 (9.1) b50

Thanks
-Ramesh

glassfish@javadesktop.org wrote:
> Hey all, I'm trying to create a webservice that uses the in-built embedded message queue. Everything works except when using the @Resource annotation with a JNDI reference to the queue and connection factory, both of them are null. Can this kind of resource injection be used within a web service or do I need to use a service locator? Note that when I use the @Resource with a test client application (appclient -client) it works fine. I'm using Sun App. Server 9.0 Update 1.
>
> Thanks,
> Mark
> [Message sent by forum member 'markshure' (markshure)]
>
> http://forums.java.net/jive/thread.jspa?messageID=237066
>
> ---------------------------------------------------------------------
> 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

markshure
Offline
Joined: 2007-09-25

Hey, thanks for the reply, I've just downloaded Sun App. Server 9.1 and I'm still getting the same problem. Here's my webservice class:

package com.example.proxy;

import java.math.*;
import java.util.*;

import javax.annotation.*;
import javax.ejb.*;
import javax.jms.*;
import javax.jms.Queue;
import javax.jws.*;

@Stateless
@WebService(endpointInterface="com.example.proxy")
public class DispatchServiceImpl implements MessageDispatcher {

@Resource(mappedName = "jms/ConnectionFactory")
private ConnectionFactory connectionFactory;

@Resource(mappedName = "jms/Queue")
private Queue queue;

@WebMethod
public List startDispatch(String receiverId,
if (queue == null && connectionFactory == null) {
System.out.println("queue and connectionFactory are null");
}

return null;
}
}

Thanks,
Mark

rampsarathy
Offline
Joined: 2005-11-23

Have you created the resources "jms/ConnectionFactory" (connection factory) and "jms/Queue" (admin object)
Are you using DAS (domain admin server) or an instance.

markshure
Offline
Joined: 2007-09-25

Yes I have, I just switched the code over to using JNDI and it works fine.

InitialContext initContext = new InitialContext();
ConnectionFactory connFactory =
(ConnectionFactory) initContext.lookup("jms/ConnectionFactory");

if (connFactory == null) {
System.out.println("ConnectionFactory is null");
}

Queue queue = (Queue) initContext.lookup("jms/Queue");
if (queue == null) {
System.out.println("Queue is null");
}

These are both fine and work as expected.

Thanks,
Mark

markshure
Offline
Joined: 2007-09-25

> Are you using DAS (domain admin server) or an instance.

I'm just using the 'domain1' straight from a clean install.

rampsarathy
Offline
Joined: 2005-11-23

Could you change the jms-service type from EMBEDDED to LOCAL in the domain.xml (under server-config) , restart the server and check if it works.

Are there any exceptions in the server.log file ?

markshure
Offline
Joined: 2007-09-25

No luck unfortunately setting it to local.

This is in the server log on start-up:

[#|2007-09-27T10:28:58.234+1000|INFO|sun-appserver9.1|javax.enterprise.resource.resourceadapter|_ThreadID=10;_ThreadName=main;|JMS Service Connection URL is :mq://javadev:7676/|#]

[#|2007-09-27T10:28:58.312+1000|INFO|sun-appserver9.1|javax.resourceadapter.mqjmsra.lifecycle|_ThreadID=10;_ThreadName=main;|MQJMSRA_RA1101: SJSMQ JMS Resource Adapter starting...|#]
[#|2007-09-27T10:28:58.359+1000|INFO|sun-appserver9.1|javax.resourceadapter.mqjmsra.lifecycle|_ThreadID=10;_ThreadName=main;|MQJMSRA_LB1101: Looking for Broker Running at:localhost:7676|#]

[#|2007-09-27T10:28:59.359+1000|WARNING|sun-appserver9.1|javax.jms|_ThreadID=10;_ThreadName=main;_RequestID=825dc612-595d-4203-95d1-99ef8974047c;|[C4003]: Error occurred on connection creation [localhost:7676]. - cause: java.net.ConnectException: Connection refused: connect|#]

[#|2007-09-27T10:29:02.500+1000|INFO|sun-appserver9.1|javax.resourceadapter.mqjmsra.lifecycle|_ThreadID=10;_ThreadName=main;|MQJMSRA_RA1101: SJSMQ JMSRA Started:LOCAL|#]

Although everything works fine when using JNDI (can connect, send message, and the MDB receives it).

Thanks,
Mark

rampsarathy
Offline
Joined: 2005-11-23

could you please create an issue for this in issue tracker, also mention the steps required to reproduce this.