-
-
Save richardschoen/765d1d62442835d68cdf1a5ad88a737f to your computer and use it in GitHub Desktop.
AS400 command PINGJAVA communicates with a Java program via data queues (DTAQ)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ctl-opt nomain; | |
ctl-opt Option(*Srcstmt:*Nodebugio:*NoUnRef) | |
Debug( *Yes ) Bnddir('QUSAPIBD'); | |
********************************************************************** | |
********************************************************************** | |
* Program Id: BL0100M01 | |
* This program gets the latitude and longitude from the data | |
* queues from java program JsonDataQueues and sends commands | |
* to ping and shutdown the java app. | |
********************************************************************** | |
********************************************************************** | |
/copy BL0100MC | |
//********************************************************* | |
// Templates | |
//********************************************************* | |
dcl-s uuidKey_t CHAR(16) TEMPLATE; | |
dcl-s maxResponseData_t CHAR(30) TEMPLATE; | |
dcl-ds uuidDS_t Template; | |
dcl-subf bytes_provided INT(10); | |
dcl-subf bytes_available INT(10); | |
dcl-subf reserved CHAR(8); | |
dcl-subf uuid LIKE(uuidKey_t); | |
end-ds; | |
//********************************************************* | |
// getLatLng returns -1 if fail, 0 if successful | |
//********************************************************* | |
dcl-proc getLatLng EXPORT; | |
dcl-pi getLatLng Int(10); | |
pAddress LIKE(address_t) VALUE; | |
lat Like(latlng_t); | |
lng Like(latlng_t); | |
end-pi; | |
//********************************************************* | |
// Variable declarations | |
//********************************************************* | |
dcl-s retvar Int(10); | |
dcl-s maxResponseDataSz Packed(5:0) | |
inz(%size(maxResponseData_t)); | |
dcl-s maxRequestDataSz Packed(5:0) inz(416); | |
// dcl-ds uuidDS LikeDs(uuidDS_t); | |
dcl-ds uuidDS QUALIFIED; | |
dcl-subf bytes_provided INT(10) INZ(%size(uuidDS)); | |
dcl-subf bytes_available INT(10) INZ(0); | |
dcl-subf reserved CHAR(8) INZ(*ALLx'00'); | |
dcl-subf uuid LIKE(uuidKey_t); | |
end-ds; | |
dcl-pr getUuid extproc('_GENUUID'); | |
dcl-parm pUuid LIKE(uuidDS_t); | |
end-pr; | |
dcl-s rcvDataQueueName CHAR(10) inz('GEORESPONS'); | |
dcl-s rcvDataQueueLib CHAR(10) inz('*LIBL'); | |
dcl-s rcvDataQueueMessage LIKE(maxResponseData_t); | |
dcl-s rcvDataQueueWait Packed(5:0) inz(5); | |
dcl-s rcvDataQueueKeyOrder CHAR(2) inz('EQ'); | |
dcl-s rcvDataQueueKeyLength PACKED(3:0) | |
inz(%size(uuidKey_t)); | |
dcl-s rcvDataQueueKey LIKE(uuidKey_t); | |
dcl-s rcvDataQueueSenderLength Packed(3:0) | |
inz(%size(maxResponseData_t)); | |
dcl-s rcvDataQueueSender LIKE(maxResponseData_t); | |
dcl-pr QRcvDtaq extpgm('QRCVDTAQ') ; | |
dcl-parm p1 LIKE(rcvDataQueueName); | |
dcl-parm p2 LIKE(rcvDataQueueLib); | |
dcl-parm p3 LIKE(maxRequestDataSz); | |
dcl-parm p4 LIKE(rcvDataQueueMessage); | |
dcl-parm p5 LIKE(rcvDataQueueWait); | |
dcl-parm p6 LIKE(rcvDataQueueKeyOrder); | |
dcl-parm p7 LIKE(rcvDataQueueKeyLength); | |
dcl-parm p8 LIKE(uuidKey_t); | |
dcl-parm p9 LIKE(rcvDataQueueSenderLength); | |
dcl-parm p10 LIKE(rcvDataQueueSender); | |
end-pr; | |
dcl-s sndDataQueueName CHAR(10) inz('GEOREQUEST'); | |
dcl-s sndDataQueueLib CHAR(10) inz('*LIBL'); | |
dcl-ds sndDataQueueMessageDS QUALIFIED; | |
dcl-subf data LIKE(address_t); | |
dcl-subf key LIKE(uuidKey_t); | |
end-ds; | |
dcl-pr QSndDtaq extpgm('QSNDDTAQ') ; | |
dcl-parm p1 LIKE(sndDataQueueName); | |
dcl-parm p2 LIKE(sndDataQueueLib); | |
dcl-parm p3 LIKE(maxRequestDataSz); | |
dcl-parm p4 LIKE(sndDataQueueMessageDS); | |
end-pr; | |
dcl-s latlng CHAR(30); | |
//********************************************************* | |
// Main routine | |
//********************************************************* | |
Clear lat; | |
Clear lng; | |
retvar = -1; | |
getUuid(uuidDS); | |
sndDataQueueMessageDS.key = uuidDs.uuid; | |
sndDataQueueMessageDS.data = pAddress; | |
rcvDataQueueKey = uuidDS.uuid; | |
rcvDataQueueWait = 5; | |
rcvDataQueueKeyOrder = 'EQ'; | |
rcvDataQueueKeyLength = %size(rcvDataQueueKey); | |
rcvDataQueueSenderLength = %size(rcvDataQueueSender); | |
QSndDtaQ (sndDataQueueName : sndDataQueueLib : | |
maxRequestDataSz : sndDataQueueMessageDS); | |
QRcvDtaQ (rcvDataQueueName : rcvDataQueueLib : | |
maxResponseDataSz : rcvDataQueueMessage : | |
rcvDataQueueWait : rcvDataQueueKeyOrder : | |
rcvDataQueueKeyLength : rcvDataQueueKey : | |
rcvDataQueueSenderLength : rcvDataQueueSender); | |
If maxResponseDataSz <> 0; | |
latlng = rcvDataQueueMessage; | |
lat = '+0' + %subst(latlng : 1 : %scan(' ' : latlng) - 1); | |
lng = %subst(latlng : %scan(' | ' : latlng) + 3 ); | |
retvar = 0; | |
EndIf; | |
Return retvar; | |
end-proc; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dcl-s address_t CHAR(400) TEMPLATE; | |
dcl-s latlng_t CHAR( 15) TEMPLATE; | |
/IF NOT DEFINED(GETLATLNG) | |
/DEFINE GETLATLNG | |
dcl-s pAddress Like(address_t); | |
dcl-s plat Like(latlng_t); | |
dcl-s plng Like(latlng_t); | |
dcl-s iLatLongRet Int(10); | |
dcl-pr getLatLng Int(10) extproc(*DCLCASE); | |
pAddress Like(address_t) VALUE; | |
lat Like(latlng_t); | |
lng Like(latlng_t); | |
end-pr; | |
// iLatLongRet = getLatLng(pAddress:plat:plng); | |
/ENDIF |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.io.IOException; | |
import java.io.InputStream; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.sql.Statement; | |
import java.util.Properties; | |
public class DB400 { | |
String driver; | |
String url; | |
String user; | |
String pwd; | |
String as400Name; | |
Connection conn; | |
String inqName; | |
String outqName; | |
DB400() throws IOException { | |
Properties props = new Properties(); | |
InputStream file = DB.class.getClassLoader().getResourceAsStream("db.properties"); | |
props.load(file); | |
this.driver = props.getProperty("driver"); | |
this.as400Name = props.getProperty("AS400"); | |
this.url = props.getProperty("dburl"); | |
this.user = props.getProperty("userName"); | |
this.pwd = props.getProperty("password"); | |
this.inqName = props.getProperty("indq"); | |
this.outqName = props.getProperty("outdq"); | |
} | |
public Connection getConnection() throws ClassNotFoundException, SQLException { | |
if (conn == null || conn.isClosed()) { | |
Class.forName(driver); | |
conn = DriverManager.getConnection(url, user, pwd); | |
} | |
return conn; | |
} | |
Statement createStatement() throws SQLException { | |
return conn.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_UPDATABLE); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.logging.log4j.LogManager; | |
import org.apache.logging.log4j.Logger; | |
import java.io.IOException; | |
import java.io.InputStream; | |
import java.text.DecimalFormat; | |
import java.util.Properties; | |
import com.ibm.as400.access.AS400; | |
import com.ibm.as400.access.AS400SecurityException; | |
import com.ibm.as400.access.DataQueue; | |
import com.ibm.as400.access.ErrorCompletingRequestException; | |
import com.ibm.as400.access.IllegalObjectTypeException; | |
import com.ibm.as400.access.KeyedDataQueue; | |
import com.ibm.as400.access.ObjectDoesNotExistException; | |
public class JsonDataQueues { | |
static final Logger LOGGER = LogManager.getLogger(JsonDataQueues.class.getName()); | |
DB400 db; | |
DataQueue readQueue; | |
KeyedDataQueue writeQueue; | |
DecimalFormat myformatter = new DecimalFormat("+000.000000000;-000.000000000"); | |
JsonDataQueues() throws IOException, AS400SecurityException { | |
this.db = new DB400(); | |
} | |
public void connect() throws Exception { | |
System.out.println("new AS400(" + db.as400Name + "," + db.user + "," + db.pwd + ")"); | |
AS400 as400 = new AS400(db.as400Name, db.user, db.pwd); | |
readQueue = new DataQueue(as400, db.inqName); | |
writeQueue = new KeyedDataQueue(as400, db.outqName); | |
as400.connectService(AS400.DATAQUEUE); | |
} | |
/** | |
* | |
* @param args is as400Name name such as 'localhost' or 'DPITEST' | |
* call with command | |
* java -cp .:JsonDataQueues-0.0.1.jar:jt400.jar JsonDataQueues 'DPITEST' | |
*/ | |
public static void main(String[] args) { | |
String data; | |
String address = null; | |
String key = null; | |
try { | |
JsonDataQueues dq = new JsonDataQueues(); | |
dq.connect(); | |
LOGGER.info("dataqueues connected, starting processing"); | |
do { | |
address = null; | |
key = null; | |
data = dq.readQueue.read(-1).getString().trim(); | |
key = data.substring(data.length() - 16); | |
if (data != null) { | |
System.out.println("data=" + data); | |
if ("STOP".equals(data.substring(0,4))) { | |
LOGGER.warn("STOP received"); | |
break; | |
} | |
if ("PING".equals(data.substring(0,4))) { | |
LOGGER.warn("PING received"); | |
dq.writeQueue.write(key, "ping received"); | |
continue; | |
} | |
address = data.substring(0, data.length() - 16).trim(); | |
if (address != null && key != null) { | |
LOGGER.info("address=" + address); | |
LOGGER.info("key=" + key); | |
JsonGeoService geo = new JsonGeoService(); | |
geo.setLatLngForAddress(address); | |
if (!geo.rooftop) { | |
LOGGER.info("address was not rooftop " + address); | |
dq.writeQueue.write(key, " "); | |
} else { | |
LOGGER.info(dq.myformatter.format(geo.lat) + " | " + dq.myformatter.format(geo.lng)); | |
dq.writeQueue.write(key, dq.myformatter.format(geo.lat) + " | " + dq.myformatter.format(geo.lng)); | |
} | |
} | |
} | |
} while( true ); | |
} catch(Exception e) { | |
LOGGER.fatal("failed:" + e.getMessage()); | |
e.printStackTrace(); | |
} | |
System.exit(0); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CMD PROMPT('options SERVER/GOOGLE/STOP') + | |
TEXT('Ping Java Pgm on Linux Server') + | |
MAXPOS(1) ALLOW(*INTERACT) | |
PARM KWD(PINGTYPE) TYPE(*CHAR) LEN(6) RSTD(*YES) + | |
DFT(GOOGLE) VALUES(GOOGLE SERVER STOP) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ctl-opt Option(*Srcstmt:*Nodebugio:*NoUnRef) Main(Main); | |
// crtpgm gah285/pingpgm module(pingpgm BL0100M01) | |
/copy QRPGLESRC,BL0100MC | |
dcl-pr QMHSNDPM EXTPGM; | |
msgID CHAR(7) CONST; | |
msgFile CHAR(20) CONST; | |
msgData CHAR(80) CONST; | |
msgDataLen INT(10) CONST; | |
msgType CHAR(10) CONST; | |
msgQueue CHAR(10) CONST; | |
msgQueueNbr INT(10) CONST; | |
msgKey CHAR(4); | |
msgErrorDS CHAR(16); | |
end-pr; | |
dcl-ds latLngDS QUALIFIED; | |
lat like(latlng_t); | |
lng like(latlng_t); | |
returnCode like(iLatLongRet); | |
end-ds; | |
dcl-proc ping EXPORT; | |
dcl-pi *N LIKEDS(latLngDS); | |
dcl-parm address LIKE(address_t) CONST; | |
end-pi; | |
iLatLongRet = getLatLng(address : plat : plng ); | |
latLngDS.lat = plat; | |
latLngDS.lng = plng; | |
latLngDS.returnCode = iLatLongRet; | |
return latLngDS; | |
end-proc; | |
dcl-proc MAIN; | |
dcl-pi *N; | |
dcl-parm COMMAND CHAR(6); | |
end-pi; | |
dcl-s key CHAR(4); | |
dcl-s msgfile CHAR(20) inz('QCPFMSG *LIBL '); | |
dcl-s pMessage CHAR(80) inz(*BLANKS); | |
dcl-s pMessageType CHAR(10) inz('*COMP '); | |
dcl-ds errorCode; | |
bytesProvided INT(10) INZ(0); | |
bytesAvail INT(10); | |
exceptionID CHAR(7); | |
*n CHAR(1); | |
end-ds; | |
if COMMAND = 'SERVER'; | |
latLngDS = ping('PING'); | |
if latLngDS.returnCode = 0; | |
pMessage = 'Ping successful'; | |
else; | |
pMessage = 'Ping failed'; | |
endIf; | |
QMHSNDPM('CPF9898' : msgFile : | |
pMessage : %LEN(pMessage): | |
pMessageType : '* ' : | |
3 : key :errorCode); | |
RETURN; | |
endIf; | |
if COMMAND = 'GOOGLE'; | |
latLngDS = ping('2221 Lakeside Blvd, Richardson, TX'); | |
if latLngDS.returnCode = 0; | |
if latLngDS.lat = ' ' and latLngDS.lng = ' ' ; | |
pMessage = 'No Lat/Lng returned for good address'; | |
else; | |
pMessage = 'Ping with good address successful'; | |
endIf; | |
else; | |
pMessage = 'Unable to contact server'; | |
endIf; | |
QMHSNDPM('CPF9898' : msgFile : | |
pMessage : %LEN(pMessage): | |
pMessageType : '* ' : | |
3 : key :errorCode); | |
RETURN; | |
endIf; | |
if COMMAND = 'STOP'; | |
latLngDS = ping('STOP'); | |
pMESSAGE = 'STOP command sent to server'; | |
QMHSNDPM('CPF9898' : msgFile : | |
pMessage : %LEN(pMessage): | |
pMessageType : '* ' : | |
3 : key :errorCode); | |
RETURN; | |
endIf; | |
RETURN; | |
end-proc; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment