Web Service API-Apache, Eclipse,CXF
HRServicesPOX/.classpath
HRServicesPOX/.project
HRServicesPOX org.eclipse.wst.jsdt.core.javascriptValidator org.eclipse.jdt.core.javabuilder org.eclipse.wst.common.project.facet.core.builder org.eclipse.wst.validation.validationbuilder org.eclipse.jem.workbench.JavaEMFNature org.eclipse.wst.common.modulecore.ModuleCoreNature org.eclipse.wst.common.project.facet.core.nature org.eclipse.jdt.core.javanature org.eclipse.wst.jsdt.core.jsNature
HRServicesPOX/.settings/.jsdtscope
HRServicesPOX/.settings/org.eclipse.jdt.core.prefs
eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 org.eclipse.jdt.core.compiler.compliance=1.7 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.source=1.7
HRServicesPOX/.settings/org.eclipse.jst.ws.cxf.core.prefs
eclipse.preferences.version=1 org.eclipse.jst.ws.cxf.core.runtime.version=2.6.1
HRServicesPOX/.settings/org.eclipse.wst.common.component
HRServicesPOX/.settings/org.eclipse.wst.common.project.facet.core.xml
HRServicesPOX/.settings/org.eclipse.wst.jsdt.ui.superType.container
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
HRServicesPOX/.settings/org.eclipse.wst.jsdt.ui.superType.name
Window
HRServicesPOX/build/classes/com/company/hr/Benefit.class
package com.company.hr; public synchronized class Benefit { private String empId; private String medical; private String dental; private String legal; private String lifeInsurance; public void Benefit(); public String getEmpId(); public void setEmpId(String); public String getMedical(); public void setMedical(String); public String getDental(); public void setSalary(String); public String getLegal(); public void setLegal(String); public String getLifeInsurance(); public void setLifeInsurance(String); }
HRServicesPOX/build/classes/com/company/hr/client/HRServiceClient.class
package com.company.hr.client; public final synchronized class HRServiceClient { private void HRServiceClient(); public static void main(String[]) throws Exception; }
HRServicesPOX/build/classes/com/company/hr/Employee.class
package com.company.hr; public synchronized class Employee implements java.io.Serializable { private static final long serialVersionUID = 1; private String gid; private String lastName; private String firstName; private java.util.Set privileges; private Salary salary; private Benefit benefit; public void Employee(); public Salary getSalary(); public Benefit getBenefit(); public java.util.Set getPrivileges(); public void setPrivileges(java.util.Set); public String getFirstName(); public void setFirstName(String); public String getGid(); public void setGid(String); public String getLastName(); public void setLastName(String); public boolean isUserInRole(String); }
HRServicesPOX/build/classes/com/company/hr/EmployeeDAO.class
package com.company.hr; public synchronized class EmployeeDAO { private Employee employee; public void EmployeeDAO(); public Employee getEmployee(String); }
HRServicesPOX/build/classes/com/company/hr/Salary.class
package com.company.hr; public synchronized class Salary { private String empId; private String band; private double salaryAmount; private double bonus; public void Salary(); public String getEmpId(); public void setEmpId(String); public String getBand(); public void setBand(String); public double getSalaryAmount(); public void setSalaryAmount(double); public double getBonus(); public void setBonus(double); }
HRServicesPOX/build/classes/com/company/hr/service/cxf.xml
HRServicesPOX/build/classes/com/company/hr/service/HRService.class
package com.company.hr.service; public abstract interface HRService { public abstract com.company.hr.Employee getEmployee(request.EmployeeRequest); public abstract com.company.hr.Benefit getEmployeeBenefit(request.BenefitRequest); public abstract com.company.hr.Salary getEmployeeSalary(request.SalaryRequest); }
HRServicesPOX/build/classes/com/company/hr/service/HRServiceImpl.class
package com.company.hr.service; public synchronized class HRServiceImpl implements HRService { public void HRServiceImpl(); public com.company.hr.Employee getEmployee(request.EmployeeRequest); public com.company.hr.Salary getEmployeeSalary(request.SalaryRequest); public com.company.hr.Benefit getEmployeeBenefit(request.BenefitRequest); }
HRServicesPOX/build/classes/com/company/hr/service/request/BenefitRequest.class
package com.company.hr.service.request; public synchronized class BenefitRequest { private String gid; private String lastName; private String firstName; public void BenefitRequest(); public String getGid(); public void setGid(String); public String getLastName(); public void setLastName(String); public String getFirstName(); public void setFirstName(String); }
HRServicesPOX/build/classes/com/company/hr/service/request/EmployeeRequest.class
package com.company.hr.service.request; public synchronized class EmployeeRequest { private String gid; public void EmployeeRequest(); public String getGid(); public void setGid(String); }
HRServicesPOX/build/classes/com/company/hr/service/request/SalaryRequest.class
package com.company.hr.service.request; public synchronized class SalaryRequest { private String gid; private String lastName; private String band; public void SalaryRequest(); public String getGid(); public void setGid(String); public String getLastName(); public void setLastName(String); public String getBand(); public void setBand(String); }
HRServicesPOX/src/com/company/hr/Benefit.java
HRServicesPOX/src/com/company/hr/Benefit.java
package
com
.
company
.
hr
;
public
class
Benefit
{
private
String
empId
;
private
String
medical
;
private
String
dental
;
private
String
legal
;
private
String
lifeInsurance
;
public
Benefit
()
{
empId
=
"12345"
;
medical
=
"Aetna"
;
dental
=
"Cigna"
;
legal
=
"John Hancock"
;
lifeInsurance
=
"State farm"
;
}
public
String
getEmpId
()
{
return
empId
;
}
public
void
setEmpId
(
String
empId
)
{
this
.
empId
=
empId
;
}
public
String
getMedical
()
{
return
medical
;
}
public
void
setMedical
(
String
medical
)
{
this
.
medical
=
medical
;
}
public
String
getDental
()
{
return
dental
;
}
public
void
setSalary
(
String
dental
)
{
this
.
dental
=
dental
;
}
public
String
getLegal
()
{
return
legal
;
}
public
void
setLegal
(
String
legal
)
{
this
.
legal
=
legal
;
}
public
String
getLifeInsurance
()
{
return
lifeInsurance
;
}
public
void
setLifeInsurance
(
String
lifeInsurance
)
{
this
.
lifeInsurance
=
lifeInsurance
;
}
}
HRServicesPOX/src/com/company/hr/client/HRServiceClient.java
HRServicesPOX/src/com/company/hr/client/HRServiceClient.java
package
com
.
company
.
hr
.
client
;
import
org
.
apache
.
cxf
.
interceptor
.
LoggingInInterceptor
;
import
org
.
apache
.
cxf
.
interceptor
.
LoggingOutInterceptor
;
import
org
.
apache
.
cxf
.
jaxws
.
JaxWsProxyFactoryBean
;
import
com
.
company
.
hr
.
Benefit
;
import
com
.
company
.
hr
.
Employee
;
import
com
.
company
.
hr
.
Salary
;
import
com
.
company
.
hr
.
service
.
HRService
;
import
com
.
company
.
hr
.
service
.
request
.
BenefitRequest
;
import
com
.
company
.
hr
.
service
.
request
.
EmployeeRequest
;
import
com
.
company
.
hr
.
service
.
request
.
SalaryRequest
;
public
final
class
HRServiceClient
{
private
HRServiceClient
()
{
}
public
static
void
main
(
String
args
[])
throws
Exception
{
//The following approach is called simple frontend.
//The simple frontend provides simple components or Java classes that use reflection to build and publish web services.
//The simple frontend uses factory components to create a service and the client. It does so by using Java reflection API.
//Here we get the implementation of the HRService API using the Java reflection API for implementing the Client.
JaxWsProxyFactoryBean
factory
=
new
JaxWsProxyFactoryBean
();
//Interceptors are components that intercept the messages exchanged or passed between web service clients and server components.
//In CXF, this is implemented through the concept of Interceptor chains.
//The concept of Interceptor chaining is the core functionality of CXF runtime.
//the following are Interceptors to log in and out messages.
factory
.
getInInterceptors
().
add
(
new
LoggingInInterceptor
());
factory
.
getOutInterceptors
().
add
(
new
LoggingOutInterceptor
());
//the following line is to bind for regular XML format instead of SOAP format
factory
.
setBindingId
(
"http://cxf.apache.org/bindings/xformat"
);
//Associate the intended Service Endpoint Interface
//Java Reflection will be used to generate the implementation.
factory
.
setServiceClass
(
HRService
.
class
);
factory
.
setAddress
(
"http://localhost:8080/HRServicesPOX/services/cxfHRService"
);
HRService
hrService
=
(
HRService
)
factory
.
create
();
//Now, start sending requests and accepting responses
EmployeeRequest
employeeRequest
=
new
EmployeeRequest
();
employeeRequest
.
setGid
(
"0223938"
);
Employee
employee
=
hrService
.
getEmployee
(
employeeRequest
);
System
.
out
.
println
(
"The Employee name is: "
+
employee
.
getLastName
()
+
", "
+
employee
.
getFirstName
());
SalaryRequest
salaryRequest
=
new
SalaryRequest
();
salaryRequest
.
setBand
(
"B7"
);
salaryRequest
.
setLastName
(
"Peterson"
);
salaryRequest
.
setGid
(
"12345"
);
Salary
salary
=
hrService
.
getEmployeeSalary
(
salaryRequest
);
System
.
out
.
println
(
"The Employee Salary is: "
+
salary
.
getSalaryAmount
()
+
", Band is "
+
salary
.
getBand
());
BenefitRequest
benefitRequest
=
new
BenefitRequest
();
benefitRequest
.
setFirstName
(
"Ken"
);
benefitRequest
.
setLastName
(
"Peterson"
);
benefitRequest
.
setGid
(
"12345"
);
Benefit
benefit
=
hrService
.
getEmployeeBenefit
(
benefitRequest
);
System
.
out
.
println
(
"The Employee Benefits are: Medical is from "
+
benefit
.
getMedical
()
+
", Dental is from "
+
benefit
.
getDental
());
System
.
exit
(
0
);
}
}
HRServicesPOX/src/com/company/hr/Employee.java
HRServicesPOX/src/com/company/hr/Employee.java
package
com
.
company
.
hr
;
import
java
.
io
.
Serializable
;
import
java
.
util
.
Set
;
import
javax
.
xml
.
bind
.
annotation
.
XmlElement
;
import
javax
.
xml
.
bind
.
annotation
.
XmlRootElement
;
import
javax
.
xml
.
bind
.
annotation
.
XmlAccessorType
;
import
javax
.
xml
.
bind
.
annotation
.
XmlAccessType
;
import
javax
.
xml
.
bind
.
annotation
.
XmlType
;
@
XmlRootElement
@
XmlAccessorType
(
XmlAccessType
.
FIELD
)
@
XmlType
(
name
=
""
)
public
class
Employee
implements
Serializable
{
private
static
final
long
serialVersionUID
=
1L
;
private
String
gid
;
private
String
lastName
;
private
String
firstName
;
private
Set
<
String
>
privileges
;
private
Salary
salary
=
new
Salary
();
private
Benefit
benefit
=
new
Benefit
();
public
Employee
()
{}
public
Salary
getSalary
()
{
return
salary
;
}
public
Benefit
getBenefit
()
{
return
benefit
;
}
public
Set
<
String
>
getPrivileges
()
{
return
privileges
;
}
public
void
setPrivileges
(
Set
<
String
>
privileges
)
{
this
.
privileges
=
privileges
;
}
public
String
getFirstName
()
{
return
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
public
String
getGid
()
{
return
gid
;
}
public
void
setGid
(
String
gid
)
{
this
.
gid
=
gid
;
}
public
String
getLastName
()
{
return
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
public
boolean
isUserInRole
(
String
role
)
{
if
(
privileges
==
null
)
{
return
false
;
}
else
{
return
privileges
.
contains
(
role
);
}
}
}
HRServicesPOX/src/com/company/hr/EmployeeDAO.java
HRServicesPOX/src/com/company/hr/EmployeeDAO.java
package
com
.
company
.
hr
;
import
java
.
util
.
HashSet
;
import
java
.
util
.
Set
;
import
com
.
company
.
hr
.
Employee
;
public
class
EmployeeDAO
{
private
Employee
employee
=
new
Employee
();
public
EmployeeDAO
()
{
employee
.
setFirstName
(
"John"
);
employee
.
setLastName
(
"Smith"
);
Set
privileges
=
new
HashSet
();
privileges
.
add
(
"Free Lunch"
);
employee
.
setPrivileges
(
privileges
);
employee
.
setGid
(
"0223938"
);
}
public
Employee
getEmployee
(
String
gid
)
{
return
employee
;
}
}
HRServicesPOX/src/com/company/hr/Salary.java
HRServicesPOX/src/com/company/hr/Salary.java
package
com
.
company
.
hr
;
public
class
Salary
{
private
String
empId
;
private
String
band
;
private
double
salaryAmount
=
0.0
;
private
double
bonus
=
0.0
;
public
Salary
()
{
empId
=
"12345"
;
band
=
"B7"
;
salaryAmount
=
50000.00
;
bonus
=
10.00
;
}
public
String
getEmpId
()
{
return
empId
;
}
public
void
setEmpId
(
String
empId
)
{
this
.
empId
=
empId
;
}
public
String
getBand
()
{
return
band
;
}
public
void
setBand
(
String
band
)
{
this
.
band
=
band
;
}
public
double
getSalaryAmount
()
{
return
salaryAmount
;
}
public
void
setSalaryAmount
(
double
salaryAmount
)
{
this
.
salaryAmount
=
salaryAmount
;
}
public
double
getBonus
()
{
return
bonus
;
}
public
void
setBonus
(
double
bonus
)
{
this
.
bonus
=
bonus
;
}
}
HRServicesPOX/src/com/company/hr/service/cxf.xml
HRServicesPOX/src/com/company/hr/service/HRService.java
HRServicesPOX/src/com/company/hr/service/HRService.java
package
com
.
company
.
hr
.
service
;
import
javax
.
jws
.
WebResult
;
import
javax
.
jws
.
WebService
;
import
javax
.
jws
.
WebParam
;
import
com
.
company
.
hr
.
Benefit
;
import
com
.
company
.
hr
.
Employee
;
import
com
.
company
.
hr
.
Salary
;
import
com
.
company
.
hr
.
service
.
request
.
BenefitRequest
;
import
com
.
company
.
hr
.
service
.
request
.
EmployeeRequest
;
import
com
.
company
.
hr
.
service
.
request
.
SalaryRequest
;
@
WebService
public
interface
HRService
{
@
WebResult
(
targetNamespace
=
""
,
name
=
"Employee"
)
Employee
getEmployee
(
@
WebParam
(
name
=
"EmployeeRequest"
)
EmployeeRequest
employeeRequest
);
@
WebResult
(
targetNamespace
=
""
,
name
=
"Benefit"
)
Benefit
getEmployeeBenefit
(
@
WebParam
(
name
=
"BenefitRequest"
)
BenefitRequest
benefitRequest
);
@
WebResult
(
targetNamespace
=
""
,
name
=
"Salary"
)
Salary
getEmployeeSalary
(
@
WebParam
(
name
=
"SalaryRequest"
)
SalaryRequest
salaryRequest
);
}
HRServicesPOX/src/com/company/hr/service/HRServiceImpl.java
HRServicesPOX/src/com/company/hr/service/HRServiceImpl.java
package
com
.
company
.
hr
.
service
;
import
javax
.
jws
.
WebResult
;
import
javax
.
jws
.
WebService
;
import
com
.
company
.
hr
.
Benefit
;
import
com
.
company
.
hr
.
Employee
;
import
com
.
company
.
hr
.
EmployeeDAO
;
import
com
.
company
.
hr
.
Salary
;
import
com
.
company
.
hr
.
service
.
request
.
BenefitRequest
;
import
com
.
company
.
hr
.
service
.
request
.
EmployeeRequest
;
import
com
.
company
.
hr
.
service
.
request
.
SalaryRequest
;
@
WebService
(
endpointInterface
=
"com.company.hr.service.HRService"
,
serviceName
=
"HumanResourceServices"
)
public
class
HRServiceImpl
implements
HRService
{
public
Employee
getEmployee
(
EmployeeRequest
employeeRequest
)
{
EmployeeDAO
dao
=
new
EmployeeDAO
();
return
dao
.
getEmployee
(
employeeRequest
.
getGid
());
}
public
Salary
getEmployeeSalary
(
SalaryRequest
salaryRequest
)
{
EmployeeDAO
dao
=
new
EmployeeDAO
();
return
dao
.
getEmployee
(
salaryRequest
.
getGid
()).
getSalary
();
}
public
Benefit
getEmployeeBenefit
(
BenefitRequest
benefitRequest
)
{
EmployeeDAO
dao
=
new
EmployeeDAO
();
return
dao
.
getEmployee
(
benefitRequest
.
getGid
()).
getBenefit
();
}
}
HRServicesPOX/src/com/company/hr/service/request/BenefitRequest.java
HRServicesPOX/src/com/company/hr/service/request/BenefitRequest.java
package
com
.
company
.
hr
.
service
.
request
;
public
class
BenefitRequest
{
private
String
gid
;
private
String
lastName
;
private
String
firstName
;
public
BenefitRequest
()
{}
public
String
getGid
()
{
return
gid
;
}
public
void
setGid
(
String
gid
)
{
this
.
gid
=
gid
;
}
public
String
getLastName
()
{
return
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
public
String
getFirstName
()
{
return
firstName
;
}
public
void
setFirstName
(
String
firstName
)
{
this
.
firstName
=
firstName
;
}
}
HRServicesPOX/src/com/company/hr/service/request/EmployeeRequest.java
HRServicesPOX/src/com/company/hr/service/request/EmployeeRequest.java
package
com
.
company
.
hr
.
service
.
request
;
public
class
EmployeeRequest
{
private
String
gid
;
public
EmployeeRequest
()
{}
public
String
getGid
()
{
return
gid
;
}
public
void
setGid
(
String
gid
)
{
this
.
gid
=
gid
;
}
}
HRServicesPOX/src/com/company/hr/service/request/SalaryRequest.java
HRServicesPOX/src/com/company/hr/service/request/SalaryRequest.java
package
com
.
company
.
hr
.
service
.
request
;
public
class
SalaryRequest
{
private
String
gid
;
private
String
lastName
;
private
String
band
;
public
SalaryRequest
()
{}
public
String
getGid
()
{
return
gid
;
}
public
void
setGid
(
String
gid
)
{
this
.
gid
=
gid
;
}
public
String
getLastName
()
{
return
lastName
;
}
public
void
setLastName
(
String
lastName
)
{
this
.
lastName
=
lastName
;
}
public
String
getBand
()
{
return
band
;
}
public
void
setBand
(
String
band
)
{
this
.
band
=
band
;
}
}
HRServicesPOX/WebContent/META-INF/MANIFEST.MF
Manifest-Version: 1.0 Class-Path:
HRServicesPOX/WebContent/WEB-INF/web.xml
HR Services contextConfigLocation classpath:com/company/hr/service/cxf.xml org.springframework.web.context.ContextLoaderListener CXFServlet org.apache.cxf.transport.servlet.CXFServlet CXFServlet /services/*