1
0
mirror of https://github.com/octoleo/plantuml-server.git synced 2024-12-22 08:48:54 +00:00

Extracted reusable doDiagramResponse() method

This commit is contained in:
Rob Oxspring 2018-04-19 12:39:09 +01:00 committed by Robert James Oxspring
parent ad09f193f4
commit 5ef45f643d
3 changed files with 16 additions and 15 deletions

View File

@ -76,7 +76,7 @@ class DiagramResponse {
request = rq; 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.addHeader("Access-Control-Allow-Origin", "*");
response.setContentType(getContentType()); response.setContentType(getContentType());
SourceStringReader reader = new SourceStringReader(uml); SourceStringReader reader = new SourceStringReader(uml);

View File

@ -85,7 +85,7 @@ public class ProxyServlet extends HttpServlet {
// generate the response // generate the response
DiagramResponse dr = new DiagramResponse(response, getOutputFormat(fmt), request); DiagramResponse dr = new DiagramResponse(response, getOutputFormat(fmt), request);
try { try {
dr.sendDiagram(uml, 0, false); dr.sendDiagram(uml, 0);
} catch (IIOException iioe) { } catch (IIOException iioe) {
// Browser has closed the connection, so the HTTP OutputStream is closed // Browser has closed the connection, so the HTTP OutputStream is closed
// Silently catch the exception to avoid annoying log // Silently catch the exception to avoid annoying log

View File

@ -47,6 +47,7 @@ public abstract class UmlDiagramService extends HttpServlet {
// build the UML source from the compressed request parameter // build the UML source from the compressed request parameter
final String[] sourceAndIdx = getSourceAndIdx(request); final String[] sourceAndIdx = getSourceAndIdx(request);
final int idx = Integer.parseInt(sourceAndIdx[1]);
final String uml; final String uml;
try { try {
uml = UmlExtractor.getUmlSource(sourceAndIdx[0]); uml = UmlExtractor.getUmlSource(sourceAndIdx[0]);
@ -56,16 +57,7 @@ public abstract class UmlDiagramService extends HttpServlet {
return; return;
} }
// generate the response doDiagramResponse(request, response, uml, idx);
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;
} }
@Override @Override
@ -73,7 +65,7 @@ public abstract class UmlDiagramService extends HttpServlet {
// build the UML source from the compressed request parameter // build the UML source from the compressed request parameter
final String[] sourceAndIdx = getSourceAndIdx(request); final String[] sourceAndIdx = getSourceAndIdx(request);
// final String uml; final int idx = Integer.parseInt(sourceAndIdx[1]);
final StringBuilder uml = new StringBuilder(); final StringBuilder uml = new StringBuilder();
final BufferedReader in = request.getReader(); final BufferedReader in = request.getReader();
@ -85,11 +77,20 @@ public abstract class UmlDiagramService extends HttpServlet {
uml.append(line).append('\n'); 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 // generate the response
DiagramResponse dr = new DiagramResponse(response, getOutputFormat(), request); DiagramResponse dr = new DiagramResponse(response, getOutputFormat(), request);
final int idx = Integer.parseInt(sourceAndIdx[1]);
try { try {
dr.sendDiagram(uml.toString(), idx, true); dr.sendDiagram(uml, idx);
} catch (IIOException iioe) { } catch (IIOException iioe) {
// Browser has closed the connection, so the HTTP OutputStream is closed // Browser has closed the connection, so the HTTP OutputStream is closed
// Silently catch the exception to avoid annoying log // Silently catch the exception to avoid annoying log