mirror of
https://github.com/octoleo/plantuml-server.git
synced 2024-11-18 18:25:11 +00:00
Merge branch 'refs/heads/master' of https://arnaudroques@github.com/arnaudroques/plantumlservlet.git into HEAD
This commit is contained in:
commit
75c8d5cef0
@ -5,7 +5,15 @@
|
|||||||
<servlet-name>plantumlservlet</servlet-name>
|
<servlet-name>plantumlservlet</servlet-name>
|
||||||
<servlet-class>net.sourceforge.plantuml.servlet.PlantUmlServlet</servlet-class>
|
<servlet-class>net.sourceforge.plantuml.servlet.PlantUmlServlet</servlet-class>
|
||||||
</servlet>
|
</servlet>
|
||||||
|
<servlet>
|
||||||
|
<servlet-name>welcome</servlet-name>
|
||||||
|
<servlet-class>net.sourceforge.plantuml.servlet.Welcome</servlet-class>
|
||||||
|
</servlet>
|
||||||
<!-- Patterns of the servlet -->
|
<!-- Patterns of the servlet -->
|
||||||
|
<servlet-mapping>
|
||||||
|
<servlet-name>welcome</servlet-name>
|
||||||
|
<url-pattern>/welcome</url-pattern>
|
||||||
|
</servlet-mapping>
|
||||||
<servlet-mapping>
|
<servlet-mapping>
|
||||||
<servlet-name>plantumlservlet</servlet-name>
|
<servlet-name>plantumlservlet</servlet-name>
|
||||||
<url-pattern>/uml/*</url-pattern>
|
<url-pattern>/uml/*</url-pattern>
|
||||||
@ -27,7 +35,7 @@
|
|||||||
<url-pattern>/proxy/*</url-pattern>
|
<url-pattern>/proxy/*</url-pattern>
|
||||||
</servlet-mapping>
|
</servlet-mapping>
|
||||||
<welcome-file-list>
|
<welcome-file-list>
|
||||||
<welcome-file>index.jsp</welcome-file>
|
<welcome-file>welcome</welcome-file>
|
||||||
</welcome-file-list>
|
</welcome-file-list>
|
||||||
<error-page>
|
<error-page>
|
||||||
<exception-type>java.lang.Throwable</exception-type>
|
<exception-type>java.lang.Throwable</exception-type>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%@ page isErrorPage="true" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
|
<%@ page isErrorPage="true" contentType="text/html; charset=utf-8" pageEncoding="utf-8" session="false" %>
|
||||||
<%
|
<%
|
||||||
String contextRoot = request.getContextPath();
|
String contextRoot = request.getContextPath();
|
||||||
%>
|
%>
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<%@ page info="index" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
|
<%@ page info="index" contentType="text/html; charset=utf-8" pageEncoding="utf-8" session="false" %>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
String contextRoot = request.getContextPath();
|
String contextRoot = request.getContextPath();
|
||||||
@ -14,10 +14,7 @@ if (encodedAttribute != null) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Object decodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.decoded");
|
Object decodedAttribute = request.getAttribute("net.sourceforge.plantuml.servlet.decoded");
|
||||||
if (decodedAttribute == null) {
|
if (decodedAttribute != null) {
|
||||||
umltext = "Bob -> Alice : hello";
|
|
||||||
imgurl = host + contextRoot + "/img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000";
|
|
||||||
} else {
|
|
||||||
umltext = decodedAttribute.toString();
|
umltext = decodedAttribute.toString();
|
||||||
}
|
}
|
||||||
%>
|
%>
|
||||||
@ -68,7 +65,11 @@ if (decodedAttribute == null) {
|
|||||||
</p>
|
</p>
|
||||||
<% } //endif %>
|
<% } //endif %>
|
||||||
</div>
|
</div>
|
||||||
|
<!-- This comment is used by the TestProxy class
|
||||||
|
@startuml
|
||||||
|
Bob -> Alice : hello
|
||||||
|
@enduml
|
||||||
|
-->
|
||||||
<%-- FOOTER
|
<%-- FOOTER
|
||||||
<%@ include file="util/footer.jspf" %> --%>
|
<%@ include file="util/footer.jspf" %> --%>
|
||||||
</body>
|
</body>
|
||||||
|
@ -170,7 +170,7 @@ public class PlantUmlServlet extends HttpServlet {
|
|||||||
response.flushBuffer();
|
response.flushBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContent(String adress) throws IOException {
|
private String getContent(String adress) throws IOException {
|
||||||
// HTTPConnection.setProxyServer("proxy", 8080);
|
// HTTPConnection.setProxyServer("proxy", 8080);
|
||||||
CookieModule.setCookiePolicyHandler(null);
|
CookieModule.setCookiePolicyHandler(null);
|
||||||
|
|
||||||
|
30
src/net/sourceforge/plantuml/servlet/Welcome.java
Normal file
30
src/net/sourceforge/plantuml/servlet/Welcome.java
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package net.sourceforge.plantuml.servlet;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import javax.servlet.RequestDispatcher;
|
||||||
|
import javax.servlet.ServletException;
|
||||||
|
import javax.servlet.http.HttpServlet;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Welcome servlet of the webapp.
|
||||||
|
* Displays the sample Bob and Alice sequence diagram.
|
||||||
|
*/
|
||||||
|
public class Welcome extends HttpServlet {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doGet(HttpServletRequest request, HttpServletResponse response)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
|
||||||
|
// set the sample
|
||||||
|
request.setAttribute("net.sourceforge.plantuml.servlet.decoded", "Bob -> Alice : hello");
|
||||||
|
request.setAttribute("net.sourceforge.plantuml.servlet.encoded", "SyfFKj2rKt3CoKnELR1Io4ZDoSa70000");
|
||||||
|
|
||||||
|
// forward to index.jsp
|
||||||
|
RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp");
|
||||||
|
dispatcher.forward(request, response);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -10,6 +10,7 @@ public class AllTests extends TestSuite {
|
|||||||
//$JUnit-BEGIN$
|
//$JUnit-BEGIN$
|
||||||
suite.addTestSuite(TestForm.class);
|
suite.addTestSuite(TestForm.class);
|
||||||
suite.addTestSuite(TestImage.class);
|
suite.addTestSuite(TestImage.class);
|
||||||
|
suite.addTestSuite(TestProxy.class);
|
||||||
//$JUnit-END$
|
//$JUnit-END$
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public class TestForm extends TestCase {
|
|||||||
public void testEmptyUrl() throws Exception {
|
public void testEmptyUrl() throws Exception {
|
||||||
WebConversation conversation = new WebConversation();
|
WebConversation conversation = new WebConversation();
|
||||||
// Fill the form and submit it
|
// Fill the form and submit it
|
||||||
WebRequest request = new GetMethodWebRequest( "http://localhost/plantuml/" );
|
WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl() );
|
||||||
WebResponse response = TestUtils.tryGetResponse(conversation, request );
|
WebResponse response = TestUtils.tryGetResponse(conversation, request );
|
||||||
WebForm formUrl = response.getForms()[1];
|
WebForm formUrl = response.getForms()[1];
|
||||||
formUrl.setParameter("url", "");
|
formUrl.setParameter("url", "");
|
||||||
@ -82,11 +82,11 @@ public class TestForm extends TestCase {
|
|||||||
WebForm forms[] = response.getForms();
|
WebForm forms[] = response.getForms();
|
||||||
assertEquals( 2, forms.length );
|
assertEquals( 2, forms.length );
|
||||||
// Ensure the Text field is empty
|
// Ensure the Text field is empty
|
||||||
assertTrue( forms[0].getParameterValue("text").startsWith("Bob"));
|
assertNull( forms[0].getParameterValue("text"));
|
||||||
// Ensure the URL field is correct
|
// Ensure the URL field is empty
|
||||||
assertTrue( forms[1].getParameterValue("url").endsWith("/img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000"));
|
assertTrue( forms[1].getParameterValue("url").isEmpty());
|
||||||
// Ensure the image is present
|
// Ensure there is no image
|
||||||
assertEquals( 1, response.getImages().length);
|
assertEquals( 0, response.getImages().length);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,9 @@ import com.meterware.httpunit.*;
|
|||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.Locale;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
|
||||||
public class TestImage extends TestCase {
|
public class TestImage extends TestCase {
|
||||||
/**
|
/**
|
||||||
@ -16,7 +19,7 @@ public class TestImage extends TestCase {
|
|||||||
WebResponse response = conversation.getResource( request);
|
WebResponse response = conversation.getResource( request);
|
||||||
// Analyze response
|
// Analyze response
|
||||||
// Verifies the Content-Type header
|
// Verifies the Content-Type header
|
||||||
assertEquals( "image/png", response.getContentType());
|
assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
|
||||||
// Get the image and verify its size
|
// Get the image and verify its size
|
||||||
InputStream responseStream = response.getInputStream();
|
InputStream responseStream = response.getInputStream();
|
||||||
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
|
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
|
||||||
@ -32,4 +35,25 @@ public class TestImage extends TestCase {
|
|||||||
assertTrue( diagramLen > 10000);
|
assertTrue( diagramLen > 10000);
|
||||||
assertTrue( diagramLen < 20000);
|
assertTrue( diagramLen < 20000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that the HTTP header of a diagram incites the browser to cache it.
|
||||||
|
*/
|
||||||
|
public void testDiagramHttpHeader() throws Exception {
|
||||||
|
WebConversation conversation = new WebConversation();
|
||||||
|
// Bob -> Alice : hello
|
||||||
|
WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"img/SyfFKj2rKt3CoKnELR1Io4ZDoSa70000");
|
||||||
|
WebResponse response = conversation.getResource( request);
|
||||||
|
// Analyze response
|
||||||
|
// Verifies the Content-Type header
|
||||||
|
assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
|
||||||
|
// Verifies the availability of the Expires entry in the response header
|
||||||
|
assertNotNull( response.getHeaderField( "Expires"));
|
||||||
|
// Verifies the availability of the Last-Modified entry in the response header
|
||||||
|
assertNotNull( response.getHeaderField( "Last-Modified"));
|
||||||
|
// Verifies the Last-Modified value is in the past
|
||||||
|
SimpleDateFormat format = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss ZZZ", Locale.ENGLISH);
|
||||||
|
Date lastModified = format.parse( response.getHeaderField( "Last-Modified"));
|
||||||
|
assertTrue( "Last-Modified is not in the past", lastModified.before( new Date()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
51
test/src/net/sourceforge/plantuml/servlet/TestProxy.java
Normal file
51
test/src/net/sourceforge/plantuml/servlet/TestProxy.java
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
package net.sourceforge.plantuml.servlet;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
import com.meterware.httpunit.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
|
||||||
|
public class TestProxy extends TestCase {
|
||||||
|
/**
|
||||||
|
* Verifies the proxified reception of the default Bob and Alice diagram
|
||||||
|
*/
|
||||||
|
public void testDefaultProxy() throws Exception {
|
||||||
|
WebConversation conversation = new WebConversation();
|
||||||
|
WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"proxy/"
|
||||||
|
+TestUtils.getServerUrl()+"welcome");
|
||||||
|
WebResponse response = conversation.getResource( request);
|
||||||
|
// Analyze response
|
||||||
|
// Verifies the Content-Type header
|
||||||
|
//assertEquals( "Response content type is not PNG", "image/png", response.getContentType());
|
||||||
|
// Get the image and verify its size (~1533 bytes)
|
||||||
|
InputStream responseStream = response.getInputStream();
|
||||||
|
ByteArrayOutputStream imageStream = new ByteArrayOutputStream();
|
||||||
|
byte[] buf = new byte[1024];
|
||||||
|
int n = 0;
|
||||||
|
while( ( n = responseStream.read( buf)) != -1) {
|
||||||
|
imageStream.write( buf, 0, n);
|
||||||
|
}
|
||||||
|
imageStream.close();
|
||||||
|
responseStream.close();
|
||||||
|
byte[] inMemoryImage = imageStream.toByteArray();
|
||||||
|
int diagramLen = inMemoryImage.length;
|
||||||
|
assertTrue( diagramLen > 1500);
|
||||||
|
assertTrue( diagramLen < 1600);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verifies that the HTTP header of a diagram incites the browser to cache it.
|
||||||
|
*/
|
||||||
|
public void testInvalidUrl() throws Exception {
|
||||||
|
WebConversation conversation = new WebConversation();
|
||||||
|
// Try to proxify an invalid address
|
||||||
|
WebRequest request = new GetMethodWebRequest( TestUtils.getServerUrl()+"proxy/invalidURL");
|
||||||
|
WebResponse response = conversation.getResource( request);
|
||||||
|
// Analyze response, it must be the empty form
|
||||||
|
// Verifies the Content-Type header
|
||||||
|
assertEquals( "Response content type is not HTML", "text/html", response.getContentType());
|
||||||
|
WebForm forms[] = response.getForms();
|
||||||
|
assertEquals( 2, forms.length );
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user