System Requirement:
JDK 1.7
aixs 1.1
JBOSS 4.2
eclipse kepler
Developing WEBSERVICE using
JAXWS(Java API for XML Web Service) and JBOSS Server
Create a class GetEmployee:
Service class is exposed as service class using annotation @webservice
Here method getEmployee() exposed as webmethod using
annotation @WebMethod.
package com.gps.service;
import javax.jws.WebMethod;
import
javax.jws.WebService;
@WebService
public class GetEmployee {
@WebMethod
public Employee [] getEmployee(){
Employee
employees[]={};
Employee
employee1= new Employee();
Employee
employee2= new Employee();
employee1.setName("prashant");
employee1.setLastname("S");
employee1.setEmpid(1063);
employee1.setProfession("Developer");
employee2.setName("Ramesh");
employee2.setLastname("M");
employee2.setEmpid(1063);
employee2.setProfession("Core
Developer");
employees[0]=employee1;
employees[1]=employee2;
return employees;
return employees;
}
}
Keep below entry in web.xml file
Keep below entry in web.xml file
<servlet>
<description>Employee Details
service</description>
<servlet-name>GetEmployee</servlet-name>
<servlet-class>com.gps.service.GetEmployee</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>GetEmployee</servlet-name>
<url-pattern>/GetEmployee</url-pattern>
</servlet-mapping>
Run on JBOSS Server
Generate WSDL file from service class
Below cammand can be used to generate the WSDL file from service class. This approach is called as Bottom Up approach
D:\jdk1.7.0_51\bin>wsgen -verbose -keep -cp . com.gps.service.GetEmployee -wsdl
Generated WSDL files
Generate Client class from WSDL using axis tool
Consuming service using java client
Employee.javaRun on JBOSS Server
Generate WSDL file from service class
Below cammand can be used to generate the WSDL file from service class. This approach is called as Bottom Up approach
D:\jdk1.7.0_51\bin>wsgen -verbose -keep -cp . com.gps.service.GetEmployee -wsdl
Generated WSDL files
Generate Client class from WSDL using axis tool
Consuming service using java client
GetEmployee.java
GetEmployeeBindingStub.java
GetEmployeeProxy.java
GetEmployeeService.java
GetEmployeeServiceLocator.java
package com.gps.service;
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
public class Client {
public
static void main(String[] args) throws ServiceException {
//
TODO Auto-generated method stub
GetEmployeeServiceLocator
locator= new
GetEmployeeServiceLocator(http://localhost:8080/SampleJaxws/GetEmployee);
try
{
//ServerInfoBindingStub stub = new ServerInfoBindingStub(locator);
GetEmployeeBindingStub
stub=(GetEmployeeBindingStub)locator.getPort(GetEmployeeBindingStub.class);//ServerInfoBindingStub stub = new ServerInfoBindingStub(locator);
Employee employee []=stub.getEmployee();
for
(Employee employee2 : employee) {
System.out.println(employee2.getName());
System.out.println(employee2.getLastname());
System.out.println(employee2.getProfession());
System.out.println(employee2.getEmpid());
System.out.println("***********************************");
}
}
catch (RemoteException e) {
//
TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Start JOBOSS on IP:
How to do please check below link.
http://stackoverflow.com/questions/16344333/jboss-mapping-ip-instead-of-localhost-works-from-within-eclipse-but-not-from
Run java client to check the response
Testing through SOAP UI
Testing through SOAP UI
Hi
ReplyDelete