http: submit a form from a Java class through a .bat file

S

Spendius

Hi,
I have a small NAS device that I can switch off once I'm logged on
to it: I just have to open the management page using my favorite
browser, type my login/pwd, then click on a 'Shutdown' button and
that's it - no need to get back down to my basement to manually
switch the contraption off.

=> I'd like write a small Java class that will
1 perform the http connection to this device web server,
2 then run/submit the 'shutdown' action to its small web server too...

Is there an easy way to perform these 2 steps (using Struts maybe) ?
I'd really like to be able to type something like:
C:\temp> java -cp %CLASSPATH% SwitchOffMyNAS
in a DOS window and have my external device to shut down...

Feasible ?
Thanks a lot in advance,
Spendius
 
L

Luuk

Hi,
I have a small NAS device that I can switch off once I'm logged on
to it: I just have to open the management page using my favorite
browser, type my login/pwd, then click on a 'Shutdown' button and
that's it - no need to get back down to my basement to manually
switch the contraption off.

=> I'd like write a small Java class that will
1 perform the http connection to this device web server,
2 then run/submit the 'shutdown' action to its small web server too...

Is there an easy way to perform these 2 steps (using Struts maybe) ?
I'd really like to be able to type something like:
C:\temp> java -cp %CLASSPATH% SwitchOffMyNAS
in a DOS window and have my external device to shut down...

Feasible ?
Thanks a lot in advance,
Spendius

it basically depend on how this page is created, and what info is
submitted, but WGET could be a sollution

http://www.gnu.org/software/wget/manual/wget.html
 
J

Jean-Baptiste Nizet

Hi,
I have a small NAS device that I can switch off once I'm logged on
to it: I just have to open the management page using my favorite
browser, type my login/pwd, then click on a 'Shutdown' button and
that's it - no need to get back down to my basement to manually
switch the contraption off.

=> I'd like write a small Java class that will
1 perform the http connection to this device web server,
2 then run/submit the 'shutdown' action to its small web server too...

Is there an easy way to perform these 2 steps (using Struts maybe) ?
I'd really like to be able to type something like:
C:\temp> java -cp %CLASSPATH% SwitchOffMyNAS
in a DOS window and have my external device to shut down...

Feasible ?
Thanks a lot in advance,
Spendius

wget is probably one of the easiest options.
I also use the iMacros Firefox addon (https://addons.mozilla.org/fr/
firefox/addon/imacros-for-firefox/) for these kinds of repetitive
tasks. After all, my browser is almos always open, and not my console.
If you really want to do it in Java, I'd recommend HtmlUnit (http://
htmlunit.sourceforge.net/). It should be a matter of 10 lines of code.

JB.
 
M

markspace

Is there an easy way to perform these 2 steps (using Struts maybe) ?


No not Struts, just use the standard API. Check out HttpURLConnection:

http://download.oracle.com/javase/6/docs/api/java/net/HttpURLConnection.html

I haven't actually done this myself, but I've seen others talk about it
so I'm sure it's feasible. You'll probably need a few more classes
besides HttpURLConnection.

I'd really like to be able to type something like:
C:\temp> java -cp %CLASSPATH% SwitchOffMyNAS
in a DOS window and have my external device to shut down...


Also feasible. Java SE installs a file association for Jar files by
default. On my own system, I can type <someJar.jar> into the Search box
on the Start Menu (bottom left on the windows task bar) and the Jar will
execute.

You have to have the Jar file on the PATH (not class path). I just set
up a single personal directory "C:\usr\bin" on my windows drive and copy
Jars I want to execute into there.
 
T

Tarkin

No not Struts, just use the standard API.  Check out HttpURLConnection:

http://download.oracle.com/javase/6/docs/api/java/net/HttpURLConnecti...

I haven't actually done this myself, but I've seen others talk about it
so I'm sure it's feasible.  You'll probably need a few more classes
besides HttpURLConnection.


Also feasible.  Java SE installs a file association for Jar files by
default.  On my own system, I can type <someJar.jar> into the Search box
on the Start Menu (bottom left on the windows task bar) and the Jar will
execute.

You have to have the Jar file on the PATH (not class path).  I just set
up a single personal directory "C:\usr\bin" on my windows drive and copy
Jars I want to execute into there.

Be sure to check out Jetty 6 or 7, as both feature the HttpClient
class-
from the Jetty 6 docs @ Codehaus:
http://docs.codehaus.org/display/JETTY/Jetty+HTTP+Client

HTH,
Tarkin
 
R

Roedy Green

Hi,
I have a small NAS device that I can switch off once I'm logged on
to it: I just have to open the management page using my favorite
browser, type my login/pwd, then click on a 'Shutdown' button and
that's it - no need to get back down to my basement to manually
switch the contraption off.

=> I'd like write a small Java class that will
1 perform the http connection to this device web server,
2 then run/submit the 'shutdown' action to its small web server too...

Is there an easy way to perform these 2 steps (using Struts maybe) ?
I'd really like to be able to type something like:
C:\temp> java -cp %CLASSPATH% SwitchOffMyNAS
in a DOS window and have my external device to shut down...

This is pretty easy. I do write little browserless browser automators
all the time using the HTTP class I wrote. See
http://mindprod.com/products1.html#HTTP

http://mindprod.com/products1.html#FILETRANSFER (Look at the Download
class, it is 90% of the way to what you need.)

for other examples, see
http://mindprod.com/products1.html#AVAILABLE
http://mindprod.com/products1.html#SUBMITTER
http://mindprod.com/products1.html#BROKENLINKS
http://mindprod.com/products1.html#VERCHECK


Hint: use Wireshare http://mindprod.com/jgloss/wireshark.html
to see just what your normal tool sends to the NAS (Network Attached
Storage), then you can check that your automaton sends the same
sequence.

see http://mindprod.com/jgloss/http.html for background information
about HTTP GET/POST and friends.
--
Roedy Green Canadian Mind Products
http://mindprod.com
To err is human, but to really foul things up requires a computer.
~ Farmer's Almanac
It is breathtaking how a misplaced comma in a computer program can
shred megabytes of data in seconds.
 
A

Arne Vajhøj

I have a small NAS device that I can switch off once I'm logged on
to it: I just have to open the management page using my favorite
browser, type my login/pwd, then click on a 'Shutdown' button and
that's it - no need to get back down to my basement to manually
switch the contraption off.

=> I'd like write a small Java class that will
1 perform the http connection to this device web server,
2 then run/submit the 'shutdown' action to its small web server too...

Is there an easy way to perform these 2 steps (using Struts maybe) ?
I'd really like to be able to type something like:
C:\temp> java -cp %CLASSPATH% SwitchOffMyNAS
in a DOS window and have my external device to shut down...

Feasible ?

Yes - use Jakarta Commons HttpClient - it has a convenient API
for this.

You could do it using the standard Java classes
URLConnection and HttpURLConnection, but maintaining the
login session is just extra work you save by using HttpClient.

Arne
 
A

Arne Vajhøj

Is there an easy way to perform these 2 steps (using Struts maybe) ?

Oh - and Struts is a server side web framework, which is not relevant
for the client side problem you have.

Arne
 
S

Spendius

Just would like to thank y'all.

In fact grâce à Jean-Baptiste I've solved my issue
with HtmlUnit within a few seconds, but I'll have
a look on other suggestions, if only for the sake
of my curiosity...

Once again *thanks*.

Spendius
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top