You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Eric Roberts <er...@tacc.utexas.edu> on 2002/06/11 22:43:27 UTC
Accessing Web Services from the web
Ok, I have a web service class that i want to use to access loads on
certain machines. It takes one parameter, the machine name. The Java
source looks like this:
(begin source here)
package samples.userguide.load;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.utils.Options;
import javax.xml.rpc.ParameterMode;
public class LoadClient
{
public static void main(String [] args) throws Exception {
Options options = new Options(args);
String endpoint = "http://localhost:" + options.getPort() +"/axis/Load.jws";
args = options.getRemainingArgs();
if (args == null || args.length != 1) {
System.err.println("Usage: LoadClient arg1");
return;
}
String s1 = new String(args[0]);
Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(new java.net.URL(endpoint) );
call.setOperationName("getBatchQueueLoad");
call.addParameter( "machine", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
String ret = "";
try {
ret = (String) call.invoke(new Object[] {s1});
}
catch(Exception e) {
System.out.println("s1 = "+s1+" ret = '"+ret+"'");
System.out.println("ret BAAAAADDDD!!\n" + e);
e.printStackTrace();
}
System.out.println(ret);
}
}
The location of this file is
/usr/local/apps/xml-axis-beta2/samples/userguide/load
The Load.jws file looks like this
(begin code here)
import java.net.URL;
import java.net.MalformedURLException;
import java.io.*;
public class Load {
public static String getBatchQueueLoad (String machine)
{
String line ="";
try {
URL u = new URL ("http://www.tacc.utexas.edu/~rich/hipcat_data/" +
machine + "_load.txt");
BufferedReader data = new BufferedReader
( new InputStreamReader( u.openStream() ));
line = data.readLine();
data.close();
}
catch (IOException e) {
System.err.println("Error: " + e);
}
return line;
}
}
The location of the Load.jws file is her
/usr/local/apps/jakarta-tomcat-4.0.4-b1/webapps/axis
Everything works great when I run the command
java samples.userguide.load.LoadClient machine_name
I get back the load on the machine.
I want to have a web interface with forms fields where I can put in the
machine name and click submit and have the load returned and displayed in
and HTML page.
Does this call for servlets/jsp? I keep reading about WSDL everywhere but
noone seems to explain how to utilize it. Every tutorial seems to stop
short of telling how to access a web service from the WEB. What am I
missing? Am I going in the right direction?
Many thanks in advance
--
_____________________________________________________________________
Eric Roberts ericrobe@tacc.utexas.edu
Grid Computing Group
Texas Advanced Computing Center
University of Texas at Austin http://www.tacc.utexas.edu/~ericrobe
_____________________________________________________________________
Re: Accessing Web Services from the web
Posted by Lyndon Durham <ne...@verizon.net>.
If you modified your LoadClient to a web service client by replacing
the main method, you could simply import it into a jsppage and invoke
your web service. You could simply use a form that takes the machine
name parameter and pass it to your web service client class. Web
Services Definition Language is the IDL of web services, it provides the
functional part that makes publishing and discovery of your web services
possible.
Re: Accessing Web Services from the web
Posted by James Black <jb...@ieee.org>.
Eric Roberts wrote:
> Does this call for servlets/jsp? I keep reading about WSDL everywhere but
> noone seems to explain how to utilize it. Every tutorial seems to stop
> short of telling how to access a web service from the WEB. What am I
> missing? Am I going in the right direction?
I will take a stab, and if I am off, I will be corrected. <g>
I think what you would need to do is process the form in some cgi program then call the web
service from your cgi program, and the result will be sent to the client, by the cgi program.
You have two parts to the web service, the client and server sides. The server side is seems
you have done. Now you just need to look at the fact that some client has to be able to call the
web service. This is where the cgi program comes in.
I hope this helps.