diff --git a/src/java/fr/paris/lutece/portal/service/progressmanager/ProgressManagerService.java b/src/java/fr/paris/lutece/portal/service/progressmanager/ProgressManagerService.java index dae6865f51..353dacca72 100644 --- a/src/java/fr/paris/lutece/portal/service/progressmanager/ProgressManagerService.java +++ b/src/java/fr/paris/lutece/portal/service/progressmanager/ProgressManagerService.java @@ -40,7 +40,7 @@ import fr.paris.lutece.portal.business.progressmanager.ProgressFeed; import java.util.ArrayList; -import java.util.Arrays; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -275,7 +275,7 @@ public List getReport( String strFeedToken, int iFromLine ) } } - return null; + return Collections.emptyList( ); } /** diff --git a/src/java/fr/paris/lutece/portal/web/progressmanager/ProgressManagerServlet.java b/src/java/fr/paris/lutece/portal/web/progressmanager/ProgressManagerServlet.java index 1ce1470155..09aee3f6d2 100644 --- a/src/java/fr/paris/lutece/portal/web/progressmanager/ProgressManagerServlet.java +++ b/src/java/fr/paris/lutece/portal/web/progressmanager/ProgressManagerServlet.java @@ -34,6 +34,7 @@ package fr.paris.lutece.portal.web.progressmanager; import fr.paris.lutece.portal.service.progressmanager.ProgressManagerService; +import fr.paris.lutece.portal.service.util.AppLogService; import fr.paris.lutece.util.json.ErrorJsonResponse; import fr.paris.lutece.util.json.JsonResponse; import fr.paris.lutece.util.json.JsonUtil; @@ -99,64 +100,69 @@ public void init( ServletConfig config ) throws ServletException public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { response.setContentType( CONTENT_TYPE ); - PrintWriter out = response.getWriter( ); + PrintWriter out = null; - // token - String strToken = (String) request.getParameter( PARAMETER_TOKEN ); - - if ( strToken == null || strToken.isEmpty( ) ) + try { - out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) ); - out.flush( ); - out.close( ); - return; - } + out = response.getWriter( ); - ProgressManagerService progressManagerService = ProgressManagerService.getInstance( ); + // token + String strToken = request.getParameter( PARAMETER_TOKEN ); - if ( !progressManagerService.isRegistred( strToken ) ) - { - out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) ); - out.flush( ); - out.close( ); - return; - } + if ( strToken == null || strToken.isEmpty( ) ) + { + out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) ); + return; + } - if ( request.getParameter( PARAMETER_PROGRESS ) != null ) - { - out.println( JsonUtil.buildJsonResponse( new JsonResponse( progressManagerService.getProgressStatus( strToken ) ) ) ); - out.flush( ); - out.close( ); - return; - } - else - if ( request.getParameter( PARAMETER_REPORT ) != null ) + ProgressManagerService progressManagerService = ProgressManagerService.getInstance( ); + + if ( !progressManagerService.isRegistred( strToken ) ) + { + out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) ); + return; + } + + if ( request.getParameter( PARAMETER_PROGRESS ) != null ) { - int iFromLine = -1; - try + out.println( JsonUtil.buildJsonResponse( new JsonResponse( progressManagerService.getProgressStatus( strToken ) ) ) ); + } + else + if ( request.getParameter( PARAMETER_REPORT ) != null ) { - iFromLine = Integer.parseInt( request.getParameter( PARAMETER_FROM_LINE ) ); + int iFromLine = -1; + try + { + iFromLine = Integer.parseInt( request.getParameter( PARAMETER_FROM_LINE ) ); + } + catch( NumberFormatException e ) + { + out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_BAD_PARAMETER ) ) ); + } + + Map mapResponse = new HashMap<>( ); + List reportLines = progressManagerService.getReport( strToken, iFromLine ); + mapResponse.put( ATTRIBUTE_NAME_LAST_LINE, iFromLine + reportLines.size( ) ); + mapResponse.put( ATTRIBUTE_NAME_LINES, reportLines ); + out.println( JsonUtil.buildJsonResponse( new JsonResponse( mapResponse ) ) ); } - catch( NumberFormatException e ) + else { - out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_BAD_PARAMETER ) ) ); + out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) ); } - - Map mapResponse = new HashMap<>( ); - List reportLines = progressManagerService.getReport( strToken, iFromLine ); - mapResponse.put( ATTRIBUTE_NAME_LAST_LINE, iFromLine + reportLines.size( ) ); - mapResponse.put( ATTRIBUTE_NAME_LINES, reportLines ); - out.println( JsonUtil.buildJsonResponse( new JsonResponse( mapResponse ) ) ); + } + catch( IOException e ) + { + AppLogService.error( e.getStackTrace( ), e ); + } + finally + { + // In every case, make sure the PrintWriter is properly sent/cleaned + if ( out != null ) + { out.flush( ); out.close( ); - return; - } - else - { - out.println( JsonUtil.buildJsonResponse( new ErrorJsonResponse( STATUS_NOT_FOUND ) ) ); } - - out.flush( ); - out.close( ); + } } }