By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,825 Members | 1,254 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,825 IT Pros & Developers. It's quick & easy.

Calling struts action on web environment from standalone java app

P: n/a
Hi @ll,

I'm investigating the possibility to call a struts action on a web
environment from a standalone java application.
I need to make this call automatically, from a crontab (on unix).
That's why I thought about doing it from within a little Java
standalone program that can be started from command line.
But how do I connect to the web/application server?
Furthermore, the action is using a Cookie! Can I somehow pass a cookie
with this call?

All help would be welcome...

Thx
Jeppe.
Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"Jeppe" <je***@freegates.be> wrote in message
news:d5**************************@posting.google.c om...
Hi @ll,

I'm investigating the possibility to call a struts action on a web
environment from a standalone java application.
I need to make this call automatically, from a crontab (on unix).
That's why I thought about doing it from within a little Java
standalone program that can be started from command line.
But how do I connect to the web/application server?
Furthermore, the action is using a Cookie! Can I somehow pass a cookie
with this call?

All help would be welcome...

Thx
Jeppe.


You could use java.net.HttpURLConnection but you'd have to write your own
Cookie management code (not impossible but can get complicated if you want
to do it properly). Unless you really want a challenge, I'd suggest checking
out the Commons HttpClient package
http://jakarta.apache.org/commons/httpclient/ It handles cookies/sessions
for you automatically ...
Jul 17 '05 #2

P: n/a

"Murray" <pa***@SPAMOFFoptusnet.SPAMMAGE.com.au> wrote in message
news:41***********************@news.optusnet.com.a u...

"Jeppe" <je***@freegates.be> wrote in message
news:d5**************************@posting.google.c om...
Hi @ll,

I'm investigating the possibility to call a struts action on a web
environment from a standalone java application.
I need to make this call automatically, from a crontab (on unix).
That's why I thought about doing it from within a little Java
standalone program that can be started from command line.
But how do I connect to the web/application server?
Furthermore, the action is using a Cookie! Can I somehow pass a cookie
with this call?

All help would be welcome...

Thx
Jeppe.
You could use java.net.HttpURLConnection but you'd have to write your own
Cookie management code (not impossible but can get complicated if you want
to do it properly). Unless you really want a challenge, I'd suggest

checking out the Commons HttpClient package
http://jakarta.apache.org/commons/httpclient/ It handles cookies/sessions
for you automatically ...


PS> This newsgroup is defunct, you'd probably get a better response by
posting at the more official comp.lang.java.help or
comp.lang.java.programmer groups
Jul 17 '05 #3

P: n/a
Murray wrote:
"Murray" <pa***@SPAMOFFoptusnet.SPAMMAGE.com.au> wrote in message
news:41***********************@news.optusnet.com.a u...
"Jeppe" <je***@freegates.be> wrote in message
news:d5**************************@posting.google .com...
Hi @ll,

I'm investigating the possibility to call a struts action on a web
environment from a standalone java application.
I need to make this call automatically, from a crontab (on unix).
That's why I thought about doing it from within a little Java
standalone program that can be started from command line.
But how do I connect to the web/application server?
Furthermore, the action is using a Cookie! Can I somehow pass a cookie
with this call?

All help would be welcome...

Thx
Jeppe.


You could use java.net.HttpURLConnection but you'd have to write your own
Cookie management code (not impossible but can get complicated if you want
to do it properly). Unless you really want a challenge, I'd suggest


checking
out the Commons HttpClient package
http://jakarta.apache.org/commons/httpclient/ It handles cookies/sessions
for you automatically ...

PS> This newsgroup is defunct, you'd probably get a better response by
posting at the more official comp.lang.java.help or
comp.lang.java.programmer groups


I don't see how he could have gotten a better response than yours. ;)

Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #4

P: n/a

"Raymond DeCampo" <rd******@spam.twcny.spam.rr.spam.com.spam> wrote in
message news:Fz********************@twister.nyroc.rr.com.. .
PS> This newsgroup is defunct, you'd probably get a better response by
posting at the more official comp.lang.java.help or
comp.lang.java.programmer groups


I don't see how he could have gotten a better response than yours. ;)

Ray


Aww shucks. Perhaps in the future then :-P
Jul 17 '05 #5

P: n/a

hi !

I had to do nearly the same : I made an applet which exchanged dat
with struts actions. The idea is to create your own http request wit
the class URLConnection.

below is the method I use to dialog with the servlet from my applet
Sorry,I don't have time to translate the comments but have a look a
this page from which I took the idea :
http://javaboutique.internet.com/tutorials/Swing/

"struts meets swing".
Furthermore if the cookie is only to keep the session, you can call th
action in the URL adding this :

../myAction.do;jsessionid=a5aaaaa767D778S?myGETVARIAB LE1=value1&mygGETvariable2=value
...

here is the code :

public String envoyer(String texte) throws IOException{
URL adresse = new URL(url) ;
URLConnection conn = adresse.openConnection();

// on place le cookie d'identifiant de session
//if(cookie!=null) if (!(cookie.equals("")))
//conn.setRequestProperty("Cookie",cookie);

conn.setDoOutput(true);

BufferedWriter out = new BufferedWriter(ne
OutputStreamWriter(conn.getOutputStream(),"UTF8")) ;
out.write(texte);

out.flush();
out.close();

//String c = conn.getHeaderField("Set-Cookie");
// on mémorise le cookies de session si il y en a un.
//if(c!=null)if(!(c.equals(""))) cookie = c;
// on précise que l'on lit du UTF8, autrement les accents donnent de
résultats castrophiques
BufferedReader in = new BufferedReader(ne
InputStreamReader(conn.getInputStream(),"UTF8"));

String reponse = "";
String line;

// je rajoute un compteur car les trois premieres lignes sont nulle
ou ne contiennent que des espaces, ce qui fait planter le parseur
int compte = 0;
while((line = in.readLine())!=null){

if (compte>2){
//System.out.println("-"+line+"-");
reponse+=line;}
compte++;
}

return reponse;

-
octopaz
-----------------------------------------------------------------------
Posted via http://www.codecomments.co
-----------------------------------------------------------------------

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.