Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/internal_…
Browse files Browse the repository at this point in the history
…artifactory
  • Loading branch information
aVolpe committed May 8, 2023
2 parents 67d0c6f + 4639c4e commit 7cb1782
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 25 deletions.
2 changes: 1 addition & 1 deletion libraries.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ ext {
hibernateVersion = '6.1.5.Final'
hibernateEhcacheVersion = '6.0.0.Alpha7'
geronimoVersion = '1.1.1'
jettyVersion = '9.4.44.v20210927'
jettyVersion = '9.4.50.v20221201'
servletApiVersion = '4.0.1'
websocketApiVersion = '1.1'
jgroupsVersion = '4.1.5.Final'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@
import java.io.IOException;
import java.io.FileInputStream;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

import org.jpos.core.Environment;
import org.jpos.iso.*;
import org.jpos.iso.packager.XMLPackager;
import org.jpos.util.Logger;
Expand All @@ -42,13 +46,16 @@ public class TestRunner
MUX mux;
ISOPackager packager;
Interpreter bsh;

long timeout;
private static final String NL = System.getProperty("line.separator");
public static final long TIMEOUT = 60000;
public TestRunner () {
super();
}
protected void initService() throws ISOException {
String packagerClass = cfg.get("packager", null);
timeout = cfg.getLong ("timeout", TIMEOUT);
if (packagerClass != null) {
try {
packager = (ISOPackager) Class.forName(packagerClass).newInstance();
Expand All @@ -60,8 +67,23 @@ protected void initService() throws ISOException {
}
}
protected void startService() {
for (int i=0; i<cfg.getInt("sessions", 1); i++)
new Thread(this).start();
int sessions = cfg.getInt("sessions", 1);
ExecutorService executor = Executors.newCachedThreadPool();
for (int i=0; i<sessions; i++)
executor.execute(this);
executor.shutdown();
if (cfg.getBoolean ("shutdown")) {
Executors.newSingleThreadExecutor().execute( () -> {
try {
if (!executor.awaitTermination(timeout, TimeUnit.MILLISECONDS)) {
log.warn("Runners didn't finish before global timeout");
}
} catch (InterruptedException e) {
log.warn("interrupted while awaiting workers termination", e);
}
getServer().shutdown();
});
}
}
public void run () {
try {
Expand All @@ -77,8 +99,6 @@ public void run () {
} catch (Throwable t) {
getLog().error (t);
}
if (cfg.getBoolean ("shutdown"))
getServer().shutdown();
}
private void runSuite (List suite, MUX mux, Interpreter bsh)
throws ISOException, IOException, EvalError
Expand Down Expand Up @@ -146,7 +166,7 @@ private void runSuite (List suite, MUX mux, Interpreter bsh)
);
ISOUtil.sleep (100); // let the channel do its logging first
if (cfg.getBoolean ("shutdown"))
evt.addMessage ("Shutting down");
evt.addMessage ("waiting for shutdown");

Logger.log (evt);
}
Expand Down Expand Up @@ -179,7 +199,7 @@ private List<TestCase> initSuite (Element suite)
if (to != null)
tc.setTimeout (Long.parseLong (to));
else
tc.setTimeout (cfg.getLong ("timeout", TIMEOUT));
tc.setTimeout (timeout);
l.add (tc);

}
Expand Down Expand Up @@ -352,14 +372,17 @@ private ISOMsg applyRequestProps (ISOMsg m, Interpreter bsh)
if (c instanceof ISOMsg) {
applyRequestProps ((ISOMsg) c, bsh);
} else if (c instanceof ISOField) {
String value = (String) c.getValue();
String value = Environment.get((String) c.getValue());
if (value.length() > 0) {
try {
if (value.charAt (0) == '!') {
m.set (i, bsh.eval (value.substring(1)).toString());
}
else if (value.charAt (0) == '#') {
m.set (i, ISOUtil.hex2byte(bsh.eval (value.substring(1)).toString()));
}
else if (!value.equals(c.getValue())) {
m.set (i, value);
}
} catch (NullPointerException e) {
m.unset (i);
Expand Down
5 changes: 5 additions & 0 deletions modules/cmf/src/main/java/org/jpos/cmf/AdditionalAmount.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public String serialize() {
return sb.toString();
}

@Override
public String toString() {
return amount + String.format ("{%s,%s,%s,%d}", accountType, amountType, currencyCode, currencyMinorUnit);
}

static AdditionalAmount parse(String data) {
Objects.requireNonNull(data);

Expand Down
5 changes: 5 additions & 0 deletions modules/cmf/src/main/java/org/jpos/cmf/CMFAmount.java
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,9 @@ public String serialize(boolean withSign){
public String serialize() {
return serialize(true, DEFAULT_AMOUNT_LENGTH);
}

@Override
public String toString() {
return amount + "{" + currency + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ public void test_containsAmountType() {
assertFalse(wrapper.containsAmountType(AmountType.AMOUNT_REMAINING_THIS_CYCLE));
}

@Test
public void toStringTest() {
AdditionalAmountsWrapper wrapper = new AdditionalAmountsWrapper();

AdditionalAmount as = new AdditionalAmount("00", new BigDecimal("200.00"), "840", AmountType.AMOUNT_SURCHARGE, 2);
AdditionalAmount ac = new AdditionalAmount("00", new BigDecimal("300.00"), "840", AmountType.AMOUNT_CASH, 2);
wrapper.add(as);
wrapper.add(ac);

assertEquals("200.00{00,42,840,2}", as.toString());
assertEquals("300.00{00,40,840,2}", ac.toString());
assertEquals("[200.00{00,42,840,2}, 300.00{00,40,840,2}]", wrapper.toString());
}
}


Expand Down
8 changes: 6 additions & 2 deletions modules/cmf/src/test/java/org/jpos/cmf/CMFAmountTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public void constructorFromStringWithSign() {
BigDecimal expectedBdAmt= new BigDecimal("123456.78").negate(); // negative!

assertEquals(0, bdAmt.compareTo(expectedBdAmt), "Expected amount '"+expectedBdAmt+"' but got '"+bdAmt+"'");
assertEquals("-123456.78{840}", am.toString());
}

@Test
Expand All @@ -51,6 +52,7 @@ public void constructorFromStringWithoutSign() {
BigDecimal expectedBdAmt= new BigDecimal("123456.78"); // no sign, asssumes positive

assertEquals(0, bdAmt.compareTo(expectedBdAmt), "Expected amount '"+expectedBdAmt+"' but got '"+bdAmt+"'");
assertEquals("123456.78{840}", am.toString());
}

@Test
Expand All @@ -59,6 +61,7 @@ public void constructorFromStringWithSign_SerializeDefault() {
String outString = "D" + "840" + "2" + "12345678";
CMFAmount am = new CMFAmount(inpString);
assertEquals(am.serialize(), outString);
assertEquals("-123456.78{840}", am.toString());
}

@Test
Expand All @@ -67,6 +70,7 @@ public void constructorFromStringWithSign_Serialize12() {
String outString = "D" + "840" + "2" + "000012345678";
CMFAmount am = new CMFAmount(inpString);
assertEquals(am.serialize(true, 12), outString);
assertEquals("-123456.78{840}", am.toString());
}

@Test
Expand All @@ -75,6 +79,7 @@ public void constructorFromStringWithoutSign_SerializeDefault() {
String outString = "C" + "840" + "2" + "12345678";
CMFAmount am = new CMFAmount(inpString);
assertEquals(am.serialize(), outString);
assertEquals("123456.78{840}", am.toString());
}

@Test
Expand All @@ -83,7 +88,6 @@ public void constructorFromStringWithSign_Serialize12WithoutSign() {
String outString = "840" + "2" + "000012345678";
CMFAmount am = new CMFAmount(inpString);
assertEquals(am.serialize(false, 12), outString); // without sign (even though it was negative... just to test)
assertEquals("-123456.78{840}", am.toString());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
public class TagsConverter implements AttributeConverter<Tags, String> {
@Override
public String convertToDatabaseColumn(Tags tags) {
return tags != null && tags.size() > 0 ? tags.toString() : "";
return tags == null ?
null :
tags.size() > 0 ? tags.toString() : "";
}

@Override
public Tags convertToEntityAttribute(String dbData) {
return new Tags(dbData);
return dbData != null ?
new Tags(dbData) :
null;
}
}
2 changes: 1 addition & 1 deletion modules/minigl/src/test/java/org/jpos/gl/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static void setUpBase () throws Exception {
String hibernateCfg = "<?xml version='1.0' encoding='utf-8'?>\n" +
"<!DOCTYPE hibernate-configuration PUBLIC\n" +
" \"-//Hibernate/Hibernate Configuration DTD 3.0//EN\"\n" +
" \"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd\">\n" +
" \"http://hibernate.org/dtd/hibernate-configuration-3.0.dtd\">\n" +
"\n" +
"<hibernate-configuration>\n" +
" <session-factory>\n" +
Expand Down
12 changes: 12 additions & 0 deletions modules/qrest/src/main/java/org/jpos/qrest/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,16 @@
public class Response {
private HttpResponseStatus status;
private Object body;
private String contentType;

public Response(HttpResponseStatus status, Object body) {
this(status, body, null);
}

public Response(HttpResponseStatus status, Object body, String contentType) {
this.status = status;
this.body = body;
this.contentType = contentType;
}

public HttpResponseStatus status() {
Expand All @@ -36,10 +43,15 @@ public Object body() {
return body;
}

public String contentType() {
return contentType;
}

@Override
public String toString() {
return "Response{" +
"status=" + status +
"contentType="+ contentType +
", body=" + body +
'}';
}
Expand Down
12 changes: 10 additions & 2 deletions modules/qrest/src/main/java/org/jpos/qrest/SendResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ private FullHttpResponse getResponse (Context ctx, HttpVersion version) {
Response response = (Response) r;
byte[] responseBody;
boolean isJson = false;

try {
if (response.body() instanceof String)
if (response.body() instanceof byte[])
responseBody = (byte[])response.body();
else if (response.body() instanceof String)
responseBody = String.valueOf(response.body()).getBytes();
else {
ObjectMapper m = ctx.get(MAPPER);
Expand All @@ -111,14 +114,19 @@ private FullHttpResponse getResponse (Context ctx, HttpVersion version) {
responseBody = m.writeValueAsBytes(response.body());
isJson = true;
}

httpResponse = new DefaultFullHttpResponse(
version,
response.status(),
copiedBuffer(responseBody));

HttpHeaders httpHeaders = httpResponse.headers();
if (isJson)

if (response.contentType() != null)
httpResponse.headers().set(CONTENT_TYPE, response.contentType());
else if (isJson)
httpResponse.headers().set(CONTENT_TYPE, APPLICATION_JSON);

if (corsHeader != null)
httpHeaders.add("Access-Control-Allow-Origin", corsHeader);
} catch (JsonProcessingException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-->

<!DOCTYPE hibernate-mapping
SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
SYSTEM "http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="org.jpos.ee.status.Status" table="status">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
-->

<!DOCTYPE hibernate-mapping
SYSTEM "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
SYSTEM "http://hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="org.jpos.ee.status.StatusTag" table="status_tag">
Expand Down
6 changes: 3 additions & 3 deletions modules/txn/src/main/java/org/jpos/transaction/Close.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ private void closeDB (Serializable o) {
tx.commit ();
ctx.remove (TX);
} catch (RuntimeException t) {
error (t);
ctx.log(t);
try {
tx.rollback();
} catch (RuntimeException rte) {
error ("Rollback error", rte);
ctx.log(rte);
}
}
}
} catch (RuntimeException ex) {
error (ex);
ctx.log(ex);
} finally {
db.close ();
}
Expand Down
7 changes: 2 additions & 5 deletions modules/txn/src/main/java/org/jpos/transaction/Open.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@

import java.io.Serializable;

import static org.jpos.transaction.TxnConstants.DB;
import static org.jpos.transaction.TxnConstants.TX;

public class Open extends TxnSupport {
int timeout = 0;
public int prepare (long id, Serializable o) {
Expand All @@ -39,8 +36,8 @@ public int prepare (long id, Serializable o) {
checkPoint (ctx);
rc = PREPARED;
} catch (Throwable t) {
error (t);
ctx.remove (DB); // "Close" participant checks
ctx.log(t);
ctx.remove (DB); // "Close" participant checks
// for DB in Context
}
return rc | NO_JOIN | READONLY;
Expand Down

0 comments on commit 7cb1782

Please sign in to comment.