Skip to content

Commit

Permalink
Fix a ton of minor issues (frankframework#7371)
Browse files Browse the repository at this point in the history
  • Loading branch information
nielsm5 authored Aug 22, 2024
1 parent 3762996 commit 4b4bd64
Show file tree
Hide file tree
Showing 54 changed files with 621 additions and 662 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.frankframework.extensions.aspose;

import static org.frankframework.functional.FunctionalUtil.logMethod;

import java.io.InputStream;
import java.net.URL;
import java.util.EnumMap;
Expand Down Expand Up @@ -80,7 +78,7 @@ private void loadAsposeLicense(AsposeLibrary library) throws Exception {
licenseWrapper.loadLicense(inputStream);
log.info("loaded Aspose [{}] license", library::name);
} catch (Exception e) {
log.error("failed to load Aspose [{}] license", logMethod(library::name), e);
log.error("failed to load Aspose [{}] license", library.name(), e);
throw e;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2019-2021 WeAreFrank!
Copyright 2019-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@
import org.frankframework.core.PipeLineSession;
import org.frankframework.core.PipeRunException;
import org.frankframework.core.PipeRunResult;
import org.frankframework.doc.Default;
import org.frankframework.pipes.FixedForwardPipe;
import org.frankframework.stream.Message;

Expand All @@ -44,26 +43,24 @@ public class AmountOfPagesPipe extends FixedForwardPipe {
public PipeRunResult doPipe(Message input, PipeLineSession session) throws PipeRunException {
int result = 0;

try (InputStream binaryInputStream = input.asInputStream(getCharset())){
Document doc = new Document(binaryInputStream);
result = doc.getPages().size();
try (InputStream binaryInputStream = input.asInputStream(charset)){
try (Document doc = new Document(binaryInputStream)) {
result = doc.getPages().size();
}
} catch (IOException e) {
throw new PipeRunException(this, "cannot encode message using charset [" + getCharset() + "]", e);
throw new PipeRunException(this, "cannot encode message using charset [" + charset + "]", e);
} catch (InvalidPasswordException ip) {
return new PipeRunResult(findForward("passwordProtected"), "File is password protected." );
}

return new PipeRunResult(getSuccessForward(), Integer.toString(result) );
return new PipeRunResult(getSuccessForward(), Integer.toString(result));
}

/**
* Charset to be used to encode the given input string
* Charset to be used to read the input message.
* Defaults to the message's known charset or UTF-8 when unknown.
*/
@Default("UTF-8")
public void setCharset(String charset){
this.charset = charset;
}
public String getCharset(){
return charset;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
*/
package org.frankframework.extensions.aspose.services.conv.impl.convertors;

import static org.frankframework.functional.FunctionalUtil.logMethod;
import static org.frankframework.functional.FunctionalUtil.logValue;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -33,6 +30,7 @@
import org.frankframework.extensions.aspose.services.conv.CisConversionResult;
import org.frankframework.extensions.aspose.services.util.ConvertorUtil;
import org.frankframework.stream.Message;
import org.frankframework.util.ClassUtils;
import org.frankframework.util.DateFormatUtils;
import org.springframework.http.MediaType;

Expand Down Expand Up @@ -124,20 +122,20 @@ public final CisConversionResult convertToPdf(MediaType mediaType, String filena
}

protected int getNumberOfPages(File file) throws IOException {
int result = 0;
if(file != null) {
try (InputStream inStream = Files.newInputStream(file.toPath())) {
Document doc = new Document(inStream);
result = doc.getPages().size();
try(Document doc = new Document(inStream)) {
return doc.getPages().size();
}
}
}

return result;
return 0;
}

protected String createErrorMsg(Exception e) {
String timestamp = DateFormatUtils.now();
log.warn("failed to convert [{}] failed! (Timestamp: [{}])", logMethod(()-> getClass().getSimpleName()), logValue(timestamp), e);
log.warn("failed to convert [{}] failed! (Timestamp: [{}])", () -> ClassUtils.classNameOf(this), () -> timestamp, () -> e);
return "Conversion to PDF failed due to a technical failure. Please contact functional support." +
"(Timestamp: " + timestamp + ")";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,30 @@
package org.frankframework.extensions.aspose.services.conv.impl.convertors;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import org.apache.commons.lang3.StringUtils;
import org.frankframework.extensions.aspose.services.conv.CisConversionResult;
import org.frankframework.extensions.aspose.services.util.ConvertorUtil;
import org.frankframework.extensions.aspose.services.util.FileConstants;
import org.frankframework.stream.Message;
import org.frankframework.stream.MessageBuilder;

import com.aspose.pdf.Document;
import com.aspose.pdf.FileSpecification;
import com.aspose.pdf.PageMode;
import com.aspose.pdf.SaveFormat;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;
import lombok.extern.log4j.Log4j2;

import org.frankframework.extensions.aspose.services.conv.CisConversionResult;
import org.frankframework.extensions.aspose.services.util.ConvertorUtil;
import org.frankframework.extensions.aspose.services.util.FileConstants;
import org.frankframework.stream.Message;

/**
* This class will combine seperate pdf files to a single pdf with attachments.
* None existing files in a CisConversionResult will be skipped!
Expand Down Expand Up @@ -133,7 +133,6 @@ private String convertToValidFileName(@Nullable String value) {

@Nonnull
private Document getPdfDocument(@Nonnull String filePath) {

if (pdfDocument == null) {
// Open the base pdf.
pdfDocument = new Document(filePath);
Expand All @@ -148,14 +147,17 @@ private Document getPdfDocument(@Nonnull String filePath) {

@Nonnull
public static Message combineFiles(@Nonnull Message parent, @Nonnull Message attachment, String fileNameToAttach, String charset) throws IOException {
Document pdfDoc = new Document(parent.asInputStream(charset));
pdfDoc.setPageMode(PageMode.UseAttachments);
try (Document pdfDoc = new Document(parent.asInputStream(charset))) {
pdfDoc.setPageMode(PageMode.UseAttachments);

pdfDoc.getEmbeddedFiles().add(new FileSpecification(attachment.asInputStream(charset), fileNameToAttach));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
pdfDoc.save(baos, SaveFormat.Pdf);
pdfDoc.getEmbeddedFiles().add(new FileSpecification(attachment.asInputStream(charset), fileNameToAttach));
MessageBuilder messageBuilder = new MessageBuilder();
try (OutputStream out = messageBuilder.asOutputStream()) {
pdfDoc.save(out, SaveFormat.Pdf);
}

return new Message(baos.toByteArray());
return messageBuilder.build();
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ public void convert(MediaType mediaType, Message message, CisConversionResult re

} finally {
doc.freeMemory();
doc.dispose();
doc.close();

// Delete always the temporary file.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,15 @@ public PdfPipe createPipe() {
return new PdfPipe();
}

@Override
@BeforeEach
public void setUp() throws Exception {
super.setUp();
pipe.setPdfOutputLocation(pdfOutputLocation.toString());
pipe.setUnpackCommonFontsArchive(true);
}

@Override
@AfterEach
public void tearDown() {
synchronized(pdfOutputLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
import javax.xml.transform.TransformerException;

import jakarta.annotation.Nonnull;
import jakarta.annotation.Nullable;

import org.frankframework.util.ClassUtils;
import org.frankframework.util.StringUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
Expand Down Expand Up @@ -136,7 +139,7 @@ public static String expandMessage(String msg, Throwable e, ExcludeClassInfoExce
List<String> msgChain = getMessages(e, msg);
Throwable t = e;
for(String message:msgChain) {
String exceptionType = filter.accept(t) ? "" : "("+t.getClass().getSimpleName()+")";
String exceptionType = filter.accept(t) ? "" : "("+ClassUtils.classNameOf(t)+")";
message = StringUtil.concatStrings(exceptionType, " ", message);
result = StringUtil.concatStrings(result, ": ", message);
t = getCause(t);
Expand Down Expand Up @@ -179,6 +182,7 @@ public interface ExcludeClassInfoExceptionFilter {
*
* <p>If none of the above is found, returns {@code null}.</p>
*/
@Nullable
private static Throwable getCause(Throwable t) {
Throwable cause = ExceptionUtils.getCause(t);
if(cause == null && t.getSuppressed().length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
*/
public class FunctionalUtil {

private FunctionalUtil() {
// No-op
}

/**
* Helper function to create a {@link Supplier} to supply the single constant argument value.
* <p>
Expand Down Expand Up @@ -145,9 +149,4 @@ public static <T> Supplier<T> supplier(Supplier<T> s) {
public static <T,R> Function<T,R> function(Function<T, R> f) {
return f;
}


private FunctionalUtil() {
// No-op
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021-2023 WeAreFrank!
Copyright 2021-2024 WeAreFrank!
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,10 @@

public class SpringUtils {

@SuppressWarnings("unchecked")
/**
* Even though this has been deprecated, we cannot use the new/alternative method due to the autowireByName capability.
*/
@SuppressWarnings({ "unchecked", "deprecation" })
public static <T> T createBean(ApplicationContext applicationContext, Class<T> beanClass) {
return (T) applicationContext.getAutowireCapableBeanFactory().createBean(beanClass, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
public class StartIbis {

@SuppressWarnings({"resource", "java:S2095"})
public static void main(String[] args) {
IbisContext ibisContext = new IbisContext();
ibisContext.init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@
import org.springframework.context.support.AbstractRefreshableConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import jakarta.annotation.Nullable;

/**
* Container of {@link Adapter Adapters} that belong together.
* A configuration may be deployed independently from other configurations.
Expand Down Expand Up @@ -465,6 +467,7 @@ public void setVersion(String version) {
* If no ClassLoader has been set it tries to fall back on the `configurations.xxx.classLoaderType` property.
* Because of this, it may not always represent the correct or accurate type.
*/
@Nullable
public String getClassLoaderType() {
if(!(getClassLoader() instanceof IConfigurationClassLoader)) { //Configuration has not been loaded yet
String type = AppConstants.getInstance().getProperty("configurations."+getName()+".classLoaderType");
Expand All @@ -474,6 +477,10 @@ public String getClassLoaderType() {
return null;
}

if(getClassLoader() == null) {
return null;
}

return getClassLoader().getClass().getSimpleName();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ protected void handle(DigesterRule rule) {
* Return the specified factory or the default factory when empty.
* The factory should be Spring wired
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
@SuppressWarnings({ "unchecked" })
private ObjectCreationFactory<Object> getFactory(String factory) {
if("null".equals(factory)) { //Check against a null-string when you don't want to use the default factory
if(log.isTraceEnabled()) log.trace("NULL factory specified, skip factory registration");
Expand Down
45 changes: 22 additions & 23 deletions core/src/main/java/org/frankframework/jms/JMSFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.frankframework.jms;

import static org.frankframework.functional.FunctionalUtil.logValue;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -27,25 +25,6 @@
import javax.naming.NamingException;
import javax.xml.transform.TransformerException;

import jakarta.annotation.Nonnull;
import jakarta.jms.BytesMessage;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.InvalidDestinationException;
import jakarta.jms.JMSException;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Queue;
import jakarta.jms.QueueSender;
import jakarta.jms.QueueSession;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
import jakarta.jms.Topic;
import jakarta.jms.TopicPublisher;
import jakarta.jms.TopicSession;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.util.Supplier;
import org.frankframework.configuration.ConfigurationException;
Expand All @@ -71,6 +50,26 @@
import org.springframework.transaction.support.TransactionSynchronizationManager;
import org.xml.sax.SAXException;

import jakarta.annotation.Nonnull;
import jakarta.jms.BytesMessage;
import jakarta.jms.ConnectionFactory;
import jakarta.jms.Destination;
import jakarta.jms.InvalidDestinationException;
import jakarta.jms.JMSException;
import jakarta.jms.MessageConsumer;
import jakarta.jms.MessageProducer;
import jakarta.jms.Queue;
import jakarta.jms.QueueSender;
import jakarta.jms.QueueSession;
import jakarta.jms.Session;
import jakarta.jms.TextMessage;
import jakarta.jms.Topic;
import jakarta.jms.TopicPublisher;
import jakarta.jms.TopicSession;
import lombok.Getter;
import lombok.Setter;
import lombok.SneakyThrows;


/**
* Provides functions for jms connections, queues and topics and acts as a facade
Expand Down Expand Up @@ -398,7 +397,7 @@ public void setMessageCorrelationID(jakarta.jms.Message message, String correlat
}
if (cidlen > correlationIdMaxLength) {
correlationID = correlationIdToHexPrefix + correlationID.substring(correlationID.length() - correlationIdMaxLength);
log.debug("correlationId shortened to [{}]", logValue(correlationID));
log.debug("correlationId shortened to [{}]", correlationID);
}
}
if (correlationIdToHex && correlationID.startsWith(correlationIdToHexPrefix)) {
Expand All @@ -409,7 +408,7 @@ public void setMessageCorrelationID(jakarta.jms.Message message, String correlat
hexCorrelationID.append(Integer.toHexString(c));
}
correlationID = hexCorrelationID.toString();
log.debug("correlationId changed, based on hexidecimal values, to [{}]", logValue(correlationID));
log.debug("correlationId changed, based on hexidecimal values, to [{}]", correlationID);
}
message.setJMSCorrelationID(correlationID);
}
Expand Down
Loading

0 comments on commit 4b4bd64

Please sign in to comment.