Thursday, August 11, 2011

Spring Web Service Step by Step

Spring Web Service Step by Step
---------------------------------------
This tutorial will guide you through building a simple web service using spring framework. This tutorial assumes that you have gone through Tutorials 1-10 & the source code for tutorials 1-10. Also refer to spring-ws-reference.pdf (http://www.lulu.com/items/volume_62/1253000/1253871/1/print/1253871.pdf & http://static.springframework.org/spring-ws/site/reference/pdf/spring-wsreference.pdf) for further information.

Step 0: Open command prompt and the go to project base directory. Here E:\aarruunn>



Step 1: Create a project named simpleWeb1. Run the following command in a command window:
C:\aarruunn> mvn archetype:create -DarchetypeGroupId=org.springframework.ws
-DarchetypeArtifactId=spring-ws-archetype -DarchetypeVesrion=1.0.0
-DgroupId=paria.league.ws -DartifactId=simpleWeb1


Note: Maven2 archetype:create is deprecated so first command may not be worked then you get error. Please used second command.



Or
C:\ aarruunn> mvn archetype:generate
-DarchetypeGroupId=org.springframework.ws
-DarchetypeArtifactId=spring-ws-archetype -DarchetypeVesrion=1.0.0
-DgroupId=paria.league.ws -DartifactId=simpleWeb1


In second command ask for the package name verification Y:. Provide y and press enter button to create project structure.
package: paria.league.ws
Y: : y



Step 2: Now you should have the simpleWeb1 project with some basic files like pom.xml simpleWeb1 folder and web.xml, spring-ws-servlet.xml under WEB-INF folder.



Step 3: Next step is to generate eclipse metadata using the mvn command as shown below: C:\tutorials\simple-tutorial\simpleWeb2>mvn eclipse:eclipse



Step 4: Open the pom.xml file under “C:\aarruunn\simpleWeb1” in a notepad and modify it to look as shown below.

<?xml version="1.0" encoding="UTF-8"?>
<project>
<!--<parent>
<artifactId>SLAAWorkspace</artifactId>
<groupId>com.mytutorial</groupId>
<version>1.0</version>
</parent>
-->
<modelVersion>4.0.0</modelVersion>
<groupId>com.mytutorial</groupId>
<artifactId>simpleWeb1</artifactId>
<packaging>war</packaging>
<name>simpleWeb1 Spring-WS Application</name>
<version>1.0-SNAPSHOT</version>
<url>http://www.springframework.org/spring-ws</url>
<build>
<finalName>simpleWeb1</finalName>
</build>
<dependencies>
<!-- Spring web services -->
<dependency>
<artifactId>spring-xml</artifactId>
<groupId>org.springframework.ws</groupId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
</exclusion>
<exclusion>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>spring-oxm-tiger</artifactId>
<groupId>org.springframework.ws</groupId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
<exclusion>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<artifactId>spring-ws-core-tiger</artifactId>
<groupId>org.springframework.ws</groupId>
<version>1.0.0</version>
<exclusions>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.sun.xml.messaging.saaj</groupId>
<artifactId>saaj-impl</artifactId>
<version>1.3</version>
<scope>runtime</scope>
<exclusions>
<exclusion>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>jaxen</groupId>
<artifactId>jaxen</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.0.6</version>
</dependency>
</dependencies>
</project>


Note: The tags will remove any transitive dependencies you would like to exclude. Look at the .pom file as shown above for the dependencies defined and you can exclude them if you wish.

Step 5: We can now import this project into eclipse. File => Import and then



Clieck Next => Browse select simpleWeb1 project structure and OK.



Click on Finish





Step 6: Next step is to create a folder “java” for the java files under “src/main”. Right click on simpleWeb1 and select “properties”. Click on
simpleWeb1 => properties => addFolder



Click on Create New Folder provide java and Finish



Step 7: Now define the input XML file and its contract. Create a new folder “etc” under “simpleWeb1” for any miscellaneous files like “simple.xml” that are not packaged.
<simpleRequest>
<firstname>John</firstname>
<surname>Smith</surname>
</simpleRequest>



Step 8: The next step is to define the schema definition for the above xml file. The “simple.xsd” should be created under “C:\tutorials\simple-tutorial\simpleWeb2\src\main\webapp\WEBINF” as shown below:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://mytutorial.com/schemas"
xmlns="http:// paria.league.ws/schemas">
<xs:element name="firstname">
<xs:complexType mixed="true" />
</xs:element>
<xs:element name="surname">
<xs:complexType mixed="true" />
</xs:element>
<xs:element name="simpleRequest">
<xs:complexType>
<xs:sequence>
<xs:element ref="firstname" />
<xs:element ref="surname" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>



Step 9: The web.xml can remain as it is.



Step 10: With spring-ws, you do not have to define the .wsdl file. It will be automatically generated based on your simple.xsd file you just created and the simple-ws-servlet.xml (the file convention is -servlet.xml) file you are about to define.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="simpleEndPoint" class="paria.league.ws.SimpleEndPoint" />
<bean class="org.springframework.ws.server.endpoint
.mapping.PayloadRootQNameEndpointMapping">
<property name="mappings">
<props>
<prop key="simpleRequest">simpleEndPoint</prop>
</props>
</property>
<property name="interceptors">
<bean class="org.springframework.ws.server.endpoint
.interceptor.PayloadLoggingInterceptor" />
</property>
</bean>

<bean id="simple" class="org.springframework.ws.wsdl.wsdl11
.DynamicWsdl11Definition">
<property name="builder">
<bean class="org.springframework.ws.wsdl.wsdl11.builder
.XsdBasedSoap11Wsdl4jDefinitionBuilder">
<property name="schema"
value="/WEB-INF/simple.xsd" />
<property name="portTypeName" value="simple" />
<property name="locationUri"
value="http://localhost:8080/simpleWeb1/
simpleService/" />
<property name="targetNamespace"
value="http://mytutorial.com/definitions" />
</bean>
</property>
</bean>
</beans>



Step 11: The next step is to define the end point class as shown below to read the incoming XML request and construct an XML response back to the caller. Create a new package paria.league.ws under “resource” and then create the java file “SimpleEndPoint.java”.

package paria.league.ws;
import org.springframework.ws.server.endpoint.AbstractDomPayloadEndpoint;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class SimpleEndPoint extends AbstractDomPayloadEndpoint {
public SimpleEndPoint() {
System.out.println("Instantiated .............. ");
}

protected Element invokeInternal(Element simpleRequest,
Document document) throws Exception {
System.out.println("Testing End Point.......................");
String fn = simpleRequest.getElementsByTagName("firstname")
.item(0).getTextContent();
String sn = simpleRequest.getElementsByTagName("surname").item(0)
.getTextContent();
String requestText = "firstname=" + fn + " " + "surname=" + sn;
System.out.println("request is for: " + requestText);
Element responseElement = document
.createElement("simpleResponse");
responseElement.setTextContent(fn + " " + sn);
return responseElement;
}
}



Step 12: Finally we need to create a Web Services client named “Client.java” to invoke our web service.

package paria.league.ws;
import java.io.StringReader;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import org.springframework.ws.client.core.WebServiceTemplate;

public class Client {
private static final String MSG =
"<simpleRequest>
<firstname>John</firstname>
<surname>Smith</surname>
</simpleRequest>";
private static final String URL = "http://localhost:8080/simpleWeb1/simpleService/";

public static void main(String[] args) {
WebServiceTemplate template = new WebServiceTemplate();
StreamSource source = new StreamSource(new StringReader(MSG));
StreamResult result = new StreamResult(System.out);
template.sendSourceAndReceiveToResult(URL, source, result);
}
}



Step 13: Add jar files for build project.
commons-httpclient-3.1.jar
commons-logging-1.1.1.jar
spring-beans-2.5.6.jar
spring-context-2.0.4.jar
spring-core-2.5.6.jar
spring-ws-core-1.0.0.jar
spring-xml-1.0.0.jar



Step 14: Open consol and go to workspace directory and build package war file.



Step 15: Write command line build E:\SLAAWorkSpace\simpleWeb1> mvn package



Step 16: War file will be store in target folder in the project.



Step 17: Copy war file and past it in webapps directory in tomcat. Deploy the “simpleWeb1” war file into Tomcat under eclipse and start the Tomcat Server.



Step 18: start the Tomcat Server.



Step 18: Open up a browser and type the following URL http://localhost:8080/simpleWeb1/simpleService/simple.wsdl to look at the generated simple.wsdl file as shown below:



Step 18: Now run client and get the response. Right clienk on client.java =>run as =>java application



Client output



Wednesday, August 10, 2011

Tcpmon Configuration & Run Test

Tcpmon Configuration & Run Test
------------------
This is very good tool to trace web service. It works independently and also plug-in is available for eclipse.
Steps
1. Download Tcpmon (free version)
2. Install Tcpmon
3. Set environment AXIS2_HOME classpath for axis2
4. Run tcpmon



5. Provide ListenPort# : 8089
6. Set target hostname: localhost (some issue is for remote system)
7. Set Target Port# : 8080
8. Click on Sender tab



9. Provide Connection Endpoint:
http://: //services/
Example:
http://localhost:8080/AutoActivation/services/PoeticToFNOTranslationService
Note: Endpoint port should be same as Target port.
10. Click on Admin tab
11. Click on Add button. One tab will be created depends on your listener port number.
12. Now run your client.
a) Client request URL port should be Tcpmon Listner port as http://localhost:8089/AutoActivation/services/PoeticToFNOTranslationService
b) Set Axis2 class path to run your client from consol or run your client using java
-Djava.ext.dirs=..\axis2\lib command.
c) Go to your client location in using cd command
>cd E:\Dev\CLP_4_0_0\4.0.0\AAServer\Samples\JAVA\AAClientTest\build\classes
Note: for compile command
javac -sourcepath ..\src MyWebServiceClient .java -d bin/ -extdirs axis2\lib
d) Run client
> java -Djava.ext.dirs=C:\apache-tomcat-6.0.29\axis2-1.5.1\lib com.emc.act.ws.ClientMain

