Importend Hints

Not all service technology can the same. You can avoid problems with this hints.

  • The transfer object (method parameters and return value) must be simple Java types or JavaBeans with below restriction:
    • Default constructor
    • setter/getter methods
    • setter/getter use interfaces by lists and maps (java.util.Collection, java.util.Map) and not the implementations (e.g. java.util.ArrayList, java.util.HashMap)
    • ...
    Example - class:
    public class Customer {
    
    	private String name = null;
    	private List cars = null;
    	
    	public Customer() {
    	}
    	
    	public String getName() {
    		return this.name;
    	}
    	public void setName(String name) {
    		this.name = name;
    	}
    	
    	public List getCars() {
    		return this.cars;
    	}
    	public void setCars(List cars) {
    		this.cars = cars;
    	}
    	
    	
    }
    			
  • Prefer Datatypes:
    • java.lang.Integer
    • java.lang.Boolean
    • java.lang.String
    • java.lang.Double
    • java.lang.Date
  • Don't use overloading from service methods:
    public interface Calculator {
    
    	// FALSE
    	int add(int a, int b);
    	long add(long a, long b);
    	
    	// make two different method names
    	int addInt(int a, int b);
    	long addLong(long a, long b);	
    }
    			
  • Every service methods must have one parameter at least and a return value:
    public interface Echo {
    
    	// false
    	String ping();
    	
    	// right
    	String echo(String echoString);
    }
    			
  • How can transport logical/business/validation errors with service methods? The service method can throw a Exception that contains an additional class (container) for this errors:
    public class ValidationError implements Serializable {
    	
    	private static final long serialVersionUID = 5930253049442253128L;
    	
    	private int code = 0;
    	private String message = "No message available!";
    
    	public ValidationError() { }
    	public ValidationError(int pvCode, String pvMessage) { 
    		setCode(pvCode);
    		setMessage(pvMessage);
    	}
    	
    	public void setCode(int pvCode) { code = pvCode; }
    	public int getCode() { return code; }
    	
    	public void setMessage(String pvMessage) { message = pvMessage; }
    	public String getMessage() { return message; }
    	
    	public String toString() {
    		return code + " - " + message;
    	}
    }
    
    // and the Exception as container for the ValidationError
    
    public class MyBusinessException extends RuntimeException {
    
    	private static final long serialVersionUID = 3669006021606741955L;
    
    	private List validationErrors = new ArrayList();
    	
    	public MyBusinessException() {}
    	public MyBusinessException(String pvMessage) {
    		super(pvMessage);
    	}
    	public List getValidationErrors() { return validationErrors; }
    	public void setValidationErrors(List pvValidationErrors) { validationErrors = pvValidationErrors; }
    	
    }
    
    // and the business method signature example
    
    public interface BusinessService {
    
    
    	public Object businessServiceMethod(Object arg) throws MyBusinessException;
    }	
    	
    			
  • Don't use complex key objects by java.util.Map implementation by transfer objects.