Post data to cgi script via Java

What I'm trying to do may seem somewhat confusing (probably not to you pros ;) so let me know if I need to clarify anything:
I have a Java program that processes a transaction. When this transaction is complete I need to post certain data back to our UNIX System. The only way I can talk to this UNIX system is by using a third party software which is a fast-cgi program. I could use a straight HTML form post but it makes some of my pages do wierd things, and often kicks me off my pages to the URL I need to post to.
This is an example of the format of the URL that I would normally have as the form action:
http://www.mywebsite.com/my-bin/myfastcgi?pib.transaction=MYTRAN&cda.text=324234!1!_!System_ok!
Notes: The ! are just delimeters, The cda.text field is what the UNIX box is waiting to accept, the pib.transaction is telling my UNIX box what I'm trying to do
So I want to try to accomplish this with Java. I have tried the following:
URL url = "http://www.mywebsite.com"
URLConnection conn = url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(false);
urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");
urlConnection.setRequestProperty("method", "POST");
String post = "/my-bin/myfastcgi?pib.transaction=MYTRAN&324234!1!_!System_ok!"
DataOutputStream dos = new DataOutputStream(conn.getOutputStream());
dos.writeBytes(post);
dos.flush();
dos.close();I have also tried the url = "http://www.mywebsite.com/my-bin/myfastcgi" and the post = ?pib.transaction=MYTRAN&324234!1!_!System_ok!"
What is happening is that the system gets hung up or I get a IOException, and needless to say doesn't update the UNIX system. Can anyone help me understand how to make this work (if it is at all possible??)
Thanks in advance.

A little more information for anyone willing to look into this. I added in some echo printing and a stack trace. It seems that my connectin is timing out on the getOutputStream(). This is pretty urgent so I really appreciate some help - if I had duke dollars I would award them - but not exactly sure how to earn them :( ... This is whats happening:
Start
URL created: http://test.parkingticketpayment.com
Connection opened
DoOutput = true ... method = Post
Bad io.
java.net.ConnectException: Connection timed out
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:426)
at java.net.Socket.connect(Socket.java:376)
at sun.net.NetworkClient.doConnect(NetworkClient.java:139)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:386)
at sun.net.www.http.HttpClient.openServer(HttpClient.java:602)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:303)
at sun.net.www.http.HttpClient.<init>(HttpClient.java:264)
at sun.net.www.http.HttpClient.New(HttpClient.java:336)
at sun.net.www.http.HttpClient.New(HttpClient.java:317)
at sun.net.www.http.HttpClient.New(HttpClient.java:312)
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:481)
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:472)
at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(HttpURLConnection.java:528)
at testPWDONE.main(testPWDONE.java:26)

