* Created on 01-Nov-2004
*
*/
package com.leocate.spreadSheets;
import javax.xml.parsers.DocumentBuilder;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.Message;
import javax.mail.BodyPart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.InternetAddress;
//import javax.activation.
import org.xml.sax.ContentHandler;
import org.xml.sax.ErrorHandler;
import org.xml.sax.InputSource;
import org.xml.sax.helpers.XMLReaderFactory;
import org.jdom.Document;
import java.io.StringReader;
* @author JPMac
*/
public class ExcelPublishingService {
private String saxparser = "org.apache.xerces.parsers.SAXParser";
public Document createSpreadSheet(MessageContext context, String fileLocation, boolean local)throws Exception{
boolean buildDocument = true;
boolean fileCreated = false;
String created = "";
String toAddress = "[EMAIL PROTECTED]";
String fromAddress = "[EMAIL PROTECTED]";
String subject = "This was a test email";
String message = "This was sent from the web service";
String host = "192.168.61.1";
String username = "reports";
String password = "xreports";
int port = 25;
Document document = null;
//String fileLocation = elements.
//String local = elements.get(0).toString();
//a file has been passed into the web service
if(local){
File xmlFile = new File(fileLocation);
buildDocument = xmlFile.exists();
}
if(buildDocument){
try{
//load up the parser
XMLReader reader = XMLReaderFactory.createXMLReader(saxparser);
//register content handler
ContentHandler contentHandler = new SpreadSheetHandler();
//register error handler
ErrorHandler errorHandler = new ServiceErrorHandler();
//set content handler
reader.setContentHandler(contentHandler);
//set error handler
reader.setErrorHandler(errorHandler);
StringReader stringReader = new StringReader(fileLocation);
InputSource saxInputSource = new InputSource(stringReader);
reader.parse(saxInputSource);
}catch(Exception ee){
String logFileName = "C:\\CFusionMX\\runtime\\logs\\NeoWebServices.log";
NeoFaultLogging neoLogging = new NeoFaultLogging(logFileName);
neoLogging.writeFault(ee,"Error in web service");
}
}
//get a document builder factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);
DocumentBuilder builder = factory.newDocumentBuilder();
//build a document response
//create a new JDOM document to return
if(fileCreated){created = "true";}else{created = "false";}
Element element = new Element("Response");
Element att = element.setAttribute("creation",created);
document = new Document(element);
Properties mailprops = new Properties();
mailprops.put("mail.smtp.host",host);
mailprops.put("mail.smtp.auth","true");
Session mailSession = Session.getDefaultInstance(mailprops,null);
Transport transport = mailSession.getTransport("smtp");
MimeMessage mailMessage = new MimeMessage(mailSession);
mailMessage.setFrom(new InternetAddress(fromAddress));
mailMessage.setRecipient(Message.RecipientType.TO,new InternetAddress(toAddress));
mailMessage.setSubject(subject);
MimeMultipart multipart = new MimeMultipart();
BodyPart bodyPart = new MimeBodyPart();
bodyPart.setContent(message,"text/html");
multipart.addBodyPart(bodyPart);
transport.connect(host,port,username,password);
mailMessage.setContent(multipart);
mailMessage.saveChanges();
transport.sendMessage(mailMessage,mailMessage.getAllRecipients());
return document;
}
-----Original Message-----
From: John McCosker [mailto:[EMAIL PROTECTED]
Sent: 03 November 2004 15:48
To: '[EMAIL PROTECTED]'
Subject: Error connecting to webservice with stub : java.lang.NoSuchMethod ExceptionGreetigs, so is it Kerry or Bush? i'm a Northern Ireland Nuetral taking an interest.
anyway back to business,
I have a problem that is confusing me here,
I am calling a webservice within a servlet.I created the wsdl from the service then generated the stubs from the wsdl.
I'd like to mention I am using axis beta 1, I know there are several updates out there but I don't want to migrate
until that new oreilly publication comes out early next year.The service uses java:MSG and returns an org.jdom.Document,
the service takes a string and boolean as parameters,
the stub effectively looks like this,File moveFile = new File(PROCESS_WAIT_LOCATION + "\\" + filename);
ExcelPublishingServiceServiceLocator serviceLocator = new ExcelPublishingServiceServiceLocator();
ExcelPublishingServiceSoapBindingStub stub = (ExcelPublishingServiceSoapBindingStub)serviceLocator.getExcelPublishingService();Document serviceResponse = stub.createSpreadSheet(passfile,true);
however the error logs show this fault message,
2004-11-03 15:33:09 StandardWrapperValve[ScheduleSystemRoot]: Servlet.service() for servlet ScheduleSystemRoot threw exception
java.lang.NoSuchMethodException: com.leocate.spreadSheets.ExcelPublishingService.createSpreadSheet(org.apache.axis.MessageContext, org.w3c.dom.Document)tried class: com.leocate.spreadSheets.ExcelPublishingService, method name: createSpreadSheet.
at org.apache.axis.message.SOAPFaultBuilder.endElement(Unknown Source)
at org.apache.axis.encoding.DeserializationContextImpl.endElement(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanEndElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.DTDConfiguration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at javax.xml.parsers.SAXParser.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContextImpl.parse(Unknown Source)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at org.apache.axis.client.Call.invoke(Unknown Source)
at neo.leocate.webserviceStubs.ExcelPublishingServiceSoapBindingStub.createSpreadSheet(ExcelPublishingServiceSoapBindingStub.java:145)at neo.leocate.schedules.ScheduleSystemRoot.doPost(ScheduleSystemRoot.java:64)
at neo.leocate.schedules.ScheduleSystemRoot.doGet(ScheduleSystemRoot.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:163)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:199)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:700)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:584)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:536)my service effectively is this,
package neo.leocate.schedules;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.ServletException;import javax.xml.rpc.ServiceException;
import java.io.IOException;
import java.io.File;import neo.leocate.webserviceStubs.Document;
import neo.leocate.webserviceStubs.Element;
import neo.leocate.webserviceStubs.ExcelPublishingServiceServiceLocator;
import neo.leocate.webserviceStubs.ExcelPublishingServiceSoapBindingStub;import com.leocate.logging.NeoFaultLogging;
/**
* @author MccoskerJ
*
*/
public class ScheduleSystemRoot extends HttpServlet {
private String PROCESS_LOCATION;
private String PROCESS_WAIT_LOCATION;
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
doPost(request,response);
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
initialiseParams();
File dir = new File(PROCESS_WAIT_LOCATION);
String[] dirListing = dir.list();
if(dirListing!=null){
String filename="";
for(int i=0;i<1;i++){
filename = dirListing[i];
}
if(!filename.equals("")){
File moveFile = new File(PROCESS_WAIT_LOCATION + "\\" + filename);
File destination = new File(PROCESS_LOCATION);
boolean success = moveFile.renameTo(new File(destination, moveFile.getName()));
//if an xml file was successfully moved,
//connect to the excel conversion web service
if(success){
String passfile = PROCESS_LOCATION + filename;
try{
ExcelPublishingServiceServiceLocator serviceLocator = new ExcelPublishingServiceServiceLocator();ExcelPublishingServiceSoapBindingStub stub = (ExcelPublishingServiceSoapBindingStub)serviceLocator.getExcelPublishingService();
Document serviceResponse = stub.createSpreadSheet(passfile,true);
if(serviceResponse!=null){
Element rootElement = serviceResponse.getRootElement();
}
}catch(ServiceException e){
String logFileName = "c:\\CFusionMX\\runtime\\logs\\NeoWebServices.log";NeoFaultLogging neoLogging = new NeoFaultLogging(logFileName);
neoLogging.writeFault(e,"Excel Web service:");
}
}
}
}
}
public void initialiseParams() throws ServletException{
getServletContext().log("getinit init");
PROCESS_LOCATION = getServletConfig().getInitParameter("PROCESS_LOCATION");
PROCESS_WAIT_LOCATION = getServletConfig().getInitParameter("PROCESS_WAIT_LOCATION");
}}
and this was the wsdl I used to generate the stubs,
<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="http://devserver:8080/axis/services/ExcelPublishingService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:impl="http://devserver:8080/axis/services/ExcelPublishingService-impl" xmlns:intf="http://devserver:8080/axis/services/ExcelPublishingService" xmlns:tns1="http://jdom.org" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><types><schema targetNamespace="http://jdom.org" xmlns="http://www.w3.org/2001/XMLSchema"><complexType name="Document"><sequence><element name="baseURI" nillable="true" type="xsd:string"/><element name="DocType" nillable="true" type="tns1:DocType"/><element name="RootElement" nillable="true" type="tns1:Element"/></sequence></complexType><complexType name="DocType"><complexContent><extension base="tns1:Content"><sequence><element name="elementName" nillable="true" type="xsd:string"/><element name="publicID" nillable="true" type="xsd:string"/><element name="systemID" nillable="true" type="xsd:string"/><element name="internalSubset" nillable="true" type="xsd:string"/></sequence></extension></complexContent></complexType><complexType name="Content"><sequence/></complexType><complexType name="Element"><complexContent><extension base="tns1:Content"><sequence><element name="name" nillable="true" type="xsd:string"/><element name="namespace" nillable="true" type="tns1:Namespace"/><element name="Attributes" nillable="true" type="SOAP-ENC:Array"/><element name="Text" nillable="true" type="xsd:string"/></sequence></extension></complexContent></complexType><complexType name="Namespace"><sequence><element name="NO_NAMESPACE" nillable="true" type="tns1:Namespace"/><element name="XML_NAMESPACE" nillable="true" type="tns1:Namespace"/></sequence></complexType><element name="Document" nillable="true" type="tns1:Document"/></schema></types><wsdl:message name="createSpreadSheetResponse">
<wsdl:part name="return" type="tns1:Document"/>
</wsdl:message>
<wsdl:message name="Exception">
<wsdl:part name="serialVersionUID" type="xsd:long"/>
</wsdl:message>
<wsdl:message name="createSpreadSheetRequest">
<wsdl:part name="fileLocation" type="xsd:string"/>
<wsdl:part name="local" type="xsd:boolean"/>
</wsdl:message>
<wsdl:portType name="ExcelPublishingService">
<wsdl:operation name="createSpreadSheet" parameterOrder="fileLocation local">
<wsdl:input message="intf:createSpreadSheetRequest"/>
<wsdl:output message="intf:createSpreadSheetResponse"/>
<wsdl:fault message="intf:Exception" name="Exception"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="ExcelPublishingServiceSoapBinding" type="intf:ExcelPublishingService">
<wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="createSpreadSheet">
<wsdlsoap:operation soapAction=""/>
<wsdl:input>
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://devserver:8080/axis/services/ExcelPublishingService" use="encoded"/></wsdl:input>
<wsdl:output>
<wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://devserver:8080/axis/services/ExcelPublishingService" use="encoded"/></wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="ExcelPublishingServiceService">
<wsdl:port binding="intf:ExcelPublishingServiceSoapBinding" name="ExcelPublishingService">
<wsdlsoap:address location="http://devserver:8080/axis/services/ExcelPublishingService"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>can anyone see what I am doing wrong