Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LUT-28047: Fixed SONAR issues with 'Exceptions' handling #434

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import fr.paris.lutece.portal.service.message.SiteMessageException;
import fr.paris.lutece.portal.service.message.SiteMessageService;
import fr.paris.lutece.portal.service.security.UserNotSignedException;
import fr.paris.lutece.portal.service.util.AppLogService;
import fr.paris.lutece.portal.service.util.AppPathService;
import fr.paris.lutece.portal.web.PortalJspBean;

Expand Down Expand Up @@ -91,19 +92,25 @@ protected void doGet( HttpServletRequest request, HttpServletResponse response )
}
catch( UserNotSignedException e )
{
response.sendRedirect( response.encodeRedirectURL( PortalJspBean.redirectLogin( request ) ) );
sendRedirection( response, response.encodeRedirectURL( PortalJspBean.redirectLogin( request ) ) );
}
}

if ( file == null || file.getPhysicalFile( ) == null )
{
SiteMessageService.setMessage( request, MESSAGE_UNKNOWN_FILE );
try
{
SiteMessageService.setMessage( request, MESSAGE_UNKNOWN_FILE );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have to refactor the sitemessage management

}
catch( SiteMessageException e )
{
sendRedirection( response, AppPathService.getSiteMessageUrl( request ) );
}
}

}
catch( SiteMessageException e )
{
response.sendRedirect( AppPathService.getSiteMessageUrl( request ) );
sendRedirection( response, AppPathService.getSiteMessageUrl( request ) );
}

if ( file != null )
Expand All @@ -115,6 +122,30 @@ protected void doGet( HttpServletRequest request, HttpServletResponse response )
response.setHeader( "Content-Disposition", "attachment; filename=\"" + file.getTitle( ) + "\";" );
outputStream.write( file.getPhysicalFile( ).getValue( ) );
}
catch ( IOException e )
{
AppLogService.error( "The file could not be sent", e );
}
}
}

/**
* Send a redirect response to the client, with a specific redirection URL
*
* @param response
* The response
* @param redirectUrl
* The redirection URL
*/
private void sendRedirection( HttpServletResponse response, String redirectUrl )
{
try
{
response.sendRedirect( redirectUrl );
}
catch( IOException e )
{
AppLogService.error( "Unable to redirect", e );
}
}

Expand Down