Introduction to JAX-WS (#1696)

* Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611]

* Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611]

* Removed unnecessary comment

* Added mockito-core dependency

* Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611]
Added Exception test cases

* Applied baeldung formatter in Eclipse

* Merged from https://github.com/eugenp/tutorials
Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611]

* Revert "Merged from https://github.com/eugenp/tutorials"

This reverts commit 74447a163b9e3f244a2578315fbdb525d20cd16b.

* Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611]

* Removed mockito version from properties

* Introduction to JAX-WS[http://jira.baeldung.com/browse/BAEL-611]
This commit is contained in:
Eunice A. Obugyei 2017-04-25 04:55:34 +00:00 committed by Sunil Mogadati
parent c10f709e17
commit a7b7ccad2d
15 changed files with 294 additions and 33 deletions

View File

@ -0,0 +1,25 @@
package com.baeldung.jaxws.client;
import com.baeldung.jaxws.server.bottomup.EmployeeService;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;
import java.net.URL;
public class EmployeeServiceClient {
public static void main(String[] args) throws Exception {
URL url = new URL("http://localhost:8081/employeeservice?wsdl");
QName qname = new QName("http://bottomup.server.jaxws.baeldung.com/", "EmployeeServiceImplService");
Service service = Service.create(url, qname);
EmployeeService employeeService = service.getPort(EmployeeService.class);
employeeService.countEmployees();
System.out.println(employeeService.countEmployees());
}
}

View File

@ -1,12 +0,0 @@
package com.baeldung.jaxws.config;
import javax.xml.ws.Endpoint;
import com.baeldung.jaxws.EmployeeServiceImpl;
public class EmployeeServicePublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/employeeservice", new EmployeeServiceImpl());
}
}

View File

