Sunil Dixit

Ranch Hand
+ Follow
since Sep 22, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sunil Dixit

Hi,

It is very simple, if your using Log4J/SLF4J then you can cofigure this fetaure.This framework will take care of all of your requirement even without stoping you code any time.
If you are not using Log4J/SLF4J and you would like to create your own soln then have a look on Appender components of Log4J.

For archive your log files either you can use TimerService OR Quartz which let you execute any code based on time.

Hope that this helps !

Thanks,
Sunil Dixit
Hey Luke,

I can give hints on EJB security, I have done this on WSAD but not on JBOSS, so probably you have do extra work/investigation.
Before I jump to the steps what I have done in WSAD, you need to understand whats wrong in code snippet.
You have configured JAAS module in JBOSS server which will be called automatcially whenever you call LoginContext.login(...)
Whenever you use EJB security there are two possiblities/paths:

1. User is already authenticated and authorised before you invoke any EJB method/s.
2. User is not authenticated and authorised before you invoke any EJB method/s.

Case 1: Principals and Credentials (returned by login API) are set in ThreadLocal before you make a call. Once server recevived these data then it trust on caller and check/extract the role information and if role matches with specified role then it allows method invocation otherwise it throws exception.

Case 2 : Whenever you pass user details using Context.SECURITY_PRINCIPAL, Context.SECURITY_CREDENTIALS then server tries to do authentication based on passed details and they are correct then its tries to match roles.

Again that dependces what EJB flow we are talking (i.e. we want that user passes their details and server first do authentication and then role check OR user details are already authenticated and we would like to use Principals and Credentials )

Now in WSAD what we do is , we defines roles and then map roles to methods (using ejb-jar.xml or annotations). before you deploy the build you use WSAD feature to collect all roles defines in EJB-jar.xml and then map these roles to specific OU (org unit). After this you start deployment and container ask you lookup all roles from LDAP or some files and map these roles to your EJB. once this mapping is done,container know what role and OU maps to which role and OU.


Hope that this helps.

Thanks,
Sunil Dixit



9 years ago
Hi,

I am not able to understand un-expected behaviour of find() API of Matcher class.
As per the java documents and my understanding, find() method return TRUE if system is able to find more occurence of sequence that matches given the pattern.

public class RejEx {

public static void main(String[] args) {
String source = "pp";
Pattern p = Pattern.compile("p*");
Matcher m = p.matcher(source);
while(m.find())
{
System.out.println("Pattern Found :"+m.group());
}
}
}

As per the code snippet,anybody will expect that while loop should get executed only once but it gets executed 2 times. So when I run this program I get output as below :
Pattern Found : pp
Pattern Found :

I does work fine if I use "p+" pattern but if use "p*" or "p?" as pattern than I am not getting output as per my expectation.

So now I have following questions :
1. Is my understanding not correct ?
2. Is there any BUG in find() API ?

cheers,
Sunil

[ May 14, 2008: Message edited by: Sunil Dixit ]

[ May 14, 2008: Message edited by: Sunil Dixit ]
[ May 14, 2008: Message edited by: Sunil Dixit ]
11 years ago
Avneet,

You need to pull only the interface/clasee which are reuired to complie your code.
So better way is you create a common.jar file which will contains all class file that you need to complie your code.
Make it sure you don't put the target jar file,if you do that then your application server wll try to deploy that.
So you have two choices :
1. Create new jar that will contain only class file.
2. You delete all deployment descriptor files from target ejb module.jar

Sunil
Hi,

change props.put(Context.PROVIDER_URL, "jnp://132.205.93.311:1099"); to props.put(Context.PROVIDER_URL, "132.205.93.311");

Is should work ! In JBoss you are not suppose to use JNP and port number.

Cheers,
Sunil
Hi,

You can do that,conside your ejb module in (myapp2.jar ) as client for ejb module reside in (pyapp2ejb.jar).So simply make a lookup (using Initial context and give the EJB Home JNDI name) and do your work. Your code will look in as below :

InitalContext ctx = new InitialContext();
ctx.lookUp("ZZZZZ");
RemotePortableObject.narrow(...);
etc..

I am not sure whether local home lookup will work or not? because its depends on which application server you�re using. But remote lookup will work for sure !


Cheers,
Sunil Dixit
Hi,
I don't agree with Kyle quotes,if that is true than we can do I/O in EJB using some helper class right ?

THIN line is EJB spec are the guidelines which say you should do that BUT it does not enforce user that he has to do that.

It 100% true that "synchronized" keyword is forbidden and the reason I have explained you.

Cheers,
Sunil Dixit
Hi shawn,
It is very simple,Let me tell you step by step:

1. In you JAR file please make it sure that you have given EJB REF i.e. nick name to your EJB. Reason is it is not good to lookup any component by its actual JNDI name beacuse if you do that than your code is tightel coupled with JNDI name,which is wrong.
2. Mentioned those EJB REF in your web.xml file using <ejb-ref> or similar tag (please look on the web ).
3.Now in your servlet class simply do the lookup,rest of all will be taken care by the container itself.
but make it sure that while you do lookup you are using the same ref-name which you have given in web.xml file.

Hope that this will help you.

Cheers,
Sunil Dixit
Hi,
Thanks for giving this information,could you please post the piece of code which is used to get the data from the database.The reason why I am asking I need to have a look how you are fethcing the data from database using Hibernate.
Let me tell you how Hibernate works, when you try to load and object using Hibernate than your POJO class is being enhanced by Hibernate framework to PROXY which know how to get/set the details from database.This PROXY will work fine till the time you have vaild Tx/Session.
The time you close you Tx/Session than this PROXY is not valid,If you want to use your POJO object outside of Tx context and try to get some information which was not loaded during PROXY had valid Tx/context than you will get same exception.
So I want to have a look how you are usning Hibernate to get the information.
After seeing that I can tell you something.

Cheers,
Sunil Dixit
Hi,
I think you can do that,As you know that we have TimerService in EJB 2.1 ownward,which can run automatically on given time period.
So you can use TimeService as background process which keep testing your data base status,if the data base is down that you can undeploy the MDB.
You need to pack your MDB as a seperate JAR file,so that when you deploy/un-deploy other component will not get effected.
And you need to explorer how you can deploy/undeploy JAR files on different conatiners.
But I can give to some start point so that you can start as far as deployment/un-deployment is concern.
If you go to your application server amin page,where you can deploy/un-deploy your EJB,just place the mouse over the link than It will show what url is being invoked.
e.g. in Tomcat if you want to stop any context than http://<host>:<port>/manager/html/stop?path=<context name> is used
and we can achive using simple java code which make connection to given url and stop the context.
So when the timer service came to know that database is down than it will undeploy your MDB and when DB is back than it will deploy the MDB.

Hope that this will help you.

Cheers,
Sunil Dixit
Hi,
Do you entity bean have any relationship with other bean ?
If yes and you are trying to fetch data using your parent entity,than you shd use aggressive fetching stg.
If you business say that you can't have aggressive fetching stg. than you need to populate the required data in you parent bean.
e.g.
Student -> Course
(1) (N)
So in student bean either you mark fetching stg as aggressive OR write necessary code in StudentBean to fetch the required data.
The exception which your talking abt is occured when you try to access something whose proxy is not initialise.
Hope that this will help you.

Cheers,
Sunil Dixit
Hi,
You are 100% right. As per the EJB spec 'synchronized' shd not be used,and the reason is very simple,as you must be knowing that 'synchronized' keyword is used to avoid sharing conflict of a common resource in multi-threaded env.
And J2EE application are multithread,so its container responsibilities to handle all these stuff for user.
Even if you use 'synchronized' keyowrd in J2EE application than you are trying to make your container life tuff which you shd not be the case. Conatiner will do better handling of common resource,so we shd not use 'synchronized' keyword.
hope that this will help you.

Cheers,
Sunil Dixit
[ July 05, 2007: Message edited by: Sunil Dixit ]
Hi Amit,
Just want to bring the fact if you are not using BMT than by default Required Tx attribute is being imposed on beans.

Sunil Dixit
Hi,
'Satou ' is right, actually EJBHandle is Serializable object which can be presisted and can be used in future to call ejb methods.
It is use to avoid re lookup/re creation of EJObject.
Only problem with EJBHandle is maintaing the reference to non-existing proxy on the server (i.e. associated ejb bean instance is no longer there) than it will throw runtime exception.
Hope that this will make clear picture to you.

Cheers,
Sunil Dixit