Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Basic WEBSERVICES doubt  RSS feed

 
Satish Kumar
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends ,
I m new to java webservices and very eager to execute a webservices example.So iI have downloaded one .Being a newbie , I want to know the sequence of steps needed to execute this example . I have all the s/w'ares necessary installed (web logic , jwsdp etc..). Here are the files of that example .
================================================================
file1: Build.xml

<project name="RailwayService" default="ear">
<target name="ear">
<servicegen destEar="Railway.ear" contextURI="Railway">
<service
javaClassComponents="IRServices.RailwayService"
targetNameSpace="www.bea.com/webservices"
serviceName="RailwayService"
serviceURI="/RailwayService"
generateTypes="True"
expandMethods="True"
style="rpc">
</service>
</servicegen>
</target>
</project>
================================================================
file2: RailwayServlet.java

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import javax.xml.rpc.ServiceFactory;
import javax.xml.rpc.Service;
import javax.xml.rpc.Call;
import javax.xml.rpc.encoding.*;
import javax.xml.rpc.ParameterMode;
import javax.xml.namespace.QName;
import java.util.StringTokenizer;
public class RailwayServlet extends HttpServlet
{
public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
PrintWriter out = res.getWriter();
res.setContentType("text/html");
String TrainNo = req.getParameter("TrainNo");
String StnFrom = req.getParameter("StnFrom");
String StnTo = req.getParameter("StnTo");
String TravelClass = req.getParameter("Class");
String JourneyDate = req.getParameter("JourneyDate");
String result = "";
String str = "<TrainNo>"+TrainNo+"</TrainNo><StnFrom>"+StnFrom+"</StnFrom><StnTo>"+StnTo+"</StnTo><TravelClass>"+TravelClass+"</TravelClass><JourneyDate>"+JourneyDate+"</JourneyDate>";
try
{
System.setProperty("java.xml.rpc.ServiceFactory","weblogic.webservice.core.rpc.ServiceFactory.Impl");
ServiceFactory factory = ServiceFactory.newInstance();
String targetNamespace = "http://www.bea.com/webservices";
QName serviceName = new QName(targetNamespace,"RailwayService");
QName portName = new QName(targetNamespace,"RailwayServiceport");
QName operationName = new QName(targetNamespace,"status");
Service service = factory.createService(serviceName);
Call call = service.createCall();
call.setPortTypeName(portName);
call.setOperationName(operationName);
call.addParameter("string",XMLType.XSD_STRING,ParameterMode.IN);
call.setReturnType(XMLType.XSD_STRING);
call.setTargetEndpointAddress("http://localhost:7001/Railway/RailwayService");
result = (String)call.invoke(new Object[] {str});
}
catch(Exception e)
{
e.printStackTrace();
}
StringTokenizer str1 = new StringTokenizer(result,"</>");
str1.nextToken();
out.println(str1.nextToken()+"in"+TravelClass+"on"+JourneyDate);
}
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
doGet(req,res);
}
}
==================================================================
File 3 :

package IRServices;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import javax.naming.*;
public class RailwayService
{
public String status(String str)
{
Connection con;
String result = null;
StringTokenizer s= new StringTokenizer(str,"<>");
s.nextToken();
String TrainNo = s.nextToken();
s.nextToken();
s.nextToken();
String StnFrom = s.nextToken();
s.nextToken();
s.nextToken();
String StnTo = s.nextToken();
s.nextToken();
s.nextToken();
String TravelClass = s.nextToken();
s.nextToken();
s.nextToken();
String JourneyDate = s.nextToken();
try
{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
con = DriverManager.getConnection("jdbc racle:thin@localhost:1900:SATISH","scott","tiger");
Statement stmt = con.createStatement();
//ResultSet rs=stmt.executeQuery("select * from TrainInfo");
ResultSet rs=stmt.executeQuery(" select travelclass from traininfo2 where trainno=1 and stnfrom='satish' and stnto='satish' and journeydate='satish'");
while(rs.next())
{
result = "<status>"+rs.getString(1)+"</status>";
}
}
catch (Exception e)
{
e.printStackTrace();
}
return(result);
}
}

=================================================================
i m in a very urgent need for a solution of this . i wuld be eagerly awaiting for any reply .

Thanks in advance
Satish
 
William Barnes
Ranch Hand
Posts: 1048
2
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you have downloaded an example which doesn't explain how to run the example. Is that correct? If all you want to do is run an example than find one which is complete. The sun site has tutorials which give you step by step instuctions. And here is another
[ March 04, 2005: Message edited by: William Barnes ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!