I have written one Java class to submit JCL to Mainframe JES using FTP. The code is able to submit the JCL but it is not retrieving the JOB log from JES SPOOL.
package com.test;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.SocketException;
import org.apache.commons.net.ftp.FTPClient;
public class MVSSpool {
private FTPClient ftp = null;
private String fUserId,fPassword,fHost,fJobPerfix,replyText;
public MVSSpool(String fUserId, String fPassword,
String fHost, String fJobPerfix) {
this.fUserId = fUserId;
this.fPassword = fPassword;
this.fHost = fHost;
this.fJobPerfix = fJobPerfix;
ftp = new FTPClient();
}
public String getfUserId() {
return fUserId;
}
public void setfUserId(String fUserId) {
this.fUserId = fUserId;
}
public void setfPassword(String fPassword) {
this.fPassword = fPassword;
}
public String getfHost() {
return fHost;
}
public void setfHost(String fHost) {
this.fHost = fHost;
}
public String getfJobPerfix() {
return fJobPerfix;
}
public void setfJobPerfix(String fJobPerfix) {
this.fJobPerfix = fJobPerfix;
}
public void submitJobToSpool(String jobName) throws Exception{
if (jobName != null){
connectMVSFtp();
InputStream is = null;
BufferedReader br = null;
String currentLine = null;
try{
ftp.retrieveFileStream("'"+jobName.trim()+"'");
replyText = ftp.getReplyString();
System.out.println("some " + replyText);
String[] replies = ftp.getReplyStrings();
String remoteFileName = replies[replies.length - 1].split(" ")[2]+ ".2";
for(String rep :replies){
System.out.println("checking .. " + rep);
}
Thread.sleep(10000);
System.out.println("getting sysout of the file " + remoteFileName);
is = ftp.retrieveFileStream(remoteFileName);
replies = ftp.getReplyStrings();
for(String rep :replies){
System.out.println("checking 2 .. " + rep);
}
if (is != null){
br = new BufferedReader(new InputStreamReader(is));
while((currentLine = br.readLine()) != null){
System.out.println(currentLine);
}
}
ftp.completePendingCommand();
System.out.println("Done...");
}catch(Exception e){
e.printStackTrace();
throw new Exception("Error in submitting Job from spool");
}finally{
ftp.disconnect();
if(br != null){
br.close();
}
if(is != null){
is.close();
}
}
}
}
/**
* @throws SocketException
* @throws IOException
*/
private void connectMVSFtp() throws SocketException, IOException {
// check if the required parameters are set already
if (fUserId == null | fPassword == null | fHost == null){
}else{
ftp.connect(fHost);
replyText = ftp.getReplyString();
System.out.println(replyText);
// login using user name and password
ftp.login(fUserId, fPassword);
replyText = ftp.getReplyString();
System.out.println(replyText);
// point the FTP to JES spool
ftp.site("filetype=jes");
replyText = ftp.getReplyString();
System.out.println(replyText);
}
}
}
I am getting below messages
230 XXXXX is logged on. Working directory is "XXXXX.".
200 SITE command was accepted
some 125-Submitting job 'XXXXX.XXXX.JCLLIB(ALIAS)' FIXrecfm 80 125 When JOB07591 is done, will retrieve its output
checking .. 125-Submitting job 'XXXXX.XXXX.JCLLIB(ALIAS)' FIXrecfm 80
checking .. 125 When JOB07591 is done, will retrieve its output
getting sysout of the file JOB07591.2
checking 2 .. 550 No spool files available for JOB07591, JesPutGet aborted
Done...enter code here