Announcement Announcement Module
Collapse
No announcement yet.
Error Handling - Again Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error Handling - Again

    Hi, I wonder if anyone can help me please.

    I'm trying to implement thread 54166. But when I delpoy my web application I get a NoSuchBeanDefinitionException on bean 'messageHandler'.

    I'm using JavaServer Faces, on Apache and with web flow 2.0.5.

    Any help would be appreciated

    Thanks

    Nick

  • #2
    Perhaps a Copy&Paste - Error? Did you copied the code from the mentioned thread?

    Code:
    <bean id="webflowExceptionHandler" class="be.mypackage.bean.support.WebflowExceptionHandlerBean" >
    <property name="messageHandler" ref="messageHandler"/>
    </bean>
    Obviously you have no messageHandler bean defined, because your exception handler does not need it.

    Please show me the code of your exception handler.

    Comment


    • #3
      i pepe,

      I didn't post any code as I'd copied my code from thread 54166. I dont have and messageHandler bean defined. That I think is what my problem is, but I dont know how to define a messageHandler for JavaServer Faces.
      I've attached the code of the of my exception handler, correctly formatted I hope!

      Code:
      
      public class InvalidCustomer implements FlowExecutionExceptionHandler 
      {
      
      	private MessageHandler messageHandler;
      	
      	@Override
      	public boolean canHandle(FlowExecutionException ex) 
      	{
      		// TODO Auto-generated method stub
      		if (findException(ex) != null)
      		{
      			return true;
      		} else {
      			return false;
      		}
      	}
      
      	@Override
      	public void handle(FlowExecutionException ex, RequestControlContext context) 
      	{
      		// TODO Auto-generated method stub
      		System.out.println(">> handle ");
      		context.getMessageContext()
      			.addMessage(new MessageBuilder().error().source(null)
      					.defaultText(findException(ex).getMessage()).build());
      
      		context.getExternalContext().requestFlowExecutionRedirect();
      	}
      	
      	private CustomerNotFoundException findException ( FlowExecutionException ex)
      	{
      		Throwable cause = ex.getCause();
      		while (cause != null)
      		{
      			if (cause instanceof CustomerNotFoundException)
      			{
      				return (CustomerNotFoundException)cause;
      			}
      		}
      		return null;
      	}
      	public void setMessageHandler(MessageHandler msgHandler)
      	{
      		System.out.println(">> setMessageHandler ");
      		this.messageHandler = msgHandler;
      	}
      But I think that my real problem is that I haven't defined a messageHandler bean

      Regards
      Nick

      Comment


      • #4
        Hi pepe,

        I should have added the definitions I've used as well, in the flow definition I have

        Code:
        <exception-handler bean="invalidCustomer" />
        and the bean defined as

        Code:
        		<bean id="invalidCustomer" class="fujitsu.com.webflow1.InvalidCustomer" >
        
        			<property name="messageHandler" ref="messageHandler"></property>
        
        	    </bean>
        Nick

        Comment


        • #5
          I dont know why you need the messageHandler property in your ExceptionHandler. You dont use it in the code, are you?

          Comment


          • #6
            Hi pepe,

            Thanks for your quick replies. Yea, I've noticed that as well. So what I'll need to work out is why the system just hangs when I hit an exception. I know that if i dont declare the exception handler I get the normal exception screen.

            When I declare my exception handler I dont get my diagnostic message at the begining of the handle method display on the standard output and it just hangs. I've got log4j switched on but dont see anything that look useful.

            Any ideas would be appreciated

            Regards,
            Nick

            Comment


            • #7
              ah ok now i understand your problem!

              you have a bug in your while-loop. it never terminates:

              Code:
              private CustomerNotFoundException findException ( FlowExecutionException ex)
              	{
              		Throwable cause = ex.getCause();
              		while (cause != null)
              		{
              			if (cause instanceof CustomerNotFoundException)
              			{
              				return (CustomerNotFoundException)cause;
              			}
              		}
              		return null;
              	}
              What you want to do is to traverse the exception via they causes, just add:
              cause=cause.getCause();

              Code:
              private CustomerNotFoundException findException ( FlowExecutionException ex)
              	{
              		Throwable cause = ex.getCause();
              		while (cause != null)
              		{
              			if (cause instanceof CustomerNotFoundException)
              			{
              				return (CustomerNotFoundException)cause;
              			}
                                      cause=cause.getCause();
              		}
              		return null;
              	}

              Comment


              • #8
                Oops

                Hi pepe,

                Yea, I know I've just seen / found it myself. Sorry for the thread.

                Thanks for your help.

                Nick.

                Comment


                • #9
                  Hi pepe,

                  I wonder if you (or someone else) can help me further on the same problem. I'm now getting the following exception in the Spring MVC Dispatcher Servlet

                  Code:
                  java.lang.IllegalStateException: The key for the flow execution is null; make sure the key is assigned first.  Execution Details = [FlowExecutionImpl@17c398e flow = 'lookupCustomer', flowSessions = list[[FlowSessionImpl@a69b6b flow = 'lookupCustomer', state = 'lookupCustomer', scope = map[[empty]]]]]
                  My handle function contains the following

                  Code:
                  		context.getMessageContext()
                  			.addMessage(new MessageBuilder().error().source(null)
                  					.defaultText(findException(ex).getMessage()).build());
                  		Object testState = context.getCurrentState();
                  
                  		if (testState instanceof ViewState) {
                  			log.debug(" testState instanceof ViewState" );
                  		    ViewState viewState = (ViewState) testState;
                  		    try 
                  		    {
                  		    	viewState.getViewFactory().getView(context).render();
                  		    }
                  		    catch (IOException e) 
                  		    {
                  			//Properly handle rendering errors here
                  		    	log.debug(e.getMessage());
                  		    }
                  		}
                  
                  		context.getExternalContext().requestFlowExecutionRedirect();
                  my flow defination contains

                  Code:
                  	<view-state id="showCustomer"
                  		view="../jsf/displayCustomerDetails.xhtml">
                  		<!-- 
                  			<transition on="request" to="nextRequest" />
                  		-->
                  		<transition on="request" to="displayAddress" />
                  		<transition on="next" to="nextRequest" />
                  		<transition on="" to="nextRequest"></transition>
                  	</view-state>
                  I've added the transition on="" to="xxxx" to see if that is what is required #

                  Now in the thread 54166 the response from 'Gert' added the following line of code

                  Code:
                  messageHandler.addError(.....)
                  but I have no messagesHandler bean defined, if I add the above I get a null pointer exception

                  Regards
                  Nick

                  Comment


                  • #10
                    Can you please add the full stack trace of your IllegalStateException. And where do you register your exception handler? When does the exception occur?

                    Comment


                    • #11
                      Pepe thanks for your reply.

                      The full stack trace is

                      Code:
                      SEVERE: Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception
                      java.lang.IllegalStateException: The key for the flow execution is null; make sure the key is assigned first.  Execution Details = [FlowExecutionImpl@1c187c8 flow = 'lookupCustomer', flowSessions = list[[FlowSessionImpl@b95f72 flow = 'lookupCustomer', state = 'lookupCustomer', scope = map[[empty]]]]]
                      	at org.springframework.webflow.execution.repository.support.AbstractFlowExecutionRepository.assertKeySet(AbstractFlowExecutionRepository.java:189)
                      	at org.springframework.webflow.execution.repository.impl.DefaultFlowExecutionRepository.putFlowExecution(DefaultFlowExecutionRepository.java:108)
                      	at org.springframework.webflow.executor.FlowExecutorImpl.launchExecution(FlowExecutorImpl.java:142)
                      	at org.springframework.webflow.mvc.servlet.FlowHandlerAdapter.handle(FlowHandlerAdapter.java:183)
                      	at org.springframework.webflow.mvc.servlet.FlowController.handleRequest(FlowController.java:172)
                      	at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
                      	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
                      	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:809)
                      	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
                      	at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:501)
                      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
                      	at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                      	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
                      	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
                      	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
                      	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
                      	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
                      	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
                      	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
                      	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
                      	at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:845)
                      	at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
                      	at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
                      	at java.lang.Thread.run(Thread.java:619)
                      The registration of my exception handler is as before

                      Code:
                      		<exception-handler bean="invalidCustomer" />
                      
                      		<bean id="invalidCustomer" class="fujitsu.com.webflow1.InvalidCustomer" >
                      The invocation of the exception happens if I enter a phone-no that doesn't exist as in the following code

                      Code:
                      		if (this.phoneNumber.equalsIgnoreCase(phoneNo))
                      		{
                      			log.debug("Customer found ");
                      			return this;
                      		}
                      		else if (phoneNo.startsWith("44"))
                      		{
                      			log.debug("Creating new Customer " + phoneNo);
                      			//throw new CustomerNotFoundException();
                      			CustomerDetails newCust = new CustomerDetails();
                      			newCust.firstName = "Jill";
                      			return newCust;
                      		} 
                      		else 
                      		{
                      			log.debug("Cust not found request " + phoneNo);
                      			throw new CustomerNotFoundException("Customer Not Found ");
                      		}
                      And the exception is defined as follows

                      Code:
                      public class CustomerNotFoundException extends Exception 
                      {
                      
                      	  public CustomerNotFoundException() {}
                      	  
                      	  public CustomerNotFoundException(String message) {
                      	    super(message);
                      	  }
                      
                      }
                      Along with the following flow

                      Code:
                      	<action-state id="lookupCustomer">
                      		<evaluate
                      			expression="customerDetails.findCustomer(customer.inputPhoneNo)"
                      			result="conversationScope.customerResult" />   <!-- flowScope.customerResult" /> -->
                      		<transition on="success" to="showCustomer" />
                      		<transition on="Customer Not Found " to="nextRequest"></transition>
                      		<transition on="lookupCustomer" to="nextRequest"></transition>
                      		<transition on="null" to="nextRequest"></transition>
                      	</action-state>
                      I'm just wondering if its not a problem with the flow. The error occurs within the action-state and therefore there's no view state for it to 'display' the error on.


                      The only other niggle I have is that thread 54166 registers a 'messageHandler' whereas I haven't registered one specifically. That thread makes a call on the messageHandler in the reply from 'Gert'


                      I suspect that its something simple - again, but can't currently see it


                      Regards,
                      Nick

                      Comment


                      • #12
                        a last question: where do you enter the action state?

                        Comment


                        • #13
                          Hi,

                          Its my first state in the flow.

                          Code:
                          <flow xmlns="http://www.springframework.org/schema/webflow"
                          	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          	xsi:schemaLocation="http://www.springframework.org/schema/webflow
                          		http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
                          
                          
                          	<action-state id="lookupCustomer">
                          		<evaluate
                          			expression="customerDetails.findCustomer(customer.inputPhoneNo)"
                          			result="conversationScope.customerResult" />   <!-- flowScope.customerResult" /> -->
                          		<transition on="success" to="showCustomer" />
                          		<transition on="Customer Not Found " to="nextRequest"></transition>
                          		<transition on="lookupCustomer" to="nextRequest"></transition>
                          		<transition on="null" to="nextRequest"></transition>
                          	</action-state>
                          I've tried using a start-state statement but get flagged as an error. I think the root of the problem is that the flowExecutionKey is not set up.

                          Regards,
                          Nick

                          Comment


                          • #14
                            i expected that and i think this is a bug in SWF. there are several other issues which i mentioned in thread 61901. A similar exception occurs when you try to handle an exception which is thrown in an evaluation in the flows first view-state in the <on-entry>-block.

                            Comment


                            • #15
                              Hi Pepe,

                              Thanks for you time and effort. So what do I / we do about getting the problems fixed?

                              Regards,
                              Nick

                              Comment

                              Working...
                              X