Calling URL from servlet
Hi!
I am trying to find a solution to this scenario:
1) A cron job will call a servlet.
2) Servlet calls a URL on remote server.
3) Remote server returns an XML document.
4) Servlet processes/parses the XML document.
5) Servlet stores XML fields into DB.
6) Servlet response (entry to log file) indicates status of transaction.
I'm stuck @ #2. What mechanism can I use to make a call to remote URL? I do not want the returning XML document to display on the client's browser; I want to process it on the back-end.
Thx!
http://java.sun.com/docs/books/tutorial/networking/urls/readingURL.html
Similar Messages
-
Calling url from a form - err using ".value" method
I'm trying to call url from a form, which seems to be the subject of many of these Posts.
I have a form with a combo box/LOV and a button. The LOV will read a url into the combo box from a table of url's.
I used the following code in the "OnClick" Java Script Event Handler section, which I pieced together from other posts in this and other forums. (i.e. I'm a pl/sql programmer trying to use Java Scripts for the first time).
OnClick
var X = FORM_DRWING.DEFAULT.A_DRILLDOWN_PATH.value;
run_form(x);
When I attempt to run this form from the "manage" window, I get a run time error "FORM_DRWING is undefined" upon clicking the button. FORM_DRWING "IS" the name of the form!
The runform() function in the "before displying form" pl/sql code section is
htp.p('<script language="JavaScript1.3">
< !--
function runForm(v_link)
window.open(V_LINK);
//-->
</script>');
This code was from yet another Post.
Any help would be appreciated.
Thanks, Larry
nullHi Larry,
the problem could be that you need to preface your form with 'document.'.
i.e.
var X = document.FORM_DRWING.DEFAULT.A_DRILLDOWN_PATH.value;
Regards Michael -
How to call URL from BADDI??
Hi,
I have a requirement to call URL from BADI, i tried to use 'CALL BROWSER' function module,
it works when we are working in GUI, but for portal/PCUI it gives sy-subrc = 2 ( Front end Error)
How to call a pop up page or URL from poral??
Thanks,
Manoj
Edited by: Manoj Lakhanpal on Sep 27, 2010 10:27 AMHi!
I'm using this code for calling a browser, you might try out as well...
MOVE 'http://www.sap.com' TO command.
CONCATENATE 'url.dll,FileProtocolHandler'
command
INTO command
SEPARATED BY space.
MOVE 'rundll32' TO lv_application.
CALL METHOD cl_gui_frontend_services=>execute
EXPORTING
APPLICATION = lv_application
PARAMETER = command
EXCEPTIONS
CNTL_ERROR = 1
ERROR_NO_GUI = 2
BAD_PARAMETER = 3
FILE_NOT_FOUND = 4
PATH_NOT_FOUND = 5
FILE_EXTENSION_UNKNOWN = 6
ERROR_EXECUTE_FAILED = 7
others = 8
Regards
Tamá -
Calling class from servlet gives 500
I have a servlet that works fine by itself, and another class that works fine by itself. However, when I try to create a new instance of the class using the servlet and access a method in the class such as:
Servlet code
Object a = new Object()
a.method
the server returns 500.
Is there some security aspect to calling classes from servlets that may be causing this?Thanks for the replies which have tracked the problem down.
The Server log says:
NoClassDefFoundError: oracle/jdbc/driver/OracleDriver
This class is needed by the class being called by the servlet.
The missing class is in a jar file which is put on the classpath when running the class in a standalone environment. I don't know if it's possible to put this jar on the classpath in the Server environment.
However a solution is to explode the jar file and put the exploded classes in the WEB-INF/classes of the Server. The only disadvantage is that they get wiped out every time I re-deploy the application war file. -
Not able to dispatch to an URL from servlet
Hi ,
I am trying to call a URL from a servlet, which is running in an oc4j instance of Oracle AS 10.1.2.0.2
My servlet (session_servlet) basically reads the session id, whenever it is accessed. It then inserts this session id into a table in an oracle database. Then, I want to access my Oracle Forms application from session_servlet, by dispatching to the URL, say
http://<my_host>/forms/frmservlet?config=test&session_id=<the_session_id_read_by_session_servlet>
session_servlet and frmservlet are running on the same Oracle AS, but on different http servers, session_servlet on port 7777 and frmservlet on the default 80.
<code snippet of my session_servlet, where I am dispatching to the URL>
getServletContext().getRequestDispatcher("http://<my_host>/forms/frmservlet?config=test&session_id="+session.getId()).forward(request,response);
But am getting the following error
500 Internal Server Error
java.lang.NullPointerException
at session_tracker.doGet(session_tracker.java:54)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:826)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:332)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:830)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.AJPRequestHandler.run(AJPRequestHandler.java:224)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].server.http.AJPRequestHandler.run(AJPRequestHandler.java:133)
at com.evermind[Oracle Application Server Containers for J2EE 10g (10.1.2.0.2)].util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:192)
at java.lang.Thread.run(Thread.java:534)
Can someone please help me on this.
Thanks,
SureshgetServletContext().getRequestDispatcher("http://<my_host>/forms/frmservlet?config=test&session_id="+session.getId()).forward(request,response)
From the Javadocs for ServletContext.getRequestDispather():
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html#getRequestDispatcher(java.lang.String)
The pathname must begin with a "/" and is interpreted as relative to the current context root. Use getContext to obtain a RequestDispatcher for resources in foreign contexts. This method returns null if the ServletContext cannot return a RequestDispatcher.
-steve- -
Hi friends,
Can we call a web URL from a ABAP program?
Is there anyway its possible ? if yes how?
Please provide the solution.
Thanks & Regards
kapilHi Kapil,
<b>Look at the below example program:-</b>
REPORT zget_mayors_for_cities.
DATA: it_citymayors TYPE TABLE OF zcitymayors,
wa_citymayors LIKE LINE OF it_citymayors,
mayor TYPE full_name,
trash TYPE string.
PARAMETERS: s_city TYPE s_city LOWER CASE.
SELECT * FROM zcitymayors INTO TABLE it_citymayors
WHERE city LIKE s_city.
* HTTP Client according to
* /people/thomas.jung3/blog/2005/07/01/bsp-create-a-weather-magnet-using-xml-feed-from-weathercom
DATA: client TYPE REF TO if_http_client,
<b>url TYPE string,</b>
xml TYPE xstring,
c_xml TYPE string,
city TYPE string.
* Converter
DATA: l_convin TYPE REF TO cl_abap_conv_in_ce.
LOOP AT it_citymayors INTO wa_citymayors.
* Use the Progress Indicator to show the user which City is processed
CALL FUNCTION 'SAPGUI_PROGRESS_INDICATOR'
EXPORTING
percentage = sy-index
text = wa_citymayors-city.
city = wa_citymayors-city.
* Spaces have to be replaced by _ in the URL
REPLACE FIRST OCCURRENCE OF space IN city WITH '_'.
<b> CONCATENATE
'http://de.wikipedia.org/wiki/Spezial:Export/' city
INTO url.</b>
****Create the HTTP client
TRY.
<b> CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = url
IMPORTING
client = client
EXCEPTIONS
OTHERS = 1.</b>
client->send( ).
client->receive( ).
xml = client->response->get_data( ).
client->close( ).
CATCH cx_root.
WRITE: / 'HTTP Connection error: ', city.
ENDTRY.
* Wikipedia does not provide a encoding with the returned XML
* so we have to do the conversion manually
TRY.
CALL METHOD cl_abap_conv_in_ce=>create
EXPORTING
encoding = 'UTF-8'
input = xml
endian = 'L'
RECEIVING
conv = l_convin.
CALL METHOD l_convin->read
IMPORTING
data = c_xml.
CATCH cx_root.
WRITE: / 'Problem during Character conversion: ', city.
ENDTRY.
****Transform XML to ABAP Values
TRY.
CALL TRANSFORMATION zwikipedia_mayor_to_abap
SOURCE XML c_xml
RESULT mayor = mayor.
CATCH cx_root.
WRITE: / 'Data loss during transformation: ', city.
ENDTRY.
* Some Mayors already have pecial Pages
REPLACE FIRST OCCURRENCE OF '[[' IN mayor WITH ''.
REPLACE FIRST OCCURRENCE OF ']]' IN mayor WITH ''.
* Some Mayors are members of a Party
SPLIT mayor AT '(' INTO mayor trash.
wa_citymayors-mayor = mayor.
WRITE: / wa_citymayors-city.
* Update Database
IF NOT wa_citymayors-mayor IS INITIAL.
UPDATE zcitymayors FROM wa_citymayors.
WRITE: wa_citymayors-mayor.
ENDIF.
ENDLOOP.
Look at the below thread for more info:-
/people/gregor.wolf3/blog/2006/06/29/use-data-from-wikipedia
Regards
Sudheer -
How to call JSp from Servlet??
Hello,
I want to call JSP page from servlet.I am using Visual Age For java 3.4. What is wrong in my code??
if (userExists) {
f.setErrors("userName","Duplicate User: Try a different username");
getServletConfig().getServletContext().
getRequestDispatcher("/jsp/forms/retry.jsp").
forward(request, response);
I am not able to get the o/p. Pls help.I can't see anything obvious, but did you take any steps towards doing output before this code (like openning an output stream)?
Not clear what f.setErrors does - presumably stuffs the error message in an attribute of the request. -
Call URL from procedure?
Hi
We have a Crystal Report Server which hosts Crystal Report and now we want to invoket report from PL/SQL procedure/function is it possible.
Means Is it possible to invoke report by calling report URL from procedure or function.
Thanks,
KuldeepYou can certainly use UTL_HTTP to call a URL from a procedure. It's not obvious to me, though, whether that is all you need or whether you need to close the loop (i.e. respond to the results of the report) which may be more challenging.
Be aware, of course, that calls via UTL_HTTP are not transactional, so it is entirely possible that the transaction that initiated the call could be rolled back after the UTL_HTTP call was made. For that reason, folks will commonly have a separate job that calls UTL_HTTP asynchronously after the triggering transaction commits.
Justin -
SAP BW 7 - Call URL from Right Click Menu
Is it possible to make a http call from the right click menu? I know this was possible in 3.5, but the new code seems to have limited my ability to edit the options that appear when I right click on a field and I need to make a call out to another web server for some external data. Is this possible?
Any information that anyone has about a potential work around would be great!!
Thx.Kristine,
Have you tried using RRI (Transaction RSBBS)? You can call URL , pass values etc.
-Saket -
Hi All,
I have to call a URL from the Navigation bar of Web IC.
I have already created a navigation bar profile and links created. but how to call a particular URL either in the personalized or standard area of the Navbar!.
is there anything i have to do with transaction launcher?.
or else any method to attach the URL to the navbar link!.
please help!.
Thank you,
sudeep v d.Hi Johannes,
I got the problem solved. there is an option
'Define URLs and Parameters' in the Transaction Launcher.
( CRM version 4.0 ).
where you have to create an ID and define the corresponding URL.
as the next step you have to goto to transaction auncher wizard and input this ID + Navbar ID, class name etc.
Regards,
sudeep v d. -
I have several static Web pages calling a JSP page using IFrame src. Is there a way to get the full URL of calling Web pages within the JSP? Below is an example to illustrate what I have to do. I don't have to call JSP from IFrame src if there is another way to make this work.
JSP is called from:
http://somewhere.com/home/
JSP outputs:
http://somewhere.com/home/
JSP is called from:
http://somewhere.com/work/
JSP outputs:
http://somewhere.com/work/Each (i)frame spawns a new HTTP request. If you want to do it all in single request, use jsp:include instead of iframe.
-
Have a java bea located at \web-inf\classes\mybeans called UserData.java
And would like to call it from my servlet to pass data located at \web-inf\classesHow would I do that?If your using webLogic server, then the below link may help you.
http://edocs.bea.com/workshop/docs81/doc/en/core/index.html -
Calling simple URL from servlet.
Hello,
i need your help. I must call a simple URL (for example) "www.sun.com" from my servlet. How can i do this ? Sorry for stupid question, but i don't know how...
Dmitri.I didn't know, Lgmqy2000, that i can delete "Duke"....... i tried to cancel it, but without results...
Dmitri -
How to call url from abap in background
Hi,
I could open url but it opens browser window
i saw several threads on how to cal url in background but no good answer
kindly help
thanks
BHi,
Try the following (primitive) example, it calls an url and display the result on screen.
Hope this will help you.
<pre>
REPORT test.
CLASS lcx_http_client DEFINITION
Minimal Error Handling
CLASS lcx_http_client DEFINITION INHERITING FROM cx_static_check.
PUBLIC SECTION.
INTERFACES:
if_t100_message.
DATA:
mv_method TYPE string, "#EC NEEDED
mv_subrc TYPE i. "#EC NEEDED
METHODS:
constructor
IMPORTING iv_method TYPE string OPTIONAL
iv_subrc TYPE i OPTIONAL
iv_msgid TYPE symsgid DEFAULT '00'
iv_msgno TYPE i DEFAULT 162.
ENDCLASS. "lcx_http_client DEFINITION
CLASS lcx_http_client IMPLEMENTATION
CLASS lcx_http_client IMPLEMENTATION.
METHOD constructor.
super->constructor( ).
mv_method = iv_method.
mv_subrc = iv_subrc.
if_t100_message~t100key-msgid = iv_msgid.
if_t100_message~t100key-msgno = iv_msgno.
if_t100_message~t100key-attr1 = 'MV_METHOD'.
if_t100_message~t100key-attr2 = 'MV_SUBRC'.
ENDMETHOD. "constructor
ENDCLASS. "lcx_http_client IMPLEMENTATION
CLASS lcl_http_client DEFINITION
Facade for if_http_client
CLASS lcl_http_client DEFINITION.
PUBLIC SECTION.
CLASS-METHODS:
get_http_client_by_url
IMPORTING iv_url TYPE string
iv_proxy_host TYPE string OPTIONAL
iv_proxy_service TYPE string OPTIONAL
PREFERRED PARAMETER iv_url
RETURNING value(ro_http_client) TYPE REF TO lcl_http_client
RAISING lcx_http_client.
DATA:
mr_http_client TYPE REF TO if_http_client.
METHODS:
send
RAISING lcx_http_client,
receive
RAISING lcx_http_client,
close
RAISING lcx_http_client,
get_response_header_fields
RETURNING value(rt_fields) TYPE tihttpnvp,
get_response_cdata
RETURNING value(rv_data) TYPE string.
ENDCLASS. "lcl_http_client DEFINITION
CLASS lcl_http_client IMPLEMENTATION
CLASS lcl_http_client IMPLEMENTATION.
METHOD get_http_client_by_url.
DATA: lv_subrc TYPE sysubrc.
CREATE OBJECT ro_http_client.
cl_http_client=>create_by_url( EXPORTING url = iv_url
proxy_host = iv_proxy_host
proxy_service = iv_proxy_service
IMPORTING client = ro_http_client->mr_http_client
EXCEPTIONS argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 999 ).
CHECK sy-subrc <> 0.
lv_subrc = sy-subrc.
RAISE EXCEPTION TYPE lcx_http_client EXPORTING iv_method = 'GET_HTTP_CLIENT_BY_URL' iv_subrc = lv_subrc.
ENDMETHOD. "get_http_client_by_url
METHOD send.
DATA: lv_subrc TYPE sysubrc.
mr_http_client->send( EXCEPTIONS http_communication_failure = 5
http_invalid_state = 6
http_processing_failed = 7
http_invalid_timeout = 8
OTHERS = 999 ).
CHECK sy-subrc <> 0.
lv_subrc = sy-subrc.
RAISE EXCEPTION TYPE lcx_http_client EXPORTING iv_method = 'SEND' iv_subrc = lv_subrc.
ENDMETHOD. "send
METHOD close.
DATA: lv_subrc TYPE sysubrc.
CALL METHOD mr_http_client->close
EXCEPTIONS
http_invalid_state = 10
OTHERS = 999.
CHECK sy-subrc <> 0.
lv_subrc = sy-subrc.
RAISE EXCEPTION TYPE lcx_http_client EXPORTING iv_method = 'CLOSE' iv_subrc = lv_subrc.
ENDMETHOD. "close
METHOD receive.
DATA: lv_subrc TYPE sysubrc.
mr_http_client->receive( EXCEPTIONS http_communication_failure = 9
http_invalid_state = 10
http_processing_failed = 11
OTHERS = 999 ).
CHECK sy-subrc <> 0.
lv_subrc = sy-subrc.
RAISE EXCEPTION TYPE lcx_http_client EXPORTING iv_method = 'RECEIVE' iv_subrc = lv_subrc.
ENDMETHOD. "receive
METHOD get_response_header_fields.
mr_http_client->response->get_header_fields( CHANGING fields = rt_fields ).
ENDMETHOD. "get_response_header_fields
METHOD get_response_cdata.
rv_data = mr_http_client->response->get_cdata( ).
ENDMETHOD. "get_response_cdata
ENDCLASS. "lcl_http_client IMPLEMENTATION
PARAMETERS: p_url TYPE string DEFAULT 'http://www.google.com' LOWER CASE,
p_phost TYPE string DEFAULT 'your_proxy_here' LOWER CASE,
p_pserv TYPE string DEFAULT '8080' LOWER CASE.
*===================================================================================
START-OF-SELECTION.
TRY .
DATA: gt_data TYPE string_table,
gv_data TYPE string,
gr_http_client TYPE REF TO lcl_http_client,
go_cx TYPE REF TO lcx_http_client.
"Initialize the http client
gr_http_client =
lcl_http_client=>get_http_client_by_url( iv_url = p_url
iv_proxy_host = p_phost
iv_proxy_service = p_pserv ).
"Call the specified URL and retrieve data from the response
gr_http_client->send( ).
gr_http_client->receive( ).
gv_data = gr_http_client->get_response_cdata( ).
"Its over....
gr_http_client->close( ).
"Display result
REPLACE ALL OCCURRENCES OF cl_abap_char_utilities=>cr_lf IN gv_data WITH cl_abap_char_utilities=>newline.
SPLIT gv_data AT cl_abap_char_utilities=>newline INTO TABLE gt_data.
LOOP AT gt_data INTO gv_data.
WRITE: / gv_data.
ENDLOOP.
CATCH lcx_http_client INTO go_cx.
MESSAGE go_cx TYPE 'S' DISPLAY LIKE 'E'.
ENDTRY.
</pre> -
hi,
I want to call a method of an object that is available in a program already running, with parameters passed from the servlet.
How to do it .
Thanks.Pls be patient with me. I tried my best and couldn't achieve what I want.
I provide the skeleton of what I have done and what I want to do.
I have my core part in /home/raja/Service/Core.java, the only java file in Service folder. When I compile it I get some four class files(which are used in Core.java file internally). I don't compile it as a package but as a single file.
I run the program in the same folder and in main method I use an infinite loop to keep the program running infinitely.
And I have a html as, usr/local/jakartaTomcat../webapps/servlets-examples/input.html. which simply gets an input string and submits to /servlet/Insert servlet class which is in ../servlets-examples/classes/Insert.class.
It put the string in DB which works fine. Also I made a package in ...servlet-examples/classes/Service in which I uploaded Core.java and compiled it and got the class files in it as a package.
In Insert class file I imported Service.*. In Insert class file I put a line like this. Core.putInPool(submittedString) which is a static method.
When I submit input.html , the string is put in DB, but it is not submitting to the program already running.
What I want to do is, I want to submit the string to the program that is running in /home/raja/Service/.
This is the program running in /home/raja/Service.
public class Core {
static ThreadPool bc= new ThreadPool(10);
public static void putString(String someStr) {
bc.putInPool(someStr);
public static void main(String args[]) throws InterruptedException {
BufferedReader dataIn = new BufferedReader(new InputStreamReader( System.in) );
while(true) {
System.out.println("\f 1.Insert\n2.option2Enter Ur choice:");
try{
ch = Integer.parseInt(dataIn.readLine());
String string="";
switch(ch) {
case 1: System.out.println("\nEnter the String:");
string = dataIn.readLine();
bc.putInPool(string);
.....In Insert.class servlet,
string = req.getParameter("userInputString");
out.println("Submitted");
Core.putInPool(string);
Maybe you are looking for
-
I am having a game issue, and I am trying to diagnose it...
I am having a problem with the demo for Empires: Dawn of the Modern world. The game hasn't been released yet, but the demo is available, and I am having a severe problem with it, but I'm not sure what is causing it. My problem is that the game cras
-
List of pending bills required from system
Hi I have 58 branches all over India. Electricity Charges for all these branches are paid by HO depending on the electricity bill received by HO from branch. Electricity amount will differ every month for every branch Now at the month end, i need to
-
Best practice for image inserts
I am planning to create new webhelp topics and edit existing topics in my project. Is it the best practice to place graphics files in the same folder as the HTML input files?
-
Hi I want to buy a WIFI+3G iPad 2 from the US apple store and get it shipped to a relative in the US to bring it down to Sri Lanka. My question is, is the iPad 2 unlocked to be used with any carrier worldwide or will i have to unlock it myself? Or is
-
Itunes won't start it says I need 10.4.7....??
So I just recently updated from 10.3.9 to 10.4 and after the switch when I try to open Itunes it says that I need 10.4.7 and I cannot figure out why..? Does anyone have any answers??