Program source code
<% @ Page contentType = "text / html; charset = gb2312"%> <% @ page import = "org.apache.xalan.processor.TransformerFactoryImpl"%> <% @ page import = "javax.xml.soap.SOAPConnectionFactory "%> <% @ Page Import =" javax.xml.soap.soapconnection "%> <% @ page import =" javax.xml.soap.MessageFactory "%> <% @ page import =" javax.xml.soap. SOAPMESSAGE "%> <% @ Page Import =" javax.xml.soap.soappart "%> <% @ page import =" javax.xml.soap.soapenvelop "%> <% @ page import =" javax.xml.soap . SoapBody "%> <% @ page import =" javax.xml.soap.soapelement "%> <% @ page import =" java.io.fileinputStream "%> <% @ page import =" javax.xml.transform. Stream.StreamSource "%> <% @ page import =" javax.xml.Messaging.urlendPoint "%> <% @ page import =" javax.xml.transform.transformerfactory "%> <% @ page import =" javax.xml .transform.transformer "%> <% @ page import =" javax.xml.transform.Source "%> <% @ page import =" javax.xml.transform.stream.streamResult "%>%>
// Next, create a message MessageFactory messageFactory = MessageFactory.newInstance (); SOAPMessage message = messageFactory.createMessage (); // create object SOAP message part SOAPPart soapPart = message.getSOAPPart (); // assembled information according to the disk C search.msg search files StreamSource preppedMsgSrc = new StreamSource (new FileInputStream ( "/ search.msg")) under the root directory; soapPart.setContent (preppedMsgSrc); // save the message message.saveChanges (); // transmitted to the destination address URLEndpoint destination = new URLEndpoint ( "http://api.google.com/search/beta2"); // send a message SOAPMessage reply = connection.call (message, destination); // save the output, the establishment of outgoing information TransformerFactory transformerFactory = Transformerfactory.newinstance ();
// parse Source styleSheet = new StreamSource ( "/ translate.xsl") according to the pattern file translate.xsl; Transformer transformer = transformerFactory.newTransformer (styleSheet); // extract the received content Source sourceContent = reply.getSOAPPart (). GetContent (); // Establish an output file results.out streamResult result = new streamResult ("/ results.out"); transformer.transform (SourceContent, Result); out.println ("file has generated C: /Results.out" ); // Close connection connection.close ();} catch (exception e) {system.out.println (E.GetMessage ());}%>
body> html>
The source code is written in full according to Google's regulations, and the program annotation is also in it, it is not coming here.
Search format
XML Version = '1.0' encoding = 'UTF-8'?> 9CBS Forum q>
Search.msg file label << key> key> is a fixed format, no need. The label refers to the content you want to search. The label
XML Version = "1.0"?>
Translate.xsl file. We started from
Rear