Drop Down

Sunday, December 8, 2019

EmployeServiceProvider

package com.rameshit.employee;

import java.util.List;

import javax.jws.WebMethod;
import javax.jws.WebService;

@WebService
public interface EmployeeService
{
@WebMethod
Employee getEmployeesInfo(Integer eid);
//List<Employee> getAllEmployee();
}
=================================

package com.rameshit.employee;

public class Employee 
{
private int empid;
private String fname;
private String lname;
private long salary;
private String company;
private String location;
public int getEmpid() {
return empid;
}
public void setEmpid(int empid) {
this.empid = empid;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public long getSalary() {
return salary;
}
public void setSalary(long salary) {
this.salary = salary;
}
public String getCompany() {
return company;
}
public void setCompany(String company) {
this.company = company;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
}
=====================================
package com.rameshit.employee;

import javax.jws.WebService;

@WebService(endpointInterface ="com.rameshit.employee.EmployeeService")
public class EmployeeServiceImpl implements EmployeeService 
{

@Override
public Employee getEmployeesInfo(Integer eid) 
{
// DB level code ie. DAO, get values from db.
Employee emp = new Employee();
if(eid!= null && eid > 0)
{
emp.setCompany("IBM");
emp.setEmpid(555);
emp.setFname("Amit");
emp.setLname("Kumar");
emp.setLocation("Noida");
emp.setSalary((long) 98789.89);
}
return emp;
}

}
=======================================
<?xml version="1.0" encoding="UTF-8"?>

<!--
 The contents of this file are subject to the terms
 of the Common Development and Distribution License
 (the "License").  You may not use this file except
 in compliance with the License.
 You can obtain a copy of the license at
 https://jwsdp.dev.java.net/CDDLv1.0.html
 See the License for the specific language governing
 permissions and limitations under the License.
 When distributing Covered Code, include this CDDL
 HEADER in each file and include the License file at
 https://jwsdp.dev.java.net/CDDLv1.0.html  If applicable,
 add the following below this CDDL HEADER, with the
 fields enclosed by brackets "[]" replaced with your
 own identifying information: Portions Copyright [yyyy]
 [name of copyright owner]
-->

<endpoints xmlns='http://java.sun.com/xml/ns/jax-ws/ri/runtime' version='2.0'>
    <endpoint
        name='EmployeeService'
        implementation='com.rameshit.employee.EmployeeServiceImpl'
        url-pattern='/employee'/>
</endpoints>
=================================================

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
  <display-name>EmployeeServiceProvider</display-name>
<listener>
<listener-class>com.sun.xml.ws.transport.http.servlet.WSServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>JAXWSServlet</servlet-name>
<servlet-class>com.sun.xml.ws.transport.http.servlet.WSServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JAXWSServlet</servlet-name>
<url-pattern>/employee</url-pattern>
</servlet-mapping>
</web-app>
===============================================
===================================================================
****************TO GENERATE ARTIFACTS USING JAXWS**********************
--------------------------------------------------------------------------------------------------------------------
D:\JavaWorkSpace\webservices2\EmployeeServiceProvider>wsgen -d src -cp build/classes -keep -verbose com.rameshit.employee.EmployeeServiceImpl



=========================
* add jars and run it.   (http://localhost:8080/EmployeeServiceProvider/employee)
* output



=====
JARS
=====


===========PUBLISH WEBSERVICE===========


package test_webPublisher;

import javax.xml.ws.Endpoint;

import com.rameshit.employee.EmployeeServiceImpl;

public class SoapPublisher {

public static void main(String[] args)
{
  Endpoint.publish("http://localhost:8888/EmployeeServiceProvider/employee", new EmployeeServiceImpl());
  //System.out.println("SuccessFully Published. ");
  //System.out.println("RUNNING ON :   http://localhost:8888/EmployeeServiceProvider/employee");
  //System.out.println("Use: http://localhost:8888/EmployeeServiceProvider/employee?wsdl");
}

}











No comments:

Post a Comment

Java 8 Notes Pics