Results 1 to 11 of 11
  1. #1
    dug201 is offline Member
    Join Date
    Aug 2012
    Location
    London, UK
    Posts
    15
    Rep Power
    0

    Default canot find sybol : method write(byte[]) - urgent help

    Hello Guys;

    I have a simple Java code tha post xml to another url.

    I'm getting an error I'm not sure how to resolve.

    the error states:

    Java Code:
    cannot ind symbol
    symbol : method write(byte[])
    location: calss java.io.OutputStreamWriter
    out.write(request.getBytes(sendEncoding));
       ^
    My Code:
    Java Code:
    static int port = 80;
    static String hostname = "xx.xx.xx.xx";
    static List<String> IDs = new ArrayList<String>(); //id for the download
    static List<String> statuses = new ArrayList<String>(); //http status for the download request 200,201,204,400
    static List<String> filenames=new ArrayList<String>();
    static List<String> sites=new ArrayList<String>();
    static String outputFolder = "/xxx/input_data/xxx/";
    boolean downloadFailed = false; //if a download fails in the download() function, wait 5 mins then retry
    
    
    public String push2(String XML_IN) {
    
    String response = "";
    
    String request = XML_IN;
    
    String sendEncoding = "UTF8"; 
    
    HttpURLConnection urlConn = null;
     
    OutputStreamWriter out = null; 
    
    InputStream in = null; 
    
    try {
    
     
    URL url = new URL("http://url"); 
    
    urlConn = (HttpURLConnection)url.openConnection(); 
    
    urlConn.setRequestMethod("POST"); 
    
    urlConn.setDoOutput(true); 
    
    urlConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
    
    urlConn.setRequestProperty("Accept","application/xml");
    
    urlConn.setRequestProperty("charset","UTF-8");
    
    
    urlConn.connect();
    
    System.out.println("CATCH-->Entering push mode"); 
    
    out = new OutputStreamWriter(urlConn.getOutputStream());
    
    out.write(request.getBytes(sendEncoding));
    
    out.flush(); 
    
    out.close();
    
    int status = urlConn.getResponseCode();
    
    System.out.println("Status code:" + status);
    
    //if http code 200 is not returned, there's an error.
    if (status!=200) {
     in = urlConn.getErrorStream();
    }
    else {
    in = urlConn.getInputStream(); 
    }
    
    
        InputStreamReader inReader = new InputStreamReader(in, sendEncoding);
         
        StringBuffer responseBuffer = new StringBuffer();
         
        char[] buffer = new char[1024]; 
    
        int bytes; 
    
        while ((bytes = inReader.read(buffer)) != -1) { 
    
            responseBuffer.append(buffer, 0, bytes); 
    
        } 
    
        response = responseBuffer.toString(); 
    
        System.out.println(response);
    
    if (status!=200) {    
        failSession("HTTP status code wasn't 200, so must be something wrong - FAILED");
        }
    } 
    
    catch (Exception e) {
    e.printStackTrace();
    } 
    
    finally { 
    if (out != null) { 
    try {out.close();} catch (Exception e) {} 
    } 
    
    if (in != null) { 
    try {in.close();} catch (Exception e) {e.printStackTrace();} 
    } 
    
    if (urlConn != null) { 
    urlConn.disconnect(); 
    } 
    }
    
    return response;
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: canot find sybol : method write(byte[]) - urgent help

    Have you looked at the API for OutputStreamWriter? If not, why not?

  3. #3
    dug201 is offline Member
    Join Date
    Aug 2012
    Location
    London, UK
    Posts
    15
    Rep Power
    0

    Default Re: canot find sybol : method write(byte[]) - urgent help

    Quote Originally Posted by Fubarable View Post
    Have you looked at the API for OutputStreamWriter? If not, why not?
    I have looked at it, still lead me to no solution. I'm a php programmer and have not touched Java for many years, so would appreciate any specific pointers or code example.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,122
    Rep Power
    20

    Default Re: canot find sybol : method write(byte[]) - urgent help

    Here's the API then.
    As you can see there is no write method that takes byte[].
    And that's no great surprise since a Writer write characters, not bytes.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    dug201 is offline Member
    Join Date
    Aug 2012
    Location
    London, UK
    Posts
    15
    Rep Power
    0

    Default Re: canot find sybol : method write(byte[]) - urgent help

    thanks.

    I've changed this bit:
    out.write(request.getBytes(sendEncoding));

    to just:
    out.write(request);

    while this works, I also needed to apply some url_encoding to the xml string being sent, and while it complies sucessfuly, when running it I get: FATAL ERROR : Caught a fatal signal or exception

    this is how I'm url encoding it:

    Java Code:
    URL url = new URL("http://xxxxxx/"); 
    
    urlConn = (HttpURLConnection)url.openConnection(); 
    
    urlConn.setRequestMethod("POST"); 
    
    urlConn.setDoOutput(true); 
    
    urlConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded"); 
    
    urlConn.setRequestProperty("Accept","application/xml");
    
    urlConn.setRequestProperty("charset","UTF-8");
    
    //urlConn.setRequestProperty("Content-Type","application/xml;charset=" + sendEncoding);
    
    urlConn.connect();
    
    System.out.println("CATCH-->Entering push mode"); 
    
    out = new OutputStreamWriter(urlConn.getOutputStream());
    
    //out.write(request.getBytes(sendEncoding));URLEncoder.encode(request,"UTF-8")
    
    String urlEncode = URLEncoder.encode(request,"UTF-8");
    
    out.write(urlEncode);
    
    System.out.println("CATCH-->XML Request:" + urlEncode);
    
    out.flush();
     
    out.close();

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,122
    Rep Power
    20

    Default Re: canot find sybol : method write(byte[]) - urgent help

    What's the full error plus stack trace.
    If it's a JVM crash then that's something we really wouldn't be able to handle here.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    dug201 is offline Member
    Join Date
    Aug 2012
    Location
    London, UK
    Posts
    15
    Rep Power
    0

    Default Re: canot find sybol : method write(byte[]) - urgent help

    thats the only error available to me.

    my issue is that, the code works fine until I url_encode it. we'll it kind of works, it successfuly posts the xml, but I'm getting a status code 500 back and I think I need to url encode me xml request and that's what the stickig point is. Any insight or other way of doing would be much appriciated.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,122
    Rep Power
    20

    Default Re: canot find sybol : method write(byte[]) - urgent help

    I'd look at the other end and see what the error is.
    Assuming you have access to wherever it is you are sending this stuff.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    dug201 is offline Member
    Join Date
    Aug 2012
    Location
    London, UK
    Posts
    15
    Rep Power
    0

    Default Re: canot find sybol : method write(byte[]) - urgent help

    Thanks Tolls.

    From your opinon am I setting all the correct urlConn.setRequestProperty headers in my code above?

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,122
    Rep Power
    20

    Default Re: canot find sybol : method write(byte[]) - urgent help

    No idea.
    I only ever look at these things when I'm actually doing them.
    I rarely bother remembering the ins and outs...and then I test it and tweak as needed.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    dug201 is offline Member
    Join Date
    Aug 2012
    Location
    London, UK
    Posts
    15
    Rep Power
    0

    Default Re: canot find sybol : method write(byte[]) - urgent help

    ha lol, thanks.

Similar Threads

  1. next and previous canot be same
    By isme in forum New To Java
    Replies: 0
    Last Post: 12-15-2010, 02:05 AM
  2. Urgent: Cannot Find Symbol!
    By helpme123 in forum New To Java
    Replies: 2
    Last Post: 11-21-2010, 01:34 AM
  3. write/read two byte arrays to one file- help!
    By leshep in forum New To Java
    Replies: 2
    Last Post: 11-27-2009, 11:10 AM
  4. Replies: 1
    Last Post: 07-04-2008, 06:39 PM
  5. Read/Find Substring/Write to new file
    By hiklior in forum New To Java
    Replies: 6
    Last Post: 04-23-2008, 03:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •