How to deifine a JNDI resource - jboss

how to define a JNDI resource on jboss 5?
My web application require a String value retrieved from the application server, on Tomcat I simply define my resource as string with value "mystring" but how can i do the same on jboss in which file?

By calling a command in the application server; for example in Glassfish you can do it by calling create-custom-resource: http://docs.oracle.com/cd/E26576_01/doc.312/e24928/jndi.htm#giowe .

Related

How can I set distinct-name on Wildfly?

I try EJB invocations from a client to a server, they are actually same copied ear files each other and on same machine.
I think that I must set "distinct-name" in somewhere, but I can not find it.
WildFly Developer Guide - EJB invocations from a remote client using JNDI:
distinct-name : This is a WildFly-specific name which can be optionally assigned to the deployments that are deployed on the server. More about the purpose and usage of this will be explained in a separate chapter. If a deployment doesn't use distinct-name then, use an empty string in the JNDI name, for distinct-name
Where is "a separate chapter"?
Set <distinct-name> attribute in jboss-app.xml(EAR) or jboss-ejb3.xml(WAR/EJB jar).

Jboss EJB and Shiro

I have a CDI -> EJB App.
I do the security in the past with JBoss j_security.
My security with Shiro works.
But my only problem is how can I get SessionContext in my EJB?
With Jboss Security I got the username, who login in the location with:
SessionContext sessionContext;
String email = sessionContext.getCallerPrincipal().getName();
Now I want to get the the username in my EJB.
How ca I set the username with SessionContext?
Thank you for help
This is a bit tricky, and it also depends on the version of JBoss that you are using. In the AS 7.x and EAP 6.x range this can't really be done by using public APIs because of several bugs.
In order to make the sessionContext aware of the user name and roles you can use JBoss specific code like I used here: https://github.com/javaeekickoff/jboss-as-jaspic-patch/commit/d691fd4532d9aeae6136e3adc2537ff81c525673
It should be something like;
SecurityContext context = SecurityActions.getSecurityContext();
context.getUtil().createSubjectInfo(new SimplePrincipal(userName),
null,
someSubject
);
Take a look at the rest of the file to see how someSubject should be created and populated.
Unfortunately for the mentioned JBoss versions #RolesAllowed will never work, since JBoss doesn't take over the already authenticated identity from the local caller, but will always consult a JBoss specific "security domain" just prior to calling the actual bean. Of course it known nothing about Shiro.

JBoss JMX twiddle Runtime not registered

I have a problem with the twiddle script on a Solaris 10 server.
I have to read some properties e.g jboss.system and others.
All properties depending on the jboss server are fine, but when I try
to read properties from java.lang, the following error occurs:
javax.management.InstanceNotFoundException: java.lang:type=Runtime is not registered.
The problem is that java.lang:type=Runtime is a Platform MBeanServer registered MBean and by default, twiddle connects you to the JBoss MBeanServer which by default, will not have the RuntimeMXBean server registered.
The easiest way to resolve this, assuming you only want to access system properties, is to point twiddle at the JBoss MBean jboss:name=SystemProperties,type=Service. The MBean exposes:
String get(String key)
String get(String key, String default)
or to retrieve all values,
Map shopwAll()
Other more laborious solutions would inlcude:
Register the Platform MBeanServer MXBeans in the JBoss MBeanServer. See this Question.
Enable the management agent in the JVM and use a JMX Connector to connect to the Platform MBeanServer. See this Question.
Use the Attach API to connect to the Platform MBeanServer of your JBoss Server by process ID. You can then reference the MXRuntime MBean.

Implementing CORBA interface in JBoss

I'm looking for a tutorial or any additional information on how to make an EJB (or underlying MBean) accessible via CORBA.
This is all I've found: http://www.jboss.org/jbossiiop
I have an existing CORBA server (java-based, but non-standard) and I want to allow it to call into my JBoss MBean. This MBean is already exposed via RMI using an EJB (v2.1).
The current AppServer target version is jboss-eap-4.3.
Edit: I'm hoping my question is just too vague to get answered so here's an update:
I want my EJB running in JBoss to register with the Corba ORB running on a remote separate server. At least I think I do. The existing CORBA client connects to services via a defined IDL/interface that I'm trying to implement via a JBoss EJB. At this point, said client connects to several instances of the same interface to pull information and manage local (same process) services via this interface. I want the JBoss EJB to be dropped in as just another implementation of this CORBA IDL.
My understanding of CORBA is rusty and weak to begin with so I'm not getting very far. I can run an ORB in JBoss easily enough, but it's not clear to me how to set up the binding so the "legacy" CORBA ORB can find it. I can change any part of the JBoss implementation to make this work, but changing the other server is difficult.
Is there a way for the EJB to register itself with a remote server (ala jndi)?
Will the existing client be able to connect to Jacorb without adding jboss specific classes?
In short you have to implement an adapter, deploy it in Jboss, register it with the remote NamingService. In your adapter implementation you call your MBeans.
Now more in details
You have a CORBA idl, you generate stubs and skeletons.
interface Stock {
int getQuote( in string company);
};
You provide necessary implementation
public class StockImpl extends StockPOA {
public int getQuote(String company) {
//forward a call to MBean here
}
}
You do the usual CORBA registration stuff. something like:
org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(...);
org.omg.PortableServer.POA poa = org.omg.PortableServer.POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
poa.the_POAManager().activate();
NamingContextExt nc = NamingContextExtHelper.narrow(orb.resolve_initial_references("NameService"));
NameComponent [] name = new NameComponent[1];
org.omg.CORBA.Object o = poa.servant_to_reference( new StockImpl(orb,poa));
name[0] = new NameComponent( "Stock", "server");
nc.bind(name, o);
orb.run();
Now your object is registered in the remote NamingService and is accessible via CORBA.
You have to include CORBA jars in the JBOSS classpath.
A Corba orb is a socket listener, so best to use the one under JBoss's control, i.e. the standard orb:
ObjectName ORB_NAME = ObjectNameFactory.create("jboss:service=CorbaORB");
ORB orb = (ORB)server.getAttribute(ORB_NAME, "ORB");
to automatically start your Corba service do it in a JBoss Service mbean:
http://community.jboss.org/wiki/examplehelloworldservice
To avoid having to compile IDL you could use the Dynamic Invocation Interface.
Have a look at how Axis2 CORBA Module does it: http://wso2.org/library/2807
You do not need an Orb on the classpath if you use the JBoss "all" configuration, this includes Corba.

JBoss5 MainDeployer MBEAN listDeployer returns empty collection

It seems that the MainDeployer MBean doesn't work/is not implemented.
how to retrieve the list of deployed application in JBoss 5?
You might be interessted in the JMX MBean View of Web-Console which can be reached using this URL http://localhost:8080/web-console/ as well as JMX-Console http://localhost:8080/jmx-console/
If you bound your jboss using parameter -b to another interface, you need to replace localhost in the URL given above.