Anyone know if you can create a topic and its connection factory programmatically? Currently I use the glassfish admin utility to create my topic and its connection factory. If I can't create it in code does glassfish/openmq have a default topic and conn factory I can use?
If you only want to circumvent creating the resources manually in the admin you can simply deploy them with the file "glassfish-resources.xml" (GF 3.1, see http://docs.oracle.com/cd/E18930_01/html/821-2417/giyhh.html).
You need an admin-object-resource like this one (for a topic):
<admin-object-resource enabled="true" jndi-name="jms/myTopic"
object-type="user" res-adapter="jmsra" res-type="javax.jms.Topic">
<property name="Name" value="physicalTopic"/>
</admin-object-resource>
Be aware that you must use different "Name" values for the Topic (here: "physicalTopic") if you implement multiple Topics whose messages should not get mixed up.
Further you need a connector-resource referencing a connector-connection-pool of type javax.jms.TopicConnectionFactory.
If you don't aim for dynamically creating resources using the deployment descriptor glassfish-resources.xml seems to be the best way.
Please note that resources deployed that way are application-scoped: http://docs.oracle.com/cd/E18930_01/html/821-2417/giydj.html
"glassfish-resources.xml" is the file for GF 3.x, for GF 2.x it was "sun-resources.xml". The file is located in the "Server Resources" folder in your project view if you are using NetBeans. Attention: the glassfish-resources.xml in "Server Resources" is only used by NetBeans if you use NetBeans to deploy! NetBeans knows how to create theses resources and conducts this task. If you deploy an EAR directly to Glassfish without NetBeans -- which seems very likely for a production environment -- you have to provide glassfish-resources.xml in:
META-INF of your EJB module or WEB-INF of your WAR for module scoped resources
META-INF of your enterprise application for application wide resources
In NetBeans you accomplish this by placing the file into the "Configuration Files" folder of your project view (which is src/conf/ in the file system).
You can easily create this resource definition by using NetBeans' [New Message-Driven Bean] wizard (simply add an MBean by selecting [New ...]). In the wizard choose "Project Destinations" > [Add]. A complete 3.1 example looks like this:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE resources PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN" "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">
<resources>
<admin-object-resource enabled="true" jndi-name="jms/myDestination" res-type="javax.jms.Topic" res-adapter="jmsra">
<property name="Name" value="PhysicalTopic"/>
</admin-object-resource>
<connector-connection-pool name="jms/myDestinationFactoryPool" connection-definition-name="javax.jms.TopicConnectionFactory" resource-adapter-name="jmsra"/>
<connector-resource enabled="true" jndi-name="jms/myDestinationFactory" pool-name="jms/myDestinationFactoryPool" />
</resources>
This is the MBean annotation:
#MessageDriven(mappedName = "java:app/jms/myDestination", activationConfig =
{
#ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
#ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "Durable"),
#ActivationConfigProperty(propertyName = "clientId", propertyValue = "NewMessageBean"),
#ActivationConfigProperty(propertyName = "subscriptionName", propertyValue = "NewMessageBean")
})
public class NewMessageBean implements MessageListener
{
[...]
Caution: "java:app/" in mappedName is correct only if you use application scoped resources. You can spare "java:app/" in the definition in glassfish-resources.xml. The GF deployment guide says: "Application-scoped resource JNDI names begin with java:app or
java:module. If one of these prefixes is not specified in the JNDI name, it is added."
You can also introduce another level of indirection by using "name" instead of "mappedName". You then have to provide a file named "application-client.xml" where the (logical) name gets mapped to an JNDI "physical" location.
Related
What I am looking for is the exact activation configuration property name in order to configure a Message Driven Bean to accept messages from a JMS Topic in Shared subscription mode
#MessageDriven(activationConfig = {
#ActivationConfigProperty(propertyName = "destinationLookup",propertyValue = "java:app/jms/testT1"),
#ActivationConfigProperty(propertyName = "destinationType",propertyValue = "javax.jms.Topic"),
//the below property is not working in GlassFish (4.1) - just to convey the idea
#ActivationConfigProperty(propertyName = "sharedSubscription",propertyValue = "TRUE")
})
//edited
Please note: the intention is to be able to use MDBs (against a shared topic for load balancing purposes) in a JavaEE application which can be scaled out horizonatally. This question is not related to a clustered setup, hence use of useSharedSubscriptionInClusteredContainer (in Open MQ) is not applicable
If I understand you correctly, you don't need to do this. The point of having multiple consumers allowed on a single subscription was to work around a Java SE limitation, which is not an issue in Java EE:
http://www.oracle.com/technetwork/articles/java/jms2messaging-1954190.html
In Java EE, you just need to create your MDB to subscribe to a topic, then configure the bean pool to have multiple MDBs:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-ejb-jar PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 EJB 3.1//EN" "http://glassfish.org/dtds/glassfish-ejb-jar_3_1-1.dtd">
<glassfish-ejb-jar>
<enterprise-beans>
<ejb>
<ejb-name>MyPooledMDB</ejb-name>
<bean-pool>
<max-pool-size>5</max-pool-size>
<resize-quantity>1</resize-quantity>
<steady-pool-size>1</steady-pool-size>
</bean-pool>
</ejb>
</enterprise-beans>
</glassfish-ejb-jar>
For more information, see the Oracle GlassFish docs:
https://docs.oracle.com/cd/E18930_01/html/821-2418/beait.html
(note that steady-pool-size === "Initial and Minimum Pool Size")
we are using the Jboss fuse 6.2 along with technical stack blueprint,camel ,activeMQ and Mybatis.
We need to know about how to configure the property files in OSGI ,
as per my knowledge we could configure .cfg files, but is there any simplest way to use like spring configuring the configuring.
In Our code we are reading from property files . using namespace ext:proeprtyplaceHolder giving that bean id and values we are giving .
Help to provide is there any simplest way to read the property files
There is several ways to add configuration, because OSGi services can access configuration via ConfigurationAdmin service. The blueprint also can access property values over it.
JBoss fuse using karaf, so you can use the following methods.
(There is some quotes from http://www.liquid-reality.de/display/liquid/2011/09/23/Karaf+Tutorial+Part+2+-+Using+the+Configuration+Admin+Service)
Configuration with Blueprint
The integration with our bean class is mostly a simple bean definition where we define the title property and assign the placeholder which will be resolved using the config admin service. The only special thing is the init-method. This is used to give us the chance to react after all changes were made like in the pure OSGi example.
For blueprint we do not need any maven dependencies as our Java Code is a pure Java bean. The blueprint context is simply activated by putting it in the OSGI-INF/blueprint directory and by having the blueprint extender loaded. As blueprint is always loaded in Karaf we do not need anything else.
<cm:property-placeholder persistent-id="ConfigApp" update-strategy="reload" >
<cm:default-properties>
<cm:property name="title" value="Default Title"/>
</cm:default-properties>
</cm:property-placeholder>
<bean id="myApp" init-method="refresh">
<property name="title" value="${title}"></property>
</bean>
After you can put a cfg file (which is a standard java property file) to
karaf's etc or deploy directory with the name of of the given persistent-id which is MyApp in our example. (For example: /etc/ConfigApp.cfg)
title=Configured title
I made a small example using weblogic 10.3.6 and EJB 3.0. Define SimpleService class, define weblogic-ejb-jar.xml in order to map SimpleService class to JNDI name, pack it as EJB component in EAR file and deploy on server. Deployment is successful and I can see ejb bean with name SimpleServiceBean. After that using standalone application connect to webloigc server through InitialContext with all necessary environment attributes I try to lookup that bean. I assume that it will be available under name ejb/SimpleService but can't found it under that name and only after I was looking through a JNDI tree name I found out that it available under name SimpleService#ds/base/ejb/SimpleService. Help me to understand what is going on? How should I configure ejb bean in order that it will be available under ejb/SimpleService as it described in the official weblogic manual? Or maybe it's a correct JNDI name for the EJB bean?
My classes and configs are:
ds.base.ejb.SimpleServiceBean:
#Stateless(mappedName = "ServiceBean")
#TransactionAttribute(NEVER)
#ExcludeDefaultInterceptors
#Remote(SimpleService.class)
public class SimpleServiceBean implements SimpleService {
...
}
weblogic-ejb-jar.xml
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>ServiceBean</ejb-name>
<jndi-name>ejb/ServiceBean</jndi-name>
<enable-call-by-reference>True</enable-call-by-reference>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
application.xml:
<application>
<display-name>web-app-ear</display-name>
<module>
<ejb>app-ejb-1.0-SNAPSHOT.jar</ejb>
</module>
</application>
Then try to get it from standalone:
InitialContext context = new InitialContext(env);
SimpleService simpleService = (SimpleService)
context.lookup("SimpleService#ds/base/ejb/SimpleService");
assert simpleService != null
there is a good FaQ about the global portal JNDI names on glassfish.org http://glassfish.java.net/javaee5/ejb/EJB_FAQ.html#SessionBeanGlobalJNDINameAssignment
It is best practise NOT to assign a jndi name but rely on the ones defined since EE 5 (e.g. SimpleService#ds/base/ejb/SimpleService)
If you add the jndi-name configuration to your weblogic-ejb-jar.xml you could actually make it available as ejb/ServiceBean but you also have to define it "old school" style in ejb-jar.xml. More on the weblogic-ejb-jar.xml can be found http://docs.oracle.com/cd/E23943_01/web.1111/e13719/ejb_jar_ref.htm
There is also a good overview about the dd in the orcl docs.
http://docs.oracle.com/cd/E23943_01/web.1111/e13719/understanding.htm#EJBPG129
Assuming, that you are working with 10.3.x server version ...
Use this.
#Stateless(mappedName="UserFacade")
public class UserFacadeImpl {
//......
}
Properties p=new Properties();
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
p.put(Context.PROVIDER_URL,"t3://localhost:7001");
InitialContext ctx=new InitialContext(p);
userFacade=(UserFacade)ctx.lookup("UserFacade#com.webservices.facade.UserFacade");
hope it helps.
I'm trying to get integration testing working for a GlassFish 2.x project, using Maven2 and Cargo. I finally have Cargo attempting to deploy my EAR but it fails to start because the data source is not configured. The app also depends on a few JMS queues and a connection factory - how do I add these?
The Cargo Glassfish 2.x plugin says existing configurations are not supported, so I can't do that.
Using the maven-glassfish-plugin is an option, but we also run OC4J so a Cargo solution would be preferred.
edit: The resources are: 1 JDBC connection pool, 1 JDBC resource, 4 JMS queues, 2 JMS connection factories and a custom security realm (pear tree optional). The realm needs an entry in the login.conf like:
myRealm {
uk.co.mycom.MyGlassFishLoginModule required;
};
I'm not sure (I never used this) but IIRC, you should be able to put your datasource configuration in a sun-resources.xml file and package it under META-INF/sun-resources.xml in your EAR and GlassFish is supposed to create the resources at deploy time.
Here is an example sun-resources.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC "-//Sun Microsystems Inc.//DTD Application Server 9.0 Domain//EN" "sun-resources_1_3.dtd">
<resources>
<jdbc-connection-pool name="SPECjPool" steady-pool-size="100"
max-pool-size="150" max-wait-time-in-millis="60000"
pool-resize-quantity="2" idle-timeout-in-seconds="300"
is-isolation-level-guaranteed="true"
is-connection-validation-required="false"
connection-validation-method="auto-commit"
fail-all-connections="false"
datasource-classname="oracle.jdbc.pool.OracleDataSource">
<property name="URL"
value="jdbc:oracle:thin:#iasperfsol12:1521:specdb"/>
<property name="User" value="spec"/>
<property name="Password" value="spec"/>
<property name="MaxStatements" value="200"/>
<property name="ImplicitCachingEnabled" value="true"/>
</jdbc-connection-pool>
<jdbc-resource enabled="true" pool-name="SPECjPool"
jndi-name="jdbc/SPECjDB"/>
</resources>
Give it a try.
Resources
The sun-resources.xml File
Thanks, that worked. The datasource seems to have gone in okay and the app has deployed. However from the doc you linked, I can't see how to add the other things I need (edited more detail into my question about these). This solution also means that I will have to (use profiles to?) build my EAR differently for IT, which is imperfect.
I somehow missed that you wanted to create other resources than Datasources and I've seen several threads reporting that the suggested approach won't work with GlassFish v2 for any resources (like JMS resources). My bad.
So, given the current state, your options are (IMO):
contribute to Cargo to provide an "existing" configuration implementation for GlassFish v2
use the maven-glassfish-plugin as you suggested
I don't have any better suggestions.
I'm currently trying to 'port' my Java EE 5 Application from Jboss 6 M2 to Glassfish 3.0.1
Jboss used to create my JMS Destination Queues a deployment-time thanks to the -service.xml files. I really liked this feature and I would like to find a way to do the same thing on Glassfish. Is this even possible ?
I'm not sure of the exact status with GlassFish 3.0.1 but according to these threads:
http://markmail.org/thread/cqj56ehulg7qdenp
http://markmail.org/thread/zs4naxy534ijbpic
creating JMS destinations at deploy time was not supported. But these threads are pretty old and things might have changed (see below).
You can however declare them in a sun-resources.xml file and pass it to the asadmin add-resources command.
That being said, several documents (like this one or this one) mention the deployment of application-scoped-resources defined in a sun-resources.xml bundled in the application (that will become glassfish-resources.xml in GlassFish 3.1) as part of the deploy/undeploy of the app but:
I don't know if this is relevant for 3.0.1.
I don't know the exact status, especially for JMS resources.
This would require testing.
With glassfish v4x, Connection factory and destinations(ie queue and topics) can be configured in domain.xml file under glassfish/domains/your-domain-name
Eg :
<resources>
<connector-connection-pool resource-adapter-name="jmsra" max-pool-size="250" steady-pool-size="1" name="jms/DurableConnectionFactory-Connection-Pool" description="connection factory for durable subscriptions" connection-definition-name="javax.jms.ConnectionFactory">
<property name="ClientId" description="MyID" value="MyID"></property>
</connector-connection-pool>
<connector-resource pool-name="jms/DurableConnectionFactory-Connection-Pool" description="connection factory for durable subscriptions" jndi-name="jms/DurableConnectionFactory"></connector-resource>
<admin-object-resource res-adapter="jmsra" description="PhysicalQueue" res-type="javax.jms.Queue" jndi-name="jms/MyQueue">
<property name="Name" value="PhysicalQueue">
</property>
</admin-object-resource>
</resources>