Set timeout for URL connection in java1.4

hi
I want to set timeout for URL connection in java 1.4..
java 5.0 provides with a setTimeout(int ) method but how should it be done in 1.4 environment
Thanks in advance
sneha

sun.net.client.defaultConnectTimeout (default: -1)
sun.net.client.defaultReadTimeout (default: -1)
See the [Networking Properties|http://java.sun.com/j2se/1.4.2/docs/guide/net/properties.html].

Similar Messages

  • Set TimeOut for SwingWorker

    nice day,
    1/ how can I get real Html size in kB with intention to set as maxValue to ProgressMonitor
    2/ how can I set/synchronize current valueOfDownLoadedHtml in kB to ProgressMonitor throught downloading Html content
    3/ how can I set TimeOut for this Tast, (maybe ... could I use Timer)
    import java.awt.BorderLayout;
    import java.awt.Insets;
    import java.awt.Toolkit;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.InputStream;
    import java.net.URL;
    import java.net.URLConnection;
    import java.nio.charset.Charset;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.ProgressMonitor;
    import javax.swing.SwingWorker;
    public class ProgressMonitorDemo extends JPanel implements ActionListener, PropertyChangeListener {
        private static final long serialVersionUID = 1L;
        private ProgressMonitor progressMonitor;
        private JButton startButton;
        private JTextArea taskOutput;
        private Task task;
        private int sizeIn_kB = 0;
        class Task extends SwingWorker<Void, Void> {
            private String str;
            int progress = 0;
            public Task(String str) {
                this.str = str;
            @Override
            public Void doInBackground() {
                if (str.equals("Loads")) {
                    addBackgroundLoadsData();
                    setProgress(0);
                    while (progress < sizeIn_kB && !isCancelled()) {
                        progress += sizeIn_kB;
                        setProgress(Math.min(progress, sizeIn_kB));
                return null;
            @Override
            public void done() {
                if (str.equals("Loads")) {
                    Toolkit.getDefaultToolkit().beep();
                    startButton.setEnabled(true);
                    progressMonitor.setProgress(0);
        public void addBackgroundLoadsData() {
            InputStream in = null;
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            String charset ="";
            try {
                String UrlString = "http://java.sun.com/";
                URL url = new URL(UrlString);
                URLConnection conn = url.openConnection();
                sizeIn_kB = conn.getContentLength();
                charset = conn.getContentEncoding();
                conn.setRequestProperty("Accept-Charset", charset);
                in = conn.getInputStream();
                int len;
                byte[] buf = new byte[1024];
                while ((len = in.read(buf)) > 0) {
                    bos.write(buf, 0, len);
                in.close();
                String charEncoding = Charset.defaultCharset().name();
                //String fileEncoding = System.getProperty("file.encoding");
                //System.out.println("File Encoding: " + fileEncoding);
                //System.out.println("Char Encoding: " + charEncoding);
                //System.out.println("Char Encoding: " + Charset.availableCharsets());
                charEncoding = "cp1250";
                String groupImport = new String(bos.toByteArray(), charEncoding);
                conn = null;
            } catch (IOException ioException) {
                ioException.printStackTrace();
                JOptionPane.showMessageDialog(null, ioException.getMessage(), "Htlm error", JOptionPane.ERROR_MESSAGE);
            } catch (StringIndexOutOfBoundsException ioException) {
                ioException.printStackTrace();
                JOptionPane.showMessageDialog(null, ioException.getMessage(), "InputStream error", JOptionPane.ERROR_MESSAGE);
        public ProgressMonitorDemo() {
            super(new BorderLayout());
            startButton = new JButton("Start");
            startButton.setActionCommand("start");
            startButton.addActionListener(this);
            taskOutput = new JTextArea(5, 20);
            taskOutput.setMargin(new Insets(5, 5, 5, 5));
            taskOutput.setEditable(false);
            add(startButton, BorderLayout.PAGE_START);
            add(new JScrollPane(taskOutput), BorderLayout.CENTER);
            setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
        @Override
        public void actionPerformed(ActionEvent evt) {
            progressMonitor = new ProgressMonitor(ProgressMonitorDemo.this, "Running a Long Task", "", 0, 100);
            progressMonitor.setProgress(0);
            task = new Task("Loads");
            task.addPropertyChangeListener(this);
            task.execute();
            startButton.setEnabled(false);
        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ("progress" == null ? evt.getPropertyName() == null : "progress".equals(evt.getPropertyName())) {
                int progress = (Integer) evt.getNewValue();
                progressMonitor.setProgress(progress);
                String message = String.format("Completed %d%%.\n", progress);
                progressMonitor.setNote(message);
                taskOutput.append(message);
                if (progressMonitor.isCanceled() || task.isDone()) {
                    Toolkit.getDefaultToolkit().beep();
                    if (progressMonitor.isCanceled()) {
                        task.cancel(true);
                        taskOutput.append("Task canceled.\n");
                    } else {
                        taskOutput.append("Task completed.\n");
                    startButton.setEnabled(true);
        private static void createAndShowGUI() {
            JFrame frame = new JFrame("ProgressMonitorDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JComponent newContentPane = new ProgressMonitorDemo();
            newContentPane.setOpaque(true);
            frame.setContentPane(newContentPane);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    See the session-descriptor element of weblogic.xml deployment descriptor:
    http://download.oracle.com/docs/cd/E21764_01/web.1111/e13712/weblogic_xml.htm#i1071981

  • Setting timeout for all the web test scripts in the solution

    Hello,
    I have around 16 web test scripts (using VSTS 2010 ultimate version) in my project (in a solution). By default the timeout set for each request is 60 sec. I need to increase the timeout to 180 sec. Currently, I am clicking on each request and modifying
    the timeout parameter from the Properties window.
    Is there any common setting for timeout available which would be acting across all the scripts?
    Thanks.

    Hello,
    We only can set Timeouts for a separate request in Visual Studio Web Test. There is no way to set Timeout for all requests in VS IDE. But you can write you own logic code using
    Timeout Property in a web test plugin to set Timeout for all requests in a web test.
    About how to write a web test plugin, please see:
    How to: Create a Web Performance Test Plug-In
    Best regards,
    Amanda Zhu <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support
    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

  • Set timeout for completion of each thread

    i have a requirement where i need to start n threads and set timeout for completion of each thread.
    if the thread is not executed successfully(because of timeout ) i have to enter in audit table that it failed because of timeout
    if executed successfully update audit table with success.
    can some one give me solution for this using ThreadPoolExecutor available jdk1.5

    Add a scheduled task to time out the task (when it would time out). Keep the Future and cancel it if the task completes successfully.
    final Future future = executor.schedule(new TimeoutTask(), timeoutMS, TimeUnit.MILLI_SECONDS);
    executor.execute(new Runnable() {
      public void run() {
          try {
             task.run();
          } finally {
             future.cancel(true);
    });

  • How to set proxy for 3G connection?

    Can anyone tell me where to set proxy for 3G connection?
    I think I've checked every section in Settings but failed to find anything.
    Thanks for your info.

    It's part of the cellular settings, and is usually set up by your 3G provider. You can't choose your own proxy server

  • Setting timeout for webservice

    hello all,
    I have made client program to connect to a webservice using dynamic url, my problem is i am unable to set the timeout of the webservice if anybody knows please let me know. my code is as follows.
    WebServiceClient ann = testpackage.TestClassService.class.getAnnotation(WebServiceClient.class);
    try {
    testpackage.TestClassService service = new testpackage.TestClassService(new URL("MY URL"), new QName(ann.targetNamespace(), ann.name()));
    testpackage.TestClass port = service.getTestClassPort();
    String result = port.getUserTask("HELLO");
    System.out.println(result);
    } catch (MalformedURLException ex) {
    using this code how can i set timeout at client side
    thanks in advance

    hi there thanks for your reply but your solution didn't worked for me. may be because of mistake in my question explanation i will explain it again
    WebServiceClient ann = testpackage.TestClassService.class.getAnnotation(WebServiceClient.class);
    try {
    testpackage.TestClassService service = new testpackage.TestClassService(new URL("MY URL"), new QName(ann.targetNamespace(), ann.name()));
    testpackage.TestClass port = service.getTestClassPort();
    String result = port.getUserTask("HELLO");
    System.out.println(result);
    } catch (MalformedURLException ex) {
    using this code i am calling my webservice and the function "getUserTask" which give me some output in return.
    now, what situation i am facing is whenever i make a call to the above function and if RTO occurs after the call of the function then my application comes in to a hang mode situation. and i am unable to do anything untill the reconnection of the network occurs.Either i have to wait for the reconnection or i have to terminate my applicartion.
    My desire is, i should be able to set my timeout period of a web service request. if no reply comes in the given time period then i should be able to raise any message to the user.
    I think ihave made myself a bit more clear.
    thanks for your reply once again.

  • Setting timeout for SOAP requests in a webservice client

    I am trying to set the timeout for a synchronous SOAP request sent to a Web Service deployed on weblogic 8.1 SP2. I tried setting timeout thru bindinginfo setTimeout() and also javax.xml.rpc.Stub _setProperty(). Both of them seem to be not working. I set the value to as low as 1 sec but i still donot get a timeout. Other properties/method from these two classes work fine though (like endpointaddress property in javax.xml.rpc.Stub and setVerbose flag to true in BindingInfo).
    Can someone please help.
    Thanks in Advance
    srini

    Our application calls the webservice provided by another company over the internet using the ssl. We use the wsdl url of the webservice on the destination while creating the port. If the destination is not available statement which creates the port blocks for around 4 minutes.
    I think the first network call gets the wsdl from the remote server. Thus we encounter delays before getting the stub created. How can I timeout such a calls.
    try {
    port = (new ServiceName_Impl(remoteWsdlURL)).getServiceNameSoap();
    } catch (IOException e) {                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Set timeout for dynamic web service call in wls

    Hi,
    I have a dynamic client using Call interface to invoke 3rd party web service. How can I set the timeout for the call? I know there is a property to set for static client.
    Thanks

    Have you checked out the stub properties:
    weblogic.wsee.transport.connection.timeout
    weblogic.wsee.transport.read.timeout
    http://edocs.beasys.com/wls/docs92/webserv/client.html#wp228628

  • Shorting the timeout for socket connection

    Hi everyone, i've got a client who owns a handle to a remote object. When the remote object quits, accesing it through a method invocation throws a java.net.SocketTimeoutException: Read timed out. That's fair, what's up is that it lasts about six seconds in sending it, and i would like to shorten the time it waits until it realises it can't connect. I've tried with sun.rmi.transport.connectionTimeout and sun.rmi.transport.tcp.readTimeout, and no success. Any idea?
    Thanks in advance.

    The "sun.rmi.transport.proxy.connectTimeout" parameter works only when HTTP is used.
    We do it manually by utilizing RMI client and server socket factories and setting socket options as appropriate. For the connect timeout, there is connect(SocketAddress endpoint, int timeout) method of the Socket class. With this approach, the application has a full control over sockets used by the RMI engine.

  • Set password for database connection at runtime

    Hi there,
    is it possible to set the password and/or the user for the database connection at runtime.
    The use case is to read the values from a file and decrypt them, and the to establish the conenction. So that i don't habe to redeploy everything if there is a change.
    Thanks in advance.

    How exactly do i set these values for the datasource?
    Edited by: Alex on 15.02.2012 09:50
    €: JDeveloper 11.1.1.5.0
    The use case is, that there is a file with an encrypted password. This should be decrypted and then be used for the connection. So when this encrypted passowrd changes, i don't want to edit and deploay the app once again. Instead the new encrypted password should be decrypted via code an then be used.
    Edited by: Alex on 15.02.2012 10:00

  • OSB: Business Service Timeout for JCA Connection

    Hi,
    I am wondering if there's any way to configure timeout for a JCA connection in OSB? It's not configurable in Business Service.
    Thanks.

    Hi Anuj,
    I am using DbAdapter. As for operation, which operation are you referring to? Where do I check to verify this?
    Thanks.
    Edited by: user13298498 on May 21, 2012 11:01 PM

  • Question on setting timeouts for leave approval

    Let us say there are three employees A is reporting to B, who inturn reports to C.
    If A applies for leave,then the notification goes to B.
    If B's position is vacant(undergoing recruitment) then the leave requests are lying under B's queue.
    Can they be forwarded to the next level (by setting timeouts).
    If yes, can please guide me with the navigation.

    hi,
    do you mean JTable or JTree. In any case, this might help:
    http://www2.gol.com/users/tame/swing/examples/SwingExamples.html
    greetz,
    stijn

  • How to set TimeOut in URL

    Hi everyone,
    " URL u = new URL(url);
    InputStream is = u.openStream();
    BufferedReader dis = new BufferedReader(new InputStreamReader(is)); "
    My problem is,
    1. if host is down,my program waits for dafult time to connect
    2. After connecting to server, there 's some problem to get response from Host.
    my program wait for response long time.
    I want to change these two timeout. Also, i 'm using jdk1.3.if it's 1.5 i can use setConnectTimeout method .
    If u have solution, please revert to me.
    Thanks
    JaiGanesh.R

    http://coding.derkeiler.com/Archive/Java/comp.lang.java.programmer/2004-01/3271.html

  • Urgent:Need to add Timeout for getting connection

    All,
    While using DriverManager.getConnection to get the connection,I need to add Timeout in my code so if I don't get a connection with in 30 seconds,I need to say'Operation Timed out.
    I was using DriverManager Api's setLoginTimeout method to set the desired time but it doesn't work.Can somebody tell me some other way to do it.

    If I use this method then if second thread reports
    Timed out after 30 seconds and then origional thread
    gets connection after 30 seconds then it'll also
    report.I dont want a connection if 30 second time
    passes.I think if second thread reports 'timed out'
    then I won't be able to explicitly kill the origional
    thread as stop method is deprecated in Thread
    class.Can you make it clear please?You can't stop the actual thread attempting the connection.
    It will require some thought on your part to correctly wrap it.
    It might not work at all because the getConnection() method, or something in it, might be synchronized.

  • Can't do the set up for tv connection

    Trying to connect ipad2 to tv but there's no tv options in video setup in settings. The only thing I've got there is captioning and start playing. Please help!!

    1. Make sure you get the right video adapter for your TV e.g. VGA or HDMI Adapter
    2. Make sure you set the correct input on your TV.

Maybe you are looking for

  • JCo Client Programming and Error Handling

    Hi all, I was wondering if anybody could help me out with some advice on error handling when writing code to send messages to SAP via a JCo Client, particularly IDocs. I understand from my reading that IDocs are always sent asyncronously to the SAP s

  • Read the c2 log file of the sql server using java

    Hi All, i want to read the c2 log file using the core java. how is it possible ? if anybody knows about this please give me the sample code to help me. i am also searching on net but i am not getting any result about this? so please help me to doing

  • Where are the authentication passwords stored in Firefox?

    I created a web site which was set up with a password and I have forgotten it. When using the URL it requires authentication the field has dots so password must be stored somewhere in Firefox but where? Peter

  • Not enough memory when converting???

    I've imported a 21 minute 720p video in to iTunes for Windows. It plays fine in iTunes. Then I try to convert it to iPad format. About 1/2 way thru the conversion, I get a message "Error occurred while converting the file XXXX. There is not enough me

  • Installing Photoshop CS with a upgrade disk

    I would like to install an upgrade version of Photoshop CS(3,4,5, etc) on a Mac Pro. I have an older version of Photoshop on a Power PC type Mac. Can I install the newer version of Photoshop CS if I have the old install disk? Or will only a full inst