PDA

View Full Version : Axis + Spring


akkachotu
May 9th, 2006, 02:34 PM
I am presently working with AXIS 1.3 Final for consuming and exposing java code as web services. I am new to Spring and looking for a basic hands-on tutorial that shows how to use Spring and AXIS. Can anyone please any good links and tutorials for the same.

Thank you for your time and reply.

laenzlinger
May 9th, 2006, 04:05 PM
For using axis with spring on the server side:

We are extending the ServletEndpointSupport class to have access to the spring context from within a service endpoint implementation:
http://www.springframework.org/docs/api/org/springframework/remoting/jaxrpc/ServletEndpointSupport.html

It is also mentioned in the Spring Reference Manual:
http://www.springframework.org/docs/reference/remoting.html#d0e12595

We are using a WSDL first appraoch:

1. Design the WSDL
2. Generate the Skeleton classes and the axis deployment descriptor using WSDL2Java tool.
3. Deploy the Web Service (in our case we "manually" deploy it by copying the deploy.wsdd into the server-config.wsdd of the axis servlet).
4. Implement the ServiceEndpoint: We map the skeleton objects into domain objects and call the Spring service layer and map the result back.

That's about it.

akkachotu
May 9th, 2006, 04:11 PM
Thank you for the reply.

When you say "4. Implement the ServiceEndpoint: We map the skeleton objects into domain objects and call the Spring service layer and map the result back.", can you please be more specific by pasting here the code snippets and the like.

laenzlinger
May 10th, 2006, 02:33 AM
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.


....

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(orderUpdateR equest.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);
}