This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

generate XML on server side is giving error

 
Yogesh Chugh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi list,
I am new to web services. I have a java class as client which is calling another java class on the server.
I am using Eclipse and jBoss 3.2.x with Axis configured.

The client code is ...

//client class

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.namespace.QName;
import javax.xml.rpc.ParameterMode;

public class StockQuoteClient {

public static void main(String [] args)
{
try {
Options options = new Options(args);

String endpointURL = options.getURL();
System.out.println(endpointURL);

String textToSend1;
String textToSend2;

args = options.getRemainingArgs();
if ((args == null) || (args.length < 1)) {
textToSend1 = "<nothing>";
textToSend2 = "<nothing>";
} else {
textToSend1 = args[0];
textToSend2 = args[1];
}

System.out.println(textToSend1);
System.out.println(textToSend2);

Service service = new Service();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress( new java.net.URL(endpointURL) );

call.setOperationName( new QName("StockQuoteService","getQuote"));
call.addParameter( "arg1", XMLType.XSD_STRING, ParameterMode.IN);
call.setReturnType( org.apache.axis.encoding.XMLType.XSD_LONG);
Long ret = (Long)call.invoke(new Object[]{textToSend2});

if(ret.equals(new Long(-1))){
System.out.println("Argument passed is not valid.Pls check!");
}
else{
System.out.println("The corresponding Value is : " + ret);
}


} catch (Exception e) {
System.err.println(e.toString());
}
}
}



and the Server java class is...

//server side java class

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Hashtable;

import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import org.jdom.DocType;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;

public class StockQuoteService {

private Hashtable htGlobal = new Hashtable();
private Connection con = null;
private Statement stmt = null;
private ResultSet rs = null;
private String driverClass = "oracle.jdbc.driver.OracleDriver";
private String xmlFilePath = "c:\\test\\test.xml";
privateElement root;
privateElement child1;

public void getData(String sym){

Hashtable ht1 = new Hashtable();
ArrayList record = new ArrayList();
ArrayList recordSet = new ArrayList();

System.out.println("******As string*******" + sym + "***********");
Long id = Long.valueOf(sym);
System.out.println("******As long*******" + id + "***********");

//String str ="SELECT * FROM holdings WHERE CL_ID = '10000'";
StringBuffer str = new StringBuffer("SELECT * FROM holdings WHERE CL_ID=");
//System.out.println("******** test area **********");
//str.append("SELECT * FROM holdings WHERE CL_ID=");
System.out.println("******** test area 1234 **********");
str.append(id);
System.out.println(str);

try {
con = getConnection();
stmt = con.createStatement();
//rs = stmt.executeQuery(str);
rs = stmt.executeQuery(str.toString());

while(rs.next()){
String symbol = rs.getString("SYMBOL");
System.out.println("*********The Symbol is" + symbol + "***********");
float total_cost = rs.getFloat("TOT_COST");
String cost = String.valueOf(total_cost);
System.out.println("*********The cost is" + cost + "***********");
record.add(symbol);
record.add(cost);
ht1.put(sym,record);

generateResponceXml(sym,symbol,cost);
}
setHtGlobal(ht1);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

public Long getQuote(String symbol) {

System.out.println(symbol);
getData(symbol);

Hashtable ht2 = new Hashtable();
ht2 = getHtGlobal();
System.out.println("The hashtable after getHtGlobal function is " + ht2);
ArrayList val = (ArrayList)ht2.get(symbol);
System.out.println("ArrayList is "+ val);
String val1 = (String)val.get(1);
System.out.println("2nd value in ArrayList is "+ val1);
if(val1 == null){
val1 = "-1";
}
return new Long(Long.parseLong(val1));
}

/**
* @return
*/
public Hashtable getHtGlobal() {
return htGlobal;
}

/**
* @param hashtable
*/
public void setHtGlobal(Hashtable hashtable) {
htGlobal = hashtable;
System.out.println("The hashtable in setHtGlobal function is " + htGlobal);
}

public Connection getConnection()
throws SQLException
{
try
{
Class.forName(driverClass).newInstance(); /* JDBC driver */
con = DriverManager.getConnection("jdbc racle:thin:@192.168.2.201:1522:gim2usr","gim2usr","gim2usr");
System.out.println("Connection is " + con);
}
catch (ClassNotFoundException e)
{
System.out.println(e.getMessage());
}
catch (SQLException e)
{
System.out.println(e.getMessage());
} catch (InstantiationException e) {
System.out.println(e.getMessage());
e.printStackTrace();
} catch (IllegalAccessException e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
//return the Connection Object
return con;
}

public void generateResponceXml(String id,String symbol, String value)
{
root = new Element("account");
root.setAttribute("id",id);
child1 = new Element("orderlist");
System.out.println("I am in XMLOutput class with path " + xmlFilePath);
try {
fillResponceXml(symbol,value);
Document doc = new Document(root);
// serialize it onto FileOutputStream
XMLOutputter serializer = new XMLOutputter( " ", true);
FileWriter writer = new FileWriter(xmlFilePath);
System.out.println("xml file generated at " + xmlFilePath);
serializer.output(doc,writer);
writer.close();
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
} catch (IOException e) {
System.out.println(e.getMessage());
}
}

public void fillResponceXml(String symb,String valu)
{
root.addContent(child1);
for(int i=0; i<4; i++)
{

Element child2 = new Element("order");
child1.addContent(child2);

for(int j=0; j<1; j++)
{

Element sym = new Element("symbol");
Elementval = new Element("value");
Elementtyp = new Element("type");

sym.setText(symb);
child2.addContent(sym);

val.setText(valu);
child2.addContent(val);

typ.setText("hold");
child2.addContent(typ);

}
}
}

}


so, here if i just comment the line
generateResponceXml(sym,symbol,cost);
in the getData() method, it works fine but if i uncomment the function..it displays error "(500) Internal server Error" on the client side.
Here I am posting the error coming on server side...

12:35:53,359 ERROR [Engine] StandardWrapperValve[AxisServlet]: Servlet.service()
for servlet AxisServlet threw exception
javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.jboss.web.catalina.security.JBossSecurityMgrRealm.invoke(JBossSec
urityMgrRealm.java:229)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve
.java:246)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.jboss.web.catalina.statistics.ContainerStatsValve.invoke(Containe
rStatsValve.java:75)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
rValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
509)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:22
3)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:594)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:619)
at java.lang.Thread.run(Thread.java:536)
12:35:53,375 ERROR [Engine] ----- Root Cause -----
java.lang.VerifyError: (class: com/ebw/crg/stock/StockQuoteService, method: fill
ResponceXml signature: (Ljava/lang/String;Ljava/lang/String V) Incompatible arg
ument to function
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:217)
at org.apache.axis.utils.ClassUtils$2.run(ClassUtils.java:187)
at java.security.AccessController.doPrivileged(Native Method)
at org.apache.axis.utils.ClassUtils.loadClass(ClassUtils.java:171)
at org.apache.axis.utils.ClassUtils.forName(ClassUtils.java:154)
at org.apache.axis.utils.cache.ClassCache.lookup(ClassCache.java:123)
at org.apache.axis.providers.java.JavaProvider.getServiceClass(JavaProvi
der.java:582)
at org.apache.axis.providers.java.JavaProvider.initServiceDesc(JavaProvi
der.java:615)
at org.apache.axis.handlers.soap.SOAPService.getInitializedServiceDesc(S
OAPService.java:342)
at org.apache.axis.deployment.wsdd.WSDDService.makeNewInstance(WSDDServi
ce.java:507)
at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getNewInstance(WSD
DDeployableItem.java:310)
at org.apache.axis.deployment.wsdd.WSDDDeployableItem.getInstance(WSDDDe
ployableItem.java:296)
at org.apache.axis.deployment.wsdd.WSDDDeployment.getServiceByNamespaceU
RI(WSDDDeployment.java:496)
at org.apache.axis.configuration.FileProvider.getServiceByNamespaceURI(F
ileProvider.java:272)
at org.apache.axis.MessageContext.getPossibleOperationsByQName(MessageCo
ntext.java:247)
at org.apache.axis.message.BodyBuilder.onStartChild(BodyBuilder.java:175
)
at org.apache.axis.encoding.DeserializationContextImpl.startElement(Dese
rializationContextImpl.java:963)
at org.apache.xerces.parsers.AbstractSAXParser.startElement(AbstractSAXP
arser.java:434)
at org.apache.xerces.impl.XMLNamespaceBinder.handleStartElement(XMLNames
paceBinder.java:832)
at org.apache.xerces.impl.XMLNamespaceBinder.startElement(XMLNamespaceBi
nder.java:568)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(XMLDTDValidat
or.java:796)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanStartElemen
t(XMLDocumentFragmentScannerImpl.java:752)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContent
Dispatcher.dispatch(XMLDocumentFragmentScannerImpl.java:1454)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(XM
LDocumentFragmentScannerImpl.java:333)
at org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardP
arserConfiguration.java:529)
at org.apache.xerces.parsers.StandardParserConfiguration.parse(StandardP
arserConfiguration.java:585)
at org.apache.xerces.parsers.XMLParser.parse(XMLParser.java:147)
at org.apache.xerces.parsers.AbstractSAXParser.parse(AbstractSAXParser.j
ava:1148)
at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
at org.apache.axis.encoding.DeserializationContextImpl.parse(Deserializa
tionContextImpl.java:242)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:538)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:376)
at org.apache.axis.server.AxisServer.invoke(AxisServer.java:304)
at org.apache.axis.transport.http.AxisServlet.doPost(AxisServlet.java:85
4)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at org.apache.axis.transport.http.AxisServletBase.service(AxisServletBas
e.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Appl
icationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationF
ilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperV
alve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextV
alve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.jboss.web.catalina.security.JBossSecurityMgrRealm.invoke(JBossSec
urityMgrRealm.java:229)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve
.java:246)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.jboss.web.catalina.statistics.ContainerStatsValve.invoke(Containe
rStatsValve.java:75)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:
2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.j
ava:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatche
rValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.j
ava:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:
509)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineVal
ve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContex
t.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.jav
a:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:22
3)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java
:594)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.proce
ssConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java
:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadP
ool.java:619)
at java.lang.Thread.run(Thread.java:536)

the deploy.wsdd file is as ...

//deploy.wsdd
<deployment xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">

<service name="StockQuoteService" provider="java:RPC">
<parameter name="className" value="com.ebw.crg.stock.StockQuoteService"/>
<parameter name="allowedMethods" value="*"/>
</service>

</deployment>

Am I missing any jar file or is there anything else?
pls help as soon as possible. i am approaching deadline.
thansk in advance.

-yogesh

PS: pls, dont go for the debugging comments. Its all for my testing.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic