Kurt Xu

Ranch Hand
+ Follow
since Sep 29, 2009
Merit badge: grant badges
For More
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 Kurt Xu

Hello all:

I compile tomcat 5.5.30 and import it to eclipse as a project, to research how the tomcat load class , I need to view the running log ,after reading through this post(http://tomcat.apache.org/tomcat-5.5-doc/logging.html) and adding below log.properties to the direcotry 'common/classes' and log4j-1.26.jar to common/lib, logs turned out not to be generated when I debug the project starting from class Catalina. No idea about it, I've tried many times.

log4j.rootLogger=DEBUG,R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=k:\\logs\\tomcat.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p%t%c-%m%n
log4j.logger.org.apache.catalina.core.ContainerBase.[Catalina].[localhost]=DEBUG, R
log4j.logger.org.apache.catalina.core=DEBUG, R
log4j.logger.org.apache.catalina.session=DEBUG, R


And the program parameter I use is 'start', vm parameter is '-Dcatalina.home="I:\My Documents\program\java\projects\eclipse\mye9.0\TOMCAT_5_5_30\mybuild-5.5.30"'
Any ideas? Thanks


Kurt Xu
12 years ago

Roberto Perillo wrote:Howdy, Kurt!

My confusion is there're many logic to select a proper concrete factory method , whose parameters are different from other's. In this case , do I still need write such factory?



Well champ, it's sort of hard to say, but, since you are using Spring, have you considered using dependency injection? You can provide the class that implements the SuccessChecker in an XML file and arrange the objects there... this way, you wouldn't have to write the factory.


The problem is the app first parse all information from a configuration xml file ,then create a proper SuccessChecker instance for every configuration , many configuration with different class of SuccessChecker requirement. I change the SuccessChecker to a abstract class like Calendar does, define multiple factory method, as following:


Every Functionality represents a piece of configuration ,requiring a SuccessChecker instance , my app is a framework to handle all kinds of request, no way to predefine a specific SuccessChekcer implement class in a framework.
thank Roberto
Hello all:
I'm writing an app to determine whether the execution result of struts action and bussiness object intercepted through intercepter of spring and struts is successful, the interface to do it is named 'SuccessChecker' , six default build-in checker implement classes have been developed, if those don't reach the requirement, you need to implement it on your own, below is part code of the factory class.



My confusion is there're many logic to select a proper concrete factory method , whose parameters are different from other's. In this case , do I still need write such factory? Is that right I don't use it and just create a implement class of SuccessChecker? But meanwhile I discovered java.util.Calendar is in a situation similar to mine. Calendar has method with different parameters to return a concrete Calendar implement class, but it's an abstract class that is extended by like GregorianCalendar. Is that suitable I mimic Calendar.
thanks.
In our project ,we need to intercept some concrete classes not implement any interfaces and we are not granted to refactor the code either cause it's developed by another department ,we can only use the common jar they offer. And another bad news is we can't easily add other opensource aop lib, like cglib, so the only intercepting way is to use jdk dynamic proxy, but it's no way to intercept classes without interface implement either. Is that possible to make a class implement a interface which includes all the method in the concrete class dynamically through spring ,then spring can intercept the class. I'm not sure if it's possible. The version is 2.0.6.
Many thanks.
13 years ago

Mark Spritzler wrote:If your classes have interfaces and implement them. Them Spring will create DynamicProxies. No need for cglib in that scenario.

Mark



Yes, I know that , unfortunately, some BO classes have interface, some don't. Looks like all I can do is to persuade my boss to add jar file.
13 years ago
Normally if we want to use aop for class not implementing some certain interface in spring, asm and cglib are must. But why struts implement interceptor which is same of aop actually without the two jar?
13 years ago

Mark Spritzler wrote:Here is your best solution.

1) Create your own Annotations and then annotate all the methods you want advised.
then write your pointcut expression to match the annotation.

for instance

"execution(@com.myapp.annotations.MyAnnotation * *(..))"

Now any method that is annotated with @MyAnnotation will match that pointcut expression. No more need of 100 pointcut expressions.

Here is my definition of that annotation




That's it.

Mark


