Results 1 to 11 of 11
- 09-03-2012, 01:35 PM #1
Member
- Join Date
- Aug 2012
- Location
- London, UK
- Posts
- 15
- Rep Power
- 0
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:
My Code:Java Code:cannot ind symbol symbol : method write(byte[]) location: calss java.io.OutputStreamWriter out.write(request.getBytes(sendEncoding)); ^
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; }
-
Re: canot find sybol : method write(byte[]) - urgent help
Have you looked at the API for OutputStreamWriter? If not, why not?
- 09-03-2012, 03:05 PM #3
Member
- Join Date
- Aug 2012
- Location
- London, UK
- Posts
- 15
- Rep Power
- 0
- 09-03-2012, 03:12 PM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 09-03-2012, 04:13 PM #5
Member
- Join Date
- Aug 2012
- Location
- London, UK
- Posts
- 15
- Rep Power
- 0
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();
- 09-03-2012, 04:24 PM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 09-03-2012, 04:32 PM #7
Member
- Join Date
- Aug 2012
- Location
- London, UK
- Posts
- 15
- Rep Power
- 0
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.
- 09-03-2012, 05:08 PM #8
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 09-03-2012, 05:17 PM #9
Member
- Join Date
- Aug 2012
- Location
- London, UK
- Posts
- 15
- Rep Power
- 0
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?
- 09-03-2012, 05:27 PM #10
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
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.
- 09-03-2012, 06:22 PM #11
Member
- Join Date
- Aug 2012
- Location
- London, UK
- Posts
- 15
- Rep Power
- 0
Similar Threads
-
next and previous canot be same
By isme in forum New To JavaReplies: 0Last Post: 12-15-2010, 01:05 AM -
Urgent: Cannot Find Symbol!
By helpme123 in forum New To JavaReplies: 2Last Post: 11-21-2010, 12:34 AM -
write/read two byte arrays to one file- help!
By leshep in forum New To JavaReplies: 2Last Post: 11-27-2009, 10:10 AM -
urgent please.what do 4 repeating fields in byte array of jpeg specify?
By hemant in forum Java 2DReplies: 1Last Post: 07-04-2008, 05:39 PM -
Read/Find Substring/Write to new file
By hiklior in forum New To JavaReplies: 6Last Post: 04-23-2008, 02:47 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks