Answer:
package com.restfulservice.coursesInfo;
import java.net.URI;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
import com.restfulservice.coursesInfo.model.Staff;
import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.representation.Form;
public class TestStaff {
public static void main(String[] args) {
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
WebResource service = client.resource(getBaseURI());
// Create one staff
Staff staff = new Staff();
staff.setStaffID(“1”);
staff.setForename(“ABC”);
staff.setSurname(“DEF”);
staff.setLocation(“XYZ”);
staff.setPhone(“12345”);
staff.setEmail(“test@test.com”);
ClientResponse response = service.path(“rest”).path(“staffs”).path(staff.getStaffID())
.accept(MediaType.APPLICATION_XML).put(ClientResponse.class, staff);
// Return code should be 201 == created resource
System.out.println(response.getStatus());
System.out.println();
// Get the Staffs
System.out.println(service.path(“rest”).path(“staffs”).accept(MediaType.TEXT_XML)
.get(String.class));
System.out.println();
// Get JSON for application
System.out.println(service.path(“rest”).path(“staffs”).accept(MediaType.APPLICATION_JSON)
.get(String.class));
System.out.println();
// Get XML for application
System.out.println(service.path(“rest”).path(“staffs”).accept(MediaType.APPLICATION_XML)
.get(String.class));
System.out.println();
// Get the Staff with id 2
System.out.println(service.path(“rest”).path(“staffs/2”).accept(MediaType.APPLICATION_XML)
.get(String.class));
System.out.println();
// delete Staff with id 3
service.path(“rest”).path(“staffs/3”).delete();
System.out.println();
// Get the all staffs, id 3 should be deleted
System.out.println(service.path(“rest”).path(“staffs”).accept(MediaType.APPLICATION_XML)
.get(String.class));
System.out.println();
// Create a Staff via A form request
Form form = new Form();
form.add(“id”, “4”);
form.add(“forename”, “wer”);
form.add(“surname”, “dfg”);
form.add(“location”, “hgf”);
form.add(“phone”, “123”);
form.add(“email”, “test@test.com”);
response = service.path(“rest”).path(“staffs”).type(MediaType.APPLICATION_FORM_URLENCODED)
.post(ClientResponse.class, form);
System.out.println(“Form response ” + response.getEntity(String.class)); // redirect
// to
// form
// page
System.out.println();
System.out.println(service.path(“rest”).path(“staffs”).accept(MediaType.APPLICATION_XML)
.get(String.class));
}
/**
* Returns Base URI
* @return URI
*/
private static URI getBaseURI() {
return UriBuilder.fromUri(“http://localhost:8081/com.restfulservice.coursesInfo”).build();
}
}
package com.soap.coursesInfo;
public class SimpleSoapWebService {
public float addition(float a, float b){
return a+b;
}
public float subtraction(float a, float b){
return a-b;
}
public float division(float a, float b){
if(b!=0){
return a/b;
}else{
return 0;
}
}
public float multiplication(float a,float b){
return a*b;
}
}
/**
* SimpleSoapWebService.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/
package com.soap.coursesInfo;
public interface SimpleSoapWebService extends java.rmi.Remote {
public float addition(float a, float b) throws java.rmi.RemoteException;
public float subtraction(float a, float b) throws java.rmi.RemoteException;
public float division(float a, float b) throws java.rmi.RemoteException;
public float multiplication(float a, float b) throws java.rmi.RemoteException;
}
package com.soap.coursesInfo;
public class SimpleSoapWebServiceProxy implements com.soap.coursesInfo.SimpleSoapWebService {
private String _endpoint = null;
private com.soap.coursesInfo.SimpleSoapWebService simpleSoapWebService = null;
public SimpleSoapWebServiceProxy() {
_initSimpleSoapWebServiceProxy();
}
public SimpleSoapWebServiceProxy(String endpoint) {
_endpoint = endpoint;
_initSimpleSoapWebServiceProxy();
}
private void _initSimpleSoapWebServiceProxy() {
try {
simpleSoapWebService = (new com.soap.coursesInfo.SimpleSoapWebServiceServiceLocator()).getSimpleSoapWebService();
if (simpleSoapWebService != null) {
if (_endpoint != null)
((javax.xml.rpc.Stub)simpleSoapWebService)._setProperty(“javax.xml.rpc.service.endpoint.address”, _endpoint);
else
_endpoint = (String)((javax.xml.rpc.Stub)simpleSoapWebService)._getProperty(“javax.xml.rpc.service.endpoint.address”);
}
}
catch (javax.xml.rpc.ServiceException serviceException) {}
}
public String getEndpoint() {
return _endpoint;
}
public void setEndpoint(String endpoint) {
_endpoint = endpoint;
if (simpleSoapWebService != null)
((javax.xml.rpc.Stub)simpleSoapWebService)._setProperty(“javax.xml.rpc.service.endpoint.address”, _endpoint);
}
public com.soap.coursesInfo.SimpleSoapWebService getSimpleSoapWebService() {
if (simpleSoapWebService == null)
_initSimpleSoapWebServiceProxy();
return simpleSoapWebService;
}
public float addition(float a, float b) throws java.rmi.RemoteException{
if (simpleSoapWebService == null)
_initSimpleSoapWebServiceProxy();
return simpleSoapWebService.addition(a, b);
}
public float subtraction(float a, float b) throws java.rmi.RemoteException{
if (simpleSoapWebService == null)
_initSimpleSoapWebServiceProxy();
return simpleSoapWebService.subtraction(a, b);
}
public float division(float a, float b) throws java.rmi.RemoteException{
if (simpleSoapWebService == null)
_initSimpleSoapWebServiceProxy();
return simpleSoapWebService.division(a, b);
}
public float multiplication(float a, float b) throws java.rmi.RemoteException{
if (simpleSoapWebService == null)
_initSimpleSoapWebServiceProxy();
return simpleSoapWebService.multiplication(a, b);
}
}
/**
* SimpleSoapWebServiceService.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/
package com.soap.coursesInfo;
public interface SimpleSoapWebServiceService extends javax.xml.rpc.Service {
public java.lang.String getSimpleSoapWebServiceAddress();
public com.soap.coursesInfo.SimpleSoapWebService getSimpleSoapWebService() throws javax.xml.rpc.ServiceException;
public com.soap.coursesInfo.SimpleSoapWebService getSimpleSoapWebService(java.net.URL portAddress) throws javax.xml.rpc.ServiceException;
}
/**
* SimpleSoapWebServiceServiceLocator.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/
package com.soap.coursesInfo;
public class SimpleSoapWebServiceServiceLocator extends org.apache.axis.client.Service implements com.soap.coursesInfo.SimpleSoapWebServiceService {
public SimpleSoapWebServiceServiceLocator() {
}
public SimpleSoapWebServiceServiceLocator(org.apache.axis.EngineConfiguration config) {
super(config);
}
public SimpleSoapWebServiceServiceLocator(java.lang.String wsdlLoc, javax.xml.namespace.QName sName) throws javax.xml.rpc.ServiceException {
super(wsdlLoc, sName);
}
// Use to get a proxy class for SimpleSoapWebService
private java.lang.String SimpleSoapWebService_address = “http://localhost:8081/com.soap.coursesInfo/services/SimpleSoapWebService”;
public java.lang.String getSimpleSoapWebServiceAddress() {
return SimpleSoapWebService_address;
}
// The WSDD service name defaults to the port name.
private java.lang.String SimpleSoapWebServiceWSDDServiceName = “SimpleSoapWebService”;
public java.lang.String getSimpleSoapWebServiceWSDDServiceName() {
return SimpleSoapWebServiceWSDDServiceName;
}
public void setSimpleSoapWebServiceWSDDServiceName(java.lang.String name) {
SimpleSoapWebServiceWSDDServiceName = name;
}
public com.soap.coursesInfo.SimpleSoapWebService getSimpleSoapWebService() throws javax.xml.rpc.ServiceException {
java.net.URL endpoint;
try {
endpoint = new java.net.URL(SimpleSoapWebService_address);
}
catch (java.net.MalformedURLException e) {
throw new javax.xml.rpc.ServiceException(e);
}
return getSimpleSoapWebService(endpoint);
}
public com.soap.coursesInfo.SimpleSoapWebService getSimpleSoapWebService(java.net.URL portAddress) throws javax.xml.rpc.ServiceException {
try {
com.soap.coursesInfo.SimpleSoapWebServiceSoapBindingStub _stub = new com.soap.coursesInfo.SimpleSoapWebServiceSoapBindingStub(portAddress, this);
_stub.setPortName(getSimpleSoapWebServiceWSDDServiceName());
return _stub;
}
catch (org.apache.axis.AxisFault e) {
return null;
}
}
public void setSimpleSoapWebServiceEndpointAddress(java.lang.String address) {
SimpleSoapWebService_address = address;
}
/**
* For the given interface, get the stub implementation.
* If this service has no port for the given interface,
* then ServiceException is thrown.
*/
public java.rmi.Remote getPort(Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
try {
if (com.soap.coursesInfo.SimpleSoapWebService.class.isAssignableFrom(serviceEndpointInterface)) {
com.soap.coursesInfo.SimpleSoapWebServiceSoapBindingStub _stub = new com.soap.coursesInfo.SimpleSoapWebServiceSoapBindingStub(new java.net.URL(SimpleSoapWebService_address), this);
_stub.setPortName(getSimpleSoapWebServiceWSDDServiceName());
return _stub;
}
}
catch (java.lang.Throwable t) {
throw new javax.xml.rpc.ServiceException(t);
}
throw new javax.xml.rpc.ServiceException(“There is no stub implementation for the interface: ” + (serviceEndpointInterface == null ? “null” : serviceEndpointInterface.getName()));
}
/**
* For the given interface, get the stub implementation.
* If this service has no port for the given interface,
* then ServiceException is thrown.
*/
public java.rmi.Remote getPort(javax.xml.namespace.QName portName, Class serviceEndpointInterface) throws javax.xml.rpc.ServiceException {
if (portName == null) {
return getPort(serviceEndpointInterface);
}
java.lang.String inputPortName = portName.getLocalPart();
if (“SimpleSoapWebService”.equals(inputPortName)) {
return getSimpleSoapWebService();
}
else {
java.rmi.Remote _stub = getPort(serviceEndpointInterface);
((org.apache.axis.client.Stub) _stub).setPortName(portName);
return _stub;
}
}
public javax.xml.namespace.QName getServiceName() {
return new javax.xml.namespace.QName(“http://staff.soap.com”, “SimpleSoapWebServiceService”);
}
private java.util.HashSet ports = null;
public java.util.Iterator getPorts() {
if (ports == null) {
ports = new java.util.HashSet();
ports.add(new javax.xml.namespace.QName(“http://staff.soap.com”, “SimpleSoapWebService”));
}
return ports.iterator();
}
/**
* Set the endpoint address for the specified port name.
*/
public void setEndpointAddress(java.lang.String portName, java.lang.String address) throws javax.xml.rpc.ServiceException {
if (“SimpleSoapWebService”.equals(portName)) {
setSimpleSoapWebServiceEndpointAddress(address);
}
else
{ // Unknown Port Name
throw new javax.xml.rpc.ServiceException(” Cannot set Endpoint Address for Unknown Port” + portName);
}
}
/**
* Set the endpoint address for the specified port name.
*/
public void setEndpointAddress(javax.xml.namespace.QName portName, java.lang.String address) throws javax.xml.rpc.ServiceException {
setEndpointAddress(portName.getLocalPart(), address);
}
}
/**
* SimpleSoapWebServiceSoapBindingStub.java
*
* This file was auto-generated from WSDL
* by the Apache Axis 1.4 Apr 22, 2006 (06:55:48 PDT) WSDL2Java emitter.
*/
package com.soap.coursesInfo;
public class SimpleSoapWebServiceSoapBindingStub extends org.apache.axis.client.Stub implements com.soap.coursesInfo.SimpleSoapWebService {
private java.util.Vector cachedSerClasses = new java.util.Vector();
private java.util.Vector cachedSerQNames = new java.util.Vector();
private java.util.Vector cachedSerFactories = new java.util.Vector();
private java.util.Vector cachedDeserFactories = new java.util.Vector();
static org.apache.axis.description.OperationDesc [] _operations;
static {
_operations = new org.apache.axis.description.OperationDesc[4];
_initOperationDesc1();
}
private static void _initOperationDesc1(){
org.apache.axis.description.OperationDesc oper;
org.apache.axis.description.ParameterDesc param;
oper = new org.apache.axis.description.OperationDesc();
oper.setName(“addition”);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName(“http://staff.soap.com”, “a”), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”), float.class, false, false);
oper.addParameter(param);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName(“http://staff.soap.com”, “b”), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”), float.class, false, false);
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”));
oper.setReturnClass(float.class);
oper.setReturnQName(new javax.xml.namespace.QName(“http://staff.soap.com”, “additionReturn”));
oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
oper.setUse(org.apache.axis.constants.Use.LITERAL);
_operations[0] = oper;
oper = new org.apache.axis.description.OperationDesc();
oper.setName(“subtraction”);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName(“http://staff.soap.com”, “a”), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”), float.class, false, false);
oper.addParameter(param);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName(“http://staff.soap.com”, “b”), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”), float.class, false, false);
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”));
oper.setReturnClass(float.class);
oper.setReturnQName(new javax.xml.namespace.QName(“http://staff.soap.com”, “subtractionReturn”));
oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
oper.setUse(org.apache.axis.constants.Use.LITERAL);
_operations[1] = oper;
oper = new org.apache.axis.description.OperationDesc();
oper.setName(“division”);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName(“http://staff.soap.com”, “a”), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”), float.class, false, false);
oper.addParameter(param);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName(“http://staff.soap.com”, “b”), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”), float.class, false, false);
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”));
oper.setReturnClass(float.class);
oper.setReturnQName(new javax.xml.namespace.QName(“http://staff.soap.com”, “divisionReturn”));
oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
oper.setUse(org.apache.axis.constants.Use.LITERAL);
_operations[2] = oper;
oper = new org.apache.axis.description.OperationDesc();
oper.setName(“multiplication”);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName(“http://staff.soap.com”, “a”), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”), float.class, false, false);
oper.addParameter(param);
param = new org.apache.axis.description.ParameterDesc(new javax.xml.namespace.QName(“http://staff.soap.com”, “b”), org.apache.axis.description.ParameterDesc.IN, new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”), float.class, false, false);
oper.addParameter(param);
oper.setReturnType(new javax.xml.namespace.QName(“http://www.w3.org/2001/XMLSchema”, “float”));
oper.setReturnClass(float.class);
oper.setReturnQName(new javax.xml.namespace.QName(“http://staff.soap.com”, “multiplicationReturn”));
oper.setStyle(org.apache.axis.constants.Style.WRAPPED);
oper.setUse(org.apache.axis.constants.Use.LITERAL);
_operations[3] = oper;
}
public SimpleSoapWebServiceSoapBindingStub() throws org.apache.axis.AxisFault {
this(null);
}
public SimpleSoapWebServiceSoapBindingStub(java.net.URL endpointURL, javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {
this(service);
super.cachedEndpoint = endpointURL;
}
public SimpleSoapWebServiceSoapBindingStub(javax.xml.rpc.Service service) throws org.apache.axis.AxisFault {
if (service == null) {
super.service = new org.apache.axis.client.Service();
} else {
super.service = service;
}
((org.apache.axis.client.Service)super.service).setTypeMappingVersion(“1.2”);
}
protected org.apache.axis.client.Call createCall() throws java.rmi.RemoteException {
try {
org.apache.axis.client.Call _call = super._createCall();
if (super.maintainSessionSet) {
_call.setMaintainSession(super.maintainSession);
}
if (super.cachedUsername != null) {
_call.setUsername(super.cachedUsername);
}
if (super.cachedPassword != null) {
_call.setPassword(super.cachedPassword);
}
if (super.cachedEndpoint != null) {
_call.setTargetEndpointAddress(super.cachedEndpoint);
}
if (super.cachedTimeout != null) {
_call.setTimeout(super.cachedTimeout);
}
if (super.cachedPortName != null) {
_call.setPortName(super.cachedPortName);
}
java.util.Enumeration keys = super.cachedProperties.keys();
while (keys.hasMoreElements()) {
java.lang.String key = (java.lang.String) keys.nextElement();
_call.setProperty(key, super.cachedProperties.get(key));
}
return _call;
}
catch (java.lang.Throwable _t) {
throw new org.apache.axis.AxisFault(“Failure trying to get the Call object”, _t);
}
}
public float addition(float a, float b) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[0]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI(“”);
_call.setEncodingStyle(null);
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
_call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName(“http://staff.soap.com”, “addition”));
setRequestHeaders(_call);
setAttachments(_call);
try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Float(a), new java.lang.Float(b)});
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachments(_call);
try {
return ((java.lang.Float) _resp).floatValue();
} catch (java.lang.Exception _exception) {
return ((java.lang.Float) org.apache.axis.utils.JavaUtils.convert(_resp, float.class)).floatValue();
}
}
} catch (org.apache.axis.AxisFault axisFaultException) {
throw axisFaultException;
}
}
public float subtraction(float a, float b) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[1]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI(“”);
_call.setEncodingStyle(null);
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
_call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName(“http://staff.soap.com”, “subtraction”));
setRequestHeaders(_call);
setAttachments(_call);
try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Float(a), new java.lang.Float(b)});
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachments(_call);
try {
return ((java.lang.Float) _resp).floatValue();
} catch (java.lang.Exception _exception) {
return ((java.lang.Float) org.apache.axis.utils.JavaUtils.convert(_resp, float.class)).floatValue();
}
}
} catch (org.apache.axis.AxisFault axisFaultException) {
throw axisFaultException;
}
}
public float division(float a, float b) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[2]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI(“”);
_call.setEncodingStyle(null);
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
_call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName(“http://staff.soap.com”, “division”));
setRequestHeaders(_call);
setAttachments(_call);
try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Float(a), new java.lang.Float(b)});
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachments(_call);
try {
return ((java.lang.Float) _resp).floatValue();
} catch (java.lang.Exception _exception) {
return ((java.lang.Float) org.apache.axis.utils.JavaUtils.convert(_resp, float.class)).floatValue();
}
}
} catch (org.apache.axis.AxisFault axisFaultException) {
throw axisFaultException;
}
}
public float multiplication(float a, float b) throws java.rmi.RemoteException {
if (super.cachedEndpoint == null) {
throw new org.apache.axis.NoEndPointException();
}
org.apache.axis.client.Call _call = createCall();
_call.setOperation(_operations[3]);
_call.setUseSOAPAction(true);
_call.setSOAPActionURI(“”);
_call.setEncodingStyle(null);
_call.setProperty(org.apache.axis.client.Call.SEND_TYPE_ATTR, Boolean.FALSE);
_call.setProperty(org.apache.axis.AxisEngine.PROP_DOMULTIREFS, Boolean.FALSE);
_call.setSOAPVersion(org.apache.axis.soap.SOAPConstants.SOAP11_CONSTANTS);
_call.setOperationName(new javax.xml.namespace.QName(“http://staff.soap.com”, “multiplication”));
setRequestHeaders(_call);
setAttachments(_call);
try { java.lang.Object _resp = _call.invoke(new java.lang.Object[] {new java.lang.Float(a), new java.lang.Float(b)});
if (_resp instanceof java.rmi.RemoteException) {
throw (java.rmi.RemoteException)_resp;
}
else {
extractAttachments(_call);
try {
return ((java.lang.Float) _resp).floatValue();
} catch (java.lang.Exception _exception) {
return ((java.lang.Float) org.apache.axis.utils.JavaUtils.convert(_resp, float.class)).floatValue();
}
}
} catch (org.apache.axis.AxisFault axisFaultException) {
throw axisFaultException;
}
}
}
package org.bean;
//import statement for JAXB for automatic conversion
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
@Entity
@XmlRootElement
public class Staff {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long staffID;
private String forename;
private String surname;
private String location;
private String phone;
private String email;
public Staff(Long staffID, String forename, String surname, String location, String phone, String email) {
super();
this.staffID = staffID;
this.forename = forename;
this.surname = surname;
this.location = location;
this.phone = phone;
this.email = email;
}
public Staff() {
// TODO Auto-generated constructor stub
}
public Long getStaffID() {
return staffID;
}
@XmlAttribute
public void setStaffID(Long staffID) {
this.staffID = staffID;
}
public String getForename() {
return forename;
}
@XmlElement
public void setForename(String forename) {
this.forename = forename;
}
public String getSurname() {
return surname;
}
@XmlElement
public void setSurname(String surname) {
this.surname = surname;
}
public String getLocation() {
return location;
}
@XmlElement
public void setLocation(String location) {
this.location = location;
}
public String getPhone() {
return phone;
}
@XmlElement
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
@XmlElement
public void setEmail(String email) {
this.email = email;
}
@Override
public String toString() {
return “StaffInfo [staffID=” + staffID + “, forename=” + forename + “, surname=” + surname + “, location=”
+ location + “, phone=” + phone + “, email=” + email + “]”;
}
}
package org.controller;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.bean.Staff;
import org.dao.StaffDao;
public class AjaxGetAllStaff extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AjaxGetAllStaff() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader(“Cache-Control”, “no-cache”);
response.setHeader(“Pragma”, “no-cache”);
String outputPage = “ajaxGetAllStaff.jsp”;
RequestDispatcher dispatcher = request.getRequestDispatcher(outputPage);
dispatcher.include(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
package org.controller;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.bean.Staff;
import org.dao.StaffDao;
public class AjaxGetStaff extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AjaxGetStaff() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader(“Cache-Control”, “no-cache”);
response.setHeader(“Pragma”, “no-cache”);
String outputPage = “ajaxGetStaff.jsp”;
RequestDispatcher dispatcher = request.getRequestDispatcher(outputPage);
dispatcher.include(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}
package org.controller;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.bean.Staff;
import org.dao.StaffDao;
public class AjaxInsertStaff extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AjaxInsertStaff() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader(“Cache-Control”, “no-cache”);
response.setHeader(“Pragma”, “no-cache”);
String outputPage = “ajaxInsertStaff.jsp”;
RequestDispatcher dispatcher = request.getRequestDispatcher(outputPage);
dispatcher.include(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
package org.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.bean.Staff;
import org.dao.StaffDao;
import org.utils.Utilities;
import com.google.appengine.labs.repackaged.org.json.JSONException;
import com.google.appengine.labs.repackaged.org.json.JSONObject;
public class ProcessAjaxGetAllStaff extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ProcessAjaxGetAllStaff() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader(“Cache-Control”, “no-cache”);
response.setHeader(“Pragma”, “no-cache”);
PrintWriter out = response.getWriter();
// pull all records from server after insertion
List<Staff> sList = new ArrayList<Staff>();
sList = StaffDao.INSTANCE.getAllStaff();
String format = request.getParameter(“format”);
request.setAttribute(“staffs”, sList);
String outputPage;
// first check that a result is retrieved
if (sList.size() == 0) {
out.println(“No Records in the Database”);
out.close();
} else if (“xml”.equals(format)) {
String output = “<?xml version=\”1.0\” encoding=\”UTF-8\”?><staffs>”;
response.setContentType(“text/xml”);
for (Staff s : sList) {
output += Utilities.jaxbObjectToXML(s);
}
output += “</staffs>”;
out.println(output);
out.close();
// There is no need to retrieve result from JSP page, just output a
// JSON Object, jQuery handles this.
} else if (“json”.equals(format)) {
response.setContentType(“application/json”);
com.google.appengine.repackaged.com.google.gson.Gson gson = new com.google.appengine.repackaged.com.google.gson.Gson();
JSONObject myObj = new JSONObject();
com.google.appengine.repackaged.com.google.gson.JsonElement staffObj = gson
.toJsonTree(sList);
try {
myObj.append(“staffInfo”, staffObj);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.println(staffObj.toString());
out.close();
} else {
response.setContentType(“text/plain”);
outputPage = “processingText.jsp”;
RequestDispatcher dispatcher = request.getRequestDispatcher(outputPage);
dispatcher.include(request, response);
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
package org.controller;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.bean.Staff;
import org.dao.Dao;
import org.dao.StaffDao;
import org.utils.Utilities;
import com.google.appengine.labs.repackaged.org.json.JSONException;
import com.google.appengine.labs.repackaged.org.json.JSONObject;
public class ProcessAjaxGetStaff extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ProcessAjaxGetStaff() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setHeader(“Cache-Control”, “no-cache”);
response.setHeader(“Pragma”, “no-cache”);
PrintWriter out = response.getWriter();
String outputPage;
String surname = request.getParameter(“surname”);
if (surname.equals(“”)) {
out.println(“Unexpected error-Javascript might be disabled”); // return
// message
// from
// server
// to
// client
// about
// this
// unexpected
// behaviour
out.close();
} else {
List<Staff> sList = new ArrayList<Staff>();
sList = StaffDao.INSTANCE.getStaff(surname);
String format = request.getParameter(“format”);
request.setAttribute(“staffs”, sList);
// first check that a result is retrieved
if (sList.size() == 0) {
out.println(“No result found for this surname”);
out.close();
}
// process result in xml if xml is chosen
else if (“xml”.equals(format)) {
String output = “<?xml version=\”1.0\” encoding=\”UTF-8\”?><staffs>”;
response.setContentType(“text/xml”);
for (Staff s : sList) {
output += Utilities.jaxbObjectToXML(s);
}
output += “</staffs>”;
out.println(output);
out.close();
// Process result in json if json is chosen
} else if (“json”.equals(format)) {
response.setContentType(“application/json”);
com.google.appengine.repackaged.com.google.gson.Gson gson = new com.google.appengine.repackaged.com.google.gson.Gson();
JSONObject myObj = new JSONObject();
com.google.appengine.repackaged.com.google.gson.JsonElement staffObj = gson
.toJsonTree(sList);
try {
myObj.append(“staffInfo”, staffObj);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
out.println(staffObj.toString());
out.close();
} else {
// otherwise send plain result to jsp page to be later loaded
// into the ajaxGetStaff.jsp
response.setContentType(“text/plain”);
outputPage = “processingText.jsp”;
RequestDispatcher dispatcher = request.getRequestDispatcher(outputPage);
dispatcher.include(request, response);
}
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
}
}