It works. If it doesn't need cglib and asm jar file it would be perfect. Our company' system is a little rigid, which means we can't easily add jar file to the existing web project. I'm very curious with that how webwork implements interceptor without cglib and asm. After all interceptor is same of aop.
13 years ago
Hello all:
for some reason, I have to make an interceptor run in all sub projects at last, but I can only configure and add an interceptor in an parent configuration from which sub projects will extend and these sub projects will also add their own specific interceptor in their order, so the order defined in the parent configuration can't be guarantee in the sub projects. We hope the newly added interceptor can run in the sub projects at last, is that possible to change programically?
thanks.
13 years ago
Hi all:
In my new project, we need to program many existing projects to intercept some action method in order to add some extra work, mainly synchronize the modified data into another db. We just need an advice but tens of pointcut, maybe over 100, from different existing projects. I want to configure the action and method info in a xml file, and then apply them as pointcut through some way. The configuration info is like below, just temporary thought.

My question is that besides a customized advisor extending StaticMethodMatcherPointcutAdvisor and implementing the method match throung the way of , such as storing the action and method names in a List and determining by List.contains(), is there an other easy and efficient way ? Such as @aspectj and aspectj schema. At least I haven't found a good way, cause it's horrible to write a very long pointcut expression in the applicationContext.xml, there're too many methods and actions to write, and it's hard to read and maintain all these pointcut expression. It's better not to import other jar file beside spring library.
13 years ago

Bang Nguyen wrote:

Kurt Xu wrote:Hi, I think you should change greetingServiceTarget's singleton to true, or just not set the attribute ,cause it is true by default.



Hi, it will not work. Moreover, this is not what we intended to do. Because just imagine the greetingServiceTarget is some JavaBean in our domain such as Student, Class, Course. From that, we can see that those objects must not be singleton. Otherwise, they will store dirty data from the same object type.

When we imagine this greetingServiceTarget as Student, Class Objects; we can see that sometimes we want to lock some specific services of these objects. That's the intention of this example.

Anyway, thanks for your contribution! Please give more suggestions so we can study!



Show me your test app, I did this kind of test, everything was ok. Not difficult
13 years ago

Mark Spritzler wrote:That's what AOP is all about adding code to your code through Aspects and Advices.

Mark



Hi, Mark:
I think aop can't insert some logic into some certain row of existing method code , can just do something other before or after existing method . If I'm wrong ,can you please show me some sample?
After interceptor is the first idea I can think of , but is abandoned right now, because the method to be intercept doesn't throw a exception,if we use after interceptor or around interceptor, we can't know whether the transaction is successful or not. the existing code is like below:

So pure after interceptor can't handle that. data must be synchronized only when inspected data updating is successful. we need insert code into some certain point of existing code and the new logic can access the rest of the method. Such as define a boolean variable to save transaction state to determine whether do synchronizing.

13 years ago
Hi, I think you should change greetingServiceTarget's singleton to true, or just not set the attribute ,cause it is true by default.
13 years ago

Shashank Ag wrote:Well some byte code manuplation apis are availble like Javassist.
But, I am still interested why AOP will not work in your case.
Have you really read the concept? Don't mind its just I am big fan of spring AOP.


well, javassist can't change class behavior after they are created, but that's exactly what I need.
13 years ago
I want to change a method body and not to change existing source code running on web app.
Does spring offer that magical function?
What I mean by change is not to replace totally but do some small changes. It's more like below to insert new logic at some point or row:


The scenario is we want to inspect a large of projects ,when new records are inserted or update in these projects running on tomcat , I hope all these data also be synchronized to my inspection database so that we can summarize latest data that need to be checked by administrator. So I need to do some extra work to the existing code, but cause the number of projects is pretty big , adding logic for every single class method is not reasonable, so I just want to add synchronizing code in a relative easy and common way. Basically we have got all the methods we need to handle and enough materials .
If it can't be possible, we had to change source code ,that would be the last way we wanna choose.
Thanks.
13 years ago

Mark Spritzler wrote:Actually, you can with Spring AOP.

It is called Introductions, and here is a link to the docs that shows how to do this

http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/aop.html#aop-introductions

Mark



To be exact, introduction need to be done at compilation time ,not runtime, cause at that moment ,bean has been created.

thanks.
13 years ago