EJB Webservices in JBoss application server sample code

SHARE & COMMENT :

also read:

Employee Service.java
----------------------
package com.crm.services;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import com.crm.bean.Employee;
/**
* @author AnilKumar
*
*/
@WebService
@SOAPBinding(style = SOAPBinding.Style.RPC)
public interface EmployeeService {
public Employee getEmployee(long pin);
}

EmployeeServiceImpl.java
-------------------------
package com.crm.services;

import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;

import com.crm.bean.Employee;
import com.crm.model.EmployeeDAO;
import com.crm.modelinterface.cmsEmployee;
/**
* @author AnilKumar
*
*/
@Stateless
@WebService(endpointInterface = "com.crm.services.EmployeeService")
@SOAPBinding(style = SOAPBinding.Style.RPC)
public class EmployeeServiceImpl {

@WebMethod(operationName = "getEmployee")
public Employee getEmployee(@WebParam(name = "pin")
long pin) {
cmsEmployee employee2 = new EmployeeDAO();
// Employee employee2 = employeeDAO.getEmployeebyemployee(pin);

Employee employee = employee2.getEmployeebyemployee(pin);

System.out.println(employee.getFirstname());
return employee;
}

}

deploy above two classes by archieving in a jar and copy it to deploy folder of jboss then run ur jboss server with url http://localhost:8080/jbossws there u will get all ur web services running in your server. the client program will be like this

package com.crm.serviceClient;

import java.net.MalformedURLException;
import java.net.URL;

import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import javax.xml.ws.WebEndpoint;
import javax.xml.ws.WebServiceClient;

import com.crm.bean.Employee;
import com.crm.services.EmployeeService;
/**
* @author AnilKumar
*
*/
@WebServiceClient(name = "EmployeeServiceImplService", targetNamespace = "http://services.crm.com/",
wsdlLocation = "http://localhost:8080/jarfilename/EmployeeServiceImpl?wsdl")
public class EmployeeServiceClient extends Service {
protected EmployeeServiceClient(URL wsdlDocumentLocation,
QName serviceName) {
super(wsdlDocumentLocation, serviceName);
// TODO Auto-generated constructor stub
}

public EmployeeServiceClient() throws MalformedURLException {
super(new URL(
"http://localhost:8080/jarfilename/EmployeeServiceImpl?wsdl"),
new QName("http://services.crm.com/",
"EmployeeServiceImplService"));
}

@WebEndpoint
public EmployeeService getEmployeeServiceport() {
return (EmployeeService) super.getPort(new QName(
"http://services.crm.com/", "EmployeeServiceImplPort"),
EmployeeService.class);

}

public static void main(String[] args) throws MalformedURLException {

try {
EmployeeService service = new EmployeeServiceClient().getEmployeeServiceport();

if (service != null) {
System.out.println("Serrvice not null");
Employee employee1 = service.getEmployee(18);

System.out.println(employee1.getFirstname());
System.out.println(employee1.getLastname());
}

} catch (Exception e) {
e.printStackTrace();
}

}

}

Comments

comments

About Krishna Srinivasan

He is Founder and Chief Editor of JavaBeat. He has more than 8+ years of experience on developing Web applications. He writes about Spring, DOJO, JSF, Hibernate and many other emerging technologies in this blog.

Speak Your Mind

*

Close
Please support the site
By clicking any of these buttons you help our site to get better