1 /*
2  * Created on Jul 6, 2004
3  *
4  * To change the template for this generated file go to
5  * Window>Preferences>Java>Code Generation>Code and Comments
6  */
7 package com.google.soap.search;
8 
9 import java.io.ByteArrayOutputStream;
10
11import javax.activation.DataSource;
12import javax.xml.transform.Templates;
13import javax.xml.transform.Transformer;
14import javax.xml.transform.TransformerFactory;
15import javax.xml.transform.stream.StreamResult;
16import javax.xml.transform.stream.StreamSource;
17
18import org.apache.soap.Fault;
19import org.apache.soap.rpc.Response;
20
21import com.borneo.util.POProperty;
22
23/**
24 * @author r
25 *
26 * To change the template for this generated type comment go to
27 * Window>Preferences>Java>Code Generation>Code and Comments
28 */
29public class TestSearch extends GoogleSearch {
30
31    /**
32     * 
33     */
34    public TestSearch() {
35        super();
36        this.setSoapServiceURL(
37//              POProperty.get("wsdl.service.addr.host")
38//                      + ":"
39//                      + IJUICProperties.get("wsdl.service.addr.port")
40//                      + "/"
41//                      + POProperty.get("wsdl.service.addr.service")
42//                      + "/"
43//                      + POProperty.get("wsdl.service.addr.port.name")
44                defaultEndpointURL              
45        );
46        // TODO Auto-generated constructor stub
47    }
48    public byte[] doTestSearch()
49    throws GoogleSearchFault
50{
51    Response response = null;
52    DataSource retrnStr = null;
53    ByteArrayOutputStream baos = new ByteArrayOutputStream();
54    try
55    {
56        response = callRemoteMethodUsingSOAP("doGoogleSearch", generateParamsVector());
57        
58        retrnStr =  response.getBodyPart(0).getDataHandler().getDataSource();
59/* testing blok below produced file for command line xslt tesing
60        
61        BufferedOutputStream bos =
62             new BufferedOutputStream(
63                    new FileOutputStream(                                                               
64                            new File("testgoogstrm.txt") ) );               
65        int c;
66        BufferedInputStream rdr = new BufferedInputStream(retrnStr.getInputStream());
67                                                   
68        while((c=rdr.read()) != -1) {
69            bos.write(c);
70        };
71        rdr.close();
72        bos.flush();
73        bos.close();
74*/      
75        StreamSource ssxml = new StreamSource(
76            retrnStr.getInputStream());
77       
78        // get xslt template used to produce the body of SOAPRequest
79        StreamSource  sstmp = new StreamSource(
80            TestSearch.class.getClassLoader().getResourceAsStream(                
81                POProperty.get("xalan.style.google.response")
82        ));
83//      DOMResult result = new DOMResult();      
84        
85        StreamResult result = new StreamResult(baos);
86        TransformerFactory tFactory = TransformerFactory.newInstance();
87        
88        Templates template = tFactory.newTemplates(sstmp);
89        Transformer transformer = template.newTransformer();
90        transformer.transform(ssxml, result);
91        
92        //Serializer serializer = SerializerFactory.getSerializer
93        //  (OutputPropertiesFactory.getDefaultMethodProperties("xml"));
94        //produce a stream and getbyteArray
95    }
96    catch(Exception exception)
97    {
98        throw new GoogleSearchFault(exception.toString());
99    }
00    if(!response.generatedFault())
01    {
02 //       Parameter parameter = response.getReturnValue();
03 //       return (GoogleSearchResult)parameter.getValue();
04        return baos.toByteArray();
05    } else
06    {
07        Fault fault = response.getFault();
08        throw new GoogleSearchFault("Fault Code = " + fault.getFaultCode() + "\nFault String = " + fault.getFaultString());
09    }
10}
11}
12