Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

HTTP_REQUEST

mshaqalaihMar 19 2019 — edited Mar 20 2019

hi every body

database version 12c

i have created an java servlet and call this servlet from Apachi Tomcat and every thing is ok , but when i call this servlet from http request through database function i get this error:

SELECT HTTP_REQUEST('http://localhost/StambaWar/stambaservlet',NULL) FROM DUAL;

<h1>HTTP Status 500 – Internal Server Error</h1><hr class="line" /><p><b>Type</b> Exception Report</p><p><b>Description</b>

The server encountered an unexpected condition that prevented it from fulfilling the request.</p><p><b>Exception</b></p><pre>java.lang.NumberFormatException

org.apache.tomcat.util.buf.Ascii.parseLong(Ascii.java:88)

org.apache.tomcat.util.buf.ByteChunk.getLong(ByteChunk.java:601)

org.apache.tomcat.util.buf.MessageBytes.getLong(MessageBytes.java:556)

org.apache.coyote.Request.getContentLengthLong(Request.java:365)

org.apache.coyote.http11.Http11Processor.prepareRequest(Http11Processor.java:792)

org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:384)

org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)

org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1415)

org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

java.lang.Thread.run(Unknown Source)

</pre><p><b>Note</b> The full stack trace of the root cause is available in the server logs.</p><hr class="line" /><h3>Apache Tomcat/9.0.16</h3></body></html>

here is my java servlet :

public class Servlet1 extends HttpServlet {

private static final String CONTENT\_TYPE = "text/html; charset=windows-1256";

public void init(ServletConfig config) throws ServletException {

    super.init(config);

}

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    response.setContentType(CONTENT\_TYPE);

    PrintWriter out = response.getWriter();

    out.println("\<html>");

    out.println("\<head>\<title>Servlet1\</title>\</head>");

    out.println("\<body>");

    out.println("\<p>The servlet has received a GET. This is the reply.\</p>");

    out.println("\</body>\</html>");

    out.close();

}

}

and this output i got it from tomcat web page:

ServletFromTomcat.png

function HTTP_REQUEST :

CREATE OR REPLACE FUNCTION HTTP_REQUEST(url_in VARCHAR2, parameters_in VARCHAR2, method_in VARCHAR2 default 'POST') RETURN VARCHAR2 AS

l_request UTL_HTTP.REQ;

l_response UTL_HTTP.RESP;

l_temp_return_value VARCHAR2(1024);

l_return_value VARCHAR2(1024);

l_parameters_length NUMBER := LENGTH(parameters_in);

BEGIN

--INSERT INTO http_requests_log (URL, PARAMS) VALUES(url_in, parameters_in);

-- Set up proxy servers if required

-- UTL_HTTP.SET_PROXY('proxy.my-company.com', 'corp.my-company.com');

l_request := UTL_HTTP.BEGIN_REQUEST (url=> url_in, method => method_in);

-- UTL_HTTP.SET_HEADER(l_request, 'User-Agent', 'Mozilla/4.0');

UTL_HTTP.SET_HEADER (r => l_request,

                   name   =>  'Content-Type',

                   value  =>  'application/x-www-form-urlencoded');

UTL_HTTP.SET_HEADER (r => l_request,

                   name   =>   'Content-Length',     

                   value  =>   l\_parameters\_length);

If parameters_in is not null then

UTL_HTTP.WRITE_TEXT (r => l_request,

                   data   =>   parameters\_in);  

End If;

l_response := UTL_HTTP.GET_RESPONSE(l_request);

LOOP

UTL\_HTTP.READ\_LINE(l\_response, l\_temp\_return\_value, TRUE);

l\_return\_value := l\_return\_value || CHR(13) || CHR(10) || l\_temp\_return\_value;

END LOOP;

UTL_HTTP.END_RESPONSE(l_response);

RETURN l_return_value;

EXCEPTION

WHEN UTL_HTTP.END_OF_BODY THEN

UTL\_HTTP.END\_RESPONSE(l\_response);

RETURN l\_return\_value;

END HTTP_REQUEST;

/

Regards

Maher

This post has been answered by mshaqalaih on Mar 20 2019
Jump to Answer
Comments
Post Details
Added on Mar 19 2019
2 comments
738 views