Skip to content

Commit

Permalink
Merge pull request #290 from b123400/fix-289
Browse files Browse the repository at this point in the history
Encoding Option zu result-dispatch hinzufügen
  • Loading branch information
zdavatz authored Oct 24, 2024
2 parents e91d9b3 + 90eb61e commit 3b40f7d
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 75 deletions.
7 changes: 3 additions & 4 deletions java/cli/src/main/java/com/ywesee/java/yopenedi/cli/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.ywesee.java.yopenedi.OpenTrans.Order;
import com.ywesee.java.yopenedi.common.Config;
import com.ywesee.java.yopenedi.converter.Converter;
import com.ywesee.java.yopenedi.OpenTrans.OpenTransWriter;
import com.ywesee.java.yopenedi.converter.Pair;
import com.ywesee.java.yopenedi.converter.Writable;
import org.apache.commons.cli.*;
Expand All @@ -21,6 +20,7 @@
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Properties;

Expand Down Expand Up @@ -193,8 +193,7 @@ static void edifactToOpenTrans(InputStream in, File outFile, CommandLine cmd, Co
} else {
out = System.out;
}
OpenTransWriter w = new OpenTransWriter(config);
w.write(otOrder, out);
otOrder.write(out, config, StandardCharsets.UTF_8);
out.close();
if (!isMultiple) {
break;
Expand All @@ -212,7 +211,7 @@ static void openTransToEdifact(InputStream in, File outFile, CommandLine cmd, Co
out = System.out;
}
Pair<Converter.FileType, Writable> result = converter.run(in);
result.snd.write(out, config);
result.snd.write(out, config, StandardCharsets.ISO_8859_1);

out.flush();
if (out instanceof FileOutputStream) {
Expand Down
3 changes: 2 additions & 1 deletion java/conf/result-dispatch.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"headers": {
"AS2-From": "janico_ch",
"AS2-To": "NOWISCC_AS2"
}
},
"encoding": "UTF-8"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -76,7 +77,7 @@ public void setRecipientGLNOverride(String replaced) {
this.recipientGLNOverride = replaced;
}

public void write(OutputStream outputStream) throws Exception {
public void write(OutputStream outputStream, Charset encoding) throws Exception {
D96AInterchangeFactory factory = D96AInterchangeFactory.getInstance();
UNEdifactInterchange41 interchange = new UNEdifactInterchange41();
Delimiters delimiters = new Delimiters();
Expand Down Expand Up @@ -627,10 +628,10 @@ public void write(OutputStream outputStream) throws Exception {
unt41.setMessageRefNum("1");
unt41.setSegmentCount(segmentCount);
message41.setMessageTrailer(unt41);
factory.toUNEdifact(interchange, new OutputStreamWriter(outputStream, StandardCharsets.ISO_8859_1));
factory.toUNEdifact(interchange, new OutputStreamWriter(outputStream, encoding));
}

public void write(OutputStream s, Config _config) throws Exception {
this.write(s);
public void write(OutputStream s, Config _config, Charset encoding) throws Exception {
this.write(s, encoding);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.ywesee.java.yopenedi.common.Config;
import com.ywesee.java.yopenedi.common.MessageExchange;
import com.ywesee.java.yopenedi.converter.Writable;
import org.apache.commons.lang.StringUtils;
import org.milyn.edi.unedifact.d96a.D96AInterchangeFactory;
import org.milyn.edi.unedifact.d96a.INVOIC.*;
import org.milyn.edi.unedifact.d96a.common.*;
Expand All @@ -17,6 +16,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void setRecipientGLNOverride(String replaced) {
this.recipientGLNOverride = replaced;
}

public void write(OutputStream outputStream) throws Exception {
public void write(OutputStream outputStream, Charset encoding) throws Exception {
D96AInterchangeFactory factory = D96AInterchangeFactory.getInstance();
UNEdifactInterchange41 interchange = new UNEdifactInterchange41();
Delimiters delimiters = new Delimiters();
Expand Down Expand Up @@ -957,10 +957,10 @@ public void write(OutputStream outputStream) throws Exception {
message41.setMessageTrailer(unt41);
interchange.setMessages(Arrays.asList(message41));

factory.toUNEdifact(interchange, new OutputStreamWriter(outputStream, StandardCharsets.ISO_8859_1));
factory.toUNEdifact(interchange, new OutputStreamWriter(outputStream, encoding));
}

public void write(OutputStream s, Config _config) throws Exception {
this.write(s);
public void write(OutputStream s, Config _config, Charset encoding) throws Exception {
this.write(s, encoding);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -78,7 +79,7 @@ public void setRecipientGLNOverride(String replaced) {
this.recipientGLNOverride = replaced;
}

public void write(OutputStream outputStream) throws Exception {
public void write(OutputStream outputStream, Charset encoding) throws Exception {
D96AInterchangeFactory factory = D96AInterchangeFactory.getInstance();
UNEdifactInterchange41 interchange = new UNEdifactInterchange41();
Delimiters delimiters = new Delimiters();
Expand Down Expand Up @@ -692,10 +693,10 @@ public void write(OutputStream outputStream) throws Exception {
message41.setMessageTrailer(unt41);
interchange.setMessages(Arrays.asList(message41));

factory.toUNEdifact(interchange, new OutputStreamWriter(outputStream, StandardCharsets.ISO_8859_1));
factory.toUNEdifact(interchange, new OutputStreamWriter(outputStream, encoding));
}

public void write(OutputStream s, Config _config) throws Exception {
this.write(s);
public void write(OutputStream s, Config _config, Charset encoding) throws Exception {
this.write(s, encoding);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
import com.ywesee.java.yopenedi.converter.Utility;
import com.ywesee.java.yopenedi.converter.Writable;

import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import java.io.OutputStream;
import java.math.BigDecimal;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Date;
import java.util.Map;
Expand Down Expand Up @@ -215,8 +217,13 @@ private void writeOrderSummary(XMLStreamWriter streamWriter) throws XMLStreamExc
streamWriter.writeEndElement(); // ORDER_SUMMARY
}

public void write(OutputStream s, Config config) throws Exception {
OpenTransWriter writer = new OpenTransWriter(config);
writer.write(this, s);
public void write(OutputStream s, Config config, Charset encoding) throws Exception {
XMLOutputFactory xof = XMLOutputFactory.newFactory();
XMLStreamWriter xmlWriter = xof.createXMLStreamWriter(s, encoding.name());
xmlWriter.writeStartDocument();
this.write(xmlWriter, config);
xmlWriter.writeEndDocument();
xmlWriter.flush();
xmlWriter.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Map;
import java.util.Set;

import com.ywesee.java.yopenedi.converter.Writable;
import org.apache.commons.io.FileUtils;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
Expand Down Expand Up @@ -117,13 +118,13 @@ public ArrayList<ResultDispatch> getResultDispatches() {
return new ArrayList<>();
}

public void dispatchResult(String gln, String edifactType, File file, String messageId) {
public void dispatchResult(String gln, String edifactType, Writable writable, String messageId) {
ArrayList<ResultDispatch> dispatches = this.getResultDispatches();
boolean anySent = false;
int i = 0;
String reasons = "";
for (ResultDispatch dispatch : dispatches) {
String reasonForNotSending = dispatch.send(gln, edifactType, file, messageId);
String reasonForNotSending = dispatch.send(gln, edifactType, writable, messageId);
if (reasonForNotSending != null) {
reasons += "Dispatch " + i + "\n";
reasons += reasonForNotSending;
Expand Down
Loading

0 comments on commit 3b40f7d

Please sign in to comment.