Java Program to run an https based url

This is the simple code to read through a java program from a simple http based procot URL
import java.net.*;
import java.io.*;
public class URLReader {
public static void main(String[] args) throws Exception {
     URL yahoo = new URL("http://mail.yahoo.com/");
     BufferedReader in = new BufferedReader(
                    new InputStreamReader(
                    yahoo.openStream()));
     String inputLine;
     while ((inputLine = in.readLine()) != null)
     System.out.println(inputLine);
     in.close();
But if i use the url https://mail.yahoo.com/ instead of http://mail.yahoo.com/ then i have an exception given below
Exception in thread "main" java.io.IOException: HTTPS hostname wrong: should be
<mail.yahoo.com>
at sun.net.www.protocol.https.HttpsClient.b(DashoA12275)
at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA12275)
at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
(DashoA12275)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
nection.java:626)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Dash
oA12275)
at java.net.URL.openStream(URL.java:913)
at URLReader.main(URLReader.java:7)
Now i want this program based on https to run. SO can anybody help me running the same program by using https? Or can anybody give me the code to run a url based on https protocol?

Same as http://forum.java.sun.com/thread.jspa?threadID=677398&tstart=0 . Check reply on the other post.

Similar Messages

  • Can a java program be run in the background?

    Hi all,
    Can a java program be run in the background without the user being aware of it? I need to make a program that continuosly monitors a pc at regular intervals and runs at all time. It should be hidden(shouldn't display on the screen while running) from the user, and also, can it be run as a system file so that even if a user checks he/she would think of it as a system file?

    I'm the administrator of all the computers. Then as I said there are commercial applications that do that.
    Presumably you expect a problem now. And implementing an acceptable solution is going to take you months. Because not only need to 'hide' the application, you also need to set up all the monitoring and logging capability. And the first will require quite a bit of JNI work along with testing (in particular as it could interfer with existing applications on the users computers.)
    I need to
    install the software in all the machines and i want
    that the users who use the machine should not be able
    to close the program through the task manager. If the users have admin rights then they can terminate a windows service.
    And if they don't have admin rights then you can simply turn off the ability to install anything.
    I want
    to know what the resources of the computers are and
    that if anyone has added a resource to it or
    not(attaching a flash usb thumbdrive etc). Lots of JNI.

  • Java program not running by the Ant

    i have a small java program.
    its a classpath problem.
    cant figure out where is the problem.
    i am running the code via Ant.
    build.xml
    <?xml version="1.0"?>
    <project name="myproject" basedir="." default="all">
        <property name="src.dir"     value="src"/>
         <property name="classes.dir" value="classes"/>
         <property name="lib.dir"     value="C:/tomcat/webapps/axis/WEB-INF/lib"/>
         <property name="runclass" value="TestClient"/>
         <target name="all" depends="clean,compile"/>
         <target name="clean">
            <delete dir="${classes.dir}"/>
        </target>
        <path id="classpath">
            <fileset dir="${lib.dir}" includes="**/*.jar"/>
        </path>
        <target name="compile">
            <mkdir dir="${classes.dir}"/>
         <javac srcdir="${src.dir}"
          destdir="${classes.dir}"
          deprecation="on"
          debug="on">
       <classpath><path refid="classpath"/></classpath>
      </javac>
         </target>
         <target name="run" depends="compile">
       <!-- run the class -->
       <java classname="${runclass}">
            <classpath>
              <pathelement path="${classpath}"/>
              <fileset dir="${lib.dir}">
                <include name="**/*.jar"/>
            </fileset>
              </classpath>
           </java>
      </target>
         </project>i invoked
    ant runand got this
    Buildfile: build.xml
    compile:
    run:
         [java] Could not find TestClient. Make sure you have it in your classpath
         [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava
    .java:170)
         [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:710)
         [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
         [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
         [java]     at org.apache.tools.ant.UnknownElement.execute(UnknownElement.ja
    va:275)
         [java]     at org.apache.tools.ant.Task.perform(Task.java:364)
         [java]     at org.apache.tools.ant.Target.execute(Target.java:341)
         [java]     at org.apache.tools.ant.Target.performTasks(Target.java:369)
         [java]     at org.apache.tools.ant.Project.executeSortedTargets(Project.jav
    a:1216)
         [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1185)
         [java]     at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(De
    faultExecutor.java:40)
         [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1068
         [java]     at org.apache.tools.ant.Main.runBuild(Main.java:668)
         [java]     at org.apache.tools.ant.Main.startAnt(Main.java:187)
         [java]     at org.apache.tools.ant.launch.Launcher.run(Launcher.java:246)
         [java]     at org.apache.tools.ant.launch.Launcher.main(Launcher.java:67)
    BUILD SUCCESSFUL
    Total time: 2 secondsso, code is not running......its dfinitely a classpath problem , because error message says "Could not find TestClient. Make sure you have it in your classpat".
    TestClient is the name of main class file.
    not sure whats wrong with this build.xml ? whats wrong in it ?
    one thing , i guess, i did not mention "." , current directory in the build.xml ......is it because of that ?
    i browsed apache manual......To Run a Java program.....first, they are making a JAR file ...and then they are executing the JAR.
    i really, dont need the JAR file......i just want to run it.....thats enough.
    somewhere, i have to do some modification in this buld.xml.......do you have any idea ?
    thank you

    TestClient folder has
    1)src
    2)classes
    3)build.xml
    i have posted the build.xml already.
    now, src folder has TestClient.java
    TestClient.java
    ==================
    import org.apache.axis.client.Call;
    import org.apache.axis.client.Service;
    import javax.xml.namespace.QName;
    public class TestClient {
       public static void main(String [] args) {
         try {
           String endpoint =
               "http://ws.apache.org:5049/axis/services/echo";
           Service  service = new Service();
           Call     call    = (Call) service.createCall();
           call.setTargetEndpointAddress( new java.net.URL(endpoint) );
           call.setOperationName(new QName("http://soapinterop.org/","echoString"));
           String ret = (String) call.invoke( new Object[] { "Hello!" } );
           System.out.println("Sent 'Hello!', got '" + ret + "'");
         } catch (Exception e) {
           System.err.println(e.toString());
    }and i did
    ant runand i got those errors.
    clearly, its not able to run it.
    looked the manual....did not find anything special about java task....still not working.

  • Getting java program to run (really basic)

    Hi,
    I'm used to running java programs through the programs I write with, like Eclipse, but now I'm trying to run a program on a compuyer without those things and I'm stuck.
    I'm running Windows XP and have downloaded the SDK Version 1.4.2, The java.com website says I have the latest software, everything is up to date.
    All the sites I see say that the way to run a program is to use the 'javac' command from the command prompt. However, doing this (with or without a file name appended) gives me the error: 'javac is not recognized as an internal or external command, operatable program or batch file.'
    What do I need to do to run a simple java program from a bunch of .java files?
    Help much appreciated, thanks.

    All which instuructions?
    1. I've followed all the instructions at 'Installation Instructions', http://www.java.com/en/download/help/5000010300.xml. They have instructions to
    .A: Download and Install: All done.
    .B: Enable and Configure: They say it only relates to browsers and applets
    .C: Test installation: Test comes out positive.
    2. The files that were downloaded: Contain no instructions
    3. All the 'Enable' instructions found here: http://www.java.com/en/download/help/index_configuration.xml
    These relate to:
    .A:Switching between Microsoft VM and JRE
    .B:Enabling JRE for browsers and Applets
    .C: Clearing the cache
    .D: Viewing the console,
    etc etc. None of them seem to be about setting a path.
    Can you tell me which instructions you mean?
    Thanks

  • Java program to run a C compiled file in SHELL unix

    hi,
    i have two queries,
    1) i have a c program which i compile to get a new file,{a exe file i suppose}, i need to execute it for 2000 times. for that i need to write a java program which can run the file in SHELL unix.
    can you suggest me how to write,
    2) also my file name starts with 0001.mnp to 1989.mnp, how to get 0001 as a number and during increment it should generate as 0002 ..0038 and so on. till 1989.
    the above java program which am goin to write should just take file 0001.mnp and convert it into 0001.bns,
    and get incremented automatically till the file 1989.

    hi,
    i have two queries,
    1) i have a c program which i compile to get a new
    file,{a exe file i suppose}, i need to execute it for
    2000 times. for that i need to write a java program
    which can run the file in SHELL unix.
    can you suggest me how to write,Read this: http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    However, you could do this all in a shell script.
    >
    2) also my file name starts with 0001.mnp to
    1989.mnp, how to get 0001 as a number and during
    increment it should generate as 0002 ..0038 and so
    on. till 1989.
    the above java program which am goin to write should
    just take file 0001.mnp and convert it into
    0001.bns,
    and get incremented automatically till the file 1989.A loop? What are you having difficulty with?
    Again, this could all be done in a shell script.

  • A Java program that runs automatically at a given time of day

    Okay Iam at the ending stages of a Java Assignment that is a MySql database, Hibernate for Mapping with a Java Server Faces front-end. All I need to do now is send emails at set time every week. Normally I know what to search for but frankly Iam stumped. Iam really just looking for a starting point for something that can run a Java Program at a set time of the week. PS my OS is Ubuntu if that is relevant but I was hoping for something that isn't platform specific so that it is portable.
    Cheers in advance.

    You can use the possibilities of your operating system, in this case Ubuntu.
    Just drop a shell script that runs your java program in the /etc/cron.weekly directory.
    --janeiros                                                                                                                                                                                                                                                                                                                                                                   

  • How to find that a java program is running for the first time on daily basi

    it is like this
    1. i will ran a java program every day and i have to find that it is running for the first time(as i may stop that program and may run again the same day )
    Pls share ur ideas

    san.kumar wrote:
    it is like this
    1. i will ran a java program every day and i have to find that it is running for the first time(as i may stop that program and may run again the same day )
    Pls share ur ideasAs kajbj said - you need to store a token / file with a run date on the file system. Each time the application runs, have it compare with the date from this file with the current date. If different, it's the first run of the day. If not, it is not the first run of the day. Each time have it update the date on the file.

  • Java Program Not Running

    Hi,
    I have a small Java program that imports Oracle.sql.* and Oracle.jdbc.*.
    It establishes a default connection and converts a String[ ] to Oracle.sql.ARRAY type.
    As per Oracle documentation, I have added paths of required .zip files in CLASSPATH variable.
    Though I am able to compile the code, but when I try to run it thru java, it gives me error:
    Exception in Thread "main" java.lang.NoClassDefFoundError: TestInstallJDBC
    The .java and .class files are in current directory and I'm using
    java TestInstallJDBC.
    What can be the problem?
    Any help is appreciated.
    Thanks

    Ah, I re-read your first post - you said you added paths to the Classpath. So you need to add . to your Classpath as well. For Windows .;<existing_classpath> or for Unix .:<existing_classpath>

  • Java program stopped running when using JVMPI

    Hi!
    I'm writting a very simple profiler using JVMPI. I intended to pause/continue it by sending signal, like kill -SIGUSR2 PID, to it, but whenever I did this, the java program that ran with the profiler stopped running, however the profiler kept running properly.
    Here's the code of the simple profiler and the testing java program.
    //myprofiler.cc
    #include <jvmpi.h>
    #include <pthread.h>
    #include <stdio.h>
    #include <signal.h>
    void sig_handler_pause(int);
    static JVMPI_Interface *jvmpi_interface;
    void notifyEvent(JVMPI_Event *event) {
    switch(event->event_type) {
    case JVMPI_EVENT_CLASS_LOAD:
    fprintf(stderr, "myprofiler> Class Load : %s\n", event->u.class_load.class_name);
    break;
    case JVMPI_EVENT_OBJECT_ALLOC:
    fprintf(stderr, "myprofiler>object alloc \n");
    break;
    extern "C" {
    JNIEXPORT jint JNICALL JVM_OnLoad(JavaVM jvm, char options, void *reserved) {
    fprintf(stderr, "myprofiler> initializing ..... \n");
    // get jvmpi interface pointer
    if ((jvm->GetEnv((void **)&jvmpi_interface, JVMPI_VERSION_1)) < 0) {
    fprintf(stderr, "myprofiler> error in obtaining jvmpi interface pointer\n");
    return JNI_ERR;
    // initialize jvmpi interface
    jvmpi_interface->NotifyEvent = notifyEvent;
    // enabling class load event notification
    jvmpi_interface->EnableEvent(JVMPI_EVENT_CLASS_LOAD, NULL);
    fprintf(stderr, "myprofiler> .... ok \n\n");
    signal(SIGUSR2,sig_handler_pause);
    return JNI_OK;
    void start(){
              fprintf(stderr,"start...\n");
         jvmpi_interface->EnableEvent(JVMPI_EVENT_OBJECT_ALLOC, NULL);
    jvmpi_interface->EnableEvent(JVMPI_EVENT_CLASS_LOAD,NULL);
    void pause(){
              fprintf(stderr,"pause...\n");
              jvmpi_interface->DisableEvent(JVMPI_EVENT_OBJECT_ALLOC, NULL);
    jvmpi_interface->DisableEvent(JVMPI_EVENT_CLASS_LOAD,NULL);
    int status=0;
    void sig_handler_pause(int sig){
         if(status == 0){
              start();
              status = 1;
         else if(status == 1){
              pause();
              status = 0;
    //Test.java
    public class Test {
    public static void main(String[] args) {
         try {
                        int i = 0;
    while(true)
                             Thread.sleep(1000);
                        System.out.println(i++);
              catch (Exception e) {
                        e.printStackTrace();
    Here're some notes:
    1)If I didn't call
    jvmpi_interface->EnableEvent(JVMPI_EVENT_OBJECT_ALLOC, NULL);
    in "start()" function, the java program Test ran properly after I sent signal to the process by using kill command in an command line;
    or
    2) If I delete "Thread.sleep(1000)" in Test.java, then whether I call
    jvmpi_interface->EnableEvent(JVMPI_EVENT_OBJECT_ALLOC, NULL);
    in "start()" or not, the Test program ran properly after I sent signal to the process.
    It seems to be a thread dead lock, but I'm not sure. Can any body help?Thanks very much.

    I should strongly recommend moving from JVMPI to JVM TI if you can. The reason is that JVMPI has been deprecated since 5.0 and can not be used with Java SE 6 and newer.
    Anyway, the issue you have may be due to the signal you are using. I'm not sure which operating system this is but on Linux the USR2 signal is used for the suspend/resume implementation. Have you looked at the Troubleshooting Guide or the Signal Chaining page for details on how signals are used and how to chain handlers? Another idea is to remove the signal handling code implementation and to use the data dump event. This is supported by both JVMPI and JVM TI so that you get an event (via the QUIT signal).

  • Calling an unix command from a java program which runs on windows

    Hello All
    I have an Java Application which is run on windows server (I)
    I have another Sun Server (II)
    I want to call an unix command on server(II) from java application which is on server(I)
    I am using Samba Server in order to share files between Windows Server and Unix Server
    Can I use samba in order to call command
    or is there any way to open an telnet session within java application
    I will be grateful if you give me some suggestion on this issue
    Regards
    BEKIR BALCIK
    J2EE Application Developer
    Argela Technologies ...

    cross post
    http://forum.java.sun.com/thread.jspa?threadID=624601&messageID=3553626#3553626

  • Https protocol based URL reading Program

    This is the simple code to read through a java program from a simple http based procot URL
    import java.net.*;
    import java.io.*;
    public class URLReader {
    public static void main(String[] args) throws Exception {
         URL yahoo = new URL("http://mail.yahoo.com/");
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        yahoo.openStream()));
         String inputLine;
         while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         in.close();
    But if i use the url https://mail.yahoo.com/ instead of http://mail.yahoo.com/ then i have an exception given below
    Exception in thread "main" java.io.IOException: HTTPS hostname wrong: should be
    <mail.yahoo.com>
    at sun.net.www.protocol.https.HttpsClient.b(DashoA12275)
    at sun.net.www.protocol.https.HttpsClient.afterConnect(DashoA12275)
    at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect
    (DashoA12275)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLCon
    nection.java:626)
    at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Dash
    oA12275)
    at java.net.URL.openStream(URL.java:913)
    at URLReader.main(URLReader.java:7)
    Now i want this program based on https to run. SO can anybody help me running the same program by using https? Or can anybody give me the code to run a url based on https protocol?

    Here is a code which works for me.
    import java.net.*;
    import java.io.*;
    public class URLConnectionReader {
        public static void main(String[] args) throws Exception {
            URL myurl = new URL("https://my.app.com/");
            URLConnection yc = myurl.openConnection();
            BufferedReader in = new BufferedReader(
                                    new InputStreamReader(
                                    yc.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null)
                System.out.println(inputLine);
            in.close();
    }Output:
    <html><head>
    <script>location.replace("/my/app?action=homeActionId");</script>
    </head></html>

  • Java Programming Contest

    Theres a world java programming contest running on http://www.logical-magic.com . This is of special relevance to those specialising in Java network programming. The first prize is a Ferrari sports car.
    Those who are interested can check it out.

    Getting that Ferrari to India will be a pain.
    Unless u know to do something like Sachin.
    Thanks for the tip anyway.
    Rgds,
    Seetesh

  • Machine environment for running a java program

    Hi,
    I am thinking about writing a client-server application. The communication between the server and the client and vice versa will be in RMI. My question is regarding the client machine environment - do I need to install JDK on the client machine in order to run the client? Can the client run on any environment?
    Thanks

    Hi,
    I am thinking about writing a client-server
    application. The communication between the server and
    the client and vice versa will be in RMI. My question
    is regarding the client machine environment - do I
    need to install JDK on the client machine in order to
    run the client? Can the client run on any environment?
    ThanksHow do java programs run?
    Compiled Java programs are stored in files as bytecode. As a Java program is running, the Java Virtual Machine (JVM), which is a piece of software, converts the bytecode into machine executable code for the particular platform on which the program is running. This code is what is executed by the processor. Bytecode is not specific to a particular platform, but the machine code generated by the JVM is.
    [url http://www.webopedia.com/TERM/J/JVM.html] definition of JVM as per webopedia[ [/url]
    Hopefully now you have an answer to your question.

  • JSP codes for running a JAVA program

    hello...
    does anyone know the JSP codes for running a Java program from my web page?? i mean i already have my java program compiled... and i just want this java program to run in the background when I click on a button or a link...
    Any idea about this?
    plz advice..
    avi

    yes... u r somewhat right... but this runs on Jakarta Tomcat...
    i'm using the Apache Http Server together with the ServletExec AS which enable the Apache server to run JSP..
    I've created a package where i've put my classes...
    WEB-INF/classes/tbd(package name)/my classes
    and i've added.. package name.. in my java program..
    and then in jsp... i've written..
    <%@ page import="tdb.*"%>
    <jsp:useBean id="exec" class="tdb.textdb" />
    <%exec.convert_data();%>
    but when i run the page it says the package does not exist...
    can anyone tell where to place the folder WEB-INF so that it can run fine?
    thx
    avi

  • Is there any way to check another Java program running status?

    HI. I want to write a Java program on hand-set but my program seems needs lots of resources and if there is another Java program running on the same hand-set simultaneously, my program will slow down. So, I want to check if there is another Java program is running on the hand-set, my program will show a message to user reminding user to close another program first.
    Is there any way to do so?

    On most recent devices, the application is not terminated but paused by using phone functions, and can be reactivated from the aplication management software. The javax.microedition.midlet package documentation is quite specific, if a tad obscure, about the MIDlet lifecycle and the role of the MIDelt methods vis-a-vis the AMS.
    {color:#0000ff}http://java.sun.com/javame/reference/apis/jsr037/javax/microedition/midlet/package-summary.html{color}
    Parenthetically, I've never been able to figure out how resumeApp should be used, nor have I seen this method invoked in any of the samples that come with the WTK, but I haven't gone through all of them.
    I believe the still-in-progress MIDP3 will make it possible to have MIDlets that share the screen with native apps and which can be minimized and restored.
    db

Maybe you are looking for