Tag: debug
Turning On Debug in JBoss
by Frank Kim on Dec.19, 2010, under JBoss
There are probably many ways of turning debug on in JBoss.
In windows the way I do it is by uncommenting the line in<JBoss>/bin/run.bat that starts with:
rem set JAVA_OPTS=-Xdebug
Uncommenting in DOS bat files is simply done by removing the rem command:
set JAVA_OPTS=-Xdebug
I created aliases for turning debug on and off. I use a script which simply replaces one string with another.
alias debugon='changeString.sh "^rem set JAVA_OPTS=-Xdebug" "set JAVA_OPTS=-Xdebug" ${JBOSS}/bin/run.bat && chmod 755 ${JBOSS}/bin/run.bat && unix2dos ${JBOSS}/bin/run.bat'
alias debugoff='changeString.sh "^set JAVA_OPTS=-Xdebug" "rem set JAVA_OPTS=-Xdebug" ${JBOSS}/bin/run.bat && chmod 755 ${JBOSS}/bin/run.bat && unix2dos ${JBOSS}/bin/run.bat'
On Unix I do a similar thing, uncommenting this line in <JBoss>/bin/run.conf:
#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
Uncommenting in Unix shell scripts is simply done by removing the # character at the beginning of the line.
JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
These are my aliases on UNIX for turning debug on and off.
alias debugon="changeString.sh '^#JAVA_OPTS=\"\$JAVA_OPTS -Xrunjdwp:transport=dt_socket' 'JAVA_OPTS=\"\$JAVA_OPTS -Xrunjdwp:transport=dt_socket' ${JBOSS_HOME}/bin/run.conf"
alias debugoff="changeString.sh '^JAVA_OPTS=\"\$JAVA_OPTS -Xrunjdwp:transport=dt_socket' '#JAVA_OPTS=\"\$JAVA_OPTS -Xrunjdwp:transport=dt_socket' ${JBOSS_HOME}/bin/run.conf"
One of the reasons I created the scripts was because on Windows suspend=y by default. Therefore when in debug mode you have to start your debugger or the JBoss server will not completely start up. On Unix suspend=n by default. If you change suspend=n on Windows too then the server will start up without waiting for the debugger to attach.
Note that you can only have one server with debug on for a given port, e.g. port 8787. So if you try to start more than one JBoss server with that port, only the first will start. The solution is to start only one server with debug on or start different servers with different debug ports.
Debugging WebSphere Applications with IBM Rational Application Developer
by Frank Kim on Apr.26, 2010, under Eclipse
IBM Rational Application Developer (RAD) is basically a typically IBM heavy version of Eclipse. WebSphere is a typically IBM heavy version of a J2EE server. Therefore you would think you could debug web applications using RAD fairly easily like you can on JBoss or ATG DAS using Eclipse.
However I could not find anyone on my latest project who knew how to do this. Fortunately after much Googling I found this PDF document, Debugging Applications in IBM Rational Application Developer, and on page 12 are instructions on how to do this.
The instructions seem to be a little out of date so here are my instructions.
- Log into your Integrated Solutions Console. The default URL is http://localhost:9060/ibm/console/login.do.
- Navigate using the left side column to Servers –> Application Servers.
- Select the Application server you want to debug from the list of Application servers.
- Under the Configuration tab select the Debugging Service link which is near the bottom right in the Additional Properties section.
- Select the “Enable service at server startup” checkbox. Note the JVM debug port.
- Press the Apply button.
- In the Messages box, which appeared at the top after pressing the Apply button, click on the Save link.
- Stop and start your Application Server. It should now be running in Debug mode.
- In RAD go to the project for the web application you want to debug.
- From the menu select Run –> Debug Configurations.
- Select Remote Java Application and press the New button (it’s the top left button). For the port set it to the JVM debug port (default is 7777).
- Press Apply. Then press Debug. It should connect to WebSphere’s JVM.
Now you can set breakpoints and even change small amounts of code which will be deployed automatically to WebSphere. No more waiting 15 minutes to test every change you make because builds are so brutally long.
Tweets for 2010-01 and 2010-02
by Frank Kim on Feb.28, 2010, under Miscellaneous
Ruby on Rails
- Numeric data types and zerofill. Explains what all those int(11) columns are in your Ruby on Rails tables. http://bit.ly/9Tcf7q #
- undefined local variable or method "acts_as_list"? – Ruby Forum. Do ruby script/plugin install acts_as_list http://bit.ly/9kFWbG #
- ruby on rails : adding child records to an existing parent without visiting the parent – Stack Overflow http://bit.ly/cQiGSP #
- Multi-Table Inheritance in Rails – When two tables are one… This is not easy and I wish it was. http://bit.ly/9fbzgk #
- has_many :through – count vs length vs size. Use count if u don’t want to load the contents of association into memory. http://bit.ly/dtqXe1 #
- A gentle reminder about pluralizations. config/initializers/inflections.rb to customize pluralizations in Ruby on Rails http://bit.ly/bN9GO5 #
- Ruby on Rails – Rails Migrations Cheatsheet – Dizzy. Pretty helpful. http://bit.ly/9wNvRx #
- RailsGuides Migrations. Nice guide, especially about explaining the naming convention which I don’t like. http://bit.ly/cjZ7aB #
ATG
- Configuring ATG to Send Email via Comcast SMTP – betweenGo. Configuring your ATG app to use your ISP’s SMTP server. http://bit.ly/7M5bhx #
- Enabling non-XA Resources in JBoss 4.2 with ATG – betweenGo. http://bit.ly/aDN3Po #
- Combining XML in ATG – betweenGo. Combining XML files not as straight-forward as w/ properties files but more flexible. http://bit.ly/8kVwvA Jan 12 12:00 PM
Eclipse
- Debugging Applications in IBM Rational Application Developer. Page 12 for how to set up server for debugging. http://bit.ly/aaYUHb #
JavaScript
- How can I submit a form along with some parameters using JavaScript? (JSF forum at JavaRanch). Answer #3 was helpful. http://bit.ly/b17ymm #
JSP
- Testing Which Page Loaded your JSP Page Fragment – betweenGo. Simple enough to do w/ JSTL but I always forget how.
http://bit.ly/cEh7IZ #
Miscellaneous
- Cygwin 1.7.x, mounts and /etc/fstab – betweenGo. Mounts are no longer saved from session to session in Cygwin 1.7. http://bit.ly/bmaYEu #
- Git in 5 Minutes http://bit.ly/bSt3dd and Git for the lazy – Spheriki http://bit.ly/aefD17 #
- The Thing About Git. Nice article describing how flexible Git is, especially compared to SVN. I may never use SVN again http://bit.ly/bD0tuS #
- I use DreamHost and am shamelessly plugging them both for a referral and to try to win an iPad. Honestly they’re great. http://bit.ly/ctYv3Z #
ATGLogColorizer for Colorizing ATG Server Outputs and Logs
by Frank Kim on Aug.18, 2009, under ATG
Color is wonderful. With color we can immediately recognize patterns, signals, warnings, etc. By using a utility that color codes your logs and server outputs to highlight errors in red, warnings in yellow, etc. you can be much more efficient about how you monitor and search.
Back in the day we used to use DynamoFilter.exe to color code the output of running ATG on the Dynamo Application Server (DAS). Now that people no longer use DAS that application is no longer useful.
Today though I found out about the open source project ATGLogColorizer. This fantastic utility works with JBoss, WebLogic, DAS and WebSphere. It works on Windows, Mac OSX, Solaris and other UNIX variants. It even works on Cygwin.
This is how I start JBoss with ATGLogColorizer on Cygwin.
${ATG}/home/bin/startDynamoOnJBOSS.bat -f -run-in-place -c default -m Foo | ATGLogColorizer.exe'
And this is how I start JBoss with ATGLogColorizer on Mac OS X.
${ATG}/home/bin/startDynamoOnJBOSS.sh -f -run-in-place -c default -m Foo | ATGLogColorizer_v1_2_OSX'
Life has become a little better.
For further reading please see and ATGLogColorizer and ATG Log Colorizer for JBoss.
How to Debug an InvalidVersionException from Updating an ATG Order
by Frank Kim on Aug.17, 2009, under Commerce
If you ever update an order outside of a transaction then the next time you update it within a transaction you will get the infamous, dreaded InvalidVersionException.
WARN atg.commerce.order.ShoppingCartModifier atg.commerce.order.InvalidVersionException: This order (o3830002) is out of date. Changes have been made to the order and the operation should be resubmitted. Order version 333, Repository item version 334. at atg.commerce.order.OrderManager.updateOrder(OrderManager.java:2557)
For example this could happen if you update your order in your JSP page.
<dsp:setvalue bean=”order.foo” value=”bar” />
To fix this problem you must always make sure to update an order within a transaction like this.
Transaction tr = null;
try {
tr = ensureTransaction();
synchronized (getOrder()) {
getOrder().setFoo("bar");
try {
getOrderManager().updateOrder(order);
}
catch (Exception exc) {
processException(exc, MSG_ERROR_UPDATE_ORDER, pRequest, pResponse);
}
}
}
finally {
if (tr != null) commitTransaction(tr);
}
In some cases you might find a method is called within a transaction by another method and in other cases it is not.
public boolean handleFoo(DynamoHttpServletRequest req, DynamoHttpServletResponse res) {
Transaction tr = null;
try {
tr = ensureTransaction();
synchronized (getOrder()) {
setFoo("bar");
try {
getOrderManager().updateOrder(order);
}
catch (Exception exc) {
processException(exc, MSG_ERROR_UPDATE_ORDER, pRequest, pResponse);
}
}
return checkFormRedirect(getSuccessUrl(), getErrorUrl(), req, res);
}
finally {
if (tr != null) commitTransaction(tr);
}
}
public void setFoo(String foo) {
getOrder().setFoo(foo);
}
In the above example the handleFoo method properly updates the order within the transaction. However calling the setFoo method directly will cause a problem since the order is not updated within a transaction. To fix this you use the same pattern again to ensure the order is updated within a transaction. It is okay to do this more than once during a request.
To debug this problem you can use Eclipse to make sure that wherever you update an order is always within a transaction. You can use the debugger to find which methods are called and/or you can use the call hierarchy to find out how methods are called.
Another way to help debug this is adding JSP code similar to the one I list below. It outputs the version of the order that the form handler has and the version that is in the repository. If there is a difference then you know that the action you took before at some point updated the order outside of a transaction.
<dspel:getvalueof bean="ShoppingCartModifier.order.id" var="orderId" />
FORM HANDLER ORDER ID: ${orderId}<br/>
FORM HANDLER ORDER VERSION: <dsp:valueof bean="ShoppingCartModifier.order.version" /><br/>
<dsp:droplet name="/atg/dynamo/droplet/RQLQueryForEach">
<dsp:param name="queryRQL" value="ID IN { \"${orderId}\" }"/>
<dsp:param name="repository" value="/atg/commerce/order/OrderRepository"/>
<dsp:param name="itemDescriptor" value="order"/>
<dsp:oparam name="output">
REPOSITORY ORDER VERSION: <dsp:valueof param="element.version"/><br/>
</dsp:oparam>
</dsp:droplet>
For further reading please see Nabble – ATG Dynamo – Commerce Assist Returns and the Transaction Management section in the ATG Programming Guide.
How to Debug No Output for ATG ForEach
by Frank Kim on Jul.28, 2009, under Page Development
Today I added a feature in my shopping cart JSP page but nothing was showing up. This was because the output of ATG ForEach droplet was blanks.
To debug this I did the following steps.
- I added an empty oparam to see if the ForEach droplet thought the collection was empty.
<dsp:oparam="empty">Empty?</dsp:oparam>
It did not.
- I outputted the count in the output oparam to see if it was looping through the collection.
<dsp:oparam="output"><dsp:valueof param="count"/> <dsp:valueof param="element"/></dsp:oparam>
It was looping through the collection.
- Finally I debugged using Eclipse the ForEach code. The ForEach code can be found in <ATG>/DAS/src/Java/atg/droplet/ForEach.java.
Using the debugger I realized that the element name of the loop was being set to something else which is why <dsp:valueof param=”element”/> was blank.
It turned out that the ForEach droplet was inside another ForEach droplet and in that droplet they set the element name like this.
<dsp:param name="elementName" value="CommerceItem" />
By setting the elementName parameter to something else in my ForEach droplet and then referencing it properly I was finally able to get the expected output.
<dsp:droplet name="/atg/dynamo/droplet/ForEach"> <dsp:param name="array" param="CommerceItem.auxiliaryData.productRef.dvds"/> <dsp:param name="elementName" value="dvd" /> <dsp:oparam name="output"> <dsp:valueof param="dvd.name" /> </dsp:oparam> </dsp:droplet>
By the way ATG documentation suggests not using elementName.
elementNameandindexNameallow you to provide a parameter name other thanelementandindex, respectively. A better way to provide a different parameter name is to use thedsp:setvaluetag.
In our example we would do this instead of setting the elementName param.
<dsp:setvalue param="dvd" paramvalue="element" />
Log SQL on ATG
by Frank Kim on Jul.04, 2008, under Configuration
Dudley Zoo Sarah the Sumatran Tiger (Life Of Pi) by donebythehandsofabrokenartist
To log SQL turn on logging debug for your Repository component.
For example, set /betweengo/repository/Repository.loggingDebug to true.
Note that a lot of SQL statements are outputted. If you want to selectively turn it on and off you can put this in your JSP where you want to start logging SQL.
<dspel:setvalue bean="/betweengo/repository/Repository.loggingDebug" value="true"/>
And then put this in your JSP where you want to stop logging SQL.
<dspel:setvalue bean="/betweengo/repository/Repository.loggingDebug" value="false"/>
Note I think this solution only works if you are using a javax.sql.DataSource like in a JBoss configuration.
For ATG’s atg.service.jdbc.FakeXADataSource there are special properties for logging SQL.
| Property | Description |
|---|---|
| loggingSQLError | logs SQL exceptions as errors |
| loggingSQLWarning | logs SQL warnings received by the pool |
| loggingSQLInfo | logs SQL statements sent by the pool |
| loggingSQLDebug | logs JDBC method calls made by the pool |
For debugging purposes most of the time you will just want to set loggingSQLInfo=true.
For further reading please see Configuring ATG Data Sources for Data Import in the ATG Installation and Configuration Guide.


