on 02-27-2006 9:42 AM
Hi
We are porting A J2ee application from weblogic to SAP Web AS.
Primarily in weblogic we always get a Connection Factory Instance from
the Connection Factory and then typecast it to either
QueueConnectionFactory or TopicConnectionFactory.(Pl. see the code
below)
-
ConnectionFactory factory = null;
QueueConnectionFactory queueFactory = null;
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY,
this.initialContextFactory);
env.put(Context.PROVIDER_URL, this.providerUrl);
context = new InitialContext(env);
factory = (ConnectionFactory)context.lookup
(this.JNDINameConnectionFactory);
queueFactory = (QueueConnectionFactory)factory;
this.connection = queueFactory.createQueueConnection();
this.session = this.connection.createQueueSession
(false, Session.AUTO_ACKNOWLEDGE);
this.queue = (Queue)context.lookup(this.queueName);
}
-
But in SAP WEB As there is not such facility provided.Is it that always
we need to lookup to the jmsfactory/default/QueueConnectionFactory for
a Queue and jmsfactory/default/TopicConnectionFactory or
jmsfactory/default/QueueConnectionFactory for Topic . Is it poosibel to
get a Connection factory Instance from where on I Could further
Typecast it to TopicConnectionFactory or QueueConnectionFactory
Instance , because this the way we normally do in Weblogic or JMS.
Also this is how the java JMS API accepts . Could you please let me
know as to are there any more configuration to be Done apart from the
JMS provider and JMS Connector in the Visual Admin for Accessing the
Topmost ConnectionFactory JNDI Instance . If no ,are there any other
workarounds , as approach for changing the code for accessing the
individual Connection Factories JNDI is not feasible for us
regards
rajesh kr
Hi Rajesh,
The JMS specification does NOT imply that a ConnectionFactory can be typecast to both QueueConnectionFactory and TopicConnectionFactory. It seems that the application is relying on some weird non-standard feature provided by BEA.
Btw, if you could cast legally ConnectionFactory to both QueueConnectionFactroy and TopicConnectionFactory, then sun and the authors of the JMS spec will not specify two different interfaces that are DESCENDANTS of it, don't you think ?
I.e. in other words if you have
interface Animal;
interface Dog extends Animal;
interface Cat extends Animal;
Then I would not expect that the following code:
((Dog)myAnimal ).bark()
((Cat)myAnimal ).meow()
is working on all implementations of the interfaces. Which is something that you want to achieve.
So, since you don't want to change the code, here is what you can do : You can create your own factory based on the adapter design pattern that implements both the interfaces (QueueConnectionFactory) and (TopicConnectionFactory) and delegates the calls to a SAP Web AS ConnectionFactory. Then you bind your adapter in the naming and let your application do its work.
Hope That Helps
Peter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi peter,
Yes You are right , But i wam still not clear with respect to the solution you are telling . Do you have any code sample with respect to the solution ur telling because what i understood is ultimately if i do have to write a ConnectionFactory based on SAP WEb AS Factory implementation , i do need to implement the ConnectionFactory as well???
regards
rajesh kr
Hi Rajesh,
Here it is a code sample, that I was thinking about
RajeshConnectionFactory implements QueueConnectionFactory, TopicConnectionFactory, Serializable {
//SAP queue and topic factories that will be initialized during deserialization
private QueueConnectionFactory sapQueueFactory;
private TopicConnectiojnFactory sapTopicFactory;
// will be invoked after deserialization, when performing lookup of this object
private void readObject(ObjectInputStream stream) {
sapQueueFactory = performLookup(PATH_TO_SAP_QUEUE_FACTORY);
sapTopicFactory = performLookup(PATH_TO_SAP_TOPIC_FACTORY);
}
//from the TopicConnectionFactoriesInterface
TopicConnection createTopicConnection() {
return sapTopicFactory.createTopicConnection();
}
//from the TopicConnectionFactoriesInterface
TopicConnection createTopicConnection(String user, String password) {
return sapTopicFactory.createTopicConnection(user,password);
}
//from the QueueConnectionFactoriesInterface
QueueConnection createQueueConnectrion() {
return sapQueueFactory.createQueueConnection();
}
QueueConnection createQueueConnectrion(String user, String password) {
return sapQueueFactory.createQueueConnection(user, password);
}
}
Then you will bind your RajeshConnectionFactory in the naming on the place your application is looking up, and your application after performing lookup can safely typecast it to whatever you want.
I hope that will solve your problems. If it works, I will not charge you for the code copyright :).
However I think it will be better if you fix the application to make it trully J2EE compatible instead of such magics.
Best Regards
Peter
User | Count |
---|---|
78 | |
9 | |
9 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.