One Star

SOAP webservice as a datasource

Hello,
I'm trying to connect to a datasource using a soap webservice with Talend.
I'd like to retreive data through this webservice and use Talend to put it into a MySQL database.
I've got the wsdl file and have completed the 'How to create a File Xml Metadata' tutorial.
The turorial was easy but when using the real life wsdl file, i got stuck at stage 4, 'Add a Metadata File on repository- Define the setting of the parse job'.
Problem is when using the New Xml File wizard, i'm not sure which 'source schema' object to drag to the 'xpath loop expression' or the 'fields to extract' either ?
here are my options
My'source schema' options are :
wsdl:definitions
@name
@targetNamespace
wsdl:types(many options available within collaspable folder)
wsdl:message(many options available within collaspable folder)
wsdlSmiley TongueortType(many options available within collaspable folder)
wsdl:binding(many options available within collaspable folder)
wsdl:service(many options available within collaspable folder)
Many thanks in advance
Soti
4 REPLIES
Community Manager

Re: SOAP webservice as a datasource

Hi
Why are you trying to extract data from a wsdl file? If you have a soap webservice as input, you should use tWebserviceInput or tSOAP component to call the webservice and load the result into Mysql, the job looks like:
tWebserviceInput(or tSOAP)--main--tMysqlOutput.
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business
Six Stars

Re: SOAP webservice as a datasource

Hi,
you schould use tWebServiceInput as Shong mentioned. Because these components were not at usable state in days I needed it for my old project, I used custom java code to work with web services as following:
package routines;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.StringWriter;
import java.io.Writer;
import javax.xml.soap.*;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
public class NAVWSInvoices {
public static void RequestWS(String destinationServiceURL, String soapAction,String inputXMLMessage,String outputXMLMessage) {
try {
// First create the connection
SOAPConnectionFactory soapConnFactory = SOAPConnectionFactory.newInstance();
SOAPConnection connection = soapConnFactory.createConnection();

// Next, create the actual message
MessageFactory messageFactory = MessageFactory.newInstance();
SOAPMessage messageRequest = messageFactory.createMessage();
// Add eventually a SoapAction header if necessary
MimeHeaders hd = messageRequest.getMimeHeaders();
hd.addHeader("SOAPAction", soapAction);
// Create objects for the message parts
SOAPPart soapPart = messageRequest.getSOAPPart();
StreamSource preparedMessageSource = new StreamSource( new FileInputStream(inputXMLMessage));
System.out.println(inputXMLMessage);
soapPart.setContent(preparedMessageSource);
messageRequest.saveChanges();
// Check the input
System.out.println("\nREQUEST:\n");
System.out.println(messageRequest.toString());
System.out.println("\nREQUEST:\n");
messageRequest.writeTo(System.out);
System.out.println();
// Send the message
SOAPMessage reply = connection.call(messageRequest, destinationServiceURL);
// Check the output
System.out.println("\nRESPONSE:\n");
// Create the transformer
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
// Extract the content of the reply
Source sourceContent = reply.getSOAPPart().getContent();

// Set the output for the transformation
StringWriter sw = new StringWriter();
StreamResult result = new StreamResult(sw);
transformer.transform(sourceContent, result);
StringBuffer sb = sw.getBuffer();
String SOAPResponse = sb.toString();
System.out.println(SOAPResponse);
System.out.println();

// Close the connection
connection.close();
Writer output = null;

// Write response to file
File file = new File(outputXMLMessage);
output = new BufferedWriter(new FileWriter(file));
output.write(SOAPResponse);
output.close();
} catch (Exception e) {
// Some error handling
System.out.println(e.getMessage());
}
}

}
One Star

Re: SOAP webservice as a datasource

Hello and thanks to you both.
I'm new to webservices & I see the error of my ways.
Which is better to use tsoap or twebservice ?
All i need to do is connect to a webservice with login parameters and download data into a local mySQL db. I don't need a continous service, just a data dump
when the job is executed.
I've been working on this Talend tutorial to learn how to use the tWebserviceInput function :
'Using the advanced settings of tWebServiceInput'
http://www.talendforge.org/tutorials/tutorial.php?language=english&idTuto=47
I completed part 1&2 but got stuck editting java code in Step 3.
I got lost in java code when trying to call the webservice functions and download data. Is this the only way or is there a simpler one without having to edit so much java code ?
Community Manager

Re: SOAP webservice as a datasource

Hi
Do you really need the advanced usage of the component? I suggest you to read the component doc and learn the basic usage of the two component, which is rather simpler. You can download the component doc from this URL:
http://www.talend.com/download.php?src=HomePage
Best regards
Shong
----------------------------------------------------------
Talend | Data Agility for Modern Business