diff --git a/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java b/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java index cae74c8..03aed5b 100644 --- a/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java +++ b/src/main/java/net/sourceforge/plantuml/servlet/DiagramResponse.java @@ -76,7 +76,7 @@ class DiagramResponse { request = rq; } - void sendDiagram(String uml, int idx, boolean badRequestOnError) throws IOException { + void sendDiagram(String uml, int idx) throws IOException { response.addHeader("Access-Control-Allow-Origin", "*"); response.setContentType(getContentType()); SourceStringReader reader = new SourceStringReader(uml); diff --git a/src/main/java/net/sourceforge/plantuml/servlet/ProxyServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/ProxyServlet.java index f99d8e2..c124122 100644 --- a/src/main/java/net/sourceforge/plantuml/servlet/ProxyServlet.java +++ b/src/main/java/net/sourceforge/plantuml/servlet/ProxyServlet.java @@ -85,7 +85,7 @@ public class ProxyServlet extends HttpServlet { // generate the response DiagramResponse dr = new DiagramResponse(response, getOutputFormat(fmt), request); try { - dr.sendDiagram(uml, 0, false); + dr.sendDiagram(uml, 0); } catch (IIOException iioe) { // Browser has closed the connection, so the HTTP OutputStream is closed // Silently catch the exception to avoid annoying log diff --git a/src/main/java/net/sourceforge/plantuml/servlet/UmlDiagramService.java b/src/main/java/net/sourceforge/plantuml/servlet/UmlDiagramService.java index 21a76d4..a90f178 100644 --- a/src/main/java/net/sourceforge/plantuml/servlet/UmlDiagramService.java +++ b/src/main/java/net/sourceforge/plantuml/servlet/UmlDiagramService.java @@ -47,6 +47,7 @@ public abstract class UmlDiagramService extends HttpServlet { // build the UML source from the compressed request parameter final String[] sourceAndIdx = getSourceAndIdx(request); + final int idx = Integer.parseInt(sourceAndIdx[1]); final String uml; try { uml = UmlExtractor.getUmlSource(sourceAndIdx[0]); @@ -56,16 +57,7 @@ public abstract class UmlDiagramService extends HttpServlet { return; } - // generate the response - DiagramResponse dr = new DiagramResponse(response, getOutputFormat(), request); - final int idx = Integer.parseInt(sourceAndIdx[1]); - try { - dr.sendDiagram(uml, idx, false); - } catch (IIOException iioe) { - // Browser has closed the connection, so the HTTP OutputStream is closed - // Silently catch the exception to avoid annoying log - } - dr = null; + doDiagramResponse(request, response, uml, idx); } @Override @@ -73,7 +65,7 @@ public abstract class UmlDiagramService extends HttpServlet { // build the UML source from the compressed request parameter final String[] sourceAndIdx = getSourceAndIdx(request); -// final String uml; + final int idx = Integer.parseInt(sourceAndIdx[1]); final StringBuilder uml = new StringBuilder(); final BufferedReader in = request.getReader(); @@ -85,11 +77,20 @@ public abstract class UmlDiagramService extends HttpServlet { uml.append(line).append('\n'); } + doDiagramResponse(request, response, uml.toString(), idx); + } + + private void doDiagramResponse( + HttpServletRequest request, + HttpServletResponse response, + String uml, + int idx) + throws IOException { + // generate the response DiagramResponse dr = new DiagramResponse(response, getOutputFormat(), request); - final int idx = Integer.parseInt(sourceAndIdx[1]); try { - dr.sendDiagram(uml.toString(), idx, true); + dr.sendDiagram(uml, idx); } catch (IIOException iioe) { // Browser has closed the connection, so the HTTP OutputStream is closed // Silently catch the exception to avoid annoying log