• Menu
  • Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

JavaBeat

Java Tutorial Blog

  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)

EJB Webservices in JBoss application server sample code

September 25, 2008 //  by Krishna Srinivasan//  Leave a Comment

also read:

  • Java EE Tutorials
  • EJB Interview Questions
  • EJB 3 Web Services
  • Annotation and Dependency Injection in EJB 3
  • Query API in EJB 3
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();
}

}

}

Category: Java EETag: EJB, JBoss, WebServices

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.

Previous Post: « How to delete a cookie on server in a J2EE application
Next Post: What is Shale Web Framework? »

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Follow Us

  • Facebook
  • Pinterest

FEATURED TUTORIALS

New Features in Spring Boot 1.4

Difference Between @RequestParam and @PathVariable in Spring MVC

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Introductiion to Jakarta Struts

What’s new in Struts 2.0? – Struts 2.0 Framework

JavaBeat

Copyright © by JavaBeat · All rights reserved
Privacy Policy | Contact