A unique ID per User / Session in logs on all levels? Log4J? - jsf

Well we are doing some performance testing to figure out what steps of our application take how much time. Of course easy to parse / filter logs with regexp are a charm.
To the problem: Our jsf application is split into several projects, which are used by other (non jsf) applications.
My first approach would have been:
if(logger.isDebugEnabled())
logger.debug("Service call took: " + (System.currentTimeMillis() - time)+ " JSESSIONID="+CookieUtil.getJsessionId(FacesContext.getCurrentInstance())) ;
(CookieUtil would read the sessionId from the HttpServletRequest)
But... obviously other projects don't like dependencies to JSF libraries, nor to my neat CookieUtil.
Does log4j provide something?
Is there another tool / concept for this?

You could accomplish what you are looking for w/ log4j MDC:
Log4j MDC
and using a Servlet Filter similar to this example:
MDCServletFilter

Related

Does `ResultQuery#fetchAsync()` work with r2dbc in jOOQ 3.15.1?

I am wanting to use non-blocking r2dbc without 'using a third party reactive stream API', and currently have this working when I configure the DSLContext with JDBC (ie. all the records are printed):
// appended to a jOOQ select query
.fetchAsync()
.thenApply{ it.map(mapping(::Film)) }
.whenComplete { result, _ -> println( result ) }
however, if I configure the DSLContext to use r2dbc (without any other changes), the println( result ) prints null :-(
I:
am using Kotlin, but not bridging to coroutines yet ... only the above calls are involved
am using io.r2dbc:r2dbc-mssql:0.8.6.RELEASE
don't know if r2dbc is 'working' in any sense ... I'm relying on jOOQ to hit me with an exception if not ... I've not seen a single piece of data relayed by r2dbc at this stage.
As of jOOQ 3.15.1, this isn't possible yet, see https://github.com/jOOQ/jOOQ/issues/11717. It's likely this will be fixed in a 3.15.x patch release

Rails cucumber uninitialized constant User (NameError)

I'm starting with BDD (cucumber + capybara + selenium chromedriver) and TDD (rspec) with factory_bot and I'm getting an error on cucumber features - step_definitions.
uninitialized constant User (NameError)
With TDD, everything is ok, the factory bot is working fine. The problem is with the cucumber.
factories.rb
FactoryBot.define do
factory :user_role do
name {"Admin"}
query_name {"admin"}
end
factory :user do
id {1}
first_name {"Mary"}
last_name {"Jane"}
email {"mary_jane#gmail.com"}
password {"123"}
user_role_id {1}
created_at {'1/04/2020'}
end
end
support/env.rb
require 'capybara'
require 'capybara/cucumber'
require 'selenium-webdriver'
require 'factory_bot_rails'
Capybara.register_driver :selenium do |app|
Capybara::Selenium::Driver.new(app, browser: :chrome)
end
Capybara.configure do |config|
config.default_driver = :selenium
end
Capybara.javascript_driver = :chrome
World(FactoryBot::Syntax::Methods)
And the problem is happening here
support/hooks.rb
Before '#admin_login' do
#user = create(:user)
end
step_definitions/admin_login.rb
Given("a registered user with the email {string} with password {string} exists") do |email, password|
#user
end
I don't know why, but I can't access the user using cucumber and factory_bot.
Anybody could help me please?
I think I need to configure something on the cucumber.
What do you think guys?
First of all Luke is correct about this being a setup issue. The error is telling you that the User model cannot be found which probably means Rails is not yet loaded. I can't remember the exact details of how cucumber-rails works but one of the things it does is to make sure that each scenario becomes an extension of a Rails integration test. This ensures that all of the Rails auto-loading has taken place and that these things are available.
Secondly I'd suggest you start simpler and use a step to create your registered user rather than using a tag. Using tags for setup is a Cucumber anti-pattern.
Finally, and more controversially I'd suggest that you don't use factory-bot when cuking. FactoryBot uses a separate configuration to create model objects directly in the datastore. This bypasses any application logic around the creation of these objects, which means the objects created by FactoryBot are going to end up being different from the objects created by your application. In real life object creation involves things like auditing, sending emails, conditional logic etc. etc. To use FactoryBot you either have to duplicate that additional creation logic and behavior or ignore it (both choices are undesirable).
You can create objects for cuking much more effectively (and quicker) by using the following pattern.
Each create method in the Rails controller delegates its work to a service object e.g.
UserController
def create
#user = CreateUserService.new(params).call
end
end
Then have your cukes use a helper module to create things for you. This module will provide tools for your steps to create users, using the above service
module UserStepHelper
def create_user(params)
CreateUserService.new(default_params.merge(params))
end
def default_params
{
...
}
end
end
World UserStepHelper
Given 'there is a registered user' do
#registered_user = create_user
end
and then use that step in the background of your feature e.g.
Background:
Given there is a registered user
And I am an admin
Scenario: Admin can see registered users
When I login and view users
Then I should see a user
Notice the absence of tagging here. Its not desirable or necessary here.
You can see an extension of this approach in a sample application I did for a CukeUp talk in 2013 here https://github.com/diabolo/cuke_up/commits/master. If you follow this commit by commit starting from first commit at the bottom you will get quite a good guide to setting up a rails project with cucumber in just the first 4 or 4 commits. If you follow it through to the end (22 commits) you'll get a basic powerful framework for creating and using model objects when cuking. I realize the project is ancient and that obviously you will have to use modern versions of everything, but the principles still apply, and I use this approach in all my work and having been doing so for at least 10 years.
So if you're using rails, it's probably advised to use cucumber-rails over cucumber. This is probably an issue where your User models have not been auto-loaded in.
Cucumber auto-loads all ruby files underneath features, with env.rb first, it's almost certainly an issue with load order / load location

Limiting the scope of a transaction in Apache Camel

I have a transacted Camel route with a number of processors
from(Constant.RouteA)
.transacted()
.process(processor1)
.process(processor2)
.process(processor3)
.wireTap(Constant.RouteB)
.wireTap(Constant.RouteC)
.end()
My problem is that I don't want the final part of the route (the wiretaps) to be part of the transaction i.e. I want them to be executed once processor3 has finished and the transaction committed.
Initially I looked at using onCompletion() but it doesn't seem to work together with transacted().
So I found another way which requires using policy() to limit the transaction scope i.e.
from(Constant.RouteA)
.policy("PROPAGATION_REQUIRED")
.process(processor1)
.process(processor2)
.process(processor3)
.end()
.wireTap(Constant.RouteB)
.wireTap(Constant.RouteC)
.end()
The problem is that this solution requires to define the SpringTransactionPolicy in the Spring configuration, but the software I'm working on doesn't use Spring. Transactions are managed by Bitronix and everything works just by using the transacted() method, which as far as I can tell doesn't allow you to limit the scope of a transaction.
Is there a simple way to achieve my goal? Hopefully without bringing Spring into the picture. Thank you!
Try to create two routes. For example:
from(direct:startRoute)
.to(Constant.RouteA)
.wireTap(Constant.RouteB)
.wireTap(Constant.RouteC);
from(Constant.RouteA)
.transacted()
.process(processor1)
.process(processor2)
.process(processor3);
Once route "Constant.RouteA" is finished all changes will committed.

How to get Hogging Thread name WLST

I want to get names of thread marked as Hogger in weblogic.
I have tried with
ThreadPoolRuntimeMBean.getHoggingThreadCount()
but this gives only count of hogging threads.
Under Self- Tuning Thread Pool Threads
Weblogic is displaying "Thread Name" ,"Stuck" (True/ false) and "Hogger" (True/ false) , So obviously weblogic developer has written some method to get these values.
I am looking for that weblogic inbuilt method (in WLST) or any other way to get names of hogging threads.
PFA Weblogic Screen Shot for more detail
or check image on this link (http://www.munzandmore.com/wp-content/uploads/2012/04/st9.jpg)
Here is a very basic WLST script to accomplish this (for a default non-clustered AdminServer installation):
connect('weblogic', 'welcome1')
serverRuntime()
cd('ThreadPoolRuntime/ThreadPoolRuntime')
for thread in cmo.getExecuteThreads():
print(thread.getName() + " - " + str(thread.isHogger()))
You can use print dir(thread) to get all the available properties and methods.
For a more complex managed server environment, you can combine the above with this example: http://wlstbyexamples.blogspot.co.za/2009/06/self-tuned-thread-pool-count.html#.ViCqTnVStBc

Using AMI+BiDir with jacorb

Does it possible to use simultaneously AMI and BiDir features with jacorb?
Both work for me, but would not work together.
Examples, coming with jacorb demonstrates either BiDir or AMI.
The error that I see is following:
SEVERE: Unexpected error during receiveMessages. Lost a message!
java.lang.NullPointerException
at rg.jacorb.orb.giop.BiDirConnectionClientInterceptor.send_request(BiDirConnectionClientInterceptor.java:125)
at org.jacorb.orb.portableInterceptor.ClientInterceptorIterator.invoke(ClientInterceptorIterator.java:129)
at org.jacorb.orb.portableInterceptor.AbstractInterceptorIterator.iterate(AbstractInterceptorIterator.java:66)
at org.jacorb.orb.portableInterceptor.ClientInterceptorIterator.iterate(ClientInterceptorIterator.java:87)
at org.jacorb.orb.DefaultClientInterceptorHandler.invokeInterceptors(DefaultClientInterceptorHandler.java:328)
at org.jacorb.orb.DefaultClientInterceptorHandler.handle_send_request(DefaultClientInterceptorHandler.java:132)
at org.jacorb.orb.Delegate.servant_preinvoke(Delegate.java:2505)
at org.jacorb.orb.ReplyReceiver.performCallback(ReplyReceiver.java:240)
at org.jacorb.orb.ReplyReceiver.replyReceived(ReplyReceiver.java:183)
at org.jacorb.orb.giop.ClientConnection.replyReceived(ClientConnection.java:355)
at org.jacorb.orb.giop.GIOPConnection.receiveMessagesLoop(GIOPConnection.java:820)
at org.jacorb.orb.giop.GIOPConnection.receiveMessages(GIOPConnection.java:527)
at org.jacorb.orb.giop.MessageReceptor.doWork(MessageReceptor.java:69)
at org.jacorb.util.threadpool.ConsumerTie.run(ConsumerTie.java:60)
at java.lang.Thread.run(Thread.java:724)
please, advise.
UPD: I modified AMI example from jacorb's demo, added BiDir functionality (copied from BiDir example) and now synchronious calls work but ansync (AMI) do not.
They should work together. This does look like a possible issue. Are you using local calls? Can you please provide your test case and submit a ticket on http://www.jacorb.org/bugzilla/
(Please note the official JacORB mailing lists are here : http://www.jacorb.org/contact.html )

Resources