13. Now the result of web service


Simple Tutorial on JUNIT Configuration with Eclipse- Helios

Simple Tutorial on JUNIT Configuration with Eclipse- Helios
---------------------------------------------------------------
1. Copy the Junit.jar from the shared folder of IP 10.254.222.116/downloads to eclipse plugin folder
2. Next Right click on the eclipse Project and click on properties



3. Below Screen will pop up



4. Click on the Add library button on right side , below screen will come



5. Check the User Library and say next



6. Click on the User Libraries





7. Click on New and enter the library name.



8. Enter the library name and click on Ok button



9. Click on the name u entered and click on Add jar from the jar file u copied from eclipse plugin and say open. This creates the library .



10. After creating the user defined libraries right click the project and Say Add user libraries and say finish.



11. Now the Junit capabilities are added to the project

Create a separate package for Junit test case and create as per the below screen



Click on Next
Give the Source Folder
Package
Name
Class which you want to test by browse





Say Ok and click on finish

Your Unit test class should be --- SAMPLE CODE ---

/** */
package com.emc.slaa.ws.junit;
import static org.junit.Assert.*;
import org.junit.Test;
import com.emc.slaa.ws.HelloWorldService;

/**
* @author arun paria
*/
public class HelloWorldUnitTest {
/**
* Test method for {@link com.emc.slaa.ws.HelloWorldService#sayHelloWorld(java.lang.String)}.
*/
@Test
public void testSayHelloWorld() {

HelloWorldService hservice= new HelloWorldService();
//assertEquals("Hello World Server:Response Succee",hservice.sayHelloWorld("Hello World"));
System.out.println("JUnit o/p:"+hservice.sayHelloWorld("Hello World"));
//fail("Not yet implemented");

}
}

