Creating a JAX –WS Web Service Using IBM RAD and WebSphere 6.1
I will discuss today creating a jax-ws web service using IBM RAD and websphere 6.1 .The theoretical parts I will cover in some other article. Today I am going to just show you all that how a jax-ws web service can be created using IBM RAD and websphere 6.1 and believe me if you are in learning phase then you will feel very happy to create web service of your own J. I will write in steps with the screen shots attached so that it will be easy for you.
Step 1:
Create a new IBM RAD Workspace. Step 2:
Create a new Dynamic Java Project named “JAXServer”. We need to enable WebService Feature pack of WAS 6.1. Follow the below snapshot.
Enter the Project name as JAXServer.
In Configuration Click on Modify Button
Select WebSphere 6.1 Feature Pack for WebServices and then press Ok. And then Click on Next and Finish.
Step 3: Create a new endpoint interface for defining our endpoint class. Right click in the src folder and add new interface and name it as “Calculator” in the com.pp package
Step 4:
Now we will define an interface for our calculator program. Write the below code in the Calculator interface.
Step 5:
Now we should define an implementing class for our interface. We should now create a class in the same package and name it as “CalculatorImpl”. This class will implement the Calculator interface and override the add method. The code that must be written inside CalculatorImpl class is given below.
package com.pp;
import javax.jws.WebService;
@WebService(endpointInterface=" com.pp.Calculator")
public class CalculatorImpl implements Calculator{
public int add(int var1, int var2) {
return var1+var2;
}
}
Now everything is explained via snapshot.
Step 6: Go to the Impl class and right click->WebServices->CreateWebService
Service Implemtation class should show the name of Impl Class. Here CalculatorImpl
Check the Option Generate WSDL file into Project
Step 7: When you click finish Wsdl will be auto genarted and you webService will be deployed. Expand the Project JAXServer and look for wsdl in wsdl folder.
Step 8:
Now validate the wsdl and Test using WebService Explorer
Step 9:
Now let us check the wsdl document that would have got generated. Type the below URL in the internet exlplorer.
This address is there in soap:address location in WSDL
Step10:
You would get the wsdl file that would have been generated for our Calculator endpoint.
Step 11:
So far we have created a service and published it. Next thing is that we must test with WebService Explorer. Right click on wsdl->WebServices->Test with WebServices Explorer
Click on the add link in under Operation
Enter the value of arg0 and arg1
For Ex : 4 and 5 I have entered
You should see the result as 9
Now you Web Service is Up and running.
Step 12: Client Creation
Create a new Dynamic Web project titled “JAXClient”. Step 13:
Now we need to create the various stubs required for accessing the service. The stubs can be auto generated. Create a package com.client and follow the diagram.
Right click on package com.client->New->Other
Under Web Services Select Web Service Client. Click on Next
Click on Browse Button of Service Definition and select the WSDL file of JAXServer Project.
Press Ok.
When you have pressed OK. You will see the below window. Verify The path and Configuration mentioned is correct or not. Server : WebSphere Application Server 6.1 WebService Runtime: IBM webSphere JAX-WS
Click on Finish. All the required files will be auto generated. See the below snapshot
Step 15:
Now Remove the WebSphere Library from the Project.
We Need only the WebSphere thin client jar for WebService Client.
Follow the below steps
Right Click on JAXClient->BuildPath->Configure Build Path
Under Libraries Tab -> Click on WebSphere Application Server 6.1. Click On Remove.
And Press OK.
When You do this all the class in client package will be marked with red sign. So we need to add thin client jar.
For me the location of thin client jaxws jar is
D:\Program Files\IBM\SDP\runtimes\base_v61\runtimes
So accordingly you need to add this
com.ibm.jaxws.thinclient_6.1.0.jar to the JAXClient by clicking on Add External Jars under Configure Build Path Option.
Step 16:
we need to create a client program that invokes the server through the stub.
Step 17:
Create a new Java class “Client” in the com.client package.
Step18:
Write the below code inside the Client class to invoke the stubs.
package com.client;
public class Client {
public static void main(String[] args) {
CalculatorImplService service = new CalculatorImplService();
Calculator calculator = service.getCalculatorImplPort();
int var1 = 20;
int var2 = 50;
int value = calculator.add(var1, var2);
System.out.println("my Web services program : ");
System.out.println(value);
}
}
Step 19:
Execute the Client.java as java Application. You would get the following output in the console
Step 20:
We have created a web service and deployed it successfully.
In the next article I am going to explain the theoretical details as well as how to create a secure web service and how any client can invoke it using certificates i.e public key.
Normalization Resolved Normalization is one of the favorite topics of interviewee. It does not matter whether you have mentioned DBMS in your resume or not .This question is going to come and the funny part is that all of us know
what is normalization?
What are the different types of normalization?
So when this question on being asked the interviewer who have already prepared for it start with the history of normalization and end with the geography of normalization but when the next question for which they have not prepared i.e. apply normalization in real case scenario.
Now here comes the real part of normalization and just because of not proper concepts, people end up confusing themselves. So the idea is to not only to get familiar with normalization but also how to apply it in real time scenario.
What is Normalization?
Database designed based on ER model may have some amount of inconsistency, ambiguity and redundancy. To resolve these issues some amount of refinement is required. This refinement process is called as Normalization. I know all of you are clear with the definition, let’s go with :
what is the need of normalization?
What are the problems we can face if we proceed without normalization?
What are the advantages of normalization?
Asking question to oneself is the best way to get familiar with all the concepts.
The need of Normalization
I am going to show you one simple E-R model database.
Student Details
Course Details
Result details
1001 Ram 11/09/1986
M4 Basic Maths 7
11/11/2004 89 A
1002 Shyam 12/08/1987
M4 Basic Maths 7
11/11/2004 78 B
1001 Ram 23/06/1987
H6 4
11/11/2004 87 A
1003 Sita 16/07/1985
C3 Basic Chemistry 11
11/11/2004 90 A
1004 Gita 24/09/1988
B3 8
11/11/2004 78 B
1002 Shyam 23/06/1988
P3 Basic Physics 13
11/11/2004 67 C
1005 Sunita 14/09/1987
P3 Basic Physics 13
11/11/2004 78 B
1003 Sita 23/10/1987
B4 5
11/11/2004 67 C
1005 Sunita 13/03/1990
H6 4
11/11/2004 56 D
1004 Gita 21/08/1987
M4 Basic Maths 7
11/11/2004 78 B
In first look the above table is looking so arranged and well in format but if we try to find out what exactly this table is saying to us , we can easily figure out the various anomalies in this table . Ok let me help you guys in finding out the same.
Insert Anomaly: We cannot insert prospective course which does not have any registered student or we cannot insert student details that is yet to register for any course.
Update Anomaly: if we want to update the course M4’s name we need to do this operation three times. Similarly we may have to update student 1003’s name twice if it changes.
Delete Anomaly: if we want to delete a course M4 , in addition to M4 occurs details , other critical details of student also will be deleted. This kind of deletion is harmful to business. Moreover, M4 appears thrice in above table and needs to be deleted thrice.
Duplicate Data: Course M4’s data is stored thrice and student 1002’s data stored twice .This redundancy will increase as the number of course offerings increases.
Process of normalization:
Before getting to know the normalization techniques in detail, let us define a few building blocks which are used to define normal form.
Determinant : Attribute X can be defined as determinant if it uniquely defines the value Y in a given relationship or entity .To qualify as determinant attribute need NOT be a key attribute .Usually dependency of attribute is represented as X->Y ,which means attribute X decides attribute Y.
Example: In RESULT relation, Marks attribute may decide the grade attribute .This is represented as Marks->grade and read as Marks decides Grade.
Marks -> Grade
In the result relation, Marks attribute is not a key attribute .Hence it can be concluded that key attributes are determinants but not all the determinants are key attributes.
Functional Dependency: Yes functional dependency has definition but let’s not care about that. Let’s try to understand the concept by example. Consider the following relation :
IName- Name of the instructor who delivered the course
Room#-Room number which is assigned to respective instructor
Marks- Scored in Course Course# by student Student #
Grade –Obtained by student Student# in course Course #
Student#,Course# together (called composite attribute) defines EXACTLY ONE value of marks .This can be symbolically represented as
Student#Course# Marks
This type of dependency is called functional dependency. In above example Marks is functionally dependent on Student#Course#.
Other Functional dependencies in above examples are:
Course# -> CourseName
Course#-> IName(Assuming one course is taught by one and only one instructor )
IName -> Room# (Assuming each instructor has his /her own and non shared room)
Marks ->Grade
Formally we can define functional dependency as: In a given relation R, X and Y are attributes. Attribute Y is functional dependent on attribute X if each value of X determines exactly one value of Y. This is represented as :
X->Y
However X may be composite in nature.
Full functional dependency: In above example Marks is fully functional dependent on student#Course# and not on the sub set of Student#Course# .This means marks cannot be determined either by student # or Course# alone .It can be determined by using Student# and Course# together. Hence Marks is fully functional dependent on student#course#.
CourseName is not fully functionally dependent on student#course# because one of the subset course# determines the course name and Student# does not having role in deciding Course name .Hence CourseName is not fully functional dependent on student #Course#.
Student#
Marks
Course#
Formal Definition of full functional dependency : In a given relation R ,X and Y are attributes. Y is fully functionally dependent on attribute X only if it is not functionally dependent on sub-set of X.However X may be composite in nature.
Partial Dependency: In the above relationship CourseName,IName,Room# are partially dependent on composite attribute Student#Course# because Course# alone can defines the coursename, IName,Room#.
Room#
IName
CourseName
Course#
Student#
Formal Definition of Partial dependency: In a given relation R, X and Y are attributes .Attribute Y is partially dependent on the attribute X only if it is dependent on subset attribute X .However X may be composite in nature.
Transitive Dependency: In above example , Room# depends on IName and in turn depends on Course# .Here Room# transitively depends on Course#.
IName
Room#
Course#
Similarly Grade depends on Marks,in turn Marks depends on Student#Course# hence Grade
Fully transitively depends on Student#Course#.
Key attributes : In a given relationship R ,if the attribute X uniquely defines all other attributes ,then the attribute X is a key attribute which is nothing but the candidate key.
Ex: Student#Course# together is a composite key attribute which determines all attributes in relationship REPORT(student#,Course#,CourseName,IName,Room#,Marks,Grade)uniquely.Hence Student# and Course# are key attributes.
Types of Normal Forms
First Normal Form(1NF)
A relation R is said to be in first normal form (1NF) if and only if all the attributes of the relation R are atomic in nature
Student Details
Course Details
Result details
1001 Ram 11/09/1986
M4 Basic Maths 7
11/11/2004 89 A
1002 Shyam 12/08/1987
M4 Basic Maths 7
11/11/2004 78 B
1001 Ram 23/06/1987
H6 4
11/11/2004 87 A
1003 Sita 16/07/1985
C3 Basic Chemistry 11
11/11/2004 90 A
1004 Gita 24/09/1988
B3 8
11/11/2004 78 B
1002 Shyam 23/06/1988
P3 Basic Physics 13
11/11/2004 67 C
1005 Sunita 14/09/1987
P3 Basic Physics 13
11/11/2004 78 B
1003 Sita 23/10/1987
B4 5
11/11/2004 67 C
1005 Sunita 13/03/1990
H6 4
11/11/2004 56 D
1004 Gita 21/08/1987
M4 Basic Maths 7
11/11/2004 78 B
Table shown above Student Details ,Course Details and Result Details can be further divided. Student Details attribute is divided into Student#(Student Number) , Student Name and date of birth. Course Details is divided into Course# ,Course Name,Prerequisites and duration. Similarly Results attribute is divided into DateOfexam,Marks and Grade.
Second Normal Form (2NF)
A relation is said to be in Second Normal Form if and only If :
It is in the first normal form ,and
No partial dependency exists between non-key attributes and key attributes.
Let us re-visit 1NF table structure.
Student# is key attribute for Student ,
Course# is key attribute for Course
Student#Course# together form the composite key attributes for result relationship.
Other attributes are non-key attributes.
To make this table 2NF compliant, we have to remove all the partial dependencies.
StudentName and DateOfBirth depends only on student#.
CourseName,PreRequisite and DurationInDays depends only on Course#
DateOfExam depends only on Course#.
To remove this partial dependency we need to split Student_Course_Result table into four separate tables ,STUDENT ,COURSE,RESULT and EXAM_DATE tables as shown in figure.
STUDENT TABLE
Student #
Student Name
DateofBirth
1001
Ram
Some value
1002
Shyam
Some value
1003
Sita
Some value
1004
Geeta
Some value
1005
Sunita
Some value
COURSE TABLE
Course#
CourseName
Duration of days
C3
Bio Chemistry
3
B3
Botany
8
P3
Nuclear Physics
1
M4
Applied Mathematics
4
H6
American History
5
B4
Zoology
9
RESULT TABLE
Student#
Course#
Marks
Grade
1001
M4
89
A
1002
M4
78
B
1001
H6
87
A
1003
C3
90
A
1004
B3
78
B
1002
P3
67
C
1005
P3
78
B
1003
B4
67
C
1005
H6
56
D
1004
M4
78
B
EXAM DATE Table
Course#
DateOfExam
M4
Some value
H6
Some value
C3
Some value
B3
Some value
P3
Some value
B4
Some value
In the first table (STUDENT) ,the key attribute is Student# and all other non-key attributes, StudentName and DateOfBirth are fully functionally dependant on the key attribute.
In the Second Table (COURSE) , Course# is the key attribute and all the non-key attributes, CourseName, DurationInDays are fully functional dependant on the key attribute.
In third table (RESULT) Student#Course# together are key attributes and all other non key attributes, Marks and Grade are fully functional dependant on the key attributes.
In the fourth Table (EXAM DATE) Course# is the key attribute and the non key attribute ,DateOfExam is fully functionally dependant on the key attribute.
At first look it appears like all our anomalies are taken away ! Now we are storing Student 1003 and M4 record only once. We can insert prospective students and courses at our will. We will update only once if we need to change any data in STUDENT,COURSE tables. We can get rid of any course or student details by deleting just one row.
Let us analyze the RESULT Table
Student#
Course#
Marks
Grade
1001
M4
89
A
1002
M4
78
B
1001
H6
87
A
1003
C3
90
A
1004
B3
78
B
1002
P3
67
C
1005
P3
78
B
1003
B4
67
C
1005
H6
56
D
1004
M4
78
B
We already concluded that :
All attributes are atomic in nature
No partial dependency exists between the key attributes and non-key attributes
RESULT table is in 2NF
Assume, at present, as per the university evaluation policy,
Students who score more than or equal to 80 marks are awarded with “A” grade
Students who score more than or equal to 70 marks up till 79 are awarded with “B” grade
Students who score more than or equal to 60 marks up till 69 are awarded with “C” grade
Students who score more than or equal to 50 marks up till 59 are awarded with “D” grade
The University management which is committed to improve the quality of education ,wants to change the existing grading system to a new grading system .In the present RESULT table structure ,
We don’t have an option to introduce new grades like A+ ,B- and E
We need to do multiple updates on the existing record to bring them to new grading definition
We will not be able to take away “D” grade if we want to.
2NF does not take care of all the anomalies and inconsistencies.
Third Normal Form (3NF)
A relation R is said to be in 3NF if and only if
It is in 2NF
No transitive dependency exists between non-key attributes and key attributes.
In the above RESULT table Student# and Course# are the key attributes. All other attributes, except grade are non-partially , non – transitively dependant on key attributes. The grade attribute is dependant on “Marks “ and in turn “Marks” is dependent on Student#Course#. To bring the table in 3NF we need to take off this transitive dependency.
Student#
Course#
Marks
1001
M4
89
1002
M4
78
1001
H6
87
1003
C3
90
1004
B3
78
1002
P3
67
1005
P3
78
1003
B4
67
1005
H6
56
1004
M4
78
UpperBound
LowerBound
Grade
100
95
A+
94
90
A
89
85
B+
84
80
B
79
75
B-
74
70
C
69
65
C-
After Normalizing tables to 3NF , we got rid of all the anomalies and inconsistencies. Now we can add new grade systems, update the existing one and delete the unwanted ones.
Hence the Third Normal form is the most optimal normal form and 99% of the databases which require efficiency in
How to search files using the “find” command in Linux If you are at *nix system, whether you are System administrator, common user, programmer or whoever; you will surely need to find file using different criteria. For that *nix system has very powerful and efficient command called “find”.
The find command is a powerful *nix utility that allows the user to find files located in the file system through various criteria such as the file name, owner, group, size, inodes, when file was last accessed, when the file status was last changed, the file's permissions, even using regular expression pattern etc.
I will try to cover maximum usage of commands that you are gonna need for any such operations. I hope after reading those examples one will easily use find command for one's problem.
Syntax for find command:
[vim]
find where-to-look criteria what-to-do
[/vim]
Instead of explaining each options and then showing you its uses with examples, better to see the use of all options while going through different examples based on various requirements.
Examples 1. Find a file "alien.coders" that exists somewhere in the file system
[vim]
$ find / -name alien.coders -print
[/vim]
If the file is found the path to the file will be printed as output. On most platforms the -print is optional, however, on some *NIX systems nothing will be printed without using print. If you don’t provide any arguments, find searches recursively through all the directories.
2.Find a file without searching network or mounted file systems
[vim]
$ find / -name alien.coders -print -xdev
[/vim]
I found it useful, when you have mounted network drives or file systems that you do not want searched (Like Windows box or other remote servers). This will surely increase the search speed greatly if the mounted file system is large or over a slow network. "-mount" does the same thing as "-xdev" to make it compatible with other versions of find.
3.Find a file without showing "Permission Denied" messages
[vim]
$ find / -name alien.coders -print 2>/dev/null
[/vim]
When find tries to search a directory or file that you do not have permission to read the message "Permission Denied" will be output to the screen. The 2>/dev/null option sends these messages to /dev/null so that the found files are easily viewed.
4.Find a file, who's name ends with .coders, within the current directory and only search 3 directories deep
[vim]
$ find . -name *.coders -maxdepth 3 -print
[/vim]
-maxdepth option allows you to specify till how much deeper you want to search for a file by specifying n digit i.e. –max depth 3 in the above example.
5.Search directories "./dir1" and "./dir2" for a file "alien.coders"
[vim]
$ find ./dir1 ./dir2 -name alien.coders -print
[/vim]
6.Search for files that are owned by the user "aliens"
[vim]
$ find /alice/in/wonderland/ -user aliens -print
[/vim]
The files output will belong to the user "aliencs". Similar criteria are -uid to search for a user by their numerical id, -group to search by a group name, and -gid to search by a group id number.
7.Find a file that is a certain type. "-type l" searches for symbolic links ( manual page of find has lot more explanation on this)
[vim]
$ find /some/directory -type l -print
[/vim]
Several types of files can be searched for:
b block (buffered) special
c character (un-buffered) special
d directory
p named pipe (FIFO)
f regular file
l symbolic link
s socket
D door (Solaris)
8.Search for directories that contains the word "alien" but do not end with ".coders"
[vim]
$ find . -name '*alien*' ! -name '*.coders' -type d -print
[/vim]
The "!" allows you to exclude results that contain the phrases following it.
9.Search files which are modified between 10 and 60 minutes:
[vim]
find . -mmin +9 -mmin -61
[/vim]
(-mmin +or – n is for minutes and –mtime + or – n is for no of days ( n*24 hours format))
(-n means less than n and +n means more than n like -9 and +61 in that example)
10.find files n days older and above certain file size
We have already seen the use of mtime and we will combine with –size option to find files which are n days older and greater than some file size in *nix. This is very common scenario for system administrator people where they need to delete some large old files to free some space in the machine.
This example of find command will find which are more than 30 days old and size greater than 1MB (1024 Kilo bytes with k option or 1024*1024 Bytes with c option instead of M and G for GB i.e. –size +1G for greater than 1Gb file size).
[vim]
find . -mtime +10 -size +1M -exec ls -l {} \;
[/vim]
11. Search files which are writable by both their owner and group:
[vim]
find . -perm -220
[/vim]
or
[vim]
find . -perm -g+w,u+w
[/vim]
The power of find find becomes extremely useful when combined with other commands. One such combination would be using find and grep together or with xargs and awk etc.
[vim]
$ find dir-path -type f -name '*.txt' -exec grep -s Aliens {} \; -print
[/vim]
This sequence uses find to look in give path for a file (-type f) with a name ending in .txt. It sends the files it finds to the grep command via the -exec option and grep searches the file found for any occurrences of the word "Aliens".
If the file is found it will be output to the screen and if the word "Aliens" is found, within one of the found files, the line that "Aliens" occurs in will also be output to the screen.
12. Find files and print those files whose name contains core.two-or-more-numeric-digits : Without Regular Expression
[vim]
find directory-path -name "core.[0-9][0-9]*[0-9]" | xargs ls -lRt | awk '{print $9}'
[/vim]
With regular expression
[vim]
find directory-path -type f -regex ".*/core\.[0-9]*" | xargs -r ls -lRt | awk '{print $9}'
[/vim]
All commands would fetch you the same result. i.e it will display the pathnames of all files in the current directory and all sub directories.
If find command doesn’t locate any matching files then it will produce no output
You may specify as many place as you wish to search the file. Ex: find /etc/dev /home/aliencoders/ . –name test
-print action lists the names of files separated by a new line or even send find’s output to xrags though pipe which separates file names using white space. So, it may cause an error if space or new line is encountered in any file name.
No issues, we have better solution. Use “-print0” instead 😀
For better format output, try to use printf similar to C programming language.
ex: find . –name ‘[!.]*’ –printf ‘Name: %10f Size: %5s \n’
Note: The ordering of find's options is important for getting the expected results as well as for performance reason.
What is the real difference between exec and xargs (Source: unix.com)?
find . -name H* -exec ls -l {} \; executes the command ls -l on each individual file.
find . -name H* | xargs ls -l constructs an argument list from the output of the find commend and passes it to ls.
Consider if the ouput of the find command produced:
H1
H2
H3
the first command would execute
ls -l H1
ls -l H2
ls -l H3
but the second would execute
ls -l H1 H2 H3
the second (xargs) is faster because xargs will collect file names and execute a command with as long as a length as possible. Often this will be just a single command.
If file name is having space then xargs will fail but exec will work because each filename is passes to exec as a single value, with special characters escaped, so it is as if the filename has been enclosed in single quotes.
For more details about how to use different arguments and options type man find
Visitor Rating: 5 Stars