File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Read Return URL From URLConnection Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Read Return URL From URLConnection" Watch "Read Return URL From URLConnection" New topic
Author

Read Return URL From URLConnection

Tim Hagerty
Greenhorn

Joined: Mar 24, 2003
Posts: 8
Hello All,
I have researched this but I can't seem to find an answer. So I must turn to the Guru's.
Does anyone know how to read a return URL after

//example - actual url has params and all.
URL u=new URL("http://www.msn.com");
URLConnection uc=u.openConnection(); is made.
I have an app that does credit card processing and I need to send a url with the customers info and then I get a return url telling me if the transaction is compete or not.
I can read the content of the page just fine but I need to be able to parse the return url.
Any help would be much appreciated.
Thanks,
Tim
Chris Smith
Ranch Hand

Joined: May 03, 2002
Posts: 42
What do you mean by "return URL"?
Tim Hagerty
Greenhorn

Joined: Mar 24, 2003
Posts: 8
By the term "return url" I am referring to the url or query string the credit card processing company will be returning to me.
For example:
I will send:
https://www.creditcard.com?cardnum=41111111111&name=John User&amt=57.00
and after the credit card processing company processes this request they will send back:
https://www.mysite.com?status=approved&message=data match
I hope this explains it clearly enough.
Thanks for your response,
Tim
Asher Tarnopolski
Ranch Hand

Joined: Jul 28, 2001
Posts: 260
in case i understand your question right...
request.getRequestURL().toString() will give you the url from which the request was made...
but still, i didn't really understand what do you want to do
[ March 25, 2003: Message edited by: Asher Tarnopolski ]

Asher Tarnopolski
SCJP,SCWCD
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56192
    
  13

Requests don't return URL's, they return responses. Are you saying that when you hit the URL of the cc company that they return a response that contains a URL as its body?
also confused,
bear


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Tim Hagerty
Greenhorn

Joined: Mar 24, 2003
Posts: 8
Really sorry for the confusion, it's not a usual process so here's an example of what happens:
Customer enters their credit card info thru my site and clicks the submit button.
I am using struts in my app so this form post is sent to it's ActionForm then to the Action object that it's tied to. This is where I call the URL object and send a "Get" thru the URL object using URLConnection to my creditcard processing company with the info the customer gave me.
example:
URL u=new URL("https://creditcardprocessing.com?c_info=Card Name&C_number=4111111111111111&C_exp=012005&T_code=02&T_amt=1.00");
URLConnection uc=u.openConnection();
uc.setDoInput(true);
uc.setDoOutput(true);
uc.setUseCaches(false);

The creditcard processing company then sends a response back to me with codes in the return url - or querystring - whatever you like to call it - URI if that helps - that tells me if the transaction succeeded or failed. There is no content in the body in the return from the creditcard company, all of the information I need is contained in the return url seperated out by params: approved=no&message=OverLimit... basicly the ccprocessing company manipulates the url before it sends it's response back to me.
The trick is, Since I am initiating this post is this manner I need to be able to read the response url. This is where I'm stumped.
I can do it just fine in asp or jsp or even php but I want to stick with my paradigm and handle the communication from the action object.
Any help or feedback is welcome, I want to learn.
Tim
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12268
    
    1
What does this "return URL" look like?
Normally when you send a request with a URL you get back a response that you can read as an InputStream - see the JavaDocs for URLConnection.
Like

Bill
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
I think what he's trying to get at is that the processor does some work, then does a sendRedirect. He can read the response page (because that's the end result with follow redirect enabled) but he doesn't know the final URL that he was redirected to.
I would check the response message using getResponseMessage()


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Read Return URL From URLConnection
 
Similar Threads
Communicate with the server without a browser.
Calling of servlet from sub menu's actionPerformed??
Main Class JFrame, Second Class - Business Logic. Business Class assign values to JFrame fields
Checking if a URL exists
reading an ftp file using URLConnection