Skip to content

Commit

Permalink
Merge pull request #3328 from mapfish/GSMFP-23
Browse files Browse the repository at this point in the history
Use StandardCharsets and stop using xml parser with raster content
  • Loading branch information
sebr72 authored Jun 14, 2024
2 parents 8ed7bf5 + 2fdb9e8 commit 2ed89b5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.annotation.PostConstruct;
import org.slf4j.Logger;
Expand Down Expand Up @@ -63,7 +64,8 @@ public final Configuration getConfig(final File configFile, final InputStream co
configuration.setConfigurationFile(configFile);
MapfishPrintConstructor.setConfigurationUnderConstruction(configuration);

final Configuration config = this.yaml.load(new InputStreamReader(configData, "UTF-8"));
final Configuration config =
this.yaml.load(new InputStreamReader(configData, StandardCharsets.UTF_8));
if (this.doValidation) {
final List<Throwable> validate = config.validate();
if (!validate.isEmpty()) {
Expand Down
24 changes: 11 additions & 13 deletions core/src/main/java/org/mapfish/print/map/style/SLDParserPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.Optional;
import java.util.function.Function;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class SLDParserPlugin implements StyleParserPlugin {
*/
public static final String STYLE_INDEX_REF_SEPARATOR = "##";

public static final String RASTER = "raster";

@Override
public final Optional<Style> parseStyle(
@Nullable final Configuration configuration,
Expand Down Expand Up @@ -85,6 +88,9 @@ private Optional<Style> tryLoadSLD(
Assert.isTrue(
styleIndex == null || styleIndex > -1, "styleIndex must be > -1 but was: " + styleIndex);

if (RASTER.equals(new String(bytes, Charset.defaultCharset()))) {
return Optional.empty();
}
final Style[] styles;
try {

Expand Down Expand Up @@ -163,27 +169,19 @@ public static class ErrorHandler extends DefaultHandler {

private static final Logger LOGGER = LoggerFactory.getLogger(ErrorHandler.class);

/**
* @param e Exception
*/
public final void error(final SAXParseException e) throws SAXException {
LOGGER.debug("XML error: {}", e.getLocalizedMessage());
LOGGER.warn("XML error: {}", e.getLocalizedMessage(), e);
super.error(e);
}

/**
* @param e Exception
*/
public final void fatalError(final SAXParseException e) throws SAXException {
LOGGER.debug("XML fatal error: {}", e.getLocalizedMessage());
LOGGER.warn("XML fatal error: {}", e.getLocalizedMessage(), e);
super.fatalError(e);
}

/**
* @param e Exception
*/
public final void warning(final SAXParseException e) {
// ignore
public final void warning(final SAXParseException e) throws SAXException {
LOGGER.warn("XML warning: {}", e.getLocalizedMessage(), e);
super.warning(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,18 @@ public final void shutdown() {
}

private void executeJob(final PrintJob job) {
LOGGER.debug(
"executeJob {}, PoolSize {}, CorePoolSize {}, Active {}, Completed {}, Task {}, isShutdown"
+ " {}, isTerminated {}",
job,
this.executor.getPoolSize(),
this.executor.getCorePoolSize(),
this.executor.getActiveCount(),
this.executor.getCompletedTaskCount(),
this.executor.getTaskCount(),
this.executor.isShutdown(),
this.executor.isTerminated());

final Future<PrintJobResult> future = this.executor.submit(job);
this.runningTasksFutures.put(
job.getEntry().getReferenceId(), new SubmittedPrintJob(future, job.getEntry()));
Expand Down Expand Up @@ -482,7 +494,6 @@ private boolean isTimeoutExceeded(final SubmittedPrintJob printJob) {
* If the status of a print job is not checked for a while, we assume that the user is no longer
* interested in the report, and we cancel the job.
*
* @param printJob
* @return is the abandoned timeout exceeded?
*/
private boolean isAbandoned(final SubmittedPrintJob printJob) {
Expand Down

0 comments on commit 2ed89b5

Please sign in to comment.