Skip to content

Commit 0205efb

Browse files
committed
Remove dead extension jnlp server endpoint
Signed-off-by: Mitch Gaffigan <mitch.gaffigan@comcast.net>
1 parent a403863 commit 0205efb

3 files changed

Lines changed: 4 additions & 165 deletions

File tree

server/src/com/mirth/connect/server/MirthWebServer.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,6 @@ public boolean accept(File file) {
347347
servletContextHandler.addFilter(new FilterHolder(new MethodFilter()), "/*", EnumSet.of(DispatcherType.REQUEST));
348348
servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart.jnlp");
349349
servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart");
350-
servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart/extensions/*");
351350
handlers.addHandler(servletContextHandler);
352351

353352
// add the default handler for misc requests (favicon, etc.)

server/src/com/mirth/connect/server/servlets/WebStartServlet.java

Lines changed: 2 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import javax.servlet.http.HttpServletResponse;
3131
import javax.xml.parsers.DocumentBuilderFactory;
3232

33-
import com.mirth.connect.client.core.BrandingConstants;
3433
import org.apache.commons.configuration2.PropertiesConfiguration;
3534
import org.apache.commons.configuration2.ex.ConfigurationException;
3635
import org.apache.commons.lang3.StringUtils;
@@ -85,10 +84,6 @@ public void doGet(HttpServletRequest request, HttpServletResponse response) thro
8584
if ((request.getRequestURI().equals(contextPathProp + "/webstart.jnlp") || request.getRequestURI().equals(contextPathProp + "/webstart")) && isWebstartRequestValid(request)) {
8685
jnlpDocument = getAdministratorJnlp(request);
8786
response.setHeader("Content-Disposition", "attachment; filename = \"webstart.jnlp\"");
88-
} else if (request.getServletPath().equals("/webstart/extensions") && isWebstartExtensionsRequestValid(request, contextPathProp)) {
89-
String extensionPath = getExtensionPath(request);
90-
jnlpDocument = getExtensionJnlp(getExtensionPath(request));
91-
response.setHeader("Content-Disposition", "attachment; filename = \"" + extensionPath + ".jnlp\"");
9287
} else {
9388
response.setContentType("");
9489
}
@@ -123,16 +118,6 @@ private boolean isWebstartRequestValid(HttpServletRequest request) {
123118
return true;
124119
}
125120

126-
private boolean isWebstartExtensionsRequestValid(HttpServletRequest request, String contextPathProp) {
127-
// Don't allow any parameters and don't allow modified URIs
128-
return request.getParameterMap().isEmpty()
129-
&& (contextPathProp + request.getServletPath() + "/" + getExtensionPath(request)).equals(StringUtils.removeEnd(request.getRequestURI(), ".jnlp"));
130-
}
131-
132-
private String getExtensionPath(HttpServletRequest request) {
133-
return StringUtils.removeEnd(StringUtils.removeStart(request.getPathInfo(), "/"), ".jnlp");
134-
}
135-
136121
protected Document getAdministratorJnlp(HttpServletRequest request) throws Exception {
137122
InputStream clientJnlpIs = null;
138123
Document document;
@@ -314,53 +299,7 @@ private boolean doesExtensionHaveClientOrSharedLibraries(MetaData extension) {
314299
return false;
315300
}
316301

317-
protected Document getExtensionJnlp(String extensionPath) throws Exception {
318-
List<MetaData> allExtensions = new ArrayList<MetaData>();
319-
allExtensions.addAll(ControllerFactory.getFactory().createExtensionController().getConnectorMetaData().values());
320-
allExtensions.addAll(ControllerFactory.getFactory().createExtensionController().getPluginMetaData().values());
321-
List<String> extensionsWithThePath = new ArrayList<String>();
322-
323-
for (MetaData metaData : allExtensions) {
324-
if (metaData.getPath().equals(extensionPath)) {
325-
extensionsWithThePath.add(metaData.getName());
326-
}
327-
}
328-
329-
DocumentBuilderFactory dbf = getSecureDocumentBuilderFactory();
330-
Document document = dbf.newDocumentBuilder().newDocument();
331-
Element jnlpElement = document.createElement("jnlp");
332-
333-
Element informationElement = document.createElement("information");
334-
335-
Element titleElement = document.createElement("title");
336-
titleElement.setTextContent("Mirth Connect Extension - [" + StringUtils.join(extensionsWithThePath, ",") + "]");
337-
informationElement.appendChild(titleElement);
338-
339-
Element vendorElement = document.createElement("vendor");
340-
vendorElement.setTextContent(BrandingConstants.COMPANY_NAME);
341-
informationElement.appendChild(vendorElement);
342-
343-
jnlpElement.appendChild(informationElement);
344-
345-
Element securityElement = document.createElement("security");
346-
securityElement.appendChild(document.createElement("all-permissions"));
347-
jnlpElement.appendChild(securityElement);
348-
349-
Element resourcesElement = document.createElement("resources");
350-
351-
getExtensionJnlp(extensionPath, document, resourcesElement, "libs/");
352-
353-
jnlpElement.appendChild(resourcesElement);
354-
jnlpElement.appendChild(document.createElement("component-desc"));
355-
document.appendChild(jnlpElement);
356-
return document;
357-
}
358-
359-
protected void getExtensionJnlp(String extensionPath, Document document, Element resourcesElement) throws Exception {
360-
getExtensionJnlp(extensionPath, document, resourcesElement, "webstart/extensions/libs/");
361-
}
362-
363-
private void getExtensionJnlp(String extensionPath, Document document, Element resourcesElement, String libraryPathPrefix) throws Exception {
302+
private void getExtensionJnlp(String extensionPath, Document document, Element resourcesElement) throws Exception {
364303
List<MetaData> allExtensions = new ArrayList<MetaData>();
365304
allExtensions.addAll(ControllerFactory.getFactory().createExtensionController().getConnectorMetaData().values());
366305
allExtensions.addAll(ControllerFactory.getFactory().createExtensionController().getPluginMetaData().values());
@@ -388,7 +327,7 @@ private void getExtensionJnlp(String extensionPath, Document document, Element r
388327
for (String library : librariesToAddToJnlp) {
389328
Element jarElement = document.createElement("jar");
390329
jarElement.setAttribute("download", "eager");
391-
jarElement.setAttribute("href", libraryPathPrefix + extensionPath + "/" + library);
330+
jarElement.setAttribute("href", "webstart/extensions/libs/" + extensionPath + "/" + library);
392331
jarElement.setAttribute("sha256", getDigest(extensionDirectory, library));
393332
resourcesElement.appendChild(jarElement);
394333
}

server/test/com/mirth/connect/server/servlets/WebStartServletTest.java

Lines changed: 2 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -203,91 +203,6 @@ public void testDoGetCoreModifiedURL() throws Exception {
203203
assertNull(response.getHeader("Content-Disposition"));
204204
}
205205

206-
@Test
207-
public void testDoGetExtension() throws Exception {
208-
// Test /webstart/extensions/testextension
209-
HttpServletRequest request = mock(HttpServletRequest.class);
210-
when(request.getRequestURI()).thenReturn("/webstart/extensions/testextension");
211-
when(request.getServletPath()).thenReturn("/webstart/extensions");
212-
when(request.getPathInfo()).thenReturn("/testextension");
213-
when(request.getParameterNames()).thenReturn(Collections.emptyEnumeration());
214-
215-
TestHttpServletResponse response = new TestHttpServletResponse();
216-
217-
webStartServlet.doGet(request, response);
218-
219-
assertEquals(normalizeWhitespace(EXTENSION_JNLP), normalizeWhitespace(response.getResponseString()));
220-
assertEquals("application/x-java-jnlp-file", response.getContentType());
221-
assertEquals("no-cache", response.getHeader("Pragma"));
222-
assertEquals("nosniff", response.getHeader("X-Content-Type-Options"));
223-
assertEquals("attachment; filename = \"testextension.jnlp\"", response.getHeader("Content-Disposition"));
224-
225-
// Test /webstart/extensions/testextension.jnlp
226-
request = mock(HttpServletRequest.class);
227-
when(request.getRequestURI()).thenReturn("/webstart/extensions/testextension.jnlp");
228-
when(request.getServletPath()).thenReturn("/webstart/extensions");
229-
when(request.getPathInfo()).thenReturn("/testextension");
230-
when(request.getParameterNames()).thenReturn(Collections.emptyEnumeration());
231-
232-
response = new TestHttpServletResponse();
233-
234-
webStartServlet.doGet(request, response);
235-
236-
assertEquals(normalizeWhitespace(EXTENSION_JNLP), normalizeWhitespace(response.getResponseString()));
237-
assertEquals("application/x-java-jnlp-file", response.getContentType());
238-
assertEquals("no-cache", response.getHeader("Pragma"));
239-
assertEquals("nosniff", response.getHeader("X-Content-Type-Options"));
240-
assertEquals("attachment; filename = \"testextension.jnlp\"", response.getHeader("Content-Disposition"));
241-
}
242-
243-
@Test
244-
public void testDoGetExtensionQueryParams() throws Exception {
245-
HttpServletRequest request = mock(HttpServletRequest.class);
246-
when(request.getRequestURI()).thenReturn("/webstart/extensions/testextension");
247-
when(request.getServletPath()).thenReturn("/webstart/extensions");
248-
when(request.getPathInfo()).thenReturn("/testextension");
249-
250-
Map<String, String[]> parameters = new HashMap<>();
251-
parameters.put("maxHeapSize", new String[] { "1024m" });
252-
253-
when(request.getParameterNames()).thenReturn(Collections.enumeration(parameters.keySet()));
254-
when(request.getParameter(anyString())).thenAnswer(new Answer<String>() {
255-
@Override
256-
public String answer(InvocationOnMock invocation) throws Throwable {
257-
Object[] args = invocation.getArguments();
258-
return parameters.get((String) args[0])[0];
259-
}
260-
});
261-
when(request.getParameterMap()).thenReturn(parameters);
262-
263-
TestHttpServletResponse response = new TestHttpServletResponse();
264-
265-
webStartServlet.doGet(request, response);
266-
267-
assertEquals("", response.getResponseString().trim());
268-
assertEquals("", response.getResponseString().trim());
269-
assertEquals("", response.getContentType());
270-
assertNull(response.getHeader("Content-Disposition"));
271-
}
272-
273-
@Test
274-
public void testDoGetExtensionModifiedURL() throws Exception {
275-
HttpServletRequest request = mock(HttpServletRequest.class);
276-
when(request.getRequestURI()).thenReturn("/webstart/extensions/testextension;rfd.bat");
277-
when(request.getServletPath()).thenReturn("/webstart/extensions");
278-
when(request.getPathInfo()).thenReturn("/testextension");
279-
when(request.getParameterNames()).thenReturn(Collections.emptyEnumeration());
280-
281-
TestHttpServletResponse response = new TestHttpServletResponse();
282-
283-
webStartServlet.doGet(request, response);
284-
285-
assertEquals("", response.getResponseString().trim());
286-
assertEquals("", response.getResponseString().trim());
287-
assertEquals("", response.getContentType());
288-
assertNull(response.getHeader("Content-Disposition"));
289-
}
290-
291206
private static class TestHttpServletResponse implements HttpServletResponse {
292207

293208
private String contentType;
@@ -521,13 +436,6 @@ protected Document getAdministratorJnlp(HttpServletRequest request) throws Excep
521436
return factory.newDocumentBuilder()
522437
.parse(new ByteArrayInputStream(CORE_JNLP.getBytes()));
523438
}
524-
525-
@Override
526-
protected Document getExtensionJnlp(String extensionPath) throws Exception {
527-
DocumentBuilderFactory factory = getSecureDocumentBuilderFactory();
528-
return factory.newDocumentBuilder()
529-
.parse(new ByteArrayInputStream(EXTENSION_JNLP.getBytes()));
530-
}
531439
}
532440

533441
private static DocumentBuilderFactory getSecureDocumentBuilderFactory() throws Exception {
@@ -558,16 +466,9 @@ private static String normalizeWhitespace(String input) {
558466
+ " <j2se href=\"http://java.sun.com/products/autodl/j2se\" max-heap-size=\"512m\" version=\"1.6+\"/>\n"
559467
+ " <jar download=\"eager\" href=\"webstart/client-lib/mirth-client.jar\" main=\"true\" sha256=\"0Lv3mOM4e10OBhk78/ST2CzHrXtm+EcZibxV7VfdbI8=\"/>\n"
560468
+ " <jar download=\"eager\" href=\"webstart/client-lib/mirth-client-core.jar\" sha256=\"testsha256\"/>\n"
561-
+ " <extension href=\"webstart/extensions/test.jnlp\"/>\n" + " </resources>\n" + " \n"
469+
+ " <jar download=\"eager\" href=\"webstart/extensions/libs/file/test-client.jar\" sha256=\"testsha256\"/>\n"
470+
+ " <jar download=\"eager\" href=\"webstart/extensions/libs/file/test-shared.jar\" sha256=\"testsha256\"/>\n" + " </resources>\n" + " \n"
562471
+ " <application-desc main-class=\"com.mirth.connect.client.ui.Mirth\">\n"
563472
+ " <argument>https://localhost:8443</argument>\n" + " <argument>99.99.99</argument>\n"
564473
+ " </application-desc>\n" + "</jnlp>";
565-
566-
private static String EXTENSION_JNLP = "<jnlp>\n" + " <information>\n"
567-
+ " <title>Mirth Connect Extension - [Test Writer,Test Reader]</title>\n"
568-
+ " <vendor>NextGen Healthcare</vendor>\n" + " </information>\n" + " <security>\n"
569-
+ " <all-permissions/>\n" + " </security>\n" + " <resources>\n"
570-
+ " <jar download=\"eager\" href=\"libs/file/test-client.jar\" sha256=\"testsha256\"/>\n"
571-
+ " <jar download=\"eager\" href=\"libs/file/test-shared.jar\" sha256=\"testsha256\"/>\n"
572-
+ " </resources>\n" + " <component-desc/>\n" + "</jnlp>\n" + "";
573474
}

0 commit comments

Comments
 (0)