changeset 163:1fe52a0cbd1f

Catch NPE and tell the user that the Session has expired. issue80 gnv/trunk@324 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Wed, 11 Nov 2009 16:24:02 +0000
parents 3be414dc974a
children 5570d9b3282f
files gnv/ChangeLog gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java
diffstat 2 files changed, 135 insertions(+), 124 deletions(-) [+]
line wrap: on
line diff
--- a/gnv/ChangeLog	Wed Nov 11 13:20:34 2009 +0000
+++ b/gnv/ChangeLog	Wed Nov 11 16:24:02 2009 +0000
@@ -1,5 +1,9 @@
 2009-11-11  Tim Englich  <tim.englich@intevation.de>
 
+	* src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java (execute): 
+	  Catch NPE and tell the user that the Session has expired. issue80
+	  
+2009-11-11  Tim Englich  <tim.englich@intevation.de>	
 	* src/main/webapp/WEB-INF/config/templates/describe-ui-static.xsl: 
 	  Remove <br/> Tag after Input-Elements
 	* src/main/webapp/WEB-INF/config/templates/describe-ui.xsl: 
--- a/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java	Wed Nov 11 13:20:34 2009 +0000
+++ b/gnv/src/main/java/de/intevation/gnv/action/NextArtifactStepAction.java	Wed Nov 11 16:24:02 2009 +0000
@@ -59,133 +59,140 @@
             SessionModel sm = SessionModelFactory.getInstance()
                     .getSessionModel(request);
             ArtifactDescription ad = sm.getArtifactDescription();
