Announcement Announcement Module
Collapse
No announcement yet.
Spring WS Exception Handling Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring WS Exception Handling

    Hi,

    I was playing around with Spring WS when i encountered this problem

    My service
    HTML Code:
    	public String createSubscription(Subscription subscriptionRequest) throws CreateFailureException{
    		System.out.println("Creating subscription .....Inside Service...............");
    		
    		String response = "Subscription Created";
    		if(subscriptionRequest.getCustomer().getEmail().equals("[email protected]")){
    			System.out.println("Detecting Error");
    			
    			CreateFailureException exception = new CreateFailureException("Subscription Creation has failed");
    			exception.setErrorCause("Junk Email Provided");
    			exception.setErrorNumber("ATX-FATAL-CL1287");
    			throw exception ;
    			
       	}
    		
    		return  response;
    	}
    throws a CreateFailureException and i populate details to the exception here.

    The idea is that when i generate a SOAP fault out of this (in my exception resolver) , i can put these details into the SOAP Fault Detail element.

    My Exception Resolver

    HTML Code:
    public class CustomFaultMappingResolver extends
    		SoapFaultMappingExceptionResolver {
    
    	private String FAULT_NAME = "SubscriptionFault";
    
    	private String FAULT_PREFIX = "tns";
    	
    	private Marshaller marshaller;
    
    	protected void customizeFault(Object endpoint, Exception exception,
    			SoapFault soapFault) {
    
    		CreateFailureException createException = (CreateFailureException)exception; 
    		
    ....
    Since, the exception being thrown by my service is CreateFailureException i would assume that at runtime it would be safe to cast it to the same in the exception resolver(to extract the values set earlier)..but instead this gives me the following exception when i invoke the service..(failing during the creation of endpoint invocation chain i think)

    HTML Code:
    ava.lang.ClassCastException: java.lang.IllegalStateException
    	at com.dj.cmg.commerce.subscription.spring.exceptionresolver.CustomFaultMappingResolver.customizeFault(CustomFaultMappingResolver.java:33)
    	at org.springframework.ws.soap.server.endpoint.AbstractSoapFaultDefinitionExceptionResolver.resolveExceptionInternal(AbstractSoapFaultDefinitionExceptionResolver.java:95)
    	at org.springframework.ws.server.endpoint.AbstractEndpointExceptionResolver.resolveException(AbstractEndpointExceptionResolver.java:81)
    	at org.springframework.ws.server.MessageDispatcher.processEndpointException(MessageDispatcher.java:308)
    	at org.springframework.ws.server.MessageDispatcher.dispatch(MessageDispatcher.java:229)
    	at org.springframework.ws.server.MessageDispatcher.receive(MessageDispatcher.java:162)
    	at org.springframework.ws.transport.support.WebServiceMessageReceiverObjectSupport.handleConnection(WebServiceMessageReceiverObjectSupport.java:87)
    	at org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter.handle(WebServiceMessageReceiverHandlerAdapter.java:57)
    	at org.springframework.ws.transport.http.MessageDispatcherServlet.doService(MessageDispatcherServlet.java:197)
    	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:476)
    	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:441)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
    	at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)..

    And finally my exception resolver configuration

    HTML Code:
      <bean id="exceptionResolver"
            class="com.dj.cmg.commerce.subscription.spring.exceptionresolver.CustomFaultMappingResolver">
        <property name="defaultFault" value="SERVER"></property>
        <property name="exceptionMappings">
         <props>
         <prop key="com.dj.cmg.commerce.subscription.service.CreateFailureException">Server,Subscription Processing Denied</prop>
        </props>
         </property>
        
        </bean>
    What am i missing here?..Any help shall be greatly appreciated..please feel free to recommend alternative approaches to address the same intent
Working...
X