Similar Messages

  • CGI Scripts in Java

    Can you write CGI scripts in Java or JavaScript and run them on a web server without modifying the server?

    The equivalent of CGI scripts in Java are servlets. To
    run servlets, you need a servlet container. I don't
    know if your web server has a servlet container or a
    way to connect a servlet container to it. Lookup
    information on J2EE (Java 2 Enterprise Edition) on
    this website.The man is correct. Or u can use JSP to the same end. You don't need J2EE tho i don't think...

  • Executing PowerShell script via JAVA

    Hi,
    I have simple powershell script as below :
    # Filename: Hello.ps1
    Write-Host
    Write-Host 'Hello World!'
    Write-Host "Good-bye World! `n"
    # end of script
    I wish to run this script via JAVA by the below JAVA code -
    import java.io.*;
    public class PsJava {
    public static void main(String[] args)
    throws IOException{
            Runtime runtime = Runtime.getRuntime();
    String cmds = (String)
    "cmd /C powershell C:/Documents and Settings/vvenkata/My         Documents/Hello.ps1";
            Process proc = runtime.exec(cmds);
            proc.getOutputStream().close();
            InputStream inputstream = proc.getInputStream();
                InputStreamReader inputstreamreader =
    new InputStreamReader(inputstream);
                BufferedReader bufferedreader =
    new BufferedReader(inputstreamreader);
    String line;
    while ((line = bufferedreader.readLine()) != null) {
                System.out.println(line);          
    Thanks
    Now, why is that I am not able to see any print statements from Hello.ps1 ? Can anyone help me on this?

    Hi,
    I have place my powershell script in the 'C' directory. and i have changed my JAVA code as below, but it still doesn't give any output in my Eclipse Console.
    import java.io.*;
    public class PsJava {
    public static void main(String[] args)
    throws IOException{
            Runtime runtime = Runtime.getRuntime();
    String cmds = (String)
    "cmd /c powershell c:/Hello.ps1";
            Process proc = runtime.exec(cmds);
            proc.getOutputStream().close();
            InputStream inputstream = proc.getInputStream();
                InputStreamReader inputstreamreader =
    new InputStreamReader(inputstream);
                BufferedReader bufferedreader =
    new BufferedReader(inputstreamreader);
    String line;
    while ((line = bufferedreader.readLine()) != null) {
                System.out.println(line);          
    Please advice me on this. If I have to create a batch file, then can you let me know how do I do that?
    Thanks

  • How can i call a CGI script from java?

    The subject pretty much says it all. I want to call a perl cgi script so i can read from/write to files on a server. I don't know how to sign applets and this would be the easiest way for me, if someone could please tell me.

    Let me get this clear. Basically what u want to do is to just call a URL, right?
    U can do it by using the following code:
    import java.applet.*;
    import java.net.*;
    import java.io.*;
    public class testhttp
    public static void main(String[] args)
    try
    URL url = new URL ("http://../testcgi.cfm");
    HttpURLConnection cxn =
    (HttpURLConnection)url.openConnection();
    cxn.setRequestMethod("POST");
    cxn.setUseCaches(false);
    cxn.setDoOutput(true);
    cxn.setDoInput(true);
    ByteArrayOutputStream bytes = new
    ByteArrayOutputStream(400);
    PrintWriter writer = new PrintWriter (bytes,true);
    writer.print("application=map&release=1&items=prog1");
    writer.flush();
    cxn.setRequestProperty("Content-
    Length",String.valueOf(bytes.size()));
    cxn.setRequestProperty("Content-
    Type","application/x-www-form-urlencoded");
    bytes.writeTo(cxn.getOutputStream());
    System.out.println(bytes);
    String currentLine;
    BufferedReader in = new BufferedReader (new
    InputStreamReader(cxn.getInputStream(),"8859_1"));
    while((currentLine = in.readLine()) != null) {
    System.out.println(currentLine); }
    catch(Exception e) { e.printStackTrace(); }
    There is also a library called HTTP client which can be found at:
    http://www.innovation.ch/java/HTTPClient/index.html
    It's very simple to use and the documentation is all there, but their web server seems to be down right now.
    Anyway, hope my post helps.

  • How to call business rules scripts via Java API

    Hi
    I have a problem. I have some scripts (business rules in essbase) that can be seen thru Administration Services Console under Business Rules folder. How can I execute these script using Provider Services (via Java API to EssBase interface)?

    hi
    i look too java api sample for "HBR Lounch"
    you can try found example in EAS folder
    C:\Hyperion\AdminServices\AppServer\InstalledApps\Tomcat\5.0.28\eas\webapps\hbrlauncher\MC_LaunchWindow.jsp
    please back, if you will have resolution :)

  • Error running HAL routine from a perl cgi script via a browser

    Hi,
    I'm getting an error while trying to run a HAL routine from a perl- cgi initiated from a web browser. Perl-Cgi script runs fine when run from command line.
    07/23/2010|183648|N/A|Info|N/A|Analytic Services Adapter Log File Started
    07/23/2010|183648|AppName/Plan2|Info|Connect|Method Started
    07/23/2010|183648|AppName/Plan2*|Error|Connect|java.lang.UnsatisfiedLinkError: no HssJNIDriver950 in java.library.path*
    07/23/2010|183648|AppName/Plan2|Error|Connect|Method Ended - Connect completed with exceptions.
    07/23/2010|183648|N/A|Info|N/A|Analytic Services Adapter Log File Ended
    I've added the following env. variables in Apache server's httpd.conf file
    SetEnv ARBORPATH "E:\\Hyperion\\products\\Essbase\\EssbaseClient"
    SetEnv APS_HOME "E:\\Hyperion\\products\\Essbase\\aps"
    SetEnv ESSLANG "English_UnitedStates.Latin1@Binary"
    SetEnv EASPATH "E:\\Hyperion\\products\\Essbase\\eas\\server"
    SetEnv HYPERION_HOME "E:\\Hyperion"
    SetEnv ESSBASEPATH "E:\\Hyperion\\products\\Essbase\\EssbaseClient"
    SetEnv EAS_HOME "E:\Hyperion\products\Essbase\eas\console"
    SetEnv CLASSPATH "E:\\Vignette\\V7\\vbis\\Hyperion\\EssbaseAdapter"
    SetEnv PATH "E:\\Hyperion\\common\\ADM\\9.5.0.0\\Essbase\\9.5.0.0\\bin;E:\\Vignette\\V7\\vbis\\Hyperion\\EssbaseAdapter\\adm;C:\\Program Files (x86)\\Java\\jre1.5.0_17\\bin\\;E:\\Hyperion\\products\\Essbase\\EssbaseClient\\bin;E:\\Hyperion\\products\\Essbase\\EssbaseClient;E:\\Hyperion\\common\\CSS\\9.5.0.0\\bin;E:\\Hyperion\\products\\Essbase\\eas\\console\\bin;"
    Any pointers would be appreciated.
    Thanks in Advance!!

    Vipul,
    Vipul Sanghvi wrote:
    I am facing problem in running a Perl CGI Script on Weblogic
    Application
    Server
    I set the CGIServlet Property in the Weblogic Properties file as
    weblogic.httpd.register.cgi-bin=weblogic.servlet.CGIServlet
    weblogic.httpd.initArgs.cgi-bin=\
    cgiDir=/weblogic/myserver/public_html/cgi-bin,\
    *.pl=/bin/perl.exe,\It shouldn't end with ,\ right?
    Was it a mistake?
    -Kumar
    >
    I installed the Perl on my system and put the perl exe in the bin
    directory
    of the Weblogic App Server. But I am getting the error "failed to
    execute
    the test.pl ". Where test.pl is a simple test perl script.
    APP server ver is WLE5 Beta[att1.html]

  • Posting date for CM rebates via Extended rebate processing

    Hi,
    we have the following scenarios for an extended rebate processing:
    1> rebate agreemetn validity period  = upto Sept 30 only
    2> Settlement Date = Oct 5
    3> CM posting date of the rebate is Sept 30
    How is it possible to make the CM posting date to the current date and not the valid to date?

    Hi Mark,
    I'm not sure, but I understand that you want to change the value of condition while you are running it. Check BADI SD_ENH_REBATES, method V13A_VERIFICATION, I see that you can change I_E_KONP. I am never use it, only I know it, so I don't tell you what kind of troubles you can find.
    I hope this helps you
    Regards
    Eduardo

  • Please Help...!!  Is this to possible add data to write excel via java script

    Team:
    Is this possible to write data to Excel using javascript.
    I have created ScriptUI Dialog window. but i can't able to store datas in Excel.
    I can add data column wise in excel( using writeln comment) but I can't able add data to Row wise.
    Please anyone help me to solve this problem...
    Thanks in Advance.
    -yajiv
    Source Window :
    and the outputs wants......
    save the excel name to the Batch ID..

    Hi Everyone!
    I can add data column wise in excel( using writeln comment) but I can't able add data to Row wise.
    Please anyone help me to solve this problem...
    Thanks in Advance...
    -yajiv....
    Code :
    var myDoc = app.activeDocument;
    var myAllLinks = myDoc.allGraphics;
    var myLink=new Array()
    var mySeen = Object;
        var myLogFile = new File("~/Desktop/Link Files.xls");
        myLogFile.open("w", undefined, undefined)
        myLogFile.writeln("Link Name");
          for ( i = 1; i < myAllLinks.length; i++ )
                var myLinkName = myAllLinks[i].itemLink.name;
                var l=myLinkName.length;
               var T=myLinkName.substring(l-4);
                if (T==".tif"){
                    myLogFile.writeln(myAllLinks[i].itemLink.name);

  • Pass in date from shell script to java program

    Hi,
    I need to pass in some parameter to my java program.
    eg 'java SomeProgram yyyy mm dd hh mm ss'
    How do i use the shell script to generate the valeus for the year, mth day etc?
    The program is running once everyday.
    I tried $argu0 = `date+%y`
    java SomeProgram $argu0
    but not working... thanks for your help!

    Then, why would you want to use 'date' to provide
    'now' to a Java program when you could just use new
    java.util.Date() which probably makes the same call
    as the Unix 'date' command?That works until you need to use a date other than 'now.'
        public static final String ISO_DATE = "yyyy-MM-dd HH:mm:ss";
        public static void main(String[] args) {
            SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat
                    .getDateTimeInstance();
            sdf.applyPattern(ISO_DATE);
            try {
                Date d = sdf.parse(args[0]);
                // rest of code here
            } catch (ParseException e) {
                // handle exception
        }Users will have to enclose there input with quotes otherwise the JVM will consider their input as two parameters, or you can change the pattern to include a character between dd and HH.

  • Unable to post data to a database via JDBC adapter in PI 7.1

    Hello experts,
    The scenario I am trying to implement is Proxy -- to -- JDBC. Earlier it was assumed that the table has primary key and therefore I started with UPDATE_INSERT structure but later on we came to know that the table does not have any primary key.
    Now, I am supposed to insert data into a database table with no primary key. Therefore I am using INSERT structure. The structure on the receiver side is something like this:
         <Statement1>
              <SKU_TMP action="INSERT">
                   <table>SKU_TMP</table>
                   <access>
                        <SKUCODE></SKUCODE>
                        <SKULIB1></SKULIB1>
                        <SKUPUC></SKUPUC>
                        <SKUNUC></SKUNUC>
                        <SKUUCLOT></SKUUCLOT>
                        <SKUNBFAR></SKUNBFAR>
                        <SKUNCHE></SKUNCHE>
                        <SKUPBRUT></SKUPBRUT>
                        <SKUEANU></SKUEANU>
                        <SKUEANC></SKUEANC>
                   </access>
              </SKU_TMP>
         </Statement1>
    The problem is that I have tried everything, even logging the DB query (though unsuccessful) but am not able to insert data into this table. The user name and password is correct. Below is the latest error:
    "Delivering the message to the application using connection JDBC_http://sap.com/xi/XI/System failed, due to: com.sap.engine.interfaces.messaging.api.exception.MessagingException: Error processing request in sax parser: Error when executing statement for table/stored proc. 'SKU_TMP' (structure 'Statement1'): java.sql.SQLException: ORA-00913: too many values ."
    Earlier I have also received the following error (while using ):
    u201CJDBC Message processing failed, due to Error processing request in sax parser: Error when executing statement for table/stored proc. 'SKU_TMP' (structure 'Statement1'): java.sql.SQLException: ORA-01747: invalid user.table.column, table.column, or column specificationu201D
    Experts, please help me to resolve this predicament.
    Best regards,
    Varun

    Hello All,
    Thanks for your valuable suggestions.
    The problem was with the 'FormatNum' function.
    This mapping is being designed for an European client and they use "," (comma) for a decimal point. But in the database insert query, the comma was being taken as a separator between values and that is how I was getting "too many values" error. I am inserting the records with a decimal point now instead of a comma and the scenario is working fine.
    Thanks again,
    Best regards,
    Varun

  • Running cgi script placed on one machine by a web server installed on anoth

    I have weblogic installed on machine 1 and
    CGI Script placed on another machine 2.
    Is it possible for Weblogic to service/run CGI Script placed on machine 2. If so how can we do it.

    Mah
    I don't know about Weblogic, but here is some code that POSTs to a CGI script (XXX.pl) with a few parameters and retrieves part of the result (and HTML table) in a large string.
    Maybe you could use this kind of thing:
    protected String getTable(String hostID, Interval interval) throws IOException{
    StringBuffer query=new StringBuffer(100);
    Socket s = new Socket("some.host.com",80);
    BufferedReader in = new BufferedReader
    (new InputStreamReader(s.getInputStream()));
    PrintWriter out= new PrintWriter(s.getOutputStream());
    Calendar c=Calendar.getInstance();
    c.setTime(interval.getStart());
    query.append("s%5fm="+MonthConverter.int2mmm(c.get(Calendar.MONTH)));
    query.append("&s%5fd="+c.get(Calendar.DAY_OF_MONTH));
    query.append("&byear="+c.get(Calendar.YEAR));
    query.append("&Report=Submit");
    out.print("POST /cgi-bin/XXX.pl?site="+hostID+" HTTP/1.0\n");
    out.print("Accept: text/html\n");
    out.print("User-Agent: yourapplicationname\n");
    out.print("From: myemail@myhost\n");
    out.print("Content-type: application/x-www-form-urlencoded\n");
    out.print("Content-length: "+query.length()+"\n\n");
    out.print(query.toString());
    out.flush();
    String line;
    boolean finished=false;
    boolean started=false;
    StringBuffer resultBuffer=new StringBuffer(1000);
    while ((line = in.readLine()) !=null
    && !finished) {
    if (line.indexOf("Tmin,Tmax and Precipitation amount")>-1)
    started=true;
    if (started)
    resultBuffer.append(line);
    if (line.indexOf("</HTML>")>0)
    finished=true;
    out.close();
    in.close();
    return resultBuffer.toString();

  • How do I control data transfer rate from Java applications to CGI scripts?

    Hi. I've written a test cgi script which echoes any data it's sent back to the client, and I'm trying to write a java application that reads data from files on my hard drive and sends it to the cgi application.
    The method I've used is the same as the one described in the tutorial on this site, ie. create an URL object, open an URLConnection, get output stream from URLConnection, write data to output stream.
    The problem however is that the java application writes to the output stream at a much faster rate than my internet connection can handle, and so when I try to send more than a few kb the data doesn't seem to get sent at all. Is there some way I can control the rate at which data is sent, or is there a better way of sending data to a cgi application?
    I'd really appreciate any help, thanks!
    Ose.

    I've done some experimenting, and it seems that the problem is with my CGI application and not the Java application after all! (sigh) I wish I hadn't spent those duke dollars now. Oh well.

  • XI to post data via HTTPS

    Hi !
    There is a government web page with an HTML page that has a FORM tag, with this attributes (action data is not real)
    action ="https://www.website.com/forms.do"
    enctype="multipart/form-data"
    method="post"
    name="form"
    inside, it has some INPUT tags:
    <INPUT name="user"></INPUT>
    <INPUT name="password"></INPUT>
    <INPUT type="file" name="file"></INPUT>
    <INPUT name="submit" type="submit" value="Send"></INPUT>
    I need XI to post the input data that it receives via RFC.
    Should I use the HTTP Adapter? SOAP Adapter?
    How can I simulate the form submission via XI ?
    How do I do to send the file data? (it is received by XI from an RFC as a long text line)
    Thanks,
    Matias.

    Maybe you can with HTTP receiver adapter and some tricks...
    But you may also follow this way: an JAVA proxy that receive the message and make all the HTTP dialog:
    Explained here:
    /people/amol.joshi2/blog/2006/06/28/must-fire-a-http-get-from-xi---try-this
    Regards,
    Sandro

  • Access System Resources using Java Applet via Java Script

    Hello
    I can access my Applet public methods (and this methods access system resources) via Java Script if I do the following: System.setSecurityManager(null);However, I'm making this post because I don't like this solution.
    Supposedly, setting the SM to null is like making the Applet (which is signed and was accepted by the user via a prompt from the browser) behave like a normal Java program that has no restrictions. (http://java.sun.com/docs/books/tutorial/essential/environment/security.html, second paragraph)
    However, this feels like a workaround of something that is supposed to be there (the SM).
    Also, if I make the methods invocation from inside the applet (using swing buttons and textboxes for example) I can use the standard SM without no problems.
    From my readings, the problem regarding Java Script invocation, comes from the fact that the Java Script is not a secure (not signed) source (because you can invoke public methods the way you wish from it i guess) on the contrary to the applet methods invoked by the buttons.
    Possible solutions I found in the web range from using the public static Object doPrivileged(PrivilegedAction action) method or imaginative things like creating new threads on the public method that call the private methods that access the system resources (supposedly because the new thread runs under the safe environment of the applet)
    I almost got a glimpse of hope with this post http://forums.sun.com/thread.jspa?threadID=5325271&tstart=0
    However, none of these solutions worked, the only results were with the setResourceManager(null)So, any one can contribute with a solution for this? Should I keep trying to find a solution other then the one I already have?
    Regards
    Cad

    1. yes
    2. yes
    Note for 2. the converter will run the applet with SUN jre for sure if the user has IE.
    IE will use the ActiveX technology to run the applet (as with Macromedia Flash).
    For Netscape I am not sure, but I would think Netsape will use the plug in provided by
    SUN.
    Note for SUN jre 1.3. If this applet is to be used within a company that uses a proxy with
    ntlm authentication the 1.3 applet cannot connect (to the Internet) through this proxy since
    ntlm athentication is supported since j2re1.4.2_03. There is one version before that but
    that one will pop up a window asking for the user's domain account and password wich
    is both lame and crappy.
    As for the IE settings, IE has a default setting that askes users the "do you trust"
    queston for AciveX controls within the Internet securety zone (tools -> internet options
    -> security).
    Sincy anybody can make ActiveX controls (allso sign them) a user that has a problem
    to find the "no" button will sooner or later install a malicuous ActiveX control (spy ware
    or a virus).
    If this user's desktop is within your company's network it will cause serious harm.
    This is why most company's disable this by changing the default internet expolorer
    settings. Since I assume you are writhing this applet to be used by a company I allso
    assumed that company has someone to maintain the desktops. In that case I
    assume that person would want to control the security within the SUN jre instead of
    letting the user deside what to trust and what not.

  • Http post with cgi script

    Hello everyone,
    I currently have a pl/sql web form that executes a cgi script... Instead of that cgi containing any html and printing a page, I would like to just grab the output and print it as text, wrapping it in my pl/sql headers and footers and the like...
    I want to use util_http post to grab the cgi output, but am a little unsure how to do this - any tips??
    Many thanks

    See this link for help:
    http://download-west.oracle.com/docs/cd/A91202_01/901_doc/appdev.901/a89852/utl_htt4.htm#1003115

Maybe you are looking for