This is an example of some simple glue code where we map some input paramters, call a spring service and translate the result (in this case the exceptions). Some kind of mapping (IMHO) is required if one starts from the WSDL, which is usually a good approach. We decided to implement the mapping "manually" in java, although more advanced mappings might make sense in more complex cases.
I actually wonder how other people out there are solving this. If somebody has a better approach, please let us know.
Code:
....
public OrderUpdateResponse updateOrder(OrderUpdateRequest orderUpdateRequest)
throws RemoteException, ProcessingException, OrderNotFoundException {
String orderId = orderUpdateRequest.getOrderId();
String message;
String newStatus;
// map the message
if (orderUpdateRequest.getMessage() != null &&
orderUpdateRequest.getMessage().length() > MAX_MESSAGE_LENGTH) {
message = orderUpdateRequest.getMessage().substring(0, MAX_MESSAGE_LENGTH);
} else {
message = orderUpdateRequest.getMessage();
}
// map the status
if (OrderStatusCode.FAILED.equals(orderUpdateRequest.getStatus())) {
newStatus = OrderStatus.FAILED;
} else if(OrderStatusCode.IN_PROVISIONING.equals(
orderUpdateRequest.getStatus())) {
newStatus = OrderStatus.IN_PROVISIONING;
} else if(OrderStatusCode.PROVISIONED.equals(orderUpdateRequest.getStatus())) {
newStatus = OrderStatus.PROVISIONED;
} else {
String errorMsg = "invalid order status requested";
if (log.isErrorEnabled()) {
log.error(errorMsg);
};
throw new RemoteException(errorMsg);
}
// now we call the operation and map the errors
try {
this.orderService_.updateStatus(orderId,newStatus,message);
} catch (....OrderNotFoundException one){
if (log.isDebugEnabled()) {
log.debug("No order has been found exception raised");
}
throw new OrderNotFoundException();
} catch (IllegalStateTransitionException igState){
if (log.isWarnEnabled()){
log.warn("Illegal State transition for order ["+orderId+"], " +
"status["+newStatus+"]");
}
throw new ProcessingException();
} catch (Exception e){
if (log.isErrorEnabled()){
log.error(e);
}
throw new ProcessingException();
}
return new OrderUpdateResponse();
}
protected void onInit() {
if (log.isDebugEnabled()) {
log.debug("-> onInit() looking up service objects from Spring");
}
this.orderService_ = (OrderService) getWebApplicationContext().getBean(
ORDER_SERVICE_NAME);
}