Win a copy of Emmy in the Key of Code this week in the General Computing forum!

Ajay Dhar

Ranch Hand
+ Follow
since Jan 26, 2011
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 Ajay Dhar

In sections 1.1 and 1.2 of MZ's notes for Web Services EE 6 cert guide, he mentions the webservices.xml deployment descriptor. Do we need to understand the webservices.xml deployment descriptor and how to use it for the EE 6 version of the exam? It's not mentioned in Java Web Services: Up and Running by Martin Kalin nor is it mentioned in the JAX-WS v2.2 spec. I can't find much info on it.

Your help is appreciated. Thanks.
This is a question regarding a statement in Ivan Krizsan's study notes on page 165, and the EJB 3.1 spec in sections 4.3.15 and 13.6.5, about reasons for using bean managed transactions. The statement I don't understand is:

Bean managed transactions "can be used with message driven beans, in order to be able to acknowledge a message even through the transaction rolls back."

I thought when BMT was used with an MDB, if the transaction rolls back, the container does not acknowledge the message. How can the message be acknowledged if the transaction rolls back?

Thanks,
Ajay
This is a question regarding code in the first example in Ivan Krizsan's OCP Java EE 6 EJB Developer Study Notes on page 22. But first on page 13 of the study notes, and in the EJB 3.1 specification (chapter 21, section 2), it states that one EJB programming restriction is that an EJB must not use writable static fields. The motivation being to ensure consistency in a distributed environment.

Here is the code of a stateful session bean taken from the study notes on page 22:



If you look at line number 26, there is a static int declared as an instance variable. This static variable is updated in the @PostConstruct method. Doesn't this violate the restriction that an EJB must not use writeable static fields?

Thanks,
Ajay
I did a little more reading and tinkering with code and I figured something out. Ok, the @Resource annotation applied to a field injects the resource into that field. The @Resource annotation applied to the class adds the particular resource specified in the annotation into the ENC for the annotated EJB. The EJB can then look up that resource using JNDI and a JNDI name of "java:/comp/env/...". Each EJB in an EJB jar has its own ENC and a WAR has one ENC for everything in the WAR.
Thank you so much for your reply

So you are saying that using the @EJB annotation with the name property on the class registers that particular EJB in the ENC with the provided name. So, that means that the @EJBs annotation shouldn't be used at the class level because there is only one EJB that you can register, and that is the annotated EJB. Is this right? I'm not sure. Because it doesn't make sense to use the @EJBs annotation for a field because you can only inject one EJB into a given field. So when do you use the @EJBs annotation?
Can someone please explain to me the difference between annotating a field in an EJB with @EJB and annotating the EJB class with the @EJB annotation and how it relates to the ENC?

To my understanding, annotating a field with @EJB injects a reference to the EJB into the field. Does it look up in the ENC to do this injection? Is all injection done from the ENC?

What does annotating a bean class with @EJB do?

Some clarification on these topics would be greatly appreciated.

Thanks.
Jeez... 5 minutes after making this post I realized that my session bean is annotated as @Stateless instead of @Stateful... Lol. I'll try it again as a Stateful bean. I'll post again if I run into any issues.
I just started going through Ivan's notes. I'm on chapter 2, Create a Stateful Session Bean. I coded the first example from this chapter in Eclipse using Glassfish.

The code example works for the most part, however I do not see the @StatefulTimeout(value=10, unit=TimeUnit.SECONDS) taking effect. Whenever I call the EJB from the servlet client multiple times within 10 seconds it displays the greeting properly, as expected. However, if I wait more than 10 seconds between requests, the session bean should timeout and I should get a NoSuchEJBException upon a subsequent request. However, I am not getting any error, a greeting is be sent back to the client. I even tried reducing the timeout to 1 second but to no avail. Also, I added @PrePassivate and @PostActivate methods to see if the @StatefulTimeout was causing the bean to passivate, but those callback methods weren't being called.

I have provided the code snippets of the stateful session bean and servlet client below. Does someone know what is going on? The @StatefulTimeout annotation doesn't seem to be taking effect. I'm a little confused.

Any help is appreciated.

Stateful Session Bean:


Servlet client:



When I use the hx:fileupload outside of a datatable I am able to store the file name and content type into my backing bean. However, when I put hx:fileupload components in a datatable the file name and content type are not stored, and they show up as null when I print them to the console.

Here is my JSF page:



Here is my backing bean (pagecode):



The reason I am keeping the fileupload components in a datatable is because there is a requirement to externalize in a properties file the number of fileupload components that are displayed. I have also externalized the accepted content types and combined max file size in properties files.

Currently I have 3 fileuploads displayed within the datatable and one outside the datatable for testing. When I try to upload the same text file in one of the uploads in the datatable and the one upload outside of the datatable I get the following print out in the console:

null null is 5 bytes and the content type is null.
C:\Users\dp0ad3\Desktop\TestUpload.txt text/plain

As you can see, the file name and content type for the upload component in the datatable are not stored, whereas this information for the upload component outside the datatable is.

Anyone know why I am seeing this behavior and/or how to work around it?

Thanks.
6 years ago
JSF
I have an interesting problem. I have a web application that I'm hosting through a third party provider on a virtual private server. The application is basically an html page which submits input to a servlet. The app is running on Tomcat 6 and the OS is CentOS.

When the CPU speed is set to 1.2 GHz and RAM at 1.2GB, the servlet takes on average 20 seconds to execute. However, when I upgrade the virtual server to CPU speed of 2.4 GHz and RAM at 1.6 GB the servlet takes 30 seconds to execute.

This is very counter intuitive. Does anyone have an idea of what could be causing worse performance after upgrading the resources??

Thanks in advance!
7 years ago
I have a composite component with a command button. The button is bound to an action listener method which is in a session bean. For some reason, when the button is clicked, the same action listener is registered three times, so the action listener method is executed three times.

I did a lot of Googling to find out why an action listener would be registered multiple times but I didn't find anything. Does anyone know what's going on?
7 years ago
JSF
Can you have bullets in a properties file? If so, how?
7 years ago
Does anyone know of a really good API for balancing HTML tags? Say for example I have the following HTML snippet:

Feedback control is the basic mechanism by which systems, whether mechanical, electrical, or biological, maintain their equilibrium or homeostasis. In the higher life forms, the conditions under which life can continue are quite narrow. A change in body temperature of half a degree is generally a sign of illness. The homeostasis of the body is maintained through the use of feedback control [Wiener 1948]. A primary contribution of C.R. Darwin during the last century was the theory that feedback over long time periods is responsible for the evolution of species. In 1931 V. Volterra explained the balance between two populations of fish in a closed pond using the theory of feedback.</P>
Feedback control may be defined as the use of difference signals, determined by comparing the actual values of system variables to their desired values, as a means of controlling a system. An everyday example of a feedback control system is an automobile speed control, which uses the difference between the actual and the desired speed to vary the fuel flow rate. Since the system output is used to regulate its input, such a device is said to be a <em>closed-loop control system</em>.</P>
In this book we shall show how to use <em>modern control theory</em> to design feedback control systems. Thus, we are concerned not with natural control systems, such as those that occur in living organisms or in society, but with man-made control systems such as those used to control aircraft, automobilies, satellites, robots, and industrial processes.</P>
Realizing that the best way to understand an area is to examine its evolution and the reasons for its existence, we shall first provide a short history of automatic control theory. Then, we give a brief discussion of the philosophies of classical and modern control theory.</P>
The references for Chapter 1 are at the end of this chapter. The references for the remainder of the book appear at the end of the book.</P>

The paragraphs are followed by closing </p> tags but none of the paragraphs start with an open <p> tag. I'm looking for an API to balance the <p> tags accurately so that I can convert the HTML page to XML and extract the paragraphs with XPATH.

Thanks,
Ajay
How do I prevent Web Harvest from removing the space after closing tags when I convert html to xml? My configuration file is shown below:



I'm using Web Harvest to extract the paragraphs (<p></p>) from an HTML page. But there's an issue. Web Harvest is removing the space after the closing tags like </b> and </a>. When I remove the HTML tags using JSoup from the results of Web Harvest there is no space between the text of a link and the following word. The same happens for text that was in bold.


Help is greatly appreciated.
Thanks for the link. I checked Amazon and they only have one book on IT infrastructure architecture and it doesn't really talk about server setup, clustering, lpars and such (I was able to look inside the book). The rest of the books are either about IT architecture in general or the architecture of cities. Anyone else know of any good resources on IT infrastructure architecture? I wouldn't be asking if I hadn't already done a few google searches.
7 years ago