Loading src/tap/resource/ForwardResource.java +20 −19 Original line number Diff line number Diff line Loading @@ -16,7 +16,8 @@ package tap.resource; * You should have received a copy of the GNU Lesser General Public License * along with TAPLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2015-2017 - Astronomisches Rechen Institut (ARI) * Copyright 2015-2019 - Astronomisches Rechen Institut (ARI), * UDS/Centre de Données astronomiques de Strasbourg (CDS) */ import java.io.BufferedReader; Loading Loading @@ -50,8 +51,8 @@ import uws.service.log.UWSLog.LogLevel; * * <p><i>See {@link #forward(String, String, HttpServletRequest, HttpServletResponse)} for more details</i></p> * * @author Grégory Mantelet (ARI) * @version 2.1 (03/2017) * @author Grégory Mantelet (ARI;CDS) * @version 2.2 (03/2019) * @since 2.1 */ public abstract class ForwardResource implements TAPResource { Loading Loading @@ -154,7 +155,7 @@ public abstract class ForwardResource implements TAPResource { File f = new File(uri.getPath()); if (f.exists() && !f.isDirectory() && f.canRead()){ // set the content length: response.setContentLength((int)f.length()); UWSToolBox.setContentLength(response, f.length()); // get the input stream: input = new BufferedReader(new FileReader(f)); Loading src/uws/UWSToolBox.java +50 −18 Original line number Diff line number Diff line package uws; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.lang.reflect.Array; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /* * This file is part of UWSLibrary. * Loading Loading @@ -31,25 +51,11 @@ import uws.service.log.UWSLog; import uws.service.request.RequestParser; import uws.service.request.UploadFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.lang.reflect.Array; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; /** * Some useful functions for the managing of a UWS service. * * @author Grégory Mantelet (CDS;ARI) * @version 4.3 (01/2019) * @version 4.4 (03/2019) */ public class UWSToolBox { Loading Loading @@ -525,8 +531,7 @@ public class UWSToolBox { response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); // Set the HTTP content length: if (contentSize > 0) response.setHeader("Content-Length", String.valueOf(contentSize)); setContentLength(response, contentSize); // Write the file into the HTTP response: output = response.getOutputStream(); Loading Loading @@ -688,4 +693,31 @@ public class UWSToolBox { return null; } /** * Set the content length in the given {@link HttpServletResponse}. * * <p><i><b>Implementation note:</b> * This could perfectly be done using * {@link HttpServletResponse#setContentLength(int)}, <b>but only if the * content size is encoded or fit in an integer value</b>. Otherwise, that * function will set no content length. * On the contrary, this current function takes a long value and set * manually the content type header. * </i></p> * * <p><i><b>Note:</b> * This function has no effect if the given {@link HttpServletResponse} is * NULL or if the given content size is ≤ 0. * </i></p> * * @param response HTTP response. * @param contentSize The content size to set. * * @since 4.4 */ public static final void setContentLength(final HttpServletResponse response, final long contentSize){ if (response != null && contentSize > 0) response.setHeader("Content-Length", String.valueOf(contentSize)); } } src/uws/job/jobInfo/SingleValueJobInfo.java +27 −25 Original line number Diff line number Diff line Loading @@ -16,7 +16,8 @@ package uws.job.jobInfo; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2017 - Astronomisches Rechen Institut (ARI) * Copyright 2017-2019 - Astronomisches Rechen Institut (ARI), * UDS/Centre de Données astronomiques de Strasbourg (CDS) */ import java.io.IOException; Loading @@ -25,6 +26,7 @@ import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse; import uws.UWSException; import uws.UWSToolBox; import uws.job.UWSJob; import uws.job.serializer.XMLSerializer; Loading @@ -47,8 +49,8 @@ import uws.job.serializer.XMLSerializer; * with {@link #setValue(String)}.</li> * </ul> * * @author Grégory Mantelet (ARI) * @version 4.2 (06/2017) * @author Grégory Mantelet (ARI;CDS) * @version 4.4 (03/2019) * @since 4.2 */ public class SingleValueJobInfo implements JobInfo { Loading Loading @@ -174,7 +176,7 @@ public class SingleValueJobInfo implements JobInfo { public void write(HttpServletResponse response) throws IOException, UWSException{ response.setCharacterEncoding("UTF-8"); response.setContentType("text/xml"); response.setContentLength(xmlRepresentation.getBytes("UTF-8").length); UWSToolBox.setContentLength(response, xmlRepresentation.getBytes("UTF-8").length); PrintWriter writer = response.getWriter(); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); Loading src/uws/job/jobInfo/XMLJobInfo.java +44 −42 Original line number Diff line number Diff line Loading @@ -16,7 +16,8 @@ package uws.job.jobInfo; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2017 - Astronomisches Rechen Institut (ARI) * Copyright 2017-2019 - Astronomisches Rechen Institut (ARI), * UDS/Centre de Données astronomiques de Strasbourg (CDS) */ import java.io.BufferedReader; Loading Loading @@ -140,8 +141,8 @@ import uws.service.request.UploadFile; * function {@link #restoreFile()}. * </p> * * @author Grégory Mantelet (ARI) * @version 4.2 (06/2017) * @author Grégory Mantelet (ARI;CDS) * @version 4.4 (03/2019) * @since 4.2 */ public class XMLJobInfo implements JobInfo { Loading Loading @@ -277,7 +278,8 @@ public class XMLJobInfo implements JobInfo { if (input != null){ try{ input.close(); }catch(IOException ioe){} }catch(IOException ioe){ } } } return xml.toString(); Loading @@ -290,7 +292,7 @@ public class XMLJobInfo implements JobInfo { if (content != null){ response.setCharacterEncoding("UTF-8"); response.setContentType("text/xml"); response.setContentLength(content.getBytes("UTF-8").length); UWSToolBox.setContentLength(response, content.getBytes("UTF-8").length); PrintWriter writer = response.getWriter(); writer.println(content); Loading Loading
src/tap/resource/ForwardResource.java +20 −19 Original line number Diff line number Diff line Loading @@ -16,7 +16,8 @@ package tap.resource; * You should have received a copy of the GNU Lesser General Public License * along with TAPLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2015-2017 - Astronomisches Rechen Institut (ARI) * Copyright 2015-2019 - Astronomisches Rechen Institut (ARI), * UDS/Centre de Données astronomiques de Strasbourg (CDS) */ import java.io.BufferedReader; Loading Loading @@ -50,8 +51,8 @@ import uws.service.log.UWSLog.LogLevel; * * <p><i>See {@link #forward(String, String, HttpServletRequest, HttpServletResponse)} for more details</i></p> * * @author Grégory Mantelet (ARI) * @version 2.1 (03/2017) * @author Grégory Mantelet (ARI;CDS) * @version 2.2 (03/2019) * @since 2.1 */ public abstract class ForwardResource implements TAPResource { Loading Loading @@ -154,7 +155,7 @@ public abstract class ForwardResource implements TAPResource { File f = new File(uri.getPath()); if (f.exists() && !f.isDirectory() && f.canRead()){ // set the content length: response.setContentLength((int)f.length()); UWSToolBox.setContentLength(response, f.length()); // get the input stream: input = new BufferedReader(new FileReader(f)); Loading
src/uws/UWSToolBox.java +50 −18 Original line number Diff line number Diff line package uws; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.io.UnsupportedEncodingException; import java.lang.reflect.Array; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /* * This file is part of UWSLibrary. * Loading Loading @@ -31,25 +51,11 @@ import uws.service.log.UWSLog; import uws.service.request.RequestParser; import uws.service.request.UploadFile; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.*; import java.lang.reflect.Array; import java.net.MalformedURLException; import java.net.URL; import java.net.URLDecoder; import java.net.URLEncoder; import java.util.Date; import java.util.Enumeration; import java.util.HashMap; import java.util.Map; /** * Some useful functions for the managing of a UWS service. * * @author Grégory Mantelet (CDS;ARI) * @version 4.3 (01/2019) * @version 4.4 (03/2019) */ public class UWSToolBox { Loading Loading @@ -525,8 +531,7 @@ public class UWSToolBox { response.setCharacterEncoding(UWSToolBox.DEFAULT_CHAR_ENCODING); // Set the HTTP content length: if (contentSize > 0) response.setHeader("Content-Length", String.valueOf(contentSize)); setContentLength(response, contentSize); // Write the file into the HTTP response: output = response.getOutputStream(); Loading Loading @@ -688,4 +693,31 @@ public class UWSToolBox { return null; } /** * Set the content length in the given {@link HttpServletResponse}. * * <p><i><b>Implementation note:</b> * This could perfectly be done using * {@link HttpServletResponse#setContentLength(int)}, <b>but only if the * content size is encoded or fit in an integer value</b>. Otherwise, that * function will set no content length. * On the contrary, this current function takes a long value and set * manually the content type header. * </i></p> * * <p><i><b>Note:</b> * This function has no effect if the given {@link HttpServletResponse} is * NULL or if the given content size is ≤ 0. * </i></p> * * @param response HTTP response. * @param contentSize The content size to set. * * @since 4.4 */ public static final void setContentLength(final HttpServletResponse response, final long contentSize){ if (response != null && contentSize > 0) response.setHeader("Content-Length", String.valueOf(contentSize)); } }
src/uws/job/jobInfo/SingleValueJobInfo.java +27 −25 Original line number Diff line number Diff line Loading @@ -16,7 +16,8 @@ package uws.job.jobInfo; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2017 - Astronomisches Rechen Institut (ARI) * Copyright 2017-2019 - Astronomisches Rechen Institut (ARI), * UDS/Centre de Données astronomiques de Strasbourg (CDS) */ import java.io.IOException; Loading @@ -25,6 +26,7 @@ import java.io.PrintWriter; import javax.servlet.http.HttpServletResponse; import uws.UWSException; import uws.UWSToolBox; import uws.job.UWSJob; import uws.job.serializer.XMLSerializer; Loading @@ -47,8 +49,8 @@ import uws.job.serializer.XMLSerializer; * with {@link #setValue(String)}.</li> * </ul> * * @author Grégory Mantelet (ARI) * @version 4.2 (06/2017) * @author Grégory Mantelet (ARI;CDS) * @version 4.4 (03/2019) * @since 4.2 */ public class SingleValueJobInfo implements JobInfo { Loading Loading @@ -174,7 +176,7 @@ public class SingleValueJobInfo implements JobInfo { public void write(HttpServletResponse response) throws IOException, UWSException{ response.setCharacterEncoding("UTF-8"); response.setContentType("text/xml"); response.setContentLength(xmlRepresentation.getBytes("UTF-8").length); UWSToolBox.setContentLength(response, xmlRepresentation.getBytes("UTF-8").length); PrintWriter writer = response.getWriter(); writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); Loading
src/uws/job/jobInfo/XMLJobInfo.java +44 −42 Original line number Diff line number Diff line Loading @@ -16,7 +16,8 @@ package uws.job.jobInfo; * You should have received a copy of the GNU Lesser General Public License * along with UWSLibrary. If not, see <http://www.gnu.org/licenses/>. * * Copyright 2017 - Astronomisches Rechen Institut (ARI) * Copyright 2017-2019 - Astronomisches Rechen Institut (ARI), * UDS/Centre de Données astronomiques de Strasbourg (CDS) */ import java.io.BufferedReader; Loading Loading @@ -140,8 +141,8 @@ import uws.service.request.UploadFile; * function {@link #restoreFile()}. * </p> * * @author Grégory Mantelet (ARI) * @version 4.2 (06/2017) * @author Grégory Mantelet (ARI;CDS) * @version 4.4 (03/2019) * @since 4.2 */ public class XMLJobInfo implements JobInfo { Loading Loading @@ -277,7 +278,8 @@ public class XMLJobInfo implements JobInfo { if (input != null){ try{ input.close(); }catch(IOException ioe){} }catch(IOException ioe){ } } } return xml.toString(); Loading @@ -290,7 +292,7 @@ public class XMLJobInfo implements JobInfo { if (content != null){ response.setCharacterEncoding("UTF-8"); response.setContentType("text/xml"); response.setContentLength(content.getBytes("UTF-8").length); UWSToolBox.setContentLength(response, content.getBytes("UTF-8").length); PrintWriter writer = response.getWriter(); writer.println(content); Loading