12. FINAL Out Put
You should get the Green color for the success .
If the unit test case is fail you will get as red.




Maven2 Step by Step

Maven2 Step by Step
------------------------------
1. Download Maven2 [apache-maven-3.0.2-src.zip] from http://maven.apache.org/download.html
2. Unzip the distribution archive, i.e. apache-maven-3.0.2-bin.zip to the directory you wish to install Maven 3.0.2. These instructions assume you chose C:\Program Files\Apache Software Foundation. The subdirectory apache-maven-3.0.2 will be created from the archive.
Note: It is binary distribution file no need to install. If you want to down load installable file then need to install maven.
3. Configure Maven
a. Windows 2000/XP
 Click on Start => My Computer
 Right click on My Computer => Properties.



 System Properties dialog will be open




 Click on Advance => Environment Variables.
 Environment Variables dialog will be open



 Click on system variable New button and add JAVA_HOME variable with value of java JDK location [C:\Program Files\Java\jdk1.6.0_17] and OK.



 Click on system variable New button and add M2_HOME variable with value of maven installation location [C:\Program Files\Apache Software Foundation\apache-maven-3.0.2] and OK.
Note: For Maven < 2.0.9, also be sure that the M2_HOME doesn't have a '\' as last character.



 Click on system variable New button and add M2 variable with value of maven bin location [%M2_HOME%\bin] and OK.



 Select Path system variable and click on Edit button and add java bin & maven bin location at the end of the path value[%M2%;%JAVA_HOME%\bin] and OK.



 Optional: In the same dialog, add the MAVEN_OPTS environment variable in the user variables to specify JVM properties, e.g. the value -Xms256m -Xmx512m. This environment variable can be used to supply extra options to Maven.
Note: It is recommended not to define. Maven internally use system java define values.
 Maven configuration completed now test the maven is working or not. Open command prompt and run mvn –version to maven installation test.



