Hi,
I am trying to access a URL with user name password and id, from GET
SERVER SIDE,
i call the server method from gwt client
than the server side connects to the URL and get the response code of
200 which means connection succesfull for authentication. after that i
cant get data from the other server as a response
here is the server site code i have , which i got it from GWT
tutorials from google,
what should i do here could some one help me out with this.
url: http://www.hotelspro.com/xf_test_3.0/hp_xml_request_parser.php?xml=
POST XML is:
DestinationListRequest
<?xml version="1.0" encoding="UTF-8" ?>
<XMLRequest>
<RequestType>DestinationListRequest</RequestType>
<RequestLogin>
<AffiliateCode>xxxxxx</AffiliateCode>
<AffiliateUsername>xxxxxx</AffiliateUsername>
<AffiliatePassword>xxxxxxx</AffiliatePassword>
<AffRequestId>11231231</AffRequestId>
<AffRequestTime>2012-05-01T12:00:00</AffRequestTime>
</RequestLogin>
<DestinationListInfo>
<CompleteList>true</CompleteList>
</DestinationListInfo>
</XMLRequest>
server side code is:
public class HTTPProxy extends HttpServlet {
protected void doPost( HttpServletRequest req, HttpServletResponse
res)
throws ServletException, IOException {
URL url=null;
String method = "GET",post = null;
int timeout = 0;
Set entrySet = req.getParameterMap().entrySet();
Map headers = new HashMap();
for( Iterator iter = entrySet.iterator(); iter.hasNext(); ){
Map.Entry header = (Map.Entry) iter.next();
String key = (String)header.getKey();
String value = ((String[])header.getValue())[0] ;
if( key.equals("method") )
method = value;
else if( key.equals("post") )
post = value;
else if( key.equals("url") )
url = new URL("http://www.hotelspro.com/xf_test_3.0/
hp_xml_request_parser.php?xml=");
else
headers.put( key, value );
}
//use a loop for handling redirects
boolean complete = false;
while( !complete ){
//set up the remote connection
HttpURLConnection urlConnection =
(HttpURLConnection)url.openConnection();
//urlConnection.setRequestProperty("AffiliateCodeValue", "xxx");
//urlConnection.setRequestProperty("AffiliateUsernameValue",
"xxx");
//urlConnection.setRequestProperty("AffiliatePasswordValue",
"xxx");
//urlConnection.setRequestProperty("AffRequestIdValue",
"1023456789");
//urlConnection.setRequestProperty("AffRequestTimeValue",
"2008-12-31T15:30:00");
//urlConnection.setRequestProperty("CompleteListValue",
"true");
urlConnection.setDoOutput(true);
urlConnection.setDoInput(true);
urlConnection.setUseCaches(false);
urlConnection.setInstanceFollowRedirects(false);
urlConnection.setRequestMethod(method);
if( timeout > 0 ) urlConnection.setConnectTimeout(timeout);
//copy the headers to the new connection
Set headersSet = headers.entrySet();
for( Iterator iter=headersSet.iterator(); iter.hasNext(); ){
Map.Entry header = (Map.Entry)iter.next();
urlConnection.setRequestProperty(
(String)header.getKey(),(String)header.getValue() );
}
//write post body to remote connection
if( post != null){
OutputStreamWriter outRemote = new
OutputStreamWriter(urlConnection.getOutputStream());
outRemote.write( post );
outRemote.flush();
}
//transfer contentType from remote connection
String contentType = urlConnection.getContentType();
if( contentType != null ) res.setContentType(contentType);
//check for a redirect
int responseCode = urlConnection.getResponseCode();
if( responseCode == 302 ){
String location = urlConnection.getHeaderField("Location");
url = new URL( location );
}
else{
//read from the appropriate stream
res.setStatus( responseCode );
BufferedInputStream in;
if( responseCode == 200 || responseCode == 201 ) // I GOT CODE
200 EVERY TIME BUT THATS IT NO RESPONSE I GOT WHAT SHOULD I DO
{
in = new
BufferedInputStream(urlConnection.getInputStream());}
else
in = new
BufferedInputStream(urlConnection.getErrorStream());
//send output to client
BufferedOutputStream out =
new BufferedOutputStream(res.getOutputStream());
int c;
while((c = in.read()) >= 0 )
out.write(c);
out.flush();
complete = true;
} } } }
--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.
No comments:
Post a Comment