Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
18.1.1 release
  • Loading branch information
davidjgraph committed May 20, 2022
1 parent 7764b25 commit 9dc0d5d
Show file tree
Hide file tree
Showing 19 changed files with 577 additions and 109 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
@@ -1,3 +1,10 @@
20-MAY-2022: 18.1.1

- [VSDX import] Fixes case when theme index is incorrect
- Checks stencil name parameter in embed servlet
- Adds DOM_PURIFY_CONFIG global variable
- Check env var is set in ExportProxy

19-MAY-2022: 18.0.8

- Deletes unused ExportProxyServlet
Expand Down
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
18.0.8
18.1.1
2 changes: 1 addition & 1 deletion etc/build/build.xml
Expand Up @@ -504,7 +504,7 @@

<target name="javac" description="Java compilation">
<mkdir dir="${javac.dir}"/>
<javac includeantruntime="false" srcdir="${src.dir}" excludes="**/EmbedServlet2.java" destdir="${javac.dir}">
<javac includeantruntime="false" srcdir="${src.dir}" destdir="${javac.dir}">
<classpath refid="javac.class.path" />
</javac>
<copy todir="${javac.dir}" file="${src.dir}/log4j.properties" />
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/mxgraph/online/EmbedServlet2.java
Expand Up @@ -24,6 +24,7 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.File;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
Expand Down Expand Up @@ -268,7 +269,7 @@ public String createEmbedJavaScript(HttpServletRequest request)

for (int i = 0; i < names.length; i++)
{
if (names[i].indexOf("..") < 0 && !done.contains(names[i]))
if (names[i].indexOf("..") < 0 && !done.contains(names[i]) && names[i].length() > 0)
{
if (names[i].equals("*"))
{
Expand All @@ -278,6 +279,9 @@ public String createEmbedJavaScript(HttpServletRequest request)
}
else
{
// Makes name canonical
names[i] = new File("/" + names[i]).getCanonicalPath().substring(1);

// Checks if any JS files are associated with the library
// name and injects the JS into the page
String[] libs = libraries.get(names[i]);
Expand Down
168 changes: 168 additions & 0 deletions src/main/java/com/mxgraph/online/ExportProxyServlet.java
@@ -0,0 +1,168 @@
package com.mxgraph.online;

import java.io.IOException;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation ExportProxyServlet
*/
@SuppressWarnings("serial")
public class ExportProxyServlet extends HttpServlet
{
private final String[] supportedServices = {"EXPORT_URL", "PLANTUML_URL", "VSD_CONVERT_URL", "EMF_CONVERT_URL"};

private void doRequest(String method, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
try
{
int serviceId = 0;
String proxyPath = "";
String queryString = "";

try
{
if (request.getQueryString() != null)
{
queryString = "?" + request.getQueryString();
}

if (request.getPathInfo() != null) // /{serviceId}/*
{
String[] pathParts = request.getPathInfo().split("/");

if (pathParts.length > 1)
{
serviceId = Integer.parseInt(pathParts[1]);
}

if (pathParts.length > 2)
{
proxyPath = String.join("/", Arrays.copyOfRange(pathParts, 2, pathParts.length));
}

if (serviceId < 0 || serviceId > supportedServices.length)
{
serviceId = 0;
}
}
}
catch (Exception e)
{
// Ignore and use 0
serviceId = 0;
}

String exportUrl = System.getenv(supportedServices[serviceId]);

if (exportUrl == null || exportUrl.isEmpty())
{
throw new Exception(supportedServices[serviceId] + " not set");
}

URL url = new URL(exportUrl + proxyPath + queryString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();

con.setRequestMethod(method);

//Copy request headers to export server
Enumeration<String> headerNames = request.getHeaderNames();

while (headerNames.hasMoreElements())
{
String headerName = headerNames.nextElement();
Enumeration<String> headers = request.getHeaders(headerName);

while (headers.hasMoreElements())
{
String headerValue = headers.nextElement();
con.addRequestProperty(headerName, headerValue);
}
}

if ("POST".equals(method))
{
// Send post request
con.setDoOutput(true);

OutputStream params = con.getOutputStream();
Utils.copy(request.getInputStream(), params);
params.flush();
params.close();
}

int responseCode = con.getResponseCode();
//Copy response code
response.setStatus(responseCode);

//Copy response headers
Map<String, List<String>> map = con.getHeaderFields();

for (Map.Entry<String, List<String>> entry : map.entrySet())
{
String key = entry.getKey();

if (key != null)
{
for (String val : entry.getValue())
{

response.addHeader(entry.getKey(), val);
}
}
}

//Copy response
OutputStream out = response.getOutputStream();

//Error
if (responseCode >= 400)
{
Utils.copy(con.getErrorStream(), out);
}
else //Success
{
Utils.copy(con.getInputStream(), out);
}

out.flush();
out.close();
}
catch (Exception e)
{
response.setStatus(
HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
e.printStackTrace();
}
}


/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
doRequest("GET", request, response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{
doRequest("POST", request, response);
}
}
14 changes: 14 additions & 0 deletions src/main/webapp/WEB-INF/web.xml
Expand Up @@ -95,6 +95,20 @@
<servlet-name>ConverterServlet</servlet-name>
<url-pattern>/convert</url-pattern>
</servlet-mapping>
<servlet>
<description/>
<display-name>ExportProxyServlet</display-name>
<servlet-name>ExportProxyServlet</servlet-name>
<servlet-class>com.mxgraph.online.ExportProxyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ExportProxyServlet</servlet-name>
<url-pattern>/export</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ExportProxyServlet</servlet-name>
<url-pattern>/service/*</url-pattern>
</servlet-mapping>
<servlet>
<description/>
<display-name>GitlabAuthServlet</display-name>
Expand Down

0 comments on commit 9dc0d5d

Please sign in to comment.