-            Collection<String> inputParameter = ad.getInputParameter();
-            Collection<InputParameter> ips = null;
-            if (inputParameter != null) {
-                ips = new ArrayList<InputParameter>(inputParameter.size());
-                Iterator<String> it = inputParameter.iterator();
-                while (it.hasNext()) {
-                    String name = it.next();
-                    String[] values = request.getParameterValues(name);
-                    InputParameter ip = new DefaultInputParameter(name, values);
-                    ips.add(ip);
-                }
-            }
-            ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory
-                                                .getInstance()
-                                                .getArtifactDatabaseClient(getLocale(request));
-            if (ad.getReachableStates() != null
-                && !ad.getReachableStates().isEmpty()) {
-                // TODO: Woher kommt der zu erreichende Status;
-                String target = null;
-                if (ad.getReachableStates().size() > 1) {
-                    target = request.getParameter("product"); // TODO HACK for
-                    // Propducts every
-                    // other Step has
-                    // currently only
-                    // one reachable
-                    // state.
-                } else {
-                    target = ad.getReachableStates().iterator().next();
-                }
-
-                ArtifactDescription artifactDescription;
-                try {
-                    artifactDescription = adc.doNextStep(sm.getSelectedArtifactFactory(), 
-                                                         sm.getCurrentArtifact(),
-                                                         target, ips);
-                } catch (Exception e) {
-                    log.error(e, e);
-                    request.setAttribute(
-                            CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e
-                                    .getMessage());
-                    artifactDescription = sm.getArtifactDescription();
-                }
-
-                Node currentUI = artifactDescription.getCurrentUI();
-                if (currentUI != null){
-                    XSLTransformer transformer = new XSLTransformer();
-                    Node dynamicUINode =  new XMLUtils().getNodeXPath(currentUI,"dynamic");
-                    if (dynamicUINode != null){
-                        String ui = transformer
-                                .transform(
-                                        dynamicUINode,
-                                        "UTF-8",
-                                        request
-                                                .getRealPath("WEB-INF/config/templates/describe-ui.xsl"));
-        
-                        request.setAttribute("ui", ui);
-                    }
-                    
-                    Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "static");
-                    if (staticUINode != null){
-                        String staticUI = transformer
-                                .transform(
-                                        staticUINode,
-                                        "UTF-8",
-                                        request
-                                                .getRealPath("WEB-INF/config/templates/describe-ui-static.xsl"));
-                        request.setAttribute("staticui", staticUI);
+            if (ad != null){
+                Collection<String> inputParameter = ad.getInputParameter();
+                Collection<InputParameter> ips = null;
+                if (inputParameter != null) {
+                    ips = new ArrayList<InputParameter>(inputParameter.size());
+                    Iterator<String> it = inputParameter.iterator();
+                    while (it.hasNext()) {
+                        String name = it.next();
+                        String[] values = request.getParameterValues(name);
+                        InputParameter ip = new DefaultInputParameter(name, values);
+                        ips.add(ip);
                     }
                 }
-                request.setAttribute("furthertargets",
-                        (ad.getReachableStates() != null && !ad
-                                .getReachableStates().isEmpty()));
-
-            } else {
-                // statistic abholen und in das sessionmodell schreiben.
-                ArtifactDescription artifactDescription;
-                try{
-                    adc.doFeed(sm.getSelectedArtifactFactory(), sm
-                            .getCurrentArtifact(), ips);
-                    
-                    Collection<ArtifactStatisticValue> statistics = adc
-                            .calculateStatistics(sm.getSelectedArtifactFactory(),
-                                    sm.getCurrentArtifact());
-                    sm.setStatistics(statistics);
-                    artifactDescription = adc
-                            .getCurrentStepDescription(sm
-                                    .getSelectedArtifactFactory(), sm
-                                    .getCurrentArtifact(),
-                                    true);
-                    
-                    request.setAttribute("diagramm", true);
-                    
-                } catch (Exception e) {
-                    log.error(e, e);
-                    request.setAttribute(
-                            CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e
-                                    .getMessage());
-                    artifactDescription = sm.getArtifactDescription();
+                ArtifactDatabaseClient adc = ArtifactDatabaseClientFactory
+                                                    .getInstance()
+                                                    .getArtifactDatabaseClient(getLocale(request));
+                if (ad.getReachableStates() != null
+                    && !ad.getReachableStates().isEmpty()) {
+                    // TODO: Woher kommt der zu erreichende Status;
+                    String target = null;
+                    if (ad.getReachableStates().size() > 1) {
+                        target = request.getParameter("product"); // TODO HACK for
+                        // Propducts every
+                        // other Step has
+                        // currently only
+                        // one reachable
+                        // state.
+                    } else {
+                        target = ad.getReachableStates().iterator().next();
+                    }
+    
+                    ArtifactDescription artifactDescription;
+                    try {
+                        artifactDescription = adc.doNextStep(sm.getSelectedArtifactFactory(), 
+                                                             sm.getCurrentArtifact(),
+                                                             target, ips);
+                    } catch (Exception e) {
+                        log.error(e, e);
+                        request.setAttribute(
+                                CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e
+                                        .getMessage());
+                        artifactDescription = sm.getArtifactDescription();
+                    }
+    
+                    Node currentUI = artifactDescription.getCurrentUI();
+                    if (currentUI != null){
+                        XSLTransformer transformer = new XSLTransformer();
+                        Node dynamicUINode =  new XMLUtils().getNodeXPath(currentUI,"dynamic");
+                        if (dynamicUINode != null){
+                            String ui = transformer
+                                    .transform(
+                                            dynamicUINode,
+                                            "UTF-8",
+                                            request
+                                                    .getRealPath("WEB-INF/config/templates/describe-ui.xsl"));
+            
+                            request.setAttribute("ui", ui);
+                        }
+                        
+                        Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "static");
+                        if (staticUINode != null){
+                            String staticUI = transformer
+                                    .transform(
+                                            staticUINode,
+                                            "UTF-8",
+                                            request
+                                                    .getRealPath("WEB-INF/config/templates/describe-ui-static.xsl"));
+                            request.setAttribute("staticui", staticUI);
+                        }
+                    }
+                    request.setAttribute("furthertargets",
+                            (ad.getReachableStates() != null && !ad
+                                    .getReachableStates().isEmpty()));
+    
+                } else {
+                    // statistic abholen und in das sessionmodell schreiben.
+                    ArtifactDescription artifactDescription;
+                    try{
+                        adc.doFeed(sm.getSelectedArtifactFactory(), sm
+                                .getCurrentArtifact(), ips);
+                        
+                        Collection<ArtifactStatisticValue> statistics = adc
+                                .calculateStatistics(sm.getSelectedArtifactFactory(),
+                                        sm.getCurrentArtifact());
+                        sm.setStatistics(statistics);
+                        artifactDescription = adc
+                                .getCurrentStepDescription(sm
+                                        .getSelectedArtifactFactory(), sm
+                                        .getCurrentArtifact(),
+                                        true);
+                        
+                        request.setAttribute("diagramm", true);
+                        
+                    } catch (Exception e) {
+                        log.error(e, e);
+                        request.setAttribute(
+                                CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, e
+                                        .getMessage());
+                        artifactDescription = sm.getArtifactDescription();
+                    }
+    
+                    Node currentUI = artifactDescription.getCurrentUI();
+                    if (currentUI != null){
+                        XSLTransformer transformer = new XSLTransformer();
+                        Node dynamicUINode =  new XMLUtils().getNodeXPath(currentUI,"dynamic");
+                        if (dynamicUINode != null){
+                            String ui = transformer
+                                    .transform(
+                                            dynamicUINode,
+                                            "UTF-8",
+                                            request
+                                                    .getRealPath("WEB-INF/config/templates/describe-ui.xsl"));
+            
+                            request.setAttribute("ui", ui);
+                        }
+                        
+                        Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "static");
+                        if (staticUINode != null){
+                            String staticUI = transformer
+                                    .transform(
+                                            staticUINode,
+                                            "UTF-8",
+                                            request
+                                                    .getRealPath("WEB-INF/config/templates/describe-ui-static.xsl"));
+                            request.setAttribute("staticui", staticUI);
+                        }
+                    }
+                    request.setAttribute("furthertargets", false);
                 }
-
-                Node currentUI = artifactDescription.getCurrentUI();
-                if (currentUI != null){
-                    XSLTransformer transformer = new XSLTransformer();
-                    Node dynamicUINode =  new XMLUtils().getNodeXPath(currentUI,"dynamic");
-                    if (dynamicUINode != null){
-                        String ui = transformer
-                                .transform(
-                                        dynamicUINode,
-                                        "UTF-8",
-                                        request
-                                                .getRealPath("WEB-INF/config/templates/describe-ui.xsl"));
-        
-                        request.setAttribute("ui", ui);
-                    }
-                    
-                    Node staticUINode = new XMLUtils().getNodeXPath(currentUI, "static");
-                    if (staticUINode != null){
-                        String staticUI = transformer
-                                .transform(
-                                        staticUINode,
-                                        "UTF-8",
-                                        request
-                                                .getRealPath("WEB-INF/config/templates/describe-ui-static.xsl"));
-                        request.setAttribute("staticui", staticUI);
-                    }
-                }
-                request.setAttribute("furthertargets", false);
+            }else{
+                log.warn("SessionTimeout has occured");
+                request.setAttribute(CommunicationKeys.REQUEST_EXCEPTION_MESSAGE_ID, 
+                                     "SessionTimeout has occured");
+                new FetchArtifactFactoriesAction().execute(mapping, form, request, response);
             }
             return super.execute(mapping, form, request, response);
     }

http://dive4elements.wald.intevation.org