Interacting with Powershell from Java

Hi,
I'm trying to run a Java application which creates a new powershell process on startup and then later on interacts with it multiple times. Calling powershell.exe and have it execute a single command and return the output works fine for me. The problem arises if I don't want the powershell process to immediately finish/exit but to stay open so I can write to its outputStream and receive results back from the inputStream.
String input = "dir";
String[] commandList = {"powershell.exe", "-Command", "dir"};
ProcessBuilder pb = new ProcessBuilder(commandList);
Process p = pb.start();
if(input != null) { 
PrintWriter writer = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(p.getOutputStream())), true);
writer.println(input);
writer.flush();
writer.close();
//p.getOutputStream().close();
Gobbler outGobbler = new Gobbler(p.getInputStream());
Gobbler errGobbler = new Gobbler(p.getErrorStream());
Thread outThread = new Thread(outGobbler);
Thread errThread = new Thread(errGobbler);
outThread.start();
errThread.start();
System.out.println("Waiting for the Gobbler threads to join...");
outThread.join();
errThread.join();
System.out.println("Waiting for the process to exit...");
int exitVal = p.waitFor();
System.out.println("\n****************************");
System.out.println("Command: " + "cmd.exe /c dir");
System.out.println("Exit Value = " + exitVal);
List<String> output = outGobbler.getOuput();
input = "";
for(String o: output) { 
input += o;
System.out.println("Final Output:");
System.out.println(input);
This code returns the result of the "dir" command from a powershell - fine. But as you can see, I'm trying to run a second "dir" command using
PrintWriter writer = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(p.getOutputStream())), true);
writer.println(input);
writer.flush();
This has no effect whatsoever - no second dir output is shown when I run my code. I've also experimented with a powershell.exe option to open the powershell but not close it immediately:
String[] commandList = {"powershell.exe", "-NoExit", "-Command", "dir"};
But then my code hangs, meaning the Gobbler's who consume the process's inputStream don't read anything - strangely enough: they don't even read the first line - there must be at least some output....
I've also tried to close the process's outputStream after writing the second "dir" command to it - didn't change anything.
But when I initially call the cmd.exe using the /k (keep open) switch:
String[] commandList = {"cmd.exe", "/k", "dir"};
I can then still write to that outputstream and invoke the second "dir" command and get the output of both "dir" commands from the inputstream fo that process.
Any help is highly appreciated.
Thanks
Kurt

