Tech-Freaks.in

Technically Driven To Perfection!

  • Increase font size
  • Default font size
  • Decrease font size
Home Tech Programming
Java Programming

Troubleshooting 'Order is not locked, but it should be locked' issue

E-mail Print PDF


Issue:

In the final step of check out flow, when the user clicks the order button he might be displayed with a message like ‘Order not locked but should be locked’.

Sample Logs:

[2/13/11 1:09:15:500 EST] 0000009f WC_ORDER      > 222ee85c:12e1d76ea52:-7ffb com.ibm.commerce.order.commands.PreProcessOrderCmdImpl.validateShippingAddress Entry

[2/13/11 1:09:15:500 EST] 0000009f WC_ORDER      < 222ee85c:12e1d76ea52:-7ffb com.ibm.commerce.order.commands.PreProcessOrderCmdImpl.validateShippingAddress Exit

[2/13/11 1:09:15:500 EST] 0000009f CommerceSrvr  A com.ibm.commerce.order.commands.PreProcessOrderCmdImpl performExecute CMN1022E: Order 11001 is not locked, but it should be locked.

[2/13/11 1:09:15:609 EST] 0000009f FfdcProvider  W com.ibm.ws.ffdc.impl.FfdcProvider logIncident FFDC1003I: FFDC Incident emitted on C

[2/13/11 1:09:16:078 EST] 0000009f servlet       I com.ibm.ws.webcontainer.servlet.ServletWrapper init SRVE0242I: [WC] [/webapp/wcs/stores] [/AjaxActionErrorResponse.jsp[2/13/11 1:09:15:890 EST] 0000009f bod           I   Order 11001 is not locked, but it should be locked.


Cause:

The final step of the order confirmation might be calling the Out-Of-Box OrderProcessCmdImpl. Before proceeding with the processing of the order, the command checks the state of order. In the database, it would check for ORDERS.LOCKED field. If the value of this field is 0, it would indicate that the order was not locked and ready for order confirmation.

This could happen if the call to the OrderPrepareCmdImpl got skipped. During the process of preparing the order, this command also locks(LOCKED=1) before the order can be confirmed using the OrderProcessCmdImpl.

The command invoked when the cart is access unlocks the orders (LOCKED=0). One command would be OrderItemDeleteCmdImpl which unlocks.


Solution:

  1. Understand the checkout flow and the possible skipped step which could miss the call to OrderPrepareCmdImpl.
  2. Ensure by using a workflow like check to ensure that OrderProcessCmdImpl should not be invoked before OrderPrepareCmdImpl invocation step is executed.



Last Updated on Sunday, 13 February 2011 13:06
 

Debugging MQ issues in Java code

E-mail Print PDF

While connecting to MQ using Java for pushing or getting data, we can experience issues. Generally, it is nice to understand the exact reason for exception. The exception may be during connecting to MQ queue manager or while sending / receiving error. The MQException class provides two variables which will help to zero down on the error. The two parameters are completionCode and reasonCode. The below snippet shows how the catch block is written to get the completionCode and reasonCode. It is assumed that the try block contains the MQ connectivity code.

try {
   //Some MQ connection code here
}  catch(MQException mqe) {
   System.err.println("MQ error occurred --> Completion code is " +
   mqe.completionCode + " and Reason code is " +  mqe.reasonCode);
}


The below block shows an excerpt of the error log.


..
..
MQ error occurred --> Completion code is 2 Reason code is 2025


Once you have the error logs, you can look up the reason code and completion code in the IBM MQ help. The link is provided below:

http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0m0/topic/com.ibm.mq.java.doc/constant-values.html#com.ibm.mq.MQException.MQCC_FAILED

For the above example:

The completion code 2 is MQCC_FAILED, which obviously means that something went wrong.

The reason code 2025 stands for MQRC_MAX_CONNS_LIMIT_REACHED, which means that maximum number of connections reached. A possible reason code which is hit when all the allocated MQ Queue manager connection is exhausted. A time to work with the MQ Admins guys!



Last Updated on Sunday, 11 April 2010 07:03
 

Simple Hit Counter Servlet

E-mail Print


Problem Statement:
Write a simple servlet which counts the total number of hits on itself and display it in the web page.
Assumptions:
1.The web container will not be restarted. If it is restarted or servlet destroyed, the hit counter will be reset.
2.The servlet is not loaded in a distributed environment.
We will be using this example to explain certain key concepts of servlet technology. We will also explain what will happen if the above assumption is not in place.
The below code shows a servlet which will display the number of hits on it.
Below is the excerpt from web.xml which shows the servlet registration and servlet URL mapping.
We should be able to access the servlet using the below URL:
http://localhost:8080/<contextName>/servlet/SimpleCounterServlet
Everytime the above URL is access, the hit counter shows an incremented value. You may like to try by closing the browser window and accessing from a different browser window.
Key Servlet Concept:
We were able to achieve the counter functionality using a single instance variable. Why?
1.Only one instance of the servlet is created.
2.Init() method is called only once. This explains the reason why the counter is not reset to 0 with every hit.
What will happen if the assumptions are removed?
1.If the web container is restarted, the old servlet instance will be destroyed. New servlet instance will be instantiated and init() will be called. Thus, we will lose the counter is the old servlet.
2.In a distributed environment, there may be multiple JVMs. For each node in which the web container is distributed, a different servlet instance may be created. Hence, the instance variable approach will fail.
For fixing the first issue, we could modify the servlet code to persist the hitCounter into a database or file. The init() would be loading the hitCounter from the file/database.
For fixing the second issue, we need to stored the hitCounter variable somewhere else... well, that somewhere is 'ApplicationScope'.
Try the above fixes as 'Home Work'!

Problem Statement

Write a simple servlet which counts the total number of hits on itself and display it in the web page.

Assumptions

  • The web container will not be restarted. If it is restarted or servlet destroyed, the hit counter will be reset.
  • The servlet is not loaded in a distributed environment.

We will be using this example to explain certain key concepts of servlet technology. We will also explain what will happen if the above assumption is not in place.

The below code shows a servlet which will display the number of hits on it.

package in.techfreaks.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class SimpleCounterServlet extends HttpServlet {
	//Instance variable used for counting hits on this servlet
	private int iHitCounter;
	
	/**
	 * init method just initializes the hitCounter to zero
	 */
	public void init() throws ServletException {
		iHitCounter = 0;
	}
	
	/**
	 * Work horse of this servlet
	 * Displays a welcome msg along with hitCounter
	 * Increments the hitCounter
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		 PrintWriter out =  response.getWriter();
		 
		 out.println("<h2> Welcome to SimpleCounterServlet.java </h2><p/>");
		 out.println("Hits on this servlet so far: "+ (++iHitCounter));		 
	}
	
	/**
	 * Passes the call to doGet method. 
	 * Thus, works similar to doGet
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}
}

Below is the excerpt from web.xml which shows the servlet registration and servlet URL mapping.

  ...

  <servlet>

    <servlet-name>SimpleCounterServlet</servlet-name>

    <servlet-class>in.techfreaks.servlet.SimpleCounterServlet</servlet-class>

  </servlet>

  ...

  <servlet-mapping>

    <servlet-name>SimpleCounterServlet</servlet-name>

      <url-pattern>/servlet/SimpleCounterServlet</url-pattern>

  </servlet-mapping>

  ....

We should be able to access the servlet using the below URL:

http://localhost:8080/<contextName>/servlet/SimpleCounterServlet

Everytime the above URL is access, the hit counter shows an incremented value. You may like to try by closing the browser window and accessing from a different browser window.

Key Servlet Concept

We were able to achieve the counter functionality using a single instance variable. Why?

  • Only one instance of the servlet is created
  • init() method is called only once. This explains the reason why the counter is not reset to 0 with every hit

What will happen if the assumptions are removed?

  • If the web container is restarted, the old servlet instance will be destroyed. New servlet instance will be instantiated and init() will be called. Thus, we will lose the counter is the old servlet.
  • In a distributed environment, there may be multiple JVMs. For each node in which the web container is distributed, a different servlet instance may be created. Hence, the instance variable approach will fail.

For fixing the first issue, we could modify the servlet code to persist the hitCounter into a database or file. The init() would be loading the hitCounter from the file/database.

For fixing the second issue, we need to stored the hitCounter variable somewhere else... well, that somewhere is 'ApplicationScope'.

Try the above two fixes for self study and post your solution in the comments below.


Last Updated on Tuesday, 15 September 2009 22:30
 

Check All checkbox using Jquery

E-mail Print

This article explains how Jquery can be used to implement a check all checkbox. On checking this 'check all' checkbox, all other checkboxes present in the page will be checked and when unchecked all the checkboxes will be unchecked.

The below HTML code provides such an example

<html>
 <head>
  <script type="text/javascript" src="/static/jquery-1.3.1.js"></script>
  <script type="text/javascript">
   //Gets called after the page is completely loaded
   $(document).ready( function() {
    //Get the click event of id checkAll
    $('input#checkAll').click(function(){
     //Get the state of checkAll button. 
     //We will use it later to assign it to all other checkboxes
     //See this currently points to checkAll element
     var checkAllState = this.checked;
     //Fetch all checkboxes
     $('input:checkbox').each(function() {
      //this now points to each checkbox iterated
      this.checked = checkAllState;
     });
    });
   });
  </script>
 </head>
 <body>
  <div><h2>Check All Check Box</h2></div>
  <div><input type="checkbox" id="checkAll" name="checkAll"/>&nbsp;<b>(Un)Check All Color</b></div>
  <div><input type="checkbox" name="yellow"/>&nbsp;Yellow</div>
  <div><input type="checkbox" name="green"/>&nbsp;Green</div>
  <div><input type="checkbox" name="red"/>&nbsp;Red</div>
  <div><input type="checkbox" name="blue"/>&nbsp;Blue</div>
  <div><input type="checkbox" name="pink"/>&nbsp;Pink</div>
    </body>
</html>

In the javascript section, comments are provided in line explaining the code.

Save the above code as a HTML including the Jquery lib in correct path and see the above code in action.


Last Updated on Wednesday, 09 September 2009 23:42
 

OS Troubleshooting

Joomla