Sunny Son's Blog (손인선)

June 23, 2016

VOA Podcast titles on 23rd June 2016

Filed under: English,써니 — sunnyson @ 6:28 pm

Uffizi, Indiana University Make Digital Copies of Sculptures
Jaguar Killed After Olympic Torch Presentation
Rare Rescue for Sick South Pole Workers
North Korea’s Missile Tests Show Progress
Islamist Extremism in America: Is Religion the Problem?
New Updates to iPhone Software

Advertisements

June 15, 2016

Oracle MFT – callout to support sub-directory

Filed under: 써니,SOA — sunnyson @ 6:07 pm
Tags: , , , , ,

Till now (June 15th 2016), Oracle MFT product doesn’t support file transferring especially with sub-directory.
So thus, I made a Java Callout in order to resolve this matter for a customer who purchased and need it urgently.


  1. Source Pre-processing
    – Java Callout : com.oracle.callout.sample.SrcPre1
    -Xml file for Callout : SrcPre1.xml
  2. Target Pre-processing
    -Java Callout : com.oracle.callout.sample.InsertFolderForFTP
    -Xml file for Callout : InsertFolderForFTP.xml
  3. Compile
    – Core-12.1.1.0.jar, mdsrt.jar should be added into CLASSPATH
    – Org.apache.commons-net-1.4.1.jar( for FTP)
  4. Install
    -$ cp InsertFolderForFTP.jar $MW_HOME/user_projects/domains/base_domain/mft/callouts/
    -$ $MW_HOME/mft/common/bin/wlst.sh
    -connect(“weblogic”, “<PASSWORD>, “t3://localhost:7001”)
    -createCallouts(‘/home/oracle/InsertFolderForFTP.xml’)
    -createCallouts(‘/home/oracle/SrcPre1.xml’)
  5. Log : /tmp/mft/*.log
    – Hard coded at Java Callout source itself. It should be changed.

Java Source code –  SrcPre1.java

package com.oracle.callout.sample;

import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

import java.io.PrintWriter;

import java.util.Map;

import oracle.tip.mft.engine.processsor.plugin.PluginContext;
import oracle.tip.mft.engine.processsor.plugin.PluginOutput;
import oracle.tip.mft.engine.processsor.plugin.PreCalloutPlugin;
import oracle.tip.mft.bean.MFTMessage;
import oracle.tip.mft.bean.SourceMessage;
import oracle.tip.mft.bean.TargetMessage;

import java.sql.*;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Hashtable;

import java.util.Iterator;
import java.util.List;

import java.util.StringTokenizer;

import javax.naming.*;

import oracle.tip.mft.engine.mds.MdsManager;
import oracle.tip.mft.mds.model.source.SourceMO;
import oracle.tip.mft.system.MFTBeanFactory;
import oracle.tip.mft.system.MFTUtil;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

import oracle.mds.core.*;

import oracle.tip.mft.common.transport.util.EngineTransportUtil;
import oracle.tip.mft.mds.model.binding.TechnologyBindingType;
import oracle.tip.mft.mds.model.category.SourceTargetCategoryType;

//import com.google.common.base.Splitter;

public class SrcPre1 implements PreCalloutPlugin {

@Override
public boolean isPayloadChangeRequired(PluginContext pluginContext, Map<String, String> map) {
return false;
}

@Override
// This function will be called only if the isPayloadChangesRequired returns false.
public PluginOutput process(PluginContext pluginContext, InputStream input, Map<String, String> calloutParams) {
PluginOutput res = new PluginOutput();

try {
PluginOutput out    = new PluginOutput();
String protocolType = “FTP”;
String FolderName   = null;

String SourceName = getSourceName(pluginContext.getMessage().toString());
MdsManager mdsMgr = (MdsManager) MFTBeanFactory.getBean(“mdsManager”);

List moList = mdsMgr.getAllSources();
SourceMO mo;

for (Iterator i$ = moList.iterator(); i$.hasNext();) {
mo = (SourceMO) i$.next();

//                logme(“\n getSourceID = [” + mo.getSource().getId() + “]”);
//                logme(“\n getSourceName = [” + mo.getSource().getName() + “]”);
//                logme(“\n getSourceID = [” + mo.getSource().toString() + “]”);
//                logme(“\n getSourceID = [” + mo.getMDSInstance().getMDSConfig().toString() + “]”);
//                logme(“\n getSourceID = [” + mo.getTypeName().toString() + “]”);
//                logme(“\n getSourceID = [” + mo.getReference().getMOName() + “]”);

SourceTargetCategoryType sourceTargetCategory =
mo.getSource().getSourceType().getSourceTargetCategory();
String _SourceName = mo.getSource().getName();
TechnologyBindingType protocal = EngineTransportUtil.getTechnologyBindingFromMO(sourceTargetCategory);
if (protocal != null && _SourceName.equals(SourceName)) {
protocolType = protocal.getType();
//                    logme(“protocolType = ” + protocolType + “,SourceName = ” + SourceName);
if (protocolType.equals(“FTP”)) {
TechnologyBindingType.FTPType ftptype = protocal.getFTP();
FolderName = ftptype.getFolder();
break;
} else if (protocolType.equals(“SSH-FTP”)) {
TechnologyBindingType.SSHFTPType sshftptype = protocal.getSSHFTP();
FolderName = sshftptype.getFolder();

break;
}
break;

}
}

logme(“++ Source [” + pluginContext.getCustomPropertyMap().get(“directory.path”) +
“/” + pluginContext.getTransformedInputFileName() +
“] with “+protocolType+”, SourceName = [” + SourceName + “]++”);
//Debug
//logme(“\n++ Source Context tostring = [” + pluginContext.getMessage().toString() + “]”);
//logme(“\n++ Source Context tostring = [” + pluginContext.getTransformedInputFileName()+ “]”);
// In order to pass root directory of source server.
pluginContext.getCustomPropertyMap().put(“FolderName”, FolderName);
return out;
} catch (Exception e) {
e.printStackTrace();
res.setException(new Exception(“Callout:RENAMEEXP- Exception in custom plugin class:\n” +
pluginContext.getMessage()));
}
return res;
}

@Override
// This function will be called only if the isPayloadChangesRequired returns true.
public PluginOutput process(PluginContext context, InputStream input, OutputStream out,
Map<String, String> calloutParams) {
return null;
}

public void logme(String text) {
try {
PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(“/tmp/mft/RenameRegexp.txt”, true)));
String timeStamp = new SimpleDateFormat(“yyyy.MM.dd.HH.mm.ss”).format(new java.util.Date());
output.write(timeStamp + “:”);
output.write(text);
output.write(“\n”);
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public String getSourceName(String _input) {
String _s2 = null, _s3 = null;

StringTokenizer st1 = new StringTokenizer(_input, “, “);
while (st1.hasMoreElements()) {
//System.out.println(st1.nextElement());
_s2 = (String) st1.nextElement();
if (_s2.contains(“sourceName=”)) {
_s3 = _s2.substring(_s2.lastIndexOf(“sourceName=”) + “sourceName=”.length());
break;
}
}
return _s3;
}

}

 


Java Source code –  InsertFolderForFTP.java

package com.oracle.callout.sample;

import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;

import java.io.File;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

import java.io.PrintWriter;

import java.util.Map;

import oracle.tip.mft.engine.processsor.plugin.PluginContext;
import oracle.tip.mft.engine.processsor.plugin.PluginOutput;
import oracle.tip.mft.engine.processsor.plugin.PreCalloutPlugin;
import oracle.tip.mft.bean.MFTMessage;
import oracle.tip.mft.bean.SourceMessage;
import oracle.tip.mft.bean.TargetMessage;

import java.sql.*;

import java.text.SimpleDateFormat;

import java.util.ArrayList;
import java.util.Hashtable;

import java.util.Iterator;
import java.util.List;

import java.util.StringTokenizer;

import javax.naming.*;

import oracle.tip.mft.system.MFTUtil;

import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPReply;

import oracle.tip.mft.bean.*;
import oracle.tip.mft.common.transport.util.EngineTransportUtil;
import oracle.tip.mft.engine.mds.MdsManager;
import oracle.tip.mft.mds.model.binding.TechnologyBindingType;
import oracle.tip.mft.mds.model.category.SourceTargetCategoryType;
import oracle.tip.mft.mds.model.security.SSH;
import oracle.tip.mft.mds.model.source.SourceMO;
import oracle.tip.mft.mds.model.target.TargetMO;
import oracle.tip.mft.security.SecurityUtility;
import oracle.tip.mft.system.GlobalContext;
import oracle.tip.mft.system.MFTBeanFactory;
import oracle.tip.mft.transport.adapter.impl.ftp.FTPTransportReceiver;
import oracle.tip.mft.transport.adapter.impl.ftp.FTPTransportUtil;

public class InsertFolderForFTP implements PreCalloutPlugin {

@Override
public boolean isPayloadChangeRequired(PluginContext pluginContext, Map<String, String> map) {
return false;
}

@Override
// This function will be called only if the isPayloadChangesRequired returns false.
public PluginOutput process(PluginContext pluginContext, InputStream input, Map<String, String> calloutParams) {
PluginOutput res = new PluginOutput();
String newfname = “”;
String oldfname = “”;
String protocol = “FTP”;

try {
// Should be considered how to get rid of these parameters. It should be inherited from MFT framework
String TargetName     = getTargetName(pluginContext.getMessage().toString());
String TargetFolder   = null;
String TargetHostname = null;
String Targetusername = null;
String Targetpassword = null;
String protocolType   = null;
int TargetPort = 21;

// this code only works for Target Pre- processing
PluginOutput out = new PluginOutput();
oldfname         = pluginContext.getTransformedInputFileName();

// Query MDS to get all target list and compare with name from MFTConsole configuration
MdsManager mdsMgr = (MdsManager) MFTBeanFactory.getBean(“mdsManager”);
List moList = mdsMgr.getAllTargets();
TargetMO mo;

for (Iterator i$ = moList.iterator(); i$.hasNext();) {
mo = (TargetMO) i$.next();

SourceTargetCategoryType sourceTargetCategory =
mo.getTarget().getTargetType().getSourceTargetCategory();

TechnologyBindingType protocal = EngineTransportUtil.getTechnologyBindingFromMO(sourceTargetCategory);
String _TargetName = mo.getTarget().getName();
if (protocal != null && _TargetName.equals(TargetName)) {
protocolType = protocal.getType();
if (protocolType.equals(“FTP”)) {
TechnologyBindingType.FTPType ftptype = protocal.getFTP();
TargetFolder   = ftptype.getFolder();
TargetHostname = ftptype.getHost();
TargetPort     = ftptype.getControlPort();
Targetusername = ftptype.getUser();
//Targetusername = ftptype.
Targetpassword = SecurityUtility.getPasswordCredentialAsString(ftptype.getPassword());
break;
} else if (protocolType.equals(“SSH-FTP”)) {
protocol = “SSH-FTP”;
TechnologyBindingType.SSHFTPType sshftptype = protocal.getSSHFTP();
TargetFolder   = sshftptype.getFolder();
TargetHostname = sshftptype.getHost();
TargetPort     = sshftptype.getPort();
Targetusername = sshftptype.getUser();
Targetpassword = SecurityUtility.getPasswordCredentialAsString(sshftptype.getPassword());
break;
}

}
}

String SourceFolder     = pluginContext.getCustomPropertyMap().get(“FolderName”);
String SubDirectoryName = pluginContext.getCustomPropertyMap().get(“directory.path”);
SubDirectoryName =
SubDirectoryName.substring(SubDirectoryName.lastIndexOf(SourceFolder) + SourceFolder.length());

if (protocol.equals(“FTP”)) {
if(SubDirectoryName.length() > 0) SubDirectoryName = SubDirectoryName.substring(1);
if(SubDirectoryName.length() > 0)
newfname = TargetFolder + “/” + SubDirectoryName + “/” + oldfname; // worked relative path but not absolute path
else
newfname = TargetFolder + “/” + oldfname; // worked relative path but not absolute path
}
else if (protocol.equals(“SSH-FTP”))
newfname = SubDirectoryName+ “/” + oldfname;

destFileName = newfname;
logme(“with ” + protocolType + “, TargetName = [” + TargetName + “]++”);

if (newfname != null && newfname.length() > 0) {
// Check & Create subdirectories for each files.
// Should be modified to process exceptions later.
if (protocol.equals(“FTP”))
checkTargetDirectoryFTP(TargetHostname, TargetPort, Targetusername, Targetpassword,
TargetFolder + “/” + SubDirectoryName);
else if (protocol.equals(“SSH-FTP”))
checkTargetDirectorySFTP(TargetHostname, TargetPort, Targetusername, Targetpassword,
TargetFolder + SubDirectoryName);

// Set new filename with sub directory name
out.setNewFileName(newfname);
}
return out;
} catch (Exception e) {
e.printStackTrace();
res.setException(new Exception(“Callout:RENAMEEXP- Exception in custom plugin class:\n” +
pluginContext.getMessage()));
}
return res;
}

@Override
// This function will be called only if the isPayloadChangesRequired returns true.
public PluginOutput process(PluginContext context, InputStream input, OutputStream out,
Map<String, String> calloutParams) {
return null;
}

public void logme(String text) {
rawlog(“++ Target [” + destFileName + “] ” + text);
}

public void rawlog(String text) {
try {
PrintWriter output = new PrintWriter(new BufferedWriter(new FileWriter(“/tmp/mft/RenameRegexp.txt”, true)));
String timeStamp = new SimpleDateFormat(“yyyy.MM.dd.HH.mm.ss”).format(new java.util.Date());
output.write(timeStamp + “:”);
output.write(text);
output.write(“\n”);
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}

public int checkTargetDirectoryFTP(String TargetHostname, int TargetPort, String Targetusername,
String Targetpassword, final String directory) {

FTPClient client = new FTPClient();

try {
if (!client.isConnected()) {
client.connect(TargetHostname, TargetPort);
client.login(Targetusername, Targetpassword);
int reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
client.disconnect();
logme(“Negative reply form FTP server, aborting, id was {}:” + reply);
throw new IOException(“failed to connect to FTP server”);
}
}

String[] iterable = directory.split(“/”);
String dir = “”;
boolean dirExists1 = client.changeWorkingDirectory(directory);
if(!dirExists1) {
for (int i = 1; i < iterable.length; i++) {
dir = dir + “/” + iterable[i];
boolean dirExists = client.changeWorkingDirectory(dir);
if (!dirExists) {
// try to create directory:
logme(” try to create directory [” + dir + “]\n”);
client.makeDirectory(dir);
dirExists = client.changeWorkingDirectory(dir);
}
if (!dirExists) {
logme(“failed to change FTP directory (forms), not doing anything\n”);
return -1;
}
}
} else {
logme(“!! Target Directory [” + directory + “] existing already, skip!!\n”);
}

if (client.isConnected()) {
client.disconnect();
}
} catch (Exception s) {
return -1;
}
return 0;
}

public int checkTargetDirectorySFTP(String TargetHostname, int TargetPort, String Targetusername,
String Targetpassword, final String directory) {

try {
//            logme(“\nEstablishing Connection.0..”);
JSch jsch = new com.jcraft.jsch.JSch();
//JSch jsch = new JSch();
//            logme(“\nEstablishing Connection..1.”);
Session session = jsch.getSession(Targetusername, TargetHostname, TargetPort);
//            logme(“\nEstablishing Connection..2.”);
session.setPassword(Targetpassword);
session.setConfig(“StrictHostKeyChecking”, “no”);
//            logme(“\nEstablishing Connection…”);
session.connect();
//           logme(“\nConnection established.”);
//           logme(“\nCrating SFTP Channel.”);
ChannelSftp sftpChannel = (ChannelSftp) session.openChannel(“sftp”);
sftpChannel.connect();

//            logme(“\nDirectory:” + sftpChannel.pwd());
//            logme(“\n directory = ” + directory + “\n”);
String[] iterable = directory.split(“/”);
String dir = “”;

Boolean dirExist = false;

try {
sftpChannel.cd(directory);
} catch (SftpException s2) {
dirExist = false;
}

if(!dirExist) {
for (int i = 1; i < iterable.length; i++) {
dir = dir + “/” + iterable[i];
try {
sftpChannel.cd(dir);
} catch (SftpException s2) {
sftpChannel.mkdir(dir);
}
}
}else {
logme(” Target Directory existing already, skip!!”);
}

sftpChannel.disconnect();
session.disconnect();
} catch (Exception s) {
s.printStackTrace();
logme(s.toString());
return -1;
}

return 0;
}

public String getTargetName(String _input) {
String _s2 = null, _s3 = null;

StringTokenizer st1 = new StringTokenizer(_input, “, “);
while (st1.hasMoreElements()) {
_s2 = (String) st1.nextElement();
if (_s2.contains(“targetName=”)) {
_s3 = _s2.substring(_s2.lastIndexOf(“targetName=”) + “targetName=”.length());
break;
}
}
return _s3;
}

private String destFileName = null;

}


SrcPre1.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<mft:Callouts xmlns:mft=”http://xmlns.oracle.com/mft&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://xmlns.oracle.com/mft callout.xsd “>
<mft:Callout description=”Insert Folder For FTP”
helpText=”File Rename with Regular Expressions”
groupName=”Source-pre” timeout=”300″
implementationClass=”com.oracle.callout.sample.SrcPre1″
libraryName=”SrcPre1.jar” name=”SrcPre1″>
</mft:Callout>
</mft:Callouts>


InsertFolderForFTP.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<mft:Callouts xmlns:mft=”http://xmlns.oracle.com/mft&#8221;
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221;
xsi:schemaLocation=”http://xmlns.oracle.com/mft callout.xsd “>
<mft:Callout description=”Insert Folder For FTP”
helpText=”File Rename with Regular Expressions”
groupName=”Target-pre” timeout=”300″
implementationClass=”com.oracle.callout.sample.InsertFolderForFTP”
libraryName=”InsertFolderForFTP.jar” name=”InsertFolderForFTP”>
</mft:Callout>
</mft:Callouts>


MFT Console

mft1mft2mft3mft4

May 19, 2016

Words – 19 May 2016

Filed under: English,써니 — sunnyson @ 3:56 pm
  • Place a mandate : 지시를 내리다
  • be stranded : 좌초되다, 오도 가도 못하다
  • converge : 집중하다. 수렴하다
  • mate, first mate : 1등 항해사
  • embark on : (사업) 착수하다. 시작하다
  • toss : (배 따위를) (파도 등이) 흔들다. 동요시키다
  • remedial : 보충하는, 보습의 . remedial class 보충 학습반
  • a late bloomer : 대기 만성형 인간
  • tutor : 개인 교사
  • tune out : 주의 하지 않다. 귀를 기울이지 않다. stop paying attention
  • to be coasting in : very well without even trying

Blog at WordPress.com.