@ -1,13 +1,13 @@
package com.baeldung.jaxws;
package com.baeldung.jaxws.server.bottomup;
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebService;
import com.baeldung.jaxws.exception.EmployeeAlreadyExists;
import com.baeldung.jaxws.exception.EmployeeNotFound;
import com.baeldung.jaxws.model.Employee;
import com.baeldung.jaxws.server.bottomup.exception.EmployeeAlreadyExists;
import com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound;
import com.baeldung.jaxws.server.bottomup.model.Employee;
@WebService
public interface EmployeeService {

View File

@ -1,4 +1,4 @@
package com.baeldung.jaxws;
package com.baeldung.jaxws.server.bottomup;
import java.util.List;
@ -6,12 +6,12 @@ import javax.inject.Inject;
import javax.jws.WebMethod;
import javax.jws.WebService;
import com.baeldung.jaxws.exception.EmployeeAlreadyExists;
import com.baeldung.jaxws.exception.EmployeeNotFound;
import com.baeldung.jaxws.model.Employee;
import com.baeldung.jaxws.repository.EmployeeRepository;
import com.baeldung.jaxws.server.bottomup.exception.EmployeeAlreadyExists;
import com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound;
import com.baeldung.jaxws.server.bottomup.model.Employee;
import com.baeldung.jaxws.server.repository.EmployeeRepository;
@WebService(serviceName = "EmployeeService", endpointInterface = "com.baeldung.jaxws.EmployeeService")
@WebService(serviceName = "EmployeeService", endpointInterface = "com.baeldung.jaxws.server.bottomup.EmployeeService")
public class EmployeeServiceImpl implements EmployeeService {
@Inject

View File

@ -1,4 +1,4 @@
package com.baeldung.jaxws.exception;
package com.baeldung.jaxws.server.bottomup.exception;
import javax.xml.ws.WebFault;

View File

@ -1,4 +1,4 @@
package com.baeldung.jaxws.exception;
package com.baeldung.jaxws.server.bottomup.exception;
import javax.xml.ws.WebFault;

View File

@ -1,4 +1,4 @@
package com.baeldung.jaxws.model;
package com.baeldung.jaxws.server.bottomup.model;
public class Employee {
private int id;

View File

@ -0,0 +1,14 @@
package com.baeldung.jaxws.server.config;
import javax.xml.ws.Endpoint;
import com.baeldung.jaxws.server.bottomup.EmployeeServiceImpl;
import com.baeldung.jaxws.server.topdown.EmployeeServiceTopDownImpl;
public class EmployeeServicePublisher {
public static void main(String[] args) {
Endpoint.publish("http://localhost:8080/employeeservicetopdown", new EmployeeServiceTopDownImpl());
Endpoint.publish("http://localhost:8080/employeeservice", new EmployeeServiceImpl());
}
}

View File

@ -1,10 +1,10 @@
package com.baeldung.jaxws.repository;
package com.baeldung.jaxws.server.repository;
import java.util.List;
import com.baeldung.jaxws.exception.EmployeeAlreadyExists;
import com.baeldung.jaxws.exception.EmployeeNotFound;
import com.baeldung.jaxws.model.Employee;
import com.baeldung.jaxws.server.bottomup.exception.EmployeeAlreadyExists;
import com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound;
import com.baeldung.jaxws.server.bottomup.model.Employee;
public interface EmployeeRepository {

View File

@ -1,11 +1,11 @@
package com.baeldung.jaxws.repository;
package com.baeldung.jaxws.server.repository;
import java.util.ArrayList;
import java.util.List;
import com.baeldung.jaxws.exception.EmployeeAlreadyExists;
import com.baeldung.jaxws.exception.EmployeeNotFound;
import com.baeldung.jaxws.model.Employee;
import com.baeldung.jaxws.server.bottomup.exception.EmployeeAlreadyExists;
import com.baeldung.jaxws.server.bottomup.exception.EmployeeNotFound;
import com.baeldung.jaxws.server.bottomup.model.Employee;
public class EmployeeRepositoryImpl implements EmployeeRepository {
private List<Employee> employeeList;

View File

@ -0,0 +1,34 @@
package com.baeldung.jaxws.server.topdown;
import javax.jws.WebMethod;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
import javax.xml.bind.annotation.XmlSeeAlso;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.4-b01
* Generated source version: 2.2
*
*/
@WebService(name = "EmployeeServiceTopDown", targetNamespace = "http://topdown.server.jaxws.baeldung.com/")
@SOAPBinding(parameterStyle = SOAPBinding.ParameterStyle.BARE)
@XmlSeeAlso({
ObjectFactory.class
})
public interface EmployeeServiceTopDown {
/**
*
* @return
* returns int
*/
@WebMethod(action = "http://topdown.server.jaxws.baeldung.com/EmployeeServiceTopDown/countEmployees")
@WebResult(name = "countEmployeesResponse", targetNamespace = "http://topdown.server.jaxws.baeldung.com/", partName = "parameters")
public int countEmployees();
}

View File

@ -0,0 +1,19 @@
package com.baeldung.jaxws.server.topdown;
import com.baeldung.jaxws.server.repository.EmployeeRepository;
import javax.inject.Inject;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService(name = "EmployeeServiceTopDown", targetNamespace = "http://topdown.server.jaxws.baeldung.com/", endpointInterface = "com.baeldung.jaxws.server.topdown.EmployeeServiceTopDown")
public class EmployeeServiceTopDownImpl implements EmployeeServiceTopDown {
@Inject private EmployeeRepository employeeRepositoryImpl;
@WebMethod
public int countEmployees() {
return employeeRepositoryImpl.count();
}
}

View File

@ -0,0 +1,94 @@
package com.baeldung.jaxws.server.topdown;
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 javax.xml.ws.WebServiceException;
import javax.xml.ws.WebServiceFeature;
/**
* This class was generated by the JAX-WS RI.
* JAX-WS RI 2.2.4-b01
* Generated source version: 2.2
*
*/
@WebServiceClient(name = "EmployeeServiceTopDown", targetNamespace = "http://topdown.server.jaxws.baeldung.com/", wsdlLocation = "file:/Users/do-enr-lap-4/Developer/baeldung/source/tutorials/jee7/src/main/java/com/baeldung/jaxws/server/topdown/wsdl/employeeservicetopdown.wsdl")
public class EmployeeServiceTopDown_Service
extends Service
{
private final static URL EMPLOYEESERVICETOPDOWN_WSDL_LOCATION;
private final static WebServiceException EMPLOYEESERVICETOPDOWN_EXCEPTION;
private final static QName EMPLOYEESERVICETOPDOWN_QNAME = new QName("http://topdown.server.jaxws.baeldung.com/", "EmployeeServiceTopDown");
static {
URL url = null;
WebServiceException e = null;
try {
url = new URL("file:/Users/do-enr-lap-4/Developer/baeldung/source/tutorials/jee7/src/main/java/com/baeldung/jaxws/server/topdown/wsdl/employeeservicetopdown.wsdl");
} catch (MalformedURLException ex) {
e = new WebServiceException(ex);
}
EMPLOYEESERVICETOPDOWN_WSDL_LOCATION = url;
EMPLOYEESERVICETOPDOWN_EXCEPTION = e;
}
public EmployeeServiceTopDown_Service() {
super(__getWsdlLocation(), EMPLOYEESERVICETOPDOWN_QNAME);
}
public EmployeeServiceTopDown_Service(WebServiceFeature... features) {
super(__getWsdlLocation(), EMPLOYEESERVICETOPDOWN_QNAME, features);
}
public EmployeeServiceTopDown_Service(URL wsdlLocation) {
super(wsdlLocation, EMPLOYEESERVICETOPDOWN_QNAME);
}
public EmployeeServiceTopDown_Service(URL wsdlLocation, WebServiceFeature... features) {
super(wsdlLocation, EMPLOYEESERVICETOPDOWN_QNAME, features);
}
public EmployeeServiceTopDown_Service(URL wsdlLocation, QName serviceName) {
super(wsdlLocation, serviceName);
}
public EmployeeServiceTopDown_Service(URL wsdlLocation, QName serviceName, WebServiceFeature... features) {
super(wsdlLocation, serviceName, features);
}
/**
*
* @return
* returns EmployeeServiceTopDown
*/
@WebEndpoint(name = "EmployeeServiceTopDownSOAP")
public EmployeeServiceTopDown getEmployeeServiceTopDownSOAP() {
return super.getPort(new QName("http://topdown.server.jaxws.baeldung.com/", "EmployeeServiceTopDownSOAP"), EmployeeServiceTopDown.class);
}
/**
*
* @param features
* A list of {@link javax.xml.ws.WebServiceFeature} to configure on the proxy. Supported features not in the <code>features</code> parameter will have their default values.
* @return
* returns EmployeeServiceTopDown
*/
@WebEndpoint(name = "EmployeeServiceTopDownSOAP")
public EmployeeServiceTopDown getEmployeeServiceTopDownSOAP(WebServiceFeature... features) {
return super.getPort(new QName("http://topdown.server.jaxws.baeldung.com/", "EmployeeServiceTopDownSOAP"), EmployeeServiceTopDown.class, features);
}
private static URL __getWsdlLocation() {
if (EMPLOYEESERVICETOPDOWN_EXCEPTION!= null) {
throw EMPLOYEESERVICETOPDOWN_EXCEPTION;
}
return EMPLOYEESERVICETOPDOWN_WSDL_LOCATION;
}
}

View File

@ -0,0 +1,45 @@
package com.baeldung.jaxws.server.topdown;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.annotation.XmlElementDecl;
import javax.xml.bind.annotation.XmlRegistry;
import javax.xml.namespace.QName;
/**
* This object contains factory methods for each
* Java content interface and Java element interface
* generated in the com.baeldung.jaxws.server.topdown package.
* <p>An ObjectFactory allows you to programatically
* construct new instances of the Java representation
* for XML content. The Java representation of XML
* content can consist of schema derived interfaces
* and classes representing the binding of schema
* type definitions, element declarations and model
* groups. Factory methods for each of these are
* provided in this class.
*
*/
@XmlRegistry
public class ObjectFactory {
private final static QName _CountEmployeesResponse_QNAME = new QName("http://topdown.server.jaxws.baeldung.com/", "countEmployeesResponse");
/**
* Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.baeldung.jaxws.server.topdown
*
*/
public ObjectFactory() {
}
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Integer }{@code >}}
*
*/
@XmlElementDecl(namespace = "http://topdown.server.jaxws.baeldung.com/", name = "countEmployeesResponse")
public JAXBElement<Integer> createCountEmployeesResponse(Integer value) {
return new JAXBElement<Integer>(_CountEmployeesResponse_QNAME, Integer.class, null, value);
}
}

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:tns="http://topdown.server.jaxws.baeldung.com/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://schemas.xmlsoap.org/wsdl/"
targetNamespace="http://topdown.server.jaxws.baeldung.com/"
name="EmployeeServiceTopDown">
<types>
<xsd:schema targetNamespace="http://topdown.server.jaxws.baeldung.com/">
<xsd:element name="countEmployeesResponse" type="xsd:int"/>
</xsd:schema>
</types>
<message name="countEmployees">
</message>
<message name="countEmployeesResponse">
<part name="parameters" element="tns:countEmployeesResponse"/>
</message>
<portType name="EmployeeServiceTopDown">
<operation name="countEmployees">
<input message="tns:countEmployees"/>
<output message="tns:countEmployeesResponse"/>
</operation>
</portType>
<binding name="EmployeeServiceTopDownSOAP" type="tns:EmployeeServiceTopDown">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="countEmployees">
<soap:operation soapAction="http://topdown.server.jaxws.baeldung.com/EmployeeServiceTopDown/countEmployees"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="EmployeeServiceTopDown">
<port name="EmployeeServiceTopDownSOAP" binding="tns:EmployeeServiceTopDownSOAP">
<soap:address location="http://localhost:8080/employeeservicetopdown"/>
</port>
</service>
</definitions>