URLConnection problem

Hi all,
I make a mini web browser jar. When i use it in standalone, it is no problem( I can go to acces http://java.sun.com), However, I place jar into web server (JNLP), i cannot access http://java.sun.com(No exception error)

My program is only access internet (e.g. http://java.sun.com). it has not a open file function. Moreover, my JNLP have already set a 'all permission'

Similar Messages

  • URLConnection problems(Sending parameters with URL)

    Guys i have some problems with sending parameters through URL using URLConnection class.
    That's my code:
    URL url = new URL("http://kiosk.homebank.kz:9090/default.asp?action=SaveContact&src=C_HOMEBANK&ClientId="+request.getParameter("ClientId")+
                        "&IdService="+request.getParameter("IdService")+
                        "&Contact="+URLEncoder.encode(request.getParameter("Contact"),"utf-8")+
                        "&Number="+URLEncoder.encode(request.getParameter("Number"),"utf-8")+
                        "&Work="+URLEncoder.encode(request.getParameter("Work"),"utf-8")+
                        "&Mobile="+URLEncoder.encode(request.getParameter("Mobile"),"utf-8"));
            URLConnection connection = url.openConnection();
            connection.setDoInput(true);
            connection.setDoOutput(true);I want just send these parameters without going to this link. How can i do it using URLConnection class? Help please!

    Try using this set method in the URL class (query is the parameters):
    protected void set(String protocol,
    String host,
    int port,
    String authority,
    String userInfo,
    String path,
    String query,
    String ref)

  • URLConnection problem further investigated

    Hi!
    I have a problem (of course). I can create an URL connection, write data to it and receive the result (see "Check result" comment) using JRE 1.4.1 without any problems. But with JRE 1.3.1 I get a FileNotFound Exception when I do "InputStream is = urlConn.getInputStream();".
    Am I doing something wrong?
    Thanks in advance for any hints.
    Magnus
    // Create CGI URL.
    String strFile = m_strDataURL + objectID;
    URL urlCodeBase = applet.getCodeBase();
    URL urlWriteCgi = new URL( urlCodeBase.getProtocol(),
    urlCodeBase.getHost(), strFile);
    // Setup URL connection.
    URLConnection urlConn = urlWriteCgi.openConnection();
    urlConn.setDoOutput(true);
    OutputStream os = urlConn.getOutputStream();
    BufferedOutputStream bos = new BufferedOutputStream(os);
    DataOutputStream dos = new DataOutputStream(bos);
    // Post data.
    cat.debug( "Writing object properties for " + objectID + "..." );
    int iNofProperties = properties.size();
    cat.debug( "Number of properties: " + iNofProperties );
    String totalBytes = null;
    for(int index=0; index < iNofProperties; index++){
    cat.debug( properties.get(index).toString() + "=" + values.get(index).toString() );
    dos.writeBytes(properties.get(index).toString());
    dos.writeBytes("=");
    dos.writeBytes(values.get(index).toString());
    if(index+1 < iNofProperties){
    dos.write('&');
    dos.flush();
    dos.close();
    // Check result.
    InputStream is = urlConn.getInputStream();
    BufferedReader in = new BufferedReader( new InputStreamReader(is) );
    String t = in.readLine();
    while( t != null) {
    t = in.readLine();
    in.close();

    In 1.3.1 and previous releases the HTTP protocol handler through a FNF exception for HTTP errors that it didn't handle. 1.4 has lots of fixes and improvements and also handles more HTTP errors automatically. If you really need to find out what 1.3.1 is doing then get a network trace and post the HTTP response from the server here.

  • URLConnection Problems

    I've read many postings trying to solve the problem of unblocking a URLConnection that is blocked.
    I tried getting the socket and port from the connection and reading the socket directly,
    that's fine when there is a problem, the inputStream is read but the socket gets blocked
    on the read.
    However, when the connection is successful and data should be streaming back, the
    read again times out.
    When I switch back to a URLConnection the opposite happens, it reads data fine when all
    is well, but when it gets stalled, I see no way to interrupt it. Any ideas?
    public String SendData() throws Exception
    if (debug)
    System.out.println("\n\n************ Sending Data ************\n");
    try
    timedout = false;
    URL url = new URL(thePath);
    //these 2 socket statements replace the 4 url ones below it
    Socket sock = new Socket(InetAddress.getByName(url.getHost()), url.getPort()==-1?80:url.getPort());
    sock.setSoTimeout(timeout);
    //this is the url way
    /* ucon = (HttpURLConnection)url.openConnection();
    ucon.setDoInput(true);
    ucon.setUseCaches(false);
    ucon.setAllowUserInteraction(false);
    //url getstream
    in = new BufferedReader(new InputStreamReader(ucon.getInputStream()));
    //socket getstream
    in = new BufferedReader(new InputStreamReader(sock.getInputStream()));
    while((s=in.readLine()) !=null)
    // This will be replace with loading into a buffer
    // inside the token class and returning.
    System.out.println(s);
    in.close();
    catch(Exception e)
    if (debug)
    System.out.println("URL timed out");
    timedout = true;

    Tried it, doesn't seem to work for 1.3.1. No my post is stupid, I forgot that I need to
    connect with the initial http protocol headers and the get commands when using
    sockets, doh! It works now.
    However, can someone please explain to me why anyone would ever use the URLConnection
    instead of sockets since there is no way I can find to force a timeout. If there were a way
    to overwrite the http timeout from Java, or a way to interrupt the blocked stream then it would
    be useful. But I've read countless solutions and none works except for manually using a
    socket and setting the socket timeout.

  • URL, URLConnection problem!

    just dont understand how can i work with with URL if i cannot set anything!!
    All methods are getters, but what if i want to keep using the same StreamHandler, the same ProtocolHandler and i just want to change the path of an already created URL object?? do i have to create an URL object each time i want to acces another resource?
    for example i make an URL that connects to "www.java.sun.com" and i download the root html page from that url, then i want to connect to http://java.sun.com/forums , and i cant just say setPath().
    Its to expensive to be creating URL objects which creates like 10 more objects internaly to just change the path!! i cannot even inerith from it cause it is final, how can i interactivly use URL as a non untouchable class?

    >
    well that was helpfull, even if it is not that
    expensive is retarded! just to change a path or
    something else does not justify creating a completly
    new web of object since the modifications of
    urls(keeping the host,protocol untouched) can happens
    a lot.It may not be as retarded as it seems. There may be some reasonable design decsions behind making a URL immutable. I haven't looked at it or thought about it, but I think it's a fairly common pattern. You have an object that depends on other objects, and those objects' state is affected by the state of the original object. Changing the state of the original has complex ripple effects, so it's easier just to fix everything when the containing object is constructed. It might be sort of a facade or mediator pattern.
    And i know how a VM works, =P !If you want to know more, here is where I got it from. That link might be the 2nd or 3rd article in the series. I'm not sure which one explains why object creation (and GC, for that matter) isn't necessarily the huge performance hit some people assume it is The whole series (3 articles, I think) is worth reading.
    &para;

  • Problem reading input stream of urlconnection within portal

    Hi,
    This may be a generic server issue rather than portal but since it's my portal app that's displaying the problem I'll post it here.
    Part of my Portal attempts to POST to a remote server to retrieve some search results.
    In environments A & B (both standalone instances) this works fine.
    In environment C this works on the managed instances in the cluster but not the admin instance.
    In environment D (again standalone) it fails, but if I add a managed instance it works from the managed instance.
    The problem I'm seeing is that I get a stuck thread and the thread dump shows it is blocked attempting to read the resulting input from a urlconnection. (Using a buffered input stream).
    I've copied the code to a standalone class that runs fine from the same server(s). I've pasted this code below, the contents of the test() method were copied directly from my webapp (urls changed here for clarity).
    Does anyone know of any securitymanager issues that may cause this?
    Or anything else for that matter?
    Code sample:
    package src.samples;
    import java.io.BufferedReader;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.net.MalformedURLException;
    import java.net.URL;
    import java.net.URLConnection;
    public class POSTTest {
         public static boolean test()
         URL url = null;
         try {
         url = new URL
    ("http://hostx:80/myapp/search.html");
         catch (MalformedURLException e)
         e.printStackTrace();
         return false;
         URLConnection urlConn;
         DataOutputStream printout;
         BufferedReader input;
         urlConn = null;
         try {
         urlConn = url.openConnection();
         catch (IOException e)
         e.printStackTrace();
         return false;
         // Let the run-time system (RTS) know that we want input.
         urlConn.setDoInput (true);
         // Let the RTS know that we want to do output.
         urlConn.setDoOutput (true);
         // No caching, we want the real thing.
         urlConn.setUseCaches (false);
         // Specify the content type.
         urlConn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
         // Send POST output (this is a POST because we write then read as per the JDK Javadoc)
         printout = null;
         String body = "";
         try {
         System.out.println("url=" + url.toString());
         printout = new DataOutputStream (urlConn.getOutputStream ());
         String content = "param1=A&param2=B&param3=C&param4=D&param5=E";
         System.out.println("urlParams= " + content);
         printout.writeBytes (content);
         System.out.println("written parameters");
         printout.flush ();
         System.out.println("flushed parameters");
         printout.close ();
         System.out.println("closed parameter stream");
         // <b>Get response data - this is where it blocks indefinitely</b>
         input = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
         System.out.println("got input");
         String str;
         while (null != ((str = input.readLine()))) {
         body = body + str + "\n";
         System.out.println("read input:");
         System.out.println(body);
         input.close ();
         System.out.println("closed input stream");
         catch (IOException e) {
         System.out.println("IOException caught: read failed");
         e.printStackTrace();
         return false;
         return true;
         * @param args
         public static void main(String[] args) {
              System.out.println("Test result= " + test());

    In your recuperar() method, read the FTP input stream into a byte array. (You can do that by copying it to a ByteArrayOutputStream and then getting the byte array from that object.) Then, return a ByteArrayInputStream based on those bytes. After you call completePendingCommand(), of course.
    That's one way.
    PC&#178;

  • URLConnection and Weblogic 6.1 Problem

    I am trying to create a URL connection to a secure site from within a JSP. This is the code I am using
      try {
        System.setProperty("java.protocol.handler.pkgs", "com.sun.net.ssl.internal.www.protocol");
        URL url = new URL("https://secure2.mde.epdq.co.uk/cgi-bin/CcxBarclaysEpdqEncTool.e");
        URLConnection conn = (URLConnection)url.openConnection();
        conn.setDoOutput(true);
        conn.setUseCaches(false);
        conn.setRequestProperty("content-type", "application/x-www-form-urlencoded");
        OutputStream outStream = conn.getOutputStream();
      } catch(IOException e) {
        e.printStackTrace();
      }The problem is that when conn.getOutputStream() is executed I receieve a fatal handshake error. I am running the JSP on weblogic 6.1 with JDK1.3. I have added the JSSE libs and made the necessary changes in java.security.
    I can run the same code as a stand-alone application (using jdk1.3 still) with no problems. However once deployed to weblogic 6.1 it crashes. It does work on WL 8.1 (but this is not an option).
    I have enabled ssl debugging within WL and receive the following
    ####<28-Nov-07 17:15:05 GMT> <Debug> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <Before license check - client CipherSuites: [3,9,8,0] server CipherSuites: [3,9,8,0]>
    ####<28-Nov-07 17:15:05 GMT> <Debug> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <No SSL/Domestic License found>
    ####<28-Nov-07 17:15:05 GMT> <Debug> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <After license check - client CipherSuites: [3,9,8,0] server CipherSuites: [3,9,8,0]>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <V2 client hello sent: version = 3.0, cipherSpecs = 4 {3, 9, 8, 0}, sessionID = 0 , challenge = 32 474da2196582eaff9b46529ac4ee36f563c13815a67e92bb385d72226f66ed7d>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <Decrypting 2 bytes...>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> < Finished decrypting 2 bytes>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> < Read throughput = Infinity bytes/sec>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <contentLen = 2, padding.length = 0, MAC.length = 0, len = 2>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <Available on alertStream: 2>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <Aborting session>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <Alert: fatal handshake_failure>
    ####<28-Nov-07 17:15:05 GMT> <Info> <SSL> <dt04230> <hwserver> <ExecuteThread: '12' for queue: 'default'> <> <> <000000> <Aborting session> I have not changed any of WL's keystores from the default settings but I would have thought it would use the standard java cacerts which is obviously fine as I ran the app stand-alone.
    If any body has faced this issue or knows of a possible solution I would greatly appreciate any response.
    Thanks

    As you said, it could be the WLS6 truststore which doesn't contain the certificate authority. Just check which files are used (cacerts, cacerts.jks,..), and maybe you can find it by checking the option startup : -Dweblogic.security.SSL.trustedCAKeyStore
    It doesn't matter when the exception is triggered (you can do an explicit handshake, or just write in the socket and then wait for an implicit handshake)

  • Problem-Writing datas to a Servlet thro' URLConnection class

    Hi,
    Iam trying to post some string data to a servlet.
    The servlet reads 2 parameters from url.And reads the xml string message thro post method.
    So in the client program, I added those parameters to the URL directly like this,
    "http://localhost/servlet/test?action1=value1&action2=value2" ,and created url object .
    And using URLConnection iam trying to post the xml string.
    But the servlet does not read the parameter values.Is my approach is correct?
    client code:
    package test;
    import java.net.*;
    import java.io.*;
    import java.util.*;
    public class Testxml{
    public static void main(String ars[])
    String XML="<?xml version='1.0'?><Test><msg>test message</msg></Test>";
    String server="http://localhost/servlet/test";
    String encodeString = URLEncoder.encode("action1") + "=" + URLEncoder.encode("something1")+"&"+URLEncoder.encode("action2") + "=" + URLEncoder.encode("something2");
    try{
         URL u = new URL(server+"?"+encodeString);
         URLConnection uc = u.openConnection();
         uc.setDoOutput(true);
         uc.setUseCaches(false);
         uc.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
         OutputStream out = uc.getOutputStream();
         PrintWriter wout = new PrintWriter(out);
         wout.write(alertXML);
         wout.flush();
         wout.close();
         System.out.println("finished");
         catch(Exception e) {
         System.out.println(e);
    Servlet code:
    package test;
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class test extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
         performTask(req, res);
    public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
         performTask(req, res);
    public void performTask(HttpServletRequest request, HttpServletResponse response) {
         try{
    String action1=request.getParameter("action1");
    String action2=request.getParameter("action2");
    if(action1.equals("something1") && action1.equals("something2") )
         ServletInputStream in = request.getInputStream();
         byte[] buffer = new byte[1024];
         String xmlMsg = "";
         int len = in.read(buffer,0,buffer.length);
         if(len>0)
         while (len > 0 ){
                   xmlMsg += new String(buffer,0,len);
                   len = in.read(buffer);
         System.out.println("xml : "+xmlMsg);
    This is not working.Even,it does not invoke servlet.Is this approach is correct?.
    Thanx,
    Rahul.

    Hi,
    Did you get the answer to your problem? I am facing the same problem, so if you have the solution, please share the same.
    TIA
    Anup

  • [HELP] URLconnection output problem....

    Good evening, i am having a big problem on writting to the URL connection, after writing and reading to it.
    This is my code
        static void conn (String []ficheiros, String[]refresh ) throws Exception
              contentor[] array = new contentor[ficheiros.length];
              int j=0;
              URL url = new URL("http://ssh:"+porto);
              URLConnection connection = url.openConnection();
              connection.setDoOutput(true);
              PrintWriter out = new PrintWriter(connection.getOutputStream());
              out.write(.....);
              out.close();
              BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
              String inputLine;
              inputLine=in.readLine();
              System.out.println("Out of input");
              in.close();
              URLConnection connection2 = url.openConnection();
              connection2.setDoOutput(true);
              PrintWriter out2 = new PrintWriter(connection2.getOutputStream());
              out2.write("Hello World")
         }I don't know if i can do this last step, but i really wanted to send another output to the server :( and he simply ignores!

    My problem is that I don't know or have any idea how to make the output so it will show all the numbers in between, my ouput it only show the first 3 number, 1 8 and 9Hello and welcome to the forum. First and foremost, please use code tags when posting code here so that your code will retain its formatting and thus will be readable -- after all, your goal is to get as many people to read your post and understand your code as possible, right?
    To do this, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.
    Another way to do this is to manually place the tags into your code by placing the tag [cod&#101;] above your pasted code and the tag [cod&#101;] below your pasted code like so:
    [cod&#101;]
      // your code goes here
      // notice how the top and bottom tags are different
    [/cod&#101;]For instance, here is your code with tags:
    import javax.swing.JOptionPane;
    public class Necklace {
       public static void main(String[] args) {
          int f, s, sum, n, p;
          String first = JOptionPane.showInputDialog("Enter first number:");
          String second = JOptionPane.showInputDialog("Enter second number:");
          f = Integer.parseInt(first);
          s = Integer.parseInt(second);
          sum = f + s;
          n = sum % 10;
          p = s;
          while (!(p == f && n == s))
             sum = n + p;
             p = n;
             n = sum % 10;
          String output = f + "" + s + "" + ++n + "";
          JOptionPane.showMessageDialog(null, output, "Necklace",
                   JOptionPane.INFORMATION_MESSAGE);
    }Next, you can declare your output String before the while loop, and then concatonate a new int on to this inside the loop. Perhaps an even better way is to use a StringBuilder object.

  • Problems with URLConnection and sessions

    Hi all,
    I'm having a problem with some applet - php communication. We have a website that you log in to. The website is in php, and I have no idea what it does, because another guy is handling it. My applet takes in information about the session id and stuff like that, and whenever I want to communicate with a page, I send the id and the requests using a post method. I've got a simple post method which writes a string to a url, then opens an input stream from that connection. Here's the code:
            /**This method posts the given string to the given URL and returns the InputStream from the URL*/
         public InputStream postToURL(URL postURL, String post) throws IOException{
              URLConnection connect = postURL.openConnection();
              connect.setDoOutput(true);
              connect.setUseCaches(false);
              OutputStreamWriter fwdOut = new OutputStreamWriter(connect.getOutputStream());
              fwdOut.write(post);
              fwdOut.flush();
              fwdOut.close();
              return connect.getInputStream();
         }I just noticed that when you run this, it logs you out of your session on the website. I commented out parts and found out that it actually doesn't log you out until I call connect.getInputStream(). I have no idea if this is the applet's fault, or the php's fault. I was hoping that some of you might have some insight as to what the problem is, and if there is something on the applet side I should change to make it work. If it is the php side, then sorry for wasting your time, and hopefully the other guy will catch it.

    shiroganeookami wrote:
    I just wanted to clarify, the session information I'm getting is actually just a login id that is used to confirm if someone has access to certain files, so it actually isn't the session information, like I thought.If I understand you correctly.
    Your are logged in to the site in PHP.
    On the site is an applet.
    When the applet connects back to the site (and you are not using the session or login here) the BROWSER loses it's session.
    Is this correct?
    If so the problem is some shoddy PHP coding. A session or whatever it is that they are actually doing is maintained using HTTP cookies. The browser's cookies are not being wiped by the Applet. What I suspect is happening is that the PHP is doing something with IP addresses and is wiping the browser session when the applet connects from the same address. Which is a mistake for a bunch of reasons.
    If it's something else then please explain what.

  • Problems issuing continuous requests to a server through URLConnection

    Hi ,
    I have a URLConnection object 'uc' obtained from a URL object tied to a server URL.
    i m issuing HTTP requests continously to this server by calling ' uc = u.openConnection()' everytime
    Hence this will return me a new URL Connection object everytime.
    After some 300-400 requests, the program ends abruptly , this may be due to shortage of resources to be allocated to the I/O streams of the URL connection.
    My question is -is there some way to issue multiple requests from the same URL Connection object ? or is there some other method of issuing multiple requests which does not consume a lot of resources ?
    Note: The server accepts only GET method, so i cant write the contents to the output stream of the connection to translate it to a new request every time .
    Thanx

    My question is -is there some way to issue multiple
    requests from the same URL Connection object ? or is
    there some other method of issuing multiple requests
    which does not consume a lot of resources ?
    A HttpURLConnection instance can only be used to issue one http request. What can be re-used is the underlying TCP connection, with the keep-alive header (HTTP 1.1 persistent connections). But that should be handled transparently and by default by the servlet engine.
    The later is able to manipulate the stream to increase performance, if you do not close the stream, i.e you don't call conn.disconnect() or by specify the "Connection: close" request property
    ( conn.setRequestProperty("Connection", "close") )
    So, you shouldn't actually close the steam, just flush it (if you close it, the physical socket connection will be terminated).
    All the http persistent connection/keep-alive issues were apparently fixed in J2SE 1.4.1 ....(are you using 1.4 ?)
    To optimize further, you could take a look at :
    http://jakarta.apache.org/commons/httpclient/

  • Problems with URLConnection

    Hi,
    I am trying to write a small program which makes use of URLConnection.
    Every time I try to read from the url connection it throws EOFException. Please suggest what am I doing wrong. Thanks a lot for all the replies. The code segment is given below.
    clientsocket=serversocket.accept();
    URL url=new URL(urlString);
    HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
    urlConnection.setDoInput(true);
    urlConnection.setDoOutput(true);
    urlConnection.connect();
    DataInputStream instream=new DataInputStream(urlConnection.getInputStream());
    DataOutputStream output=new DataOutputStream(clientsocket.getOutputStream());
    byte b1;
    while((b1=instream.readByte())!=-1)   =>exception is thrown here
    output.write(b1);
    output.flush();
    }

    Hi Rohit,
    I haven't tried ur code yet. But, I can give suggestion on how to read from the URLConnection object.
    1) No need to type cast to HttpURLConnection the URLConnection object u get after opening the url. Let it be a normal URLConnection object.
    2) Change the order of setDoInput() and setDoOutput()
    3) Instead of a DataInputStream, use a BufferedInputStream.
    4) Then use the BufferedInputStream object's read() method. For efficiency u can use read(byte[] buff, int offset, int length). For this create a byte buffer first.
    5) In your case, if u want to use BufferedInputStream.read() only, then instead of using a byte variable use an int variable.
    Hope that helps.
    -JP

  • Facing problems with URLConnection under high load

    Hi,
    I have a piece of code that acts as a load balancer. Under high load scenario - 200+ different simulataneous users, it throws some errors.
    Following is a snippet from that code -
                   URL url = new URL(site);
                   URLConnection urlconnection = url.openConnection();
                   urlconnection.setDoInput(true);
                   urlconnection.setDoOutput(true);
                   urlconnection.setUseCaches(false);
                   DataOutputStream dataoutputstream =
                             new DataOutputStream(urlconnection.getOutputStream());
                   dataoutputstream.writeBytes(posServiceRequest);
                   dataoutputstream.flush();
                   dataoutputstream.close();
                   InputStream inputstream = urlconnection.getInputStream();
                   httpservletresponse.setContentType(urlconnection.getContentType());
                   rewriteStreams(inputstream, httpservletresponse.getOutputStream());
                   inputstream.close();
    Somewhere after around 200 odd users, this piece of code throws an error - "Error writing to server", a stacktrace print shows that the error occurs at the following line -
    InputStream inputstream = urlconnection.getInputStream();
    Any pointers would be appreciated.
    Thanks,
    -rahul

    More information please. What is the exception class, what is its entire text, and what is the stack trace.

  • Problem writing to urlconnection

    i want to write to a text file in the server
    i use printwriter,the code:
    url=new URL("http://www25.brinkster.com/yohaim/Highscore.txt");
    connection=url.openConnection();
    connection.setDoOutput(true);
    in=new BufferedReader(new InputStreamReader(connection.getInputStream()));
    this is working and i can read the data from the txt file, but
    when i try to write like this:
    out=new PrintWriter(connection.getOutputStream());
    out.println(l)
    out.println(dl.playerName());
              out.close();
                   in.close();
    nothing happen and the file not updating,
    i dong get any error?
    the txt file is in the server where the applet is.

    Hi !
    When reading a file , the reference is made w.r.t the code base (where the applet class file actually exists). But the same is not possible when writing into a file on the server directly from the Applet. I guess u can use the Applet-Sevlet combo to acheive this.
    Hope this helps.
    Reg,
    Vinay

  • Can some one give me clear answer how to set timeouts on URLConnection ?

    I am amazed why Sun did not specify a simple method like setReadTimeout
    on URLConnection or provide a way to get refernce to the underlying socket objet. By default the timeout is infinite!
    I am using JDK 1.4 and these appraoches:
    -Dsun.net.client.defaultConnectTimeout=<value in milliseconds>
    -Dsun.net.client.defaultReadTimeout=<value in milliseconds>
    also don't work.
    I do not have access to Socket object. Please help.
    I am using URLConnection in my client application on HTTPS and doing heavy load form POST processing. I tried
    Sockets as well but they don't work. URLConnection works perfectly fine except for the timeouts nightmare.

    OK this might sound crazy but you may have been onto it right from the start. I was having the exact same (frustrating) problem with the URLConnection waiting forever on a dead server and no way to terminate it. I tried something like what you said in your first post:
    System.setProperty("sun.net.client.defaultReadTimeout", "10000");
    and it worked. I played around with the number and it it was apparent to the naked eye that it was working (if you can believe that...).
    Of course, I'm using JDK 1.4.1_01 by now, so this might be different now.
    ttfn.

Maybe you are looking for

  • No multipage view of embedded pdf on iPad

    Beginning from IOS 4 some pdf pages are embeded in an htm page, so you can see only a limited view on the pdf. you can´t move the pdf behind the html page, as you can on the original and you can´t move eg. to a second pdf page. For example:  http://b

  • Problem with SOAP Servlet

    Hi, I have a SOAP servlet, but It is the fist SOAPServlet as I use. I think that the vsd that developper of SOAP servlet provide is ok. But, I do not understand which is the XML that I could provide to it. It is posible that I have a problem with XML

  • Double Buffering and Components

    Hello I am wondering how do I turn off double buffering for my components. This is important for printing as double buffering makes the print job alot of MB

  • New programs not working and websites not displaying correctly

    I need a little assistance. My older G5 is running Mac OS X (10.3.x), Mac OS X 10.3.9 (7W98) - I don't have the funds to upgrade right now - and during an update to iTunes awhile back the power was accidently cut and then my mess began. ITunes would

  • Start/stop the OMS Services on Same Host

    Hi, I have OMS, Repository database and Agent on the same host..... I want to stop and start the services... ========================== FOR Shutdown ===================================== Stop the Agent $cd $ORACLE_HOME/agent10g/bin/emctl stop agent s