| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.server -> Re: Forward http request from Sevlet to Package Procedure
I am not abolutely sure this is the cause, but I believe
that ServletRequest.setAttribute() is not for what you
are trying to use it for. As I understood, you are
attempting to pass modified request parameters to the
PL/SQL procedure, and you were trying to set them
using setAttribute() since there is apparently no
setParameter() method. I do not think this is correct,
as setAttribute() cannot be used for setting request
parameters (at least that's what I understood from
the docs.)
And later you are trying to use RequestDispatcher.forward() to forward request to an absolute URL - I believe this doesn't work the way you expect, too. It is documented, that RequestDispatcher can dispatch requests only within servlet context. It cannot forward your request to a foreign handler and get the response back from it (foreign in this case means external to the servlet context.) To properly forward the request they way you want, I think you should use java.net.URL or URLConnection class to post your modified request to your PL/SQL procedure's URL. There is one problem with that though: if your form has to be multipart/form-data, then you will have to encode the request parameters to this format yourself, otherwise you can build a String with all parameters and use URLEncoder to encode them into x-www-form-urlencoded.
Your other option here is to create a JDBC connection to the Oracle database the procedure is at, execute the procedure and then retrieve the content it generated from OWA and print it to the output stream. Not really hard, but a bit more complex than using java.net.URL to post your modified request.
Hope this helps.
-- Vladimir Zakharychev (bob@dpsp-yes.com) http://www.dpsp-yes.com Dynamic PSP(tm) - the first true RAD toolkit for Oracle-based internet applications. All opinions are mine and do not necessarily go in line with those of my employer. "Art" <ajs5mz2_at_yahoo.com> wrote in message news:28874e4d.0211180441.5a71a817_at_posting.google.com...Received on Mon Nov 18 2002 - 11:29:42 CST
> Vladimir,
>
> I do some preprocessing then setup some attributes to pass the data
> back from the servlet to the package.
>
> There has to be a way to get PL/SQL and java to talk to each other. I
> know I'm not the first person to try this.
>
> Anyway: Here is the code in question
>
> public void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> // this.dumpParametersSorted(request,response);
>
> TreeMap map = new TreeMap();
> Enumeration keys = request.getParameterNames();
> while (keys.hasMoreElements()) {
> String key = (String) keys.nextElement();
> map.put(key,(String) request.getParameter(key));
> }
>
>
> TreeMap sortedSites = new TreeMap();
> TreeMap sortedDates = new TreeMap();
>
>
> Set sortedkeys = map.keySet();
> Iterator i = sortedkeys.iterator();
> while (i.hasNext()) {
> String key = (String) i.next();
> String value = (String) request.getParameter(key);
> String idx = null;
> if (key.lastIndexOf("_") != -1) {
> idx = key.substring(key.lastIndexOf("_")+1,key.length());
> }
> if (key.startsWith("site_appl_arr_")) {
> sortedSites.put(idx,value);
> System.err.print("Key = "+key+" index = "+idx+" value =
> "+value+"\n");
> }
> else if (key.startsWith("adapt_date_arr_")) {
> if ((value != null) && (value.length() > 5)) {
> sortedDates.put(idx,value);
> System.err.print("Key = "+key+" index = "+idx+" value
> = "+value+"\n");
> }
> }
> }
>
> String site_appl_arr = this.getStringList(sortedSites);
> String adapt_date_arr = this.getStringList(sortedDates);
>
> System.err.print("\nsite_appl_arr \n"+site_appl_arr);
> System.err.print("\nadapt_date_arr \n "+adapt_date_arr);
>
> request.setAttribute("site_appl_arr",site_appl_arr);
> request.setAttribute("adapt_date_arr",adapt_date_arr);
>
>
> RequestDispatcher disp =
> request.getRequestDispatcher("http://oastest.md.myserver.com/orat/plsql/w_cm_updt.doc_expeditor");
> disp.forward(request,response);
>
> }
>
> You can see where I'm using a RequestDispatcher.forward to send the
> request and reponse object to PL/SQL.
>
> Any help here would be greatly appriciated.
>
> Art
>
>
>
>
> "Vladimir M. Zakharychev" <bob_at_dpsp-yes.com> wrote in message
news:<aqov7s$mf5$1_at_babylon.agtel.net>...
> > Not sure this is the right NG to ask, .misc looks more like it.
> > Anyway, without seeing a snippet of your servlet code and
> > possibly package specification it's hard to say why this doesn't
> > work. How are you passing control to the package? Do you
> > call it via JDBC or are you attempting to redirect the client
> > to the right place after you're done with that extra processing?
> >
> > If you work through JDBC, then you gotta emulate PL/SQL
> > gateway (mod_plsql) in your servlet (set up environment,
> > call the package procedure and pass it relevant parameters,
> > collect package output and stream it to the client) if your
> > package uses OWA and outputs anything to the client,
> > otherwise it's pretty safe to simply call the procedure through
> > JDBC and supply all relevant data to it.
> >
> > If you do some preprocessing and then redirect client browser
> > to the new location I don't see why it shouldn't work except
> > for one tricky issue: there are actually three HTTP 1.1 status
> > codes that do redirection - 302, 303 and 307, while in HTTP 1.0
> > there was only 302. 302 means "redo your request to this new
> > location preserving the method" while 303 means "GET response
> > from this new location" and 307 means practically the same as
> > 302. Regretably, most browsers behave on 302 the way they
> > should for 303 - they GET the new location no matter the
> > method they used originally (so if original method was POST,
> > 302 will cause GET on new location instead of POST with the
> > same data), especially if the protocol in use is HTTP 1.0.
> > So you actually should use 307 code in your response and
> > hope that the browser on the other side understands HTTP 1.1.
> > Take a look at RFC 2616 (http://www.ietf.org/rfc/rfc2616.txt)
> > for more details on HTTP status codes and expected user agent
> > behavior.
> >
> > hth.
> >
> > --
> > Vladimir Zakharychev (bob@dpsp-yes.com) http://www.dpsp-yes.com
> > Dynamic PSP(tm) - the first true RAD toolkit for Oracle-based internet applications.
> > All opinions are mine and do not necessarily go in line with those of my employer.
> >
> >
> > "Art" <ajs5mz2_at_yahoo.com> wrote in message
news:28874e4d.0211111008.6765ec35_at_posting.google.com...
> > > Hi,
> > >
> > > I'm trying to foward an http request from a servlet to an Oracle
> > > Package Procedure. The package in question is an update package the
> > > normally processes a forms post method.
> > >
> > > I have redireced the forms post method the a java servelt for some
> > > additional processing and would like to pass the request to the
> > > package procedure.
> > >
> > > Is this possible? Are there some special contraints that must be met
> > > to allow this to work?
> > >
> > > The oracle package procedure response to the http request coming
> > > directly from a form just fine but it does not respond to a request
> > > coming from a servlet.
> > >
> > > Thanks,
> > >
> > > Art
![]() |
![]() |