user4491593 wrote:
BUT: my Gobblers only read the output of all my commands Then why don't change your Gobbler code ? ;)
Test this, it's ugly and needs improvemens, but by now works fine on linux and windows:
public class Gobbler implements Runnable {
    private PrintStream out;
    private String message;
    private BufferedReader reader;
    public Gobbler(InputStream inputStream, PrintStream out) {
        this.reader = new BufferedReader(new InputStreamReader(inputStream));
               this.out = out;
        this.message = ( null != message ) ? message : "";
    public void run() {
        String line;
        try {
            while (null != (line = this.reader.readLine())) {
                out.println(message + line);
            this.reader.close();
        } catch (IOException e) {
            System.err.println("ERROR: " + e.getMessage());
public class PowerConsole {
    private ProcessBuilder pb;
    Process p;
    boolean closed = false;
    PrintWriter writer;
    PowerConsole(String[] commandList) {
        pb = new ProcessBuilder(commandList);
        try {
            p = pb.start();
        } catch (IOException ex) {
            throw new RuntimeException("Cannot execute PowerShell.exe", ex);
        writer = new PrintWriter(new OutputStreamWriter(new BufferedOutputStream(p.getOutputStream())), true);
        Gobbler outGobbler = new Gobbler(p.getInputStream(), System.out);
        Gobbler errGobbler = new Gobbler(p.getErrorStream(), System.out);
        Thread outThread = new Thread(outGobbler);
        Thread errThread = new Thread(errGobbler);
        outThread.start();
        errThread.start();
    public void execute(String command) {
        if (!closed) {
            writer.println(command);
            writer.flush();
        } else {
            throw new IllegalStateException("Power console has ben closed.");
    public void close() {
        try {
            execute("exit");
            p.waitFor();
        } catch (InterruptedException ex) {
    public static void main(String[] args) throws IOException, InterruptedException {
        /*   PowerConsole pc = new PowerConsole(new String[]{"/bin/bash"});
        PowerConsole pc = new PowerConsole(new String[]{"/bin/bash"});
        pc.execute("pwd");
        pc.execute("ls");
        pc.execute("cd /");
        pc.execute("ls -l");
        pc.execute("cd ~");
        pc.execute("find . -name 'test.*' -print");
        pc.close();
        //      PowerConsole pc = new PowerConsole(new String[]{"cmd.exe"});
        PowerConsole pc = new PowerConsole(new String[]{"powershell.exe", "-NoExit", "-Command", "-"});
        System.out.println("========== Executing dir");
        pc.execute("dir");
        System.out.println("========== Executing cd\\");
        pc.execute("cd \\"); Thread.sleep(2000);
        System.out.println("========== Executing dir");
        pc.execute("dir"); Thread.sleep(2000);
        System.out.println("========== Executing cd \\temp");
        pc.execute("cd \\temp"); Thread.sleep(2000);
        System.out.println("========== Executing dir");
        pc.execute("dir"); Thread.sleep(2000);
        System.out.println("========== Executing cd \\bubba");
        pc.execute("cd \\bubba"); Thread.sleep(2000);
        System.out.println("========== Exiting .... bye.");
        pc.close();
}I tested this and there is still a little problem -look at the test below.
It seems that when thecommand
executed in the powershell prints only a one ot two lines,
powershell doesn't flush the output stream
.... but this rather problem of powershell, not the java code
I have not a clue how to force powershell to flush
it's output stream after each command.
C:\temp>java -jar PowerShell.jar
========== Executing dir
    Directory: Microsoft.PowerShell.Core\FileSystem::C:\temp
Mode                LastWriteTime     Length Name
-a---        2012-01-09     01:16       5290 PowerShell.jar
========== Executing cd\
========== Executing dir
    Directory: Microsoft.PowerShell.Core\FileSystem::C:\
Mode                LastWriteTime     Length Name
d----        2012-01-08     02:56            61587b977687a6e22fbe
d----        2011-12-14     03:19            Documents and Settings
d----        2011-12-15     00:05            oraclexe
d-r--        2012-01-08     03:44            Program Files
d----        2012-01-05     19:59            sqldeveloper
d----        2012-01-09     01:15            temp
d----        2012-01-09     01:13            WINDOWS
-a---        2011-12-14     03:12          0 AUTOEXEC.BAT
-a---        2011-12-14     03:12          0 CONFIG.SYS
========== Executing cd \temp
========== Executing dir
    Directory: Microsoft.PowerShell.Core\FileSystem::C:\temp
Mode                LastWriteTime     Length Name
-a---        2012-01-09     01:16       5290 PowerShell.jar
========== Executing cd \bubba
Set-Location : Cannot find path 'C:\bubba' because it does not exist.
At line:1 char:3
+ cd  <<<< \bubba
========== Exiting .... bye.
C:\temp>

Similar Messages

  • Interacting with adapters from Spring Component, especially db adapter

    hello everybody,
    I try to interact with adapters from my Spring component. I actually try to start my query and to receive the result in my Spring Component.
    I've already search for documentation about api to communicate with it or documentation about the classes created during the db adapter creation... But .. no result..
    So I'm trying to do it my self but I encounter some problems when I'm trying to call the query on the dbAdapter and trying to "play" with the classes created by the db adapter.
    Could anyone say me HOW we can interact with adapters from Spring component (in the class bean)?
    Also, how can I access to the variables? Is there an equivalent of "getVariableData" and "setVariableData" that I can use in the Spring Component? with which jar and/or import?
    I copy/paste what I've already done.
    So My Composite contains a Web Service "getStatusByCC" which is linked to a Mediator. The Mediator calls the Spring Component "SprinCallDB" and the Spring Component is linked to a database adapter called "getCreditValidation". The transformation in the mediator component is correct (I test it without the call to the db and it works fine)
    First, there is the classes created and added to my project by the db adapter :
    Creditcardinfo.java
    package com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    * <p>Java class for Creditcardinfo complex type.
    * <p>The following schema fragment specifies the expected content contained within this class.
    * <pre>
    * &lt;complexType name="Creditcardinfo">
    * &lt;complexContent>
    * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    * &lt;sequence>
    * &lt;element name="ccnumber">
    * &lt;simpleType>
    * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string">
    * &lt;maxLength value="20"/>
    * &lt;/restriction>
    * &lt;/simpleType>
    * &lt;/element>
    * &lt;element name="status" minOccurs="0">
    * &lt;simpleType>
    * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}string">
    * &lt;maxLength value="20"/>
    * &lt;/restriction>
    * &lt;/simpleType>
    * &lt;/element>
    * &lt;/sequence>
    * &lt;/restriction>
    * &lt;/complexContent>
    * &lt;/complexType>
    * </pre>
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "Creditcardinfo", propOrder = {
    "ccnumber",
    "status"
    public class Creditcardinfo {
    @XmlElement(required = true)
    protected String ccnumber;
    protected String status;
    * Gets the value of the ccnumber property.
    * @return
    * possible object is
    * {@link String }
    public String getCcnumber() {
    return ccnumber;
    * Sets the value of the ccnumber property.
    * @param value
    * allowed object is
    * {@link String }
    public void setCcnumber(String value) {
    this.ccnumber = value;
    * Gets the value of the status property.
    * @return
    * possible object is
    * {@link String }
    public String getStatus() {
    return status;
    * Sets the value of the status property.
    * @param value
    * allowed object is
    * {@link String }
    public void setStatus(String value) {
    this.status = value;
    CreditcardinfoCollection.java
    package com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation;
    import java.util.ArrayList;
    import java.util.List;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    * <p>Java class for CreditcardinfoCollection complex type.
    * <p>The following schema fragment specifies the expected content contained within this class.
    * <pre>
    * &lt;complexType name="CreditcardinfoCollection">
    * &lt;complexContent>
    * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    * &lt;sequence>
    * &lt;element name="Creditcardinfo"
    * type="{http://xmlns.oracle.com/pcbpel/adapter/db/top/getCreditValidation}Creditcardinfo" maxOccurs="unbounded" minOccurs="0"/>
    * &lt;/sequence>
    * &lt;/restriction>
    * &lt;/complexContent>
    * &lt;/complexType>
    * </pre>
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "CreditcardinfoCollection", propOrder = {
    "creditcardinfo"
    public class CreditcardinfoCollection {
    @XmlElement(name = "Creditcardinfo")
    protected List<Creditcardinfo> creditcardinfo;
    * Gets the value of the creditcardinfo property.
    * <p>
    * This accessor method returns a reference to the live list,
    * not a snapshot. Therefore any modification you make to the
    * returned list will be present inside the JAXB object.
    * This is why there is not a <CODE>set</CODE> method for the creditcardinfo property.
    * <p>
    * For example, to add a new item, do as follows:
    * <pre>
    * getCreditcardinfo().add(newItem);
    * </pre>
    * <p>
    * Objects of the following type(s) are allowed in the list
    * {@link Creditcardinfo }
    public List<Creditcardinfo> getCreditcardinfo() {
    if (creditcardinfo == null) {
    creditcardinfo = new ArrayList<Creditcardinfo>();
    return this.creditcardinfo;
    GetCreditValidationSelectCcnb.java
    package com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation;
    import javax.xml.bind.annotation.XmlAccessType;
    import javax.xml.bind.annotation.XmlAccessorType;
    import javax.xml.bind.annotation.XmlElement;
    import javax.xml.bind.annotation.XmlType;
    * <p>Java class for getCreditValidationSelect_ccnb complex type.
    * <p>The following schema fragment specifies the expected content contained within this class.
    * <pre>
    * &lt;complexType name="getCreditValidationSelect_ccnb">
    * &lt;complexContent>
    * &lt;restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
    * &lt;sequence>
    * &lt;element name="ccnb" type="{http://www.w3.org/2001/XMLSchema}string"/>
    * &lt;/sequence>
    * &lt;/restriction>
    * &lt;/complexContent>
    * &lt;/complexType>
    * </pre>
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "getCreditValidationSelect_ccnb", propOrder = {
    "ccnb"
    public class GetCreditValidationSelectCcnb {
    @XmlElement(required = true)
    protected String ccnb;
    * Gets the value of the ccnb property.
    * @return
    * possible object is
    * {@link String }
    public String getCcnb() {
    return ccnb;
    * Sets the value of the ccnb property.
    * @param value
    * allowed object is
    * {@link String }
    public void setCcnb(String value) {
    this.ccnb = value;
    ObjectFactory.java
    package com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation;
    import javax.xml.bind.JAXBElement;
    import javax.xml.bind.annotation.XmlElementDecl;
    import javax.xml.bind.annotation.XmlRegistry;
    import javax.xml.namespace.QName;
    * This object contains factory methods for each
    * Java content interface and Java element interface
    * generated in the com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation package.
    * <p>An ObjectFactory allows you to programatically
    * construct new instances of the Java representation
    * for XML content. The Java representation of XML
    * content can consist of schema derived interfaces
    * and classes representing the binding of schema
    * type definitions, element declarations and model
    * groups. Factory methods for each of these are
    * provided in this class.
    @XmlRegistry
    public class ObjectFactory {
    private final static QName CreditcardinfoCollectionQNAME = new QName("http://xmlns.oracle.com/pcbpel/adapter/db/top/getCreditValidation", "CreditcardinfoCollection");
    private final static QName GetCreditValidationSelectCcnbInputParametersQNAME = new QName("http://xmlns.oracle.com/pcbpel/adapter/db/top/getCreditValidation", "getCreditValidationSelect_ccnbInputParameters");
    * Create a new ObjectFactory that can be used to create new instances of schema derived classes for package: com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation
    public ObjectFactory() {
    * Create an instance of {@link CreditcardinfoCollection }
    public CreditcardinfoCollection createCreditcardinfoCollection() {
    return new CreditcardinfoCollection();
    * Create an instance of {@link GetCreditValidationSelectCcnb }
    public GetCreditValidationSelectCcnb createGetCreditValidationSelectCcnb() {
    return new GetCreditValidationSelectCcnb();
    * Create an instance of {@link Creditcardinfo }
    public Creditcardinfo createCreditcardinfo() {
    return new Creditcardinfo();
    * Create an instance of {@link JAXBElement }{@code <}{@link CreditcardinfoCollection }{@code >}}
    @XmlElementDecl(namespace = "http://xmlns.oracle.com/pcbpel/adapter/db/top/getCreditValidation", name = "CreditcardinfoCollection")
    public JAXBElement<CreditcardinfoCollection> createCreditcardinfoCollection(CreditcardinfoCollection value) {
    return new JAXBElement<CreditcardinfoCollection>(_CreditcardinfoCollection_QNAME, CreditcardinfoCollection.class, null, value);
    * Create an instance of {@link JAXBElement }{@code <}{@link GetCreditValidationSelectCcnb }{@code >}}
    @XmlElementDecl(namespace = "http://xmlns.oracle.com/pcbpel/adapter/db/top/getCreditValidation", name = "getCreditValidationSelect_ccnbInputParameters")
    public JAXBElement<GetCreditValidationSelectCcnb> createGetCreditValidationSelectCcnbInputParameters(GetCreditValidationSelectCcnb value) {
    return new JAXBElement<GetCreditValidationSelectCcnb>(_GetCreditValidationSelectCcnbInputParameters_QNAME, GetCreditValidationSelectCcnb.class, null, value);
    package-info.java
    @javax.xml.bind.annotation.XmlSchema(namespace = "http://xmlns.oracle.com/pcbpel/adapter/db/top/getCreditValidation", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
    package com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation;
    GetCreditValidation_ptt.java
    package getcreditvalidation.validationforccwithspring.creditcardvalidation.db.adapter.pcbpel.com.oracle.xmlns;
    import javax.jws.WebMethod;
    import javax.jws.WebParam;
    import javax.jws.WebResult;
    import javax.jws.WebService;
    import javax.jws.soap.SOAPBinding;
    import javax.jws.soap.SOAPBinding.ParameterStyle;
    import javax.xml.bind.annotation.XmlSeeAlso;
    import javax.xml.ws.Action;
    // !DO NOT EDIT THIS FILE!
    // This source file is generated by Oracle tools
    // Contents may be subject to change
    // For reporting problems, use the following
    // Version = Oracle WebServices (11.1.1.0.0, build 111209.0821.28162)
    @WebService(targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/CreditCardValidation/validationForCCWithSpring/getCreditValidation",
    name="getCreditValidation_ptt")
    @XmlSeeAlso(
    { com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation.ObjectFactory.class })
    public interface GetCreditValidation_ptt
    @WebMethod
    @SOAPBinding(parameterStyle=ParameterStyle.BARE)
    @Action(input="http://xmlns.oracle.com/pcbpel/adapter/db/CreditCardValidation/validationForCCWithSpring/getCreditValidation/getCreditValidation_ptt/getCreditValidationSelectRequest",
    output="http://xmlns.oracle.com/pcbpel/adapter/db/CreditCardValidation/validationForCCWithSpring/getCreditValidation/getCreditValidation_ptt/getCreditValidationSelectResponse")
    @WebResult(targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/top/getCreditValidation",
    partName="CreditcardinfoCollection", name="CreditcardinfoCollection")
    public com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation.CreditcardinfoCollection getCreditValidationSelect(@WebParam(targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/top/getCreditValidation",
    partName="getCreditValidationSelect_inputParameters", name="getCreditValidationSelect_ccnbInputParameters")
    com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation.GetCreditValidationSelectCcnb getCreditValidationSelect_inputParameters);
    Here there is the classes linked to the Spring Component and the configuration file :
    SpringCallDB
    <?xml version="1.0" encoding="windows-1252" ?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jee="http://www.springframework.org/schema/jee"
    xmlns:lang="http://www.springframework.org/schema/lang"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:sca="http://xmlns.oracle.com/weblogic/weblogic-sca"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-2.5.xsd http://xmlns.oracle.com/weblogic/weblogic-sca META-INF/weblogic-sca.xsd">
    <!--Spring Bean definitions go here-->
    <sca:service name="CCSpringService" target="CCSpringImpl"
    type="validationForCC.spring.service.api.ISpringCCService"/>
    <bean id="CCSpringImpl" class="validationForCC.spring.service.impl.SpringCCServiceImpl">
    <property name="dbRequest" ref="getCreditValidation"/>
    </bean>
    <sca:reference type="getcreditvalidation.validationforccwithspring.creditcardvalidation.db.adapter.pcbpel.com.oracle.xmlns.GetCreditValidation_ptt"
    name="getCreditValidation"/>
    </beans>
    CreditCardNumber.java
    package validationForCC.spring.model;
    public class CreditCardNumber {
    private String ccNumber;
    public CreditCardNumber() {
    super();
    public void setCcNumber(String nb){
    this.ccNumber = nb;
    public String getCcNumber(){
    return ccNumber;
    Response.java
    package validationForCC.spring.model;
    public class Response {
    String reply;
    public Response() {
    super();
    public void setReply(String rep){
    this.reply = rep;
    public String getReply(){
    return reply;
    ISpringCCService.java
    package validationForCC.spring.service.api;
    import validationForCC.spring.model.CreditCardNumber;
    import validationForCC.spring.model.Response;
    public interface ISpringCCService {
    * @param ccn
    * @return
    public Response getCCStatus(CreditCardNumber ccn);
    SpringCCServiceImpl.java
    package validationForCC.spring.service.impl;
    import com.oracle.xmlns.pcbpel.adapter.db.top.getcreditvalidation.*;
    import java.util.List;
    import javax.jws.WebParam;
    import validationForCC.spring.model.CreditCardNumber;
    import validationForCC.spring.model.Response;
    public class SpringCCServiceImpl {
    public SpringCCServiceImpl() {
    super();
    private getcreditvalidation.validationforccwithspring.creditcardvalidation.db.adapter.pcbpel.com.oracle.xmlns.GetCreditValidation_ptt dbRequest;
    public Response getCCStatus(CreditCardNumber ccn){
    Response resp = new Response();
    CreditcardinfoCollection resultSet;
    GetCreditValidationSelectCcnb selectCCNb = new GetCreditValidationSelectCcnb();
    selectCCNb.setCcnb(ccn.getCcNumber());
    resultSet = dbRequest.getCreditValidationSelect(selectCCNb);
    resp.setReply((resultSet.getCreditcardinfo().get(0).getStatus()));
    return resp;
    public getcreditvalidation.validationforccwithspring.creditcardvalidation.db.adapter.pcbpel.com.oracle.xmlns.GetCreditValidation_ptt getDbRequest(){
    return dbRequest;
    public void setDbRequest(getcreditvalidation.validationforccwithspring.creditcardvalidation.db.adapter.pcbpel.com.oracle.xmlns.GetCreditValidation_ptt dbReq){
    this.dbRequest = dbReq;
    So, the line which is the cause of the error is the following :
    resultSet = dbRequest.getCreditValidationSelect(selectCCNb);
    in the SpringCCServiceImpl.java class
    And there is the error I obtain :
    +weblogic.sca.api.ScaException: java.lang.RuntimeException: BINDING.JCA-12563 Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'getCreditValidationSelect' failed due to: DBReadInteractionSpec Execute Failed Exception. Query name: [getCreditValidationSelect], Descriptor name: [getCreditValidation.Creditcardinfo]. Caused by Exception [EclipseLink-6003] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.QueryException Exception Description: The number of arguments provided to the query for execution does not match the number of arguments in the query definition. Query: ReadAllQuery(name="getCreditValidationSelect" referenceClass=Creditcardinfo ). See root exception for the specific exception. This exception is considered not retriable, likely due to a modelling mistake. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution.
    Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'getCreditValidationSelect' failed due to: DBReadInteractionSpec Execute Failed Exception. Query name: [getCreditValidationSelect], Descriptor name: [getCreditValidation.Creditcardinfo]. Caused by Exception [EclipseLink-6003] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.QueryException Exception Description: The number of arguments provided to the query for execution does not match the number of arguments in the query definition. Query: ReadAllQuery(name="getCreditValidationSelect" referenceClass=Creditcardinfo ). See root exception for the specific exception. This exception is considered not retriable, likely due to a modelling mistake. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution.
    java.lang.RuntimeException: BINDING.JCA-12563 Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'getCreditValidationSelect' failed due to: DBReadInteractionSpec Execute Failed Exception. Query name: [getCreditValidationSelect], Descriptor name: [getCreditValidation.Creditcardinfo]. Caused by Exception [EclipseLink-6003] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.QueryException Exception Description: The number of arguments provided to the query for execution does not match the number of arguments in the query definition. Query: ReadAllQuery(name="getCreditValidationSelect" referenceClass=Creditcardinfo ). See root exception for the specific exception. This exception is considered not retriable, likely due to a modelling mistake. ". The invoked JCA adapter raised a resource exception. Please examine the above error message ca
    Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'getCreditValidationSelect' failed due to: DBReadInteractionSpec Execute Failed Exception. Query name: [getCreditValidationSelect], Descriptor name: [getCreditValidation.Creditcardinfo]. Caused by Exception [EclipseLink-6003] (Eclipse Persistence Services - 2.3.1.v20111018-r10243): org.eclipse.persistence.exceptions.QueryException Exception Description: The number of arguments provided to the query for execution does not match the number of arguments in the query definition. Query: ReadAllQuery(name="getCreditValidationSelect" referenceClass=Creditcardinfo ). See root exception for the specific exception. This exception is considered not retriable, likely due to a modelling mistake. ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution. +
    Any idea is welcome! :)
    If you have great urls to communicate with adapters and variables from spring component, don't hesitate to post it!
    Thanks in advance,
    Sophie
    Edited by: 953383 on Sep 18, 2012 6:41 AM
    Edited by: 953383 on Sep 18, 2012 6:43 AM
    Edited by: 953383 on Sep 18, 2012 6:46 AM

    Hello,
    Finally, I can interact with my db adapter.
    But, I ask you the following question : is there any documentation on the manner to interact with adapters and other component of the suite and on all classes generated?
    Thanks in advance,
    Sophie

  • Interfacing with vb from java

    Hi,
    is it possible to interface with vb from java.
    I have a vb program with a method stop() which just stops the program. I want to be able to call this method from my java program in order to stop the vb program.
    Is this possible?
    I d really appreciate any help.
    Thanks Jim

    Hi,
    there is a Java / COM bridge. You can reach COM from Java and
    VB from COM.
    Have fun,
    Klaus

  • Unable to establish connection with SQLServer from Java Application

    Dear All,
    I am facing the issue of establishing connection with SQL Server from Java project developed in NWDS. I am writing a jaas plug-in, as a part of that I am writing a login module to authenticate a web application through jaas, and I got need of fetching some data from SQL Server which is located in remote host. I am getting error in the line of code
    <b>Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver")</b>
    I also added the 3 jar files (msbase.jar,mssqlserver.jar,and msutil.jar) to my login module project and copied the same files at C:\usr\sap\J2E\JC01\j2ee\cluster\server0\bin\ext\MSSQL.
    My MI Landscape is j2ee stack + abap stack +WAS 6.40 with MAXDb as a database.
    Could anyone please let me know the solution if you are aware of it.
    Thanks and Regards,
    Kishore

    I solved it by writing the following code
    Connection con;
    Statement stmt;
    DataSource ds;
    Context ctx;
    ctx = new InitialContext();
    if(ctx == null)     throw new Exception("Boom - No Context");
    ds=(DataSource)ctx.lookup("jdbc/SQLDB");     
    con = ds.getConnection();
    stmt = con.createStatement();
    String query = "SELECT * FROM SubjectBIR where Subject_ID='" + user + "'";
    ResultSet result  = stmt.executeQuery(query);
    stmt.close();
    con.close();

  • Problems connecting with database from java API

    I've benn using XSQLRequest and I found a problem with
    connections, because it can't connect from Java to database, but
    if I access to a .xsql it works.
    And also if I link to a .xsql first and after that I try to
    access to Database form my servlet it works. So I think my
    problem is to initialize the XSQLConfig.xml file in OC4J server.
    Thanks in advance

    Would you provide the way you deploy your XSQL app to OC4J and
    how you get JDBC connection using JAVA? I execute the next code more or less:
    miXSQLRequest = new XSQLRequest(XSQLQuery.getDOM
    (),null);
    miXSQLRequest.process(htParamsIn, pWriter, pErrors);
    but and it's probabily my mistake I don't get any conecction
    from the session or something similar because I thought that
    it's made by XSQLRequest, and the XSQLRequest class takes the
    default values of the connection pool from the file
    XSQLConfig.xml (I put this file inside the lib directory of
    OC4J) as the XSQLServlet.
    Thanks for your help

  • Interacting with perl through java.

    I'm trying to do something with Java that I haven't managed to do until now. I'm trying to interact with a perl process giving him input and reading output.
    I have a perl module that has several functions and the idea is to launch a process in a java program with the following line :
    perl -e 'while(<STDIN>) { eval $_ ; }'
    and then give the process the necessary input and the read the given output.
    For instance with the above line you can do the following:
    [user@host ~]$ perl -e 'while(<STDIN>) { eval $_ ; }'
    print "Hello World\n";
    Hello World
    Here is the code I'm using:
    import java.io.BufferedReader;
    public class ExecProgram {
    private static Runtime runtime;
    private static Process process;
    public static void main(String[] args) {
         runtime = Runtime.getRuntime();
         try {
         process = runtime.exec("/usr/bin/perl -e 'while(<STDIN>) { eval $_ ; }'");
              process = runtime.exec(cmd);
         } catch (IOException e) {
              System.err.println("Error executing process");
         PrintWriter out = new PrintWriter(process.getOutputStream());
         String commandLine = "print \"Hello World\n\"";
         out.println(commandLine);
         BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
         try {
         String line;
         while ((line = in.readLine()) != null)
              System.out.println("Output: "+line);
         } catch (IOException e) {
         System.err.println("Error reading output");
    As you can see I'm using Runtime class to interact with the process but nothing happens if replace the exec line with:
    process = runtime.exec("ls");
    I can see in the output the listing of the current directory.
    Have you ever tried something like this? Is this the correct way for doing this?

    Have you ever tried something like this? I have. Here's a rough sample:
        public static void main(String[] args) throws Exception {       
            String[] cmd = new String[]{
                "/usr/bin/perl",
                "-e",
                "while(<>){ eval or die $@; }"
            final Process p = Runtime.getRuntime().exec(cmd);
            new Thread(){
                public void run(){
                    try{
                        BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
                        for(String line; (line = r.readLine()) != null; System.out.println("ProcessOUT:: "+line));
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            new Thread(){
                public void run(){
                    try{
                        BufferedReader r = new BufferedReader(new InputStreamReader(p.getErrorStream()));
                        for(String line; (line = r.readLine()) != null; System.err.println("ProcessERR:: "+line));
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            new Thread(){
                public void run(){
                    try{
                        OutputStream out = p.getOutputStream();
                        for(int ii = 0; ii < commands.length; ii++){
                            System.err.println("Sending command: "+commands[ii]);
                            out.write(commands[ii].getBytes());
                            out.write('\n');
                            out.flush();
                    catch (Throwable t){
    //                    t.printStackTrace();
            }.start();
            int exit = p.waitFor();
            System.err.println("Process exited with code: "+exit);
        static final String[]
            commands = {
                "print \"The road goes ever\\n\";",
                "print \"ever\\n\";",
                "print \"on.\\n\";",
                "exit 13;"
        ;

  • How to call sql procedure with parameter from java

    Hello,
    i am trying to call one sql procedure with two parameters from java.
    the first parameter is In parameter, the second is OUT.
    the return value of this java method should be this second parameter value.
    the following is my java code:
    protected String getNextRunNumber() {
         String runnumber=null;
         String sql = "{call APIX.FNC_SST_EXPORT.GET_NEXT_RUNNUMBER (?,?)}";
    CallableStatement state = null;
    try{
         Connection con= getDatabaseConnection();
         state = con.prepareCall(sql);
         state.setString(1, m_appKeyExport);
         state.registerOutParameter(2,Types.NUMERIC,0);
         state.execute();
    ResultSet resultR = (ResultSet)state.getObject(2);
         while (resultR.next()) {
              runnumber=resultR.getBigDecimal(1).toString();
    catch (SQLException e){System.out.println("You can not get the export next run number properly");}
    return runnumber;
    i got error message like:
    java.lang.ClassCastException: java.math.BigDecimal
    As far as i knew, if the parameter is number or decimal, we should give also the paramer scale to the method: state.registerOutParameter(), but i still get this error message.
    Please help me to solve this problem.
    Thanks a lot.

    state.execute();
    i try to use debug to find the problem, in this line, i saw
    OracleCallableStatement(OraclePreparedStatement).execute() line: 642 [local variables unavailable]
    is this the problem?

  • Call an interactive UNIX command from java

    Hi,
    I want to call a UNIX command from java. When issue the command 'htpasswd -c filename username' on UNIX terminal, it asks for the new password and the then confirmation password again (yeah, unfortunately the htpasswd installed on our system does not allow you proivde the password on the command line. So have to work interactively ). Now, I have written a simple java program RunCommand.java. I am hardcoding the password for the htpasswd command in the file (in the real situation, password will be generated dynamically). I want to issue 'java RunCommand' on the UNIX command line and get back the command prompt without being asked for the password twice. The code is below, but the Outputstream does not work as expected. It always asks for inputs. Any idea? Many thanks.
    import java.io.*;
    public class RunCommand {
    public static void main(String args[]) throws Exception {
    String s = null;
    try {
    String cmd = "htpasswd -c filename username ";
    // run a Unix command
    Process p = Runtime.getRuntime().exec(cmd);
    BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
    BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));
    OutputStream stdOut = p.getOutputStream();
    String pswd = "mypassword";
    while ((s = stdInput.readLine()) != null) {
         s = stdInput.readLine();
         stdOut.write(pswd.getBytes());          
         stdOut.flush();
    System.out.println("Here is the standard error of the command (if any):\n");
    while ((s = stdError.readLine()) != null) {
    System.out.println(s);
    stdOut.close();
    stdInput.close();
    stdError.close();
    System.exit(0);
    catch (IOException e) {
    System.out.println("exceptions caught: ");
    e.printStackTrace();
    System.exit(-1);

    There are only about 9 billion responses a day on how to do this. Use the search feature.

  • Interact with exe in java

    Hi!
    I got a old exe file, that no more maintain by any team.
    Unfortunately, requirement has it that I need to run this exe, do some interaction, such as "enter" and "wait" and "input value", get "value"
    And it has to be retrive by java,
    can anyone give idea how should this done?
    I know I can excute this program, but I don't know how to fetch the program any more key board input...
    Thanks

    What sort of exe?
    If it is a GUI, then you will need to use JNI to interact with it. You might find a 3rd party tool that already does this for the GUI/OS that you are targetting. If not you have to write it yourself.
    If it is a command line application then you can use Runtime.exec(). That creates a process without output and input streams. The input stream allows you to send text to the process.

  • Interacting with database from web

    Here's the situation. I have some dumb terminal (client) that interacts with a server, which holds a database. I want users to be able to query that database from the web and have it create a page with the results.
    Since I did not know cgi, or servlets, etc., I devised a primitive method. I was planning on having the database create html files and send it to the webserver so the users can interact with the premade html files. This is not a good idea :) since there would be thousands of files made.
    What is the best way to interact with the database? Servlets? Can you use servlets freely or do you need a commercial license? Please exuse my newbiness :)

    You don't need any commercial software to use Servlets and JSPs.
    Have a look at the Tomcat servlet engine from Jakarta:
    http://jakarta.apache.org
    I expect that if you search these forums (particularly the JDBC and JavaServer Pages forums) you'll find various examples of JSPs and Servlets that connect to a database to allow primitive querying capabilities.
    Hope this helps.

  • ORA-28183 when connect proxy user with password from java

    1. Create user on database 10.2.0.1.0
    create user scott identified by tiger;
    create user jeff identified by secnt;
    grant connect, resource to scott;
    grant create session to jeff;
    alter user jeff grant connect through scott authenticated using password;
    2. Try to open proxy session from java
    DriverManager.registerDriver(new OracleDriver());
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//db.garage:1521/ILINK", "scott", "tiger");
    if (conn != null && conn instanceof OracleConnection) {
         Properties properties = new Properties();
         properties.put(OracleConnection.PROXY_USER_NAME, "jeff");
         properties.put(OracleConnection.PROXY_USER_PASSWORD, "secnt");
         ((OracleConnection)conn).openProxySession(OracleConnection.PROXYTYPE_USER_NAME, properties);
         ((OracleConnection)conn).close(OracleConnection.PROXY_SESSION);
    conn.close();
    3. Got the following error for step 2
    Exception in thread "main" java.sql.SQLException: ORA-28183: proper authentication not provided by proxy
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:316)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:277)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:272)
         at oracle.jdbc.driver.T4CTTIoauthenticate.receiveOauth(T4CTTIoauthenticate.java:647)
         at oracle.jdbc.driver.T4CConnection.doProxySession(T4CConnection.java:852)
         at oracle.jdbc.driver.PhysicalConnection.openProxySession(PhysicalConnection.java:1548)
         at ch.tie.cluster.Test.run(Test.java:30)
         at ch.tie.cluster.Test.main(Test.java:19)
    4. If i grant connect without using password like:
    alter user jeff grant connect through scott
    everything is fine, but i need password authentication.
    Thanks in advance.

    did you try using the oci driver?

  • I have AD and Exchange 2010 installed on different servers. can I control both with powershell from the AD server?

    Hi all,
    I have a lab env that include: 2 server 2012 with AD DS, 1 server 2012 with Exchange 2010, 1 server 2012 that I will install later Edge server.
    I have a script that can build all my AD and Exchange infrastructure . This script was tested on single server that hosted both AD DS and Exchange. 
    My question is how to run the script let say from one of the AD DS servers and do his magic also on the Exchange server?
    momu

    Hi,
    Take a look at this:
    https://gallery.technet.microsoft.com/office/Create-a-new-implicit-5fdafe45
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

  • Can I remotely failover clusters with powershell from a non clustered server? Windows Server 2008 R2

    Hello,
    I'm trying to remotely administer my windows clusters and fail them over with a PowerShell Script.  The server I'm using is not a clustered server.  I've already installed the Failover Clustering Tools.  I'm able to retrieve information about
    my clusters but when I try to fail them over I receive an error saying "The cluster service is not running."
    The command I'm using is 'Get-ClusterNode $Server | Get-ClusterGroup | Move-ClusterGroup'
    Error message:  'Get-ClusterNode : The cluster service is not running.  Make sure that the service is running on all nodes in the cluster'
    Is there a way to install the cluster service or is there a different way to go around this error?
    Thank you!

    Hi Armando,
    To get cluster node information, please try to use the cmd cluster.exe, like:
    cluster.exe node NodeName /force
    For more detailed information to use clusterexe, please refer to this article:
    Mapping Cluster.exe Commands to Windows PowerShell Cmdlets for Failover Clusters
    To remotely manage Cluster server, you can also try the powershell pssession with the cmdlet enter-pssession to accesss the remote server:
    Learn How to Manage Remote PowerShell Sessions
    I hope this helps.

  • Need help with porting from Java 1.1 to 1.4

    One of our applications is an applet and we're in the
    process of upgrading it's version of Java from 1.1 to 1.4. For the most part,the upgrade has gone smoothly, but we are having two big problems. The first problem is that the list objects on one of the windows resize when a mouse event occurs on the Tabbed Panel it sits on. The list object is made from a Symantec class called MultiList. The list actually shrinks so that the data on it can hardly be seen.
    The other problem is that when dispose() is called on all of the windows, an IllegalStateException: Cannot dispose InputContext while its active error occurs.

    If you people have nothing good to say, please do the
    rest of us in the forum(s) a favor and don't say
    anything at all.
    Also, do not assume that threads are posted because
    people are lazy and haven't researched their
    problem(s).
    People post threads in these forums looking for help,
    not abuse.What are you talking about?
    If the original poster disregarded my advice and searched the bug database as indicated, they would have found the answer to their question. I know. I had the same problem and solved it by using the workaround I found in the bug database.
    I would say it was very helpful advice.

  • Interacting with a compiled LABView executable from another VI

    I'm using a piece of hardware that has it's driver executable written in LABView. I would like to interact with it from the inside of my own VI. There's no dedicated LABView driver and I don't have access to the source code. Communication happens over USB. The particular functionality that I need is changing one numeric control, which governs the current that's provided.
    Could someone help me with this in any way?
    If that matters, I'm using LV2013.

    Was the exe built with VI Server/ActiveX enabled? If so, all you need is a set control value method. If your company was the one that commissioned the exe, for a small cost the vendor can enable this option and rebuild it. If you did commission it, you should have required the source code in the contract.
    Other options include using something like AutoIT. You could also turn on NI-Spy/I/O Trace and capture all of the VISA commands. Even though there might not be a driver, you should have a manual that you can read. Implementing a single command should be pretty trivial.

Maybe you are looking for

  • Configration

    how we can configure oracle warehouse builder 10g r2 with oracle 10g database and how we can create repository in oracle warehouse builder 10g r2 Plz explain step by step because i am new

  • Why cant I listen to the entire song on my computer only on my iPod  or am I doing something wrong ?

    When I download a song from iTunes I could only listen to entire cut on my iPod. I would like to listen to the entire cut on my computer, is this possible ?

  • SG300-28 VLAN`s

    I would like to swich SG300-28 grouped into separate VLAN ports. (firmware ver. 1.3.7.18)   L2 mode 1 separate vlan - Ports 1-4    - Connected to port 1 on the router DHCP1 link    - To ports 2-4 - stations that receive addresses from DHCP1 2 separat

  • Document Management Nodes

    Hi, I have an Item Attribute of Type 'Document' in my WF. When I go to WF monitor to launch this workflow, I see an attachment icon next to this attribute, meaning I can attach a document before launching the wf. But when I click on this icon, it giv

  • Why does the download of the free upgrade to firefox not install. Instead it still keeps asking me to upgrade

    we are trying to download the free upgrade to Firefox 8, It acts as though the download is happening. After it completes, we still get the notice that we are using an old version of Firefox. Thank you for any help you can give us.