b. Unix or Linux
 Extract the distribution archive, i.e. apache-maven-3.0.2-bin.tar.gz to the directory you wish to install Maven 3.0.2. These instructions assume you chose /usr/local/apache-maven. The subdirectory apache-maven-3.0.2 will be created from the archive.
 In a command terminal, add the M2_HOME environment variable,
E.g. export M2_HOME=/usr/local/apache-maven/apache-maven-3.0.2.
 Add the M2 environment variable, e.g. export M2=$M2_HOME/bin.
 Optional: Add the MAVEN_OPTS environment variable to specify JVM properties, e.g. export MAVEN_OPTS="-Xms256m -Xmx512m". This environment variable can be used to supply extra options to Maven.
 Add M2 environment variable to your path, e.g. export PATH=$M2:$PATH.
 Make sure that JAVA_HOME is set to the location of your JDK,
E.g. export JAVA_HOME=/usr/java/jdk1.5.0_02 and that $JAVA_HOME/bin is in your PATH environment variable.
 Run mvn --version to verify that it is correctly installed.



Saturday, June 25, 2011

ShareKhan Review/Experience

ShareKhan Review/Experience

Here I Arun Paria sharing my ShareKhan experience.
ShareKhan service and administration is totally fraud. They (ShareKhan all information and admin people) always say lie and cheat & fraud. Only lie. Guys if you planning to open sharekhan demat account be-careful and open account with your own risk.

I open sharekhan site and raise request for new account. I got three sharekhan salesman calls. I met all three representatives. There are lot of gaps of all those three’s demo. I asked every one if I buy any share brokerage will be same or not. Everyone says yes which is totally wrong. I came to know this reality after opening and stated transaction.

In demo sharekhan representative describe different types of plan. I choose most simple which is classical plan and brokerage 0.5% for delivery and 0.4% for intraday. I buy share @0.95 rupees 1000 quantity. According to my transaction it will be 0.95 X 1000 = 950 and brokerage 950 X 5% = 4.5 total 955 around. But sharekhan deduct 1062.5 rupees from account it means they take brokerage charge 12.01%. I call to sharekhan office for clarification. They told me if I buy or sale any share less than 50 rupees brokerage charge will be calculated on quantity. I ask to tell me how they calculate brokerage charges for share for less than 50 rupees and more than 50 rupees. They not ask me it is there internal calculation it will not be disclose. I ask to telle-caller for my normal brokerage charge, she told me it is 1% not 0.5%. Immediate talk with sales representative who open my account, he clame that he did correct but office person change that. It is not possible to change the brokerage charge before 4 months and no possibilities return back my money. So if you do trading thy will charge brokerage 12%.

So guys understand how sharekhan cheat me. I had lost my lot of money. It is my responsibility to raise my voice against it. Please care full before go to sharekhan.

Saturday, January 1, 2011

ক্যালেন্ডার

ক্যালেন্ডার
______________ মেঘেঢাকা তারা
দেওয়াল কিংবা ক্যানভাস এখন স্মৃতি
পোস্টার কিংবা পেল্লাই ফোটো
দখল করেছে আমর জায়গা,
আমি ছোট হতে হতে এখন
টেবিলের কোনে কিংবা টিভির মাথায়
আর আধুনিকতার জোয়ারে আরও ছোট্ট
মোবাইল কিংবা তোমার ল্যাপটপে,
আমার বুকে শুধু অংকের অধ্যায়
গোল গোল দাগে ভরিয়ে দাও আমার বুক
তোমার সুখ দুঃখের দিনো লিপি দিনপঞ্জিকা-
কতো হাসি-কান্না-আনন্দ-উৎসবে
আমি তোমার দিনের সাথি, থাকি সারা বছর|

একটি বছর আগে ঠিক এই দিনটায়
কতো আনন্দে আতস বাজির রসনাই-এ
জানিয়ে ছিলে আমায় সাদর অভ্যর্থনা|
আজ শেষ লগ্নে আমি অযত্নে অবহেলিত
অস্তিত্ব হীনতায় আমার ঠিকানা এখন আস্থাকুড়ে,
সুখে দুঃখে ছিলাম তোমার চিরো সাথি হয়ে
ওসব ময়লাধরা পুরান মলিন স্মৃতি|
আজ অন্য কেউ এসেছে আমার জায়গায়
অভ্যর্থনার জোয়ারে ভেসে, থাকবে- আরও একটা বছর
নিয়ে আসুক তোমার জীবনে নতুন ছোঁয়া
নতুন বছরের নতুন শুভেচছা |