• Entries (RSS)
  • Comments (RSS)

Keep the generated JSP Source file in WebSphere Application Server

Posted by | Posted in WebSphere | Posted on 30-05-2011

Tagged Under : ,

Keep the generated JSP Source file in WebSphere Application Server

We all know the location of generated Java source file from JSP in WebSphere Commerce. Suppose you are working in an WebSphere Application Server environment, not in WebSphere Commerce and you want to see the JSP source files generated by WAS. If you look in the temp directory of WebSphere, we can see only the .class files. Not the source file. WebSphere Application Server by default does not keep the generated Java source file. However we can instruct WebSphere to keep the generated Java source file in the temp directory. The location where WebSphere keeps the generated Java source file remains same. Of course you can change it, if you want to, by specifying some other configuration parameters.
Read the rest of this entry »

Creating a Hello World RESTful web service with RAD and WebSphere Application Server using IBM JAX-RS

Posted by | Posted in WebSphere | Posted on 22-05-2011

Tagged Under : , , ,

Creating a Hello World RESTful web service with RAD and WebSphere Application Server using IBM JAX-RS

REST is the buzzword now. So its time to learn how to create a RESTful web service now. Here is my simple hello world tutorial on creating a RESTful web service using Rapid Application Developer and IBM JAX-RS. JAX-RS is a Java API for developing REST applications. JAX-RS 1.0 defines a server-side component API to build REST applications. This ia an implementation of the JAX-RS (JSR 311) specification.

All the REST implementations I have seen need a minimum Java 1.5 to run. All these implementations use annotations. So my code will not work on WebSphere Application Server 6 and below versions. The minimum required version is WebSphere Application Server 6.1. I have tested these examples only in WAS 7. You need to have Feature pack for Web 2.0 for WebSphere installed on your application server. So once you have your app server ready with Web 2.0 feature pack installed then you have pretty much everything to get started. Follow the below steps to create your first hello world RESTful web service with RAD and WAS 7. For my development purposes I was using RAD 7.5. But I am sure that the following steps will work even for other RAD version too.

1. Create a Dynamic Web Project. Go to File -> New -> Other -> Web -> Dynamic Web Project. The ‘New Dynamic Web Project’ wizard opens up. Enter a name for your project and fill all the required data. The project name I used was RESTWeb.

2. We need to copy the IBM JAX-RS libraries needs to be copied to your project’s classpath.
Go to APPSERVER_ROOT/web2fep/optionalLibraries/jaxrs_1.X/ directory, and copy the following libraries to WEB-INF\lib folder of your project.

* jsr311-api.jar
* commons-lang.jar
* slf4j-api.jar
* slf4j-jdk14.jar
* ibm-wink-jaxrs.jar

If you are using a WAS 6.1 installation that does not have JAXB libraries installed, you must copy the following JAXB JAR file also to your WEB-INF\lib directory.

* ibm-jaxb-2.1.0.jar

3. Creation of the resource.
3.1. Create a Java class. I called my Java class as HelloWorld.java

	package com.albees.rest;
 
	public class HelloWorld {
 
	}

3.2 Annotate the java class to represent the relative path of the resource.

	package com.albees.rest;
 
	import javax.ws.rs.Path;
 
	@Path("/helloworld")
	public class HelloWorld {
 
	}

Here /helloworld will be the relative path to access this service.

3.3. Create the java method and annotate with GET annotation.

	package com.albees.rest;
 
	import javax.ws.rs.GET;
	import javax.ws.rs.Path;
 
	@Path("/helloworld")
	public class HelloWorld {
 
		@GET
		public String sayHello(){
			return "Hello World";
		}
	}

Whenever an HTTP GET request is received by this class, the sayHello method will be invoked as it is annotated with GET.

OK. Now we are done with the resource creation. We have a class that can be accessed with relative URL /helloworld which will return “Hello World” whenever we send an HTTP GET request.

4. Create an application configuration sub class. This class is used for returning the java JAX-RS java classes. The complete source code for the application configuration sub class is given below.

	package com.albees.rest;
 
	import java.util.HashSet;
	import java.util.Set;
 
	import javax.ws.rs.core.Application;
 
	public class HelloWorldConfig extends Application {
		public Set<Class<?>> getClasses() {
			Set<Class<?>> classes = new HashSet<Class<?>>();
			classes.add(HelloWorld.class);
			return classes;
		}
 
	}

5. Modify the web.xml.
We need to modify the web.xml so that the servlet container knows that the web application is JAX-RS supported and what are the JAX-RS classes by specifying the application configuration sub class as a parameter. My web.xml code is given below.

	<?xml version="1.0" encoding="UTF-8"?>
	<web-app id="WebApp_ID" version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
		<display-name>RESTWeb</display-name>
		<welcome-file-list>
			<welcome-file>index.html</welcome-file>
			<welcome-file>index.htm</welcome-file>
			<welcome-file>index.jsp</welcome-file>
			<welcome-file>default.html</welcome-file>
			<welcome-file>default.htm</welcome-file>
			<welcome-file>default.jsp</welcome-file>
		</welcome-file-list>
 
		<servlet>
			<servlet-name>REST</servlet-name>
			<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
			<init-param>
				<param-name>javax.ws.rs.Application</param-name>
				<param-value>com.albees.rest.HelloWorldConfig</param-value>
			</init-param>
			<load-on-startup>1</load-on-startup>
		</servlet>
		<servlet-mapping>
			<servlet-name>REST</servlet-name>
			<url-pattern>/rest/*</url-pattern>
		</servlet-mapping>
	</web-app>

We are done with our first JAX-RS RESTful Hello World web service with RAD and WebSphere Application Server. Now it is time to see our RESTful web service in action. Deploy the project in the server and access the service using the following URL.

	http://localhost:9080/RESTWeb/rest/helloworld

Where localhost is the server name and 9080 is your server’s default http port. RESTWeb is your context root and rest is the url pattern for accessing your rest web services. helloworld is the relative path of the resource.

Compiled JSP source location in WebSphere Commerce

Posted by | Posted in WebSphere Commerce | Posted on 19-05-2011

Tagged Under : , ,

Compiled JSP source location in WebSphere Commerce.

Do you know the location of the compiled JSP source file in WebSphere Commerce? WebSphere Commerce stores all the generated Java source files from the JSP, not just the class files. This is really helpful if you want to debug your JSP code, and do not know where exactly the error occurs. The location of compiled JSP source file is

WC_INSTALL_DIR\wasprofile\temp\localhost\server1\WC\Stores.war\

WC_INSTALL_DIR is the location where you have installed your WebSphere Commerce. wasprofile is the name of your WebSphere Application Server profile. In the server environments the value will be different (for me in WebSphere Commerce Developer 7, the profile location is wasprofile)

Ajax with jQuery:A sample program

Posted by | Posted in JQuery | Posted on 30-03-2011

Lets see how to use Ajax with jQuery:

For this we are using two jsp pages. One page which contains the ajax call to the other and displays the content without refreshing the page.

Our first page is Ajax.jsp which depicts Shooping books Online applciation. In this page, the user is asked to enter the value in the image and press tab to see the list of books available for shopping online. If the user enters mismatching words , he will get an error message.

Steps:

1. Load the jquery.js file

2. Add a textbox to enter the characters and a paragraph area for the items to be displayed

3. Add the jquery function which does an ajax call to names.jsp and fetches the data. If the user enter the right credentials, fetched data will be displayed.

4. Output screens


Thus we have seen a very simple example of jquery with ajax

WebSphere Commerce 7 Order Flow process for Elite B2B Starter Store

Posted by | Posted in WebSphere Commerce | Posted on 02-12-2010

Tagged Under : , , ,

WebSphere Commerce 7 Order Flow process for Elite B2B Starter Store

I was doing a POC (Proof of Concept) on ATP inventory using WCS 7. One of the minimum requirements for my POC was a successful order generation and order should be in completed state. So I published an extended site store with ATP as the inventory model. Placed an order. Everything was fine till this moment. But somehow my order was not moving to the completed state. Then I realized that I need to have some scheduled jobs in place in order to move one order state from another. In this post I will explain the complete steps required to change the order’s status to shipped state. These steps worked for me. So I believe these steps works for you too. These steps were performed on WebSphere Commerce 7 Toolkit with Fix pack 1 installed.

1. Place an order. When you add an item to the cart, the order status will be ‘P’ (Pending). Once you complete the check out process, the order status will become ‘M’ (Pending payment approval). When I placed the order, I used the payment system as ‘Simple Punchout’ so that I can approve the payment from Commerce Accelerator.

2. Approve the payment. In order to approve the payment, logon to Commerce Accelerator and select your store. If your user id has the required permissions you will be able to see a Payments menu in commerce accelerator. I always use wcsadmin as my user and I never had a permission issue. To see the payments menu the minimum required roles are Customer Representative, Customer Supervisor, Seller and Sales manager. Under Payments click on ‘List installed Payment Plugins’ submenu. The list of payment plugins installed will be presented to you.

Select the payment plugin for approving the payment. In my case since I used Simple Punchout as the payment mode, I have selected SimplePunchoutPlugin from the list of options. Now click on ‘Find Pending Payments’. This will list all the orders that are pending the authorization. Select the order you want to approve and click on Change. Enter the details required. Select the transaction result as Success and click on Finish. Now if you check the order status, it will still be displayed as ‘Pending payment approval’. Ie, even though we approved the payment, it’s still not reflected in our order status.

3. Order Payment Synchronize. Now to move the approved order to the next state, we need a scheduled job. To schedule a job in WebSphere Commerce version 7 follow the below steps.
3.1. Logon to Administration console.
3.2. Select site from site/store selection window.
3.3. Go to Configuration->Scheduler
3.4. Click on New to create a new scheduled job.
3.5. Schedule a job with the following details.
Job Name: OrderPaymentSynchronize
Interval: 1800
Job Priority: 10
Start Date: Enter today’s date
Start time: 00:00

OrderPaymentSynchronize will take the orders with the status ‘M’ and check if the order has been authorized or not. If the order is authorized it will change the status to ‘C’ (Payment Approved).

Entering the start time as 00:00 will result in running the job immediately. Now the new status will be ‘C’ (Payment Approved).

4. Release the order to fulfillment. We need another scheduled job for releasing the order for fulfillment. Create an Job at store level with the following parameters.
Job Name: ReleaseToFullfillment
Parameter: commandName=ReleaseToFulfillment&storeType_1=B2C&storeType_2=B2B&storeType_3=MHS&storeType_4=RHS&storeType_5=SHS
Interval: 1800
Job Priority: 10
Start Date: Enter today’s date
Start time: 00:00

ReleaseToFullfillment job queries orders in the following states: ‘C’, ‘M’, ‘I’, ‘B’, ‘L’, ‘A’ and if the order is ready to release to fulfillment, it changes the order status to ‘R’.

Now the status of the order will be ‘R’ (Inventory fulfilled).

5. Create a pick batch. To create a pick batch logon to commerce accelerator and go to Logistics -> Pick Batches. This window will display all the pick batches currently present in the system. In our case we need to create a new pick batch. So click on Create button. A pick batch will be created and it will be available in pick batches window.

6. Create a package. Once the pick batch is ready, the item should ship to the buyer. The packaging and shipping happens in the warehouse. To create a package, navigate to Logistics -> ‘Releases Ready to Ship’ menu of Commerce Accelerator. Select the release and click on Packages. It will list the existing packages. To create a new one, click on New button and enter the details. Once the package is created, ship the item to buyer.

7. Confirm shipment. Once the item is shipped to the buyer, we need to confirm that the shipment has been sent. To confirm the shipment, navigate to Logistics -> ‘Releases Ready to Ship’ menu of Commerce Accelerator. Select the shipment you want to confirm and click on ‘Confirm Shipment’. You will get a confirmation message saying that the shipment has been confirmed. Now the status will be changed to ‘S’(shipped).