Skip to content

Commit

Permalink
Add test and simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
gberaudo committed Oct 1, 2020
1 parent 774975b commit a8e95d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import org.locationtech.jts.util.Assert;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.processor.Processor;
import org.mapfish.print.url.data.DataUrlConnection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -113,8 +112,7 @@ protected synchronized ClientHttpResponse executeInternal(final HttpHeaders head
return executeCallbacksAndRequest(this.request);
}
if ("data".equals(this.uri.getScheme())) {
final DataUrlConnection duc = new DataUrlConnection(this.uri.toURL());
final InputStream is = duc.getInputStream();
final InputStream is = this.uri.toURL().openStream();
final ConfigFileResolverHttpResponse response =
new ConfigFileResolverHttpResponse(is, headers);
LOGGER.debug("Resolved request: {} using DataUrlConnection.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.mapfish.print.TestHttpClientFactory;
import org.mapfish.print.config.Configuration;
import org.mapfish.print.config.ConfigurationFactory;
import org.mapfish.print.url.data.Handler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
Expand All @@ -26,6 +27,9 @@
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
public class ConfigFileResolvingHttpRequestFactoryTest extends AbstractMapfishSpringTest {

static {
Handler.configureProtocolHandler();
}
private static final String BASE_DIR = "/org/mapfish/print/servlet/";
private static final String HOST = "host.com";

Expand All @@ -40,7 +44,7 @@ public class ConfigFileResolvingHttpRequestFactoryTest extends AbstractMapfishSp
@Before
public void setUp() throws Exception {
requestFactory.registerHandler(input -> true,
createFileHandler(URI::getPath)
createFileHandler(URI::getPath)
);

final Configuration config = configurationFactory.getConfig(getFile(BASE_DIR + "config.yaml"));
Expand Down Expand Up @@ -154,4 +158,19 @@ public void testCreateRequestIllegalFile() throws Exception {

request.execute();
}

@Test
public void testCreateRequestDataGet() throws Exception {
final URI uri = new URI(
"data:image/png;base64,iVBORw0KGgoAAA" +
"ANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4" +
"//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU" +
"5ErkJggg==");
final ClientHttpRequest request = resolvingFactory.createRequest(uri, HttpMethod.GET);
final ClientHttpResponse response = request.execute();
assertEquals(HttpStatus.OK, response.getStatusCode());

final byte[] actual = IOUtils.toByteArray(response.getBody());
assertEquals(85, actual.length);
}
}

0 comments on commit a8e95d9

Please sign in to comment.