• Post Reply Bookmark Topic Watch Topic
  • New Topic

sendRedirect fails to post data along with url if the data is too large

 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I am trying to send the xmlresponse from servlet to client(php)through sendredirect method(posting along with url parameters). It sends response well if the data(xmlresponse) is small.But It fails if the data is too large.

Http://localhost/manager/test.php?reply=%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0D%0A%3C%21DOCTYPE+ etc etc......

"reply" is sending the xml response to the browser in the form of string.It fails if it sends large xml response.

Is there any way to send the large xml data to posturl.Exception i am facing is Arrayindexoutofbound exceptions: 8192..I also tried to increase maxHttpHeadersize but still no luck. Any suggestions please?
 
Baseet Ahmed
Ranch Hand
Posts: 225
Java Notepad Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Salaam/Hi,

As far as my knowledge is concern, there is a limit for URLs data.
Beyond that you cannot go.
But as mentioned by you,you are getting Arrayindexoutofbound exception, which may be because of your array variable's length taking input from "reply".
Have you checked the code properly ?

Regards
Baseet Ahmed
*******************
Say Salaam before starting communication(verbal+nonverbal),even before Hi/Hello.
Salaam : Assalam Alekum (Peace may upon you.)
*******************
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd rather see the stack trace, but yes, there is a limit to how long the URL is allowed to be. The problem is that the limit is different depending on who is sending the data and where it is going.

Anyway, if are able to POST the data, you could consider writing an auto-submitting form, that is you write a a page with a hidden form and all the fields as hidden inputs, then at the end of the form use JavaScript to submit the form. POST doesn't have the same limit as GET requests and can often be several megabytes or more without problems.
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my servlet code snippets where i am trying to redirect the xml response back to the client

private void success(HttpServletResponse response, String jobsConsole, String responsexml) throws IOException {

StringBuffer url = new StringBuffer(returnpathURL);

url.append("?reply=" + URLEncoder.encode(responsexml, m_charset));

log("Redirecting to: " + url.toString());
response.sendRedirect(url.toString());
}

i tried increasing the httpheadersize in server.xml but still i cannot redirect the xml response.sometimes the xml response exceeds about 20k

David,
i am sending xml response through doPost(). But by the way i shall try yoursuggestions of passing hidden variable from the form.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It doesn't matter that that you are sending it from within doPost, since sendRedirect always causes the browser to GET the data, not POST.

In effect you are sending a location to the browser and telling it "Hey, go GET this"
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
david,

as you mentioned i tried to send the hidden variable "reply" from the form. I did not get any response back from the server.


here is my sample php code with hidden variable:

sample.php code

<form name="myform" method="post" action="$srvletpath$srvletwebpath/servlet/Send" >

<input type="hidden" value="" name="display">
<input type="hidden" value="" name="reply">;
</form>

how to get this variable in posturl servlet
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and how to set this hidden variable in sendRedirect() method

i tried with setHeader(reply,value);
But it failed to send back to the client
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
after you close your form, you should have a javascript block that says document.form.submit()

(the site will block the JS if i try to write it here)
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And based on your initial post, it should look like this:

 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
code above seems to send the xml from client to server.

I need to pass the xml response from server to the client..In servlet how do we send this xml response back to the client url.Can we send the URL parameters as hidden variable through sendRedirect method? I am having the javascript in my php program as follows.

<Script Language="JavaScript">
function load() {
document.myform.submit();
}
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<form name="myform" method="post" action="http://localhost/manager/test.php" > <input type="hidden" value="" name="display"><input type="hidden" value="%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0D%0A%3C%21DOCTYPE" name="reply">;</form>//submit here!

How do we redirect the url with "reply" hidden variable using sendRedirect method to php client.

Any suggestions please reply soon.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm confused.

I assume you have the following:
a server running servlets
a client viewing things in their browser
another server running PHP

I am assuming that the browser sends some data to the servlet, and the servlet then wants to direct the browser to send some dtaa to the PHP machine. Is this anywhere close?
 
Prasad Tamirisa
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why do you want to send such a long string (information) in the url? Y don't you go for post method..??
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<form name="myform" method="post" action="http://localhost/manager/test.php" > <input type="hidden" value="" name="display"><input type="hidden" value="%3C%3Fxml+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0D%0A%3C%21DOCTYPE" name="reply">;</form>//submit here!

How do we redirect the url with "reply" hidden variable using sendRedirect method to php client.

Any suggestions please reply soon.
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David,

I am really sorry if i am not explained well.

My client is php and my server is java and servlet is controller in between.

from php i am sending some input values(say: show config) to servlet and servlet inturn process the input value and produce xmlstring. This xmlstring is then redirected to php page through sendRedirect(url).Detailed url - see my previous posts

xmlstring from the url is then parsed in php code using Domobject and then outputs the result in the screen.

Problem:

Sometimes I cannot send the xmlstring using sendredirect() as xml may be too large to post in url.

How do i solve this issue? As i am new to java please give me some valuable suggestions
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, so here is my interpretation of your processing. Please correct me if I am wrong.

PHP application sends data to the srevlet.
Servlet does processing and sends data to the PHP client.
The PHP client should then send that data to (???) somewhere.

What is the PHP doing with the data?
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you are nearer to the point

Finally php gets the data(xmlstring) from the redirected URL and displays the output after undergo parsing with Domdocument. Parsing stuffs i am doing in php itself
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes, you are nearer to the point

Finally php gets the data(xmlstring) from the redirected URL and displays the output after undergo parsing with Domdocument. Parsing stuffs i am doing in php itself
 
rev sam
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is my php code snippets..


$xsl_filepath = $GLOBALS["web_rootpath"].'rep/xsl/test.xsl';

// Create a DomDocument object from the xml string
// NOTE: "reply" is the xmlstring where we got from the servlet post url

if( !$domXmlObj = domxml_open_mem( $reply) ) {
die( "Cannot parse the xml file." );
}

// Create a DomDocument object from the xslt file.
$domXsltObj = domxml_xslt_stylesheet_file( $xsl_filepath );

// Create a DomDocument object from the xslt transformation
// of the xml and xslt file.
$domTranObj = $domXsltObj->process( $domXmlObj );

// Display the output of the DomDocument object in th screen
// from the xslt transformation.
---------------------------******----------------------------

Here is my java servlet code where it actually sends the xmldata to client

private void success( HttpServletResponse response, String returnpathtophp, String reply, String destination, String display ) throws IOException {

StringBuffer url = new StringBuffer( "http://localhost/manager/test.php");

// reply has the xml and redirects to posturl

url.append( "?reply=" + URLEncoder.encode(reply,m_charset) );

log( "Redirecting to: "+url.toString() );
response.sendRedirect( url.toString());
}


------*******------------

Here is the reply xml in redirected POST url(from servlet to php)


http://localhost/xxx/xx/test.php?reply=%3C%3Fxml
+version%3D%221.0%22+encoding%3D%22UTF-8%22%3F%3E%0D%0A%3C%21DOCTYPE+Sch+SYSTEM
+%22ServerResponse.dtd%22%3E%0D%0A%3CScheduler%3E%0D%0A++%3CCon
+Ho%3D%22amq%3Atcp%3A%2F%2Flocalhost%3A61616%22+User%3D%22username%22
+Password%3D%22password%22+CQueue%3D%22CQCon%22+RetryAttempts%3D%223%22
+RetryPeriod%3D%22100%22+RetryTimeout%3D%22100%22+%2F%3E%0D%0A%3C%2FSch%3E%0D%0A%0D%0A


[BPSouther: Added new line chars to the Url to make the rest of this (long) thread readable]
[ May 29, 2008: Message edited by: Ben Souther ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given that there is a limit to the length that you can have for a URL and given that that length can not always be known (it varies from browser to browser, and across different proxies, routers, etc...) it makes no sense to try to pass large amounts of data in query strings.

You're going to need to take another approach.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65519
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please be sure to use UBB code tags when posting code to the forums. Unformatted code is extermely hard to read and many people that might be able to help you will just move along. Please read this for more information.

You can go back and change your post to add code tags by clicking the .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!