JSP Custom tag not working correctly for multiple users

I am doing some support work for an existing web system. When doing single user access (a custom tag is called within the JSP); the output of the Custom tag is fine. However, during multiple user access to the JSP, as I could see on the log files, 2 users access the custom tag at exactly the same time- the output of one of the users was incorrect. The custom tag btw, uses TreeMap, Stringbuffer and does not have a body, only attributes passed to it. It takes an input file and a Hashmap as input attributes and it sets a string in the page context which is later being used in the JSP. No error is logged, its just that the string produced(placed in the page context) is incorrect. This only happens when this tag is called at same time(when multiple users accessing the page)Has anyone encountered this problem? Is there a known pooling/thread problem with custom tags?

[880 byte] By [Mutyaa] at [2007-11-27 6:56:06]
# 1
Aren't you using static or application variables?
BalusCa at 2007-7-12 18:32:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
> Aren't you using static or application variables?No, there were no static and application variables in the code. The problem looks like it does not process the Hashmap passed as an object attribute to the tag, only again when multiple users access it.
Mutyaa at 2007-7-12 18:32:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
in a servlet/jsp (a jsp is compiled into a servlet), the class atrributes are shared. only the variables declared in the doservice (doGet or doPost) method are threadsafe.post your jsp plz
java_2006a at 2007-7-12 18:32:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> in a servlet/jsp (a jsp is compiled into a servlet),

> the class atrributes are shared. only the

> variables declared in the doservice (doGet or doPost)

> method are threadsafe.

>

> post your jsp plz

here's the snippet of the jsp code:

<%@ page language="java"

errorPage="Error.jsp"

autoFlush="false"

buffer="128kb"

import="java.text.*,

java.math.BigDecimal,

java.rmi.RemoteException,

java.util.*,

java.io.*,

%>

<%@ include file="Secure.jsp" %>

// a set of request.getParameter are being called here

HashMap myMap = new HashMap();

myMap.put(xmlDPhoneNumber, dPhoneNumber);

myMap.put(xmlDPhoneType, "D");

myMap.put(xmlDPhoneExt, dExtension);

myMap.put(xmlDPhoneDigits, dPhoneDigits);

// other myMap putting of key values are called here

%>

<test:applyCustomerSearchValuesid="resultXml"xmlTemplate="/xml/message/CustomerUpdateRequest.xml"

xmlMap="<%= myMap %>" />

<test:transformXMLString id="customerUpdateRequest"

xmlString="<%= resultXml.toString() %>"

xslFileName="/xsl/message/CustomerCreateRequest.xsl"

paramMap="<%= PMap %>"/>

now here's the thing: the xml produced by test:applyCustomerSearchValues is resultXml which is used in test:transformXMLString. I got no problem with the output of test:transformXMLString.I am sure that a phone number is being passed into the former as part of the HashMap key-value. However when test:applyCustomerSearchValues is called when 2 users access the jsp, it seems like the the first xml produced does not have the phone number in it - but the other has it. The xml is OK for both users, its just that the values of the HashMap do not seem to be passed correctly into the xml produced.

here's the snippet of the log, the first httpWorkerThread-80-6 does not have the phone number, however the second one-httpWorkerThread-80-7 has the phone number. The first one should also have a phone number as in the start of the log, the number was listed, but as the system called the test:applyCustomerSearchValues tag, the number was not included. There are different phone numbers for the 2 users. The odd thing here is, the userID which is the 'LastUpdatedBy' element has been set correctly. The userID is being fetched from a session attribute while the phone number is fetched from a request parameter, both are being placed in the HashMap attribute passed to the custom tag.

2007-06-05 10:55:41,954 DEBUG [httpWorkerThread-80-6] (?:?) - ApplyCustomerSearchValuesTag : String produced is :<Values><Customer>

<Status>

<CustomerType></CustomerType>

<FirstContactDate>2007-06-05</FirstContactDate>

<StatusFlags>

<Fraud>N</Fraud>

<BadCheck>N</BadCheck>

<BadCredit>N</BadCredit>

<DoNotMerge>N</DoNotMerge>

<ARHoldRefundCheck>N</ARHoldRefundCheck>

</StatusFlags>

<LastUpdatedDateTime>2007-06-05 10:55:41</LastUpdatedDateTime>

<LastUpdatedBy>5555</LastUpdatedBy>

<OPAlertClass></OPAlertClass>

<MailListStoreID></MailListStoreID>

<OriginatingSource>CSA</OriginatingSource>

</Status>

<DPhone id="D">

<DPhoneNumber></DPhoneNumber>

<DPhoneDigits></DPhoneDigits>

<DPhoneType></DPhoneType>

<DExtension></DExtension>

<DAreaCode></DAreaCode>

<DPhoneCountryCode></DPhoneCountryCode>

</DPhone>

</Customer>

</Values>

2007-06-05 10:55:41,954 DEBUG [httpWorkerThread-80-7] (?:?) - ApplyCustomerSearchValuesTag : String produced is :<Values><Customer>

<Status>

<CustomerType>N</CustomerType>

<FirstContactDate>2007-06-05</FirstContactDate>

<StatusFlags>

<Fraud>N</Fraud>

<BadCheck>N</BadCheck>

<BadCredit>N</BadCredit>

<DoNotMerge>N</DoNotMerge>

<ARHoldRefundCheck>N</ARHoldRefundCheck>

</StatusFlags>

<LastUpdatedDateTime>2007-06-05 10:55:41</LastUpdatedDateTime>

<LastUpdatedBy>1840</LastUpdatedBy>

<OPAlertClass></OPAlertClass>

<MailListStoreID></MailListStoreID>

<OriginatingSource>CSA</OriginatingSource>

</Status>

<DPhone id="D">

<DPhoneNumber>(123) 123-4788</DPhoneNumber>

<DPhoneDigits>1231234788</DPhoneDigits>

<DPhoneType>D</DPhoneType>

<DExtension></DExtension>

<DAreaCode>123</DAreaCode>

<DPhoneCountryCode>US</DPhoneCountryCode>

</DPhone>

</Customer>

</Values>

Message was edited by:

Mutya

Mutyaa at 2007-7-12 18:32:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
I notice that you are doing an XSL transformation, but you didn't post that part of your code. The javax.xml.transform.Transformer object is not thread-safe, so if you are sharing a Transformer between multiple threads, that might be your problem.
DrClapa at 2007-7-12 18:32:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

> I notice that you are doing an XSL transformation,

> but you didn't post that part of your code. The

> javax.xml.transform.Transformer object is not

> thread-safe, so if you are sharing a Transformer

> between multiple threads, that might be your problem.

The transformer part was ok. The problem was in the output of the call to test:applyCustomerSearchValues. The xml string result produced by this custom tag was missing a phonenumber as shown in the log file. But I am sure that the phone number was existing in the HashMap passed to it. The implementation of creating the xml in this tag is only appending data using Stringbuffer and NOT using any xml stream, jaxp or jdom class. Would using a synchronized block when calling the test:applyCustomerSearchValues tag help?

Ex:

<%

synchronized(this){

%>

<test:applyCustomerSearchValues id="resultXml" xmlTemplate="/xml/message/CustomerUpdateRequest.xml"

xmlMap="<%= myMap %>" />

<% } %>

Mutyaa at 2007-7-12 18:32:56 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...