Search This Blog

Thursday, July 12, 2012

How to run a unix command remotely using java

 

Download the jar file from ,

http://www.jcraft.com/jsch/

http://nchc.dl.sourceforge.net/project/jsch/jsch.jar/0.1.48/jsch-0.1.48.jar

package test1;
import com.jcraft.jsch.*;
import java.io.*;
public class Class2 {
  public Class2() {
    super();
  }
  public static void main(String[] args) throws Exception {
    testconnect();
  }
      public static void testconnect() throws JSchException, IOException {
           String userName = "xxxx";
           String password ="xxxx";
           String hostName = "xxx.xx.oracle.com";
           int port = 22;
        String sdstestCommand = "env";
              JSch jsch = new JSch();
              Session session = jsch.getSession(userName, hostName, port);
              session.setConfig("StrictHostKeyChecking", "no");
              session.setPassword(password);
              session.connect();    
              ChannelExec channel = (ChannelExec) session.openChannel("exec");
              channel.setCommand(sdstestCommand);
              channel.setInputStream(null);
              ((ChannelExec) channel).setErrStream(System.err);
              InputStream in = channel.getInputStream();
              channel.connect();
              System.out.println("Unix system connected...");
              byte[] tmp = new byte[1024];
              while (true){
                  while (in.available() > 0) {
                      int i = in.read(tmp, 0, 1024);
                      if (i < 0) {
                          break;
                      }
                      String line = new String(tmp, 0, i);
                      System.out.println("Unix system console output: " +line);
                  }
                  if (channel.isClosed()){
                      break;
                  }
                  try {
                      Thread.sleep(1000);
                  } catch (Exception ee){
                      //ignore
                  }
              }
              channel.disconnect();
              session.disconnect();     
          }
    }

Wednesday, July 11, 2012

SOA 11g using ant scripts to deploy and undeploy

 

1. First Set JAVA_HOME

set JAVA_HOME=D:\fmw1115\Middleware\jdk160_24

2. set PATH=D:\fmw1115\Middleware\modules\org.apache.ant_1.7.1\bin;%PATH%
3. cd D:\fmw1115\Middleware\jdeveloper\bin

4. Note the down the directory where your SOA Project is there 

D:\bugs-download\Bug14258512\RuleAPITest\RuleAPITest\HelloSOA

5. Compile and package the soa project

ant -f ant-sca-package.xml -DcompositeDir=D:\bugs-download\Bug14258512\RuleAPITest\RuleAPITest\HelloSOA  -DcompositeName=HelloSOA  -Drevision=1.0  -Dscac.application.home=D:\bugs-download\Bug14258512\RuleAPITest\RuleAPITest
6. Deploy the SOA Project
ant -f ant-sca-deploy.xml  -DserverURL=http://localhost:7001  -DsarLocation=D:\bugs-download\Bug14258512\RuleAPITest\RuleAPITest\HelloSOA\deploy\sca_HelloSOA_rev1.0.jar  -Doverwrite=true  -Duser=weblogic  -Dpassword=xxxxx
7. To undeploy use the following command ,
ant -f ant-sca-deploy.xml  -DserverURL=http://localhost:7001    -Duser=weblogic  -Dpassword=xxxx  -DcompositeName=BR_FndIntg_SimpleRuleIVP -Drevision=6.18 undeploy

 

Using this batch script , you can deploy the same composite with say 100 revisions

----------------
@REM initialize test value to be "true"
@SET intCounter=1
:while
@REM test condition
@IF %intCounter% GTR 100 (GOTO wend)
@REM procedure where condition is "true"
@echo ==============================================================================================================
@echo %intCounter%
Rem call ant -f ant-sca-package.xml -DcompositeDir=D:\bugs-download\Bug14258512\RuleAPITest\RuleAPITest\SimpleRule  -DcompositeName=SimpleRule  -Drevision=%intCounter%.0  -Dscac.application.home=D:\bugs-download
\Bug14258512\RuleAPITest\RuleAPITest
Rem call ant -f ant-sca-deploy.xml  -DserverURL=http://localhost:7001  -DsarLocation=D:\bugs-download\Bug14258512\RuleAPITest\RuleAPITest\SimpleRule\deploy\sca_SimpleRule_rev%intCounter%.0.jar  -Doverwrite=true  -
Duser=weblogic  -Dpassword=xxxxxx
call ant -f ant-sca-deploy.xml  -DserverURL=http://localhost:7001    -Duser=weblogic  -Dpassword=xxxxx-DcompositeName=SimpleRule  -Drevision=%intCounter%.0 undeploy
@REM set new test value
@SET /a intCounter=intCounter+1
@REM loop
@echo ==============================================================================================================
@GOTO while
:wend

-----------------