From f0493c581c8f92d2447890d0f132acc97bff10d6 Mon Sep 17 00:00:00 2001 From: Maxime Sinclair Date: Wed, 18 Dec 2013 19:17:47 +0100 Subject: [PATCH] [FEATURE] PNG added to the url format The old URL format http://server/plantuml/img/... is now relaced by http://server/plantuml/png/... --- .../plantuml/servlet/ImgServlet.java | 2 +- src/main/webapp/WEB-INF/web.xml | 4 ++++ src/main/webapp/index.jsp | 2 +- .../plantuml/servlet/TestForm.java | 8 +++---- .../plantuml/servlet/TestImage.java | 22 +++++++++++++++++-- 5 files changed, 30 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/sourceforge/plantuml/servlet/ImgServlet.java b/src/main/java/net/sourceforge/plantuml/servlet/ImgServlet.java index 12941be..3598f99 100644 --- a/src/main/java/net/sourceforge/plantuml/servlet/ImgServlet.java +++ b/src/main/java/net/sourceforge/plantuml/servlet/ImgServlet.java @@ -34,7 +34,7 @@ public class ImgServlet extends UmlDiagramService { @Override public String getSource(String uri) { - String[] result = uri.split("/img/", 2); + String[] result = uri.split("/img/|/png/", 2); if (result.length != 2) { return ""; } else { diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 222fc12..1523ca5 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -52,6 +52,10 @@ plantumlservlet /form + + imgservlet + /png/* + imgservlet /img/* diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp index 4d4f716..0680eab 100644 --- a/src/main/webapp/index.jsp +++ b/src/main/webapp/index.jsp @@ -7,7 +7,7 @@ - + diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java b/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java index 6d4a509..8b63a88 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestForm.java @@ -20,7 +20,7 @@ public class TestForm extends WebappTestCase { WebForm forms[] = response.getForms(); assertEquals(2, forms.length); assertEquals("url", forms[1].getParameterNames()[0]); - assertTrue(forms[1].getParameterValue("url").endsWith("/img/" + TestUtils.SEQBOB)); + assertTrue(forms[1].getParameterValue("url").endsWith("/png/" + TestUtils.SEQBOB)); // Ensure the generated image is present assertEquals(1, response.getImages().length); @@ -43,7 +43,7 @@ public class TestForm extends WebappTestCase { // Ensure the Text field is correct assertEquals("version", forms[0].getParameterValue("text")); // Ensure the URL field is correct - assertTrue(forms[1].getParameterValue("url").endsWith("/img/" + TestUtils.VERSION)); + assertTrue(forms[1].getParameterValue("url").endsWith("/png/" + TestUtils.VERSION)); // Ensure the image is present assertEquals(1, response.getImages().length); } @@ -109,7 +109,7 @@ public class TestForm extends WebappTestCase { // Ensure the Text field is correct assertTrue(forms[0].getParameterValue("text").startsWith("@startditaa")); // Ensure the URL field is correct - assertTrue(forms[1].getParameterValue("url").endsWith("/img/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00")); + assertTrue(forms[1].getParameterValue("url").endsWith("/png/SoWkIImgISaiIKnKuDBIrRLJu798pKi12m00")); // Ensure the image is present assertEquals(1, response.getImages().length); } @@ -148,7 +148,7 @@ public class TestForm extends WebappTestCase { // Ensure the Text field is filled assertEquals(forms[0].getParameterValue("text"), "@startuml\nBob -> Alice : hello\n@enduml"); // Ensure the URL field is filled - assertEquals(forms[1].getParameterValue("url"), getServerUrl() + "img/" + TestUtils.SEQBOB); + assertEquals(forms[1].getParameterValue("url"), getServerUrl() + "png/" + TestUtils.SEQBOB); // Ensure the the image is present assertEquals(1, response.getImages().length); } diff --git a/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java b/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java index b0f6cd5..6463d07 100644 --- a/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java +++ b/src/test/java/net/sourceforge/plantuml/servlet/TestImage.java @@ -17,7 +17,7 @@ public class TestImage extends WebappTestCase { */ public void testVersionImage() throws Exception { WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/" + TestUtils.VERSION); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "png/" + TestUtils.VERSION); WebResponse response = conversation.getResource(request); // Analyze response // Verifies the Content-Type header @@ -44,7 +44,7 @@ public class TestImage extends WebappTestCase { public void testDiagramHttpHeader() throws Exception { WebConversation conversation = new WebConversation(); // Bob -> Alice : hello - WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/" + TestUtils.SEQBOB); + WebRequest request = new GetMethodWebRequest(getServerUrl() + "png/" + TestUtils.SEQBOB); WebResponse response = conversation.getResource(request); // Analyze response // Verifies the Content-Type header @@ -63,4 +63,22 @@ public class TestImage extends WebappTestCase { ; // Do nothing } } + + /** + * Verifies that the HTTP header of a diagram incites the browser to cache it. + */ + public void testOldImgURL() throws Exception { + WebConversation conversation = new WebConversation(); + // Bob -> Alice : hello + WebRequest request = new GetMethodWebRequest(getServerUrl() + "img/" + TestUtils.SEQBOB); + WebResponse response = conversation.getResource(request); + // Analyze response + // Verifies the Content-Type header + assertEquals("Response content type is not PNG", "image/png", response.getContentType()); + // Consume the response + InputStream responseStream = response.getInputStream(); + while (responseStream.read() != -1) { + ; // Do nothing + } + } }