tutorials.de Buch-Aktion 05/2012
ERLEDIGT
JA
ANTWORTEN
8
ZUGRIFFE
514
EMPFEHLEN
  • An Twitter übertragen
  • An Facebook übertragen
AUF DIESES THEMA
ANTWORTEN
  1. #1
    sunfy sunfy ist offline Mitglied
    Registriert seit
    Nov 2003
    Beiträge
    10
    Hallo Leutz,
    ich bin gerade dabei mich in Axis und Webservices einzuarbeiten.

    Dazu schreibe ich ein Webservice, der die convertCurrency Funktion von google benutzt um Währungen umzurechnen.
    Falls jemand diesen Google Service nicht kennt:
    Wenn man in dem Google Suche "5 Dollar in Euro" eingibt, bekommt man die Währung mit dem aktuellen Kurs umgerechnet. --> 5 U.S. dollars = 3.65657452 Euros

    Für diese Funktion möchte ich nun auf Basis des Axis Frameworks ein Webservice schreiben, der einen Wert, die InputWährung und die OutputWährung übergeben bekommt, sich dann mit google verbindet, die Abfrage macht und das Ergebniss wieder zurückgibt.

    Soweit die Idee.

    Ich habe einen Tomcat Server installiert, darauf Axis und so weiter. Das läuft auch alles ganz gut. Habe bereits erste Webservices geschrieben, die etwas berechnen und jeweils dazu ein jsp Client, mit dem man die zu berechnenden Zahlen an den Webservice übergibt.

    Jetzt hänge ich allerdings daran eine Suchanfrage an google zu stellen.
    Hat damit von euch schonmal jemand gearbeitet?
    Kann mir da jemand weiterhelfen?

    Welche archive von google muss ich da importieren / einbinden, mit welchen Befehlen kann man google dann benutzen?

    Gruß Sunfy
     

  2. #2
    NightWalk3r NightWalk3r ist offline Mitglied Bronze
    Registriert seit
    Aug 2007
    Beiträge
    28
    wenn ich des richtig verstanden hab, solte es doch auch reichen die gewünschte seite von google zu icludieren(z.b. http://www.google.de/search?hl=de&q=...+in+euro&meta=) und dir des resultat herauszufiltern
     

  3. #3
    sunfy sunfy ist offline Mitglied
    Registriert seit
    Nov 2003
    Beiträge
    10
    hmm, würde vielleicht auch gehen, aber das ist keine gute Lösung des Problems.
    hat sonst noch niemand mit Axis / Soap eine Suchanfrage an die Google API programmiert?

    Gruß Sunfy
     

  4. #4
    NightWalk3r NightWalk3r ist offline Mitglied Bronze
    Registriert seit
    Aug 2007
    Beiträge
    28
     

  5. #5
    sunfy sunfy ist offline Mitglied
    Registriert seit
    Nov 2003
    Beiträge
    10
    Alle Beispiele die man auf der Google Website findet sind nur noch für Ajax beschrieben.
    Ich bräuchte das ganze aber für das Axis Framework.
    ( Axis ist eine Erweiterung von SOAP)

    Auf den Google Websites steht, dass google die API für SOAP nicht weiter supportet, aber den Dienst erstmal weiter laufen lässt.
    Daher findet man dort keine tutorials zur Entwicklung mit Axis / Soap mehr.

    Daher bräuchte ich die Hilfe von jemandem, der das schonmal gemacht hatte, oder noch eine Quelle kennt, bei der man Tutorials dazu findet.
    Geändert von sunfy (13.08.07 um 18:41 Uhr)
     

  6. #6
    sunfy sunfy ist offline Mitglied
    Registriert seit
    Nov 2003
    Beiträge
    10
    Zitat Zitat von NightWalk3r Beitrag anzeigen
    wenn ich des richtig verstanden hab, solte es doch auch reichen die gewünschte seite von google zu icludieren(z.b. http://www.google.de/search?hl=de&q=...+in+euro&meta=) und dir des resultat herauszufiltern
    Also, ich habe die Variante mit der googleApi jetzt aufgegeben. Probiere es nun mit der Apache httpClient library.
    Doch wenn ich nach deren Tutorial vorgehe bekomme ich von meinem Webservice immer eine
    Server returned HTTP response code: 500 Fehlermeldung
    Code 500 sagt folgendes aus:
    Code 500 Teilt dem Client mit, dass der Server einen internen Fehler entdeckt hat und deshalb den Request nicht beantworten kann.

    Also habe ich irgendwo im Webservice ein Fehler, doch wo.
    Wie kann ich herausfinden, was genau der Fehler ist?
     

  7. #7
    sunfy sunfy ist offline Mitglied
    Registriert seit
    Nov 2003
    Beiträge
    10
    ich habe jetzt mal verschiedene varianten ausprobiert, doch jedesmal bekomme ich einen Fehlercode 500. Ich habe mal die versch. Varianten aufgelistet.
    Nicht wundern, den Funktionsparameter url benutze ich erstmal nicht, um diese Fehlerquelle auszuschließen.

    Woran kann es liegen, dass ich jedesmal, die Fehlermeldung (siehe unten) bekomme?

    Als erstes habe ich die Variante aus dem Tutorial von Apache ausprobiert.
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    
    public void getHttpRequest(String url) throws Exception {
    //     Create an instance of HttpClient.
           HttpClient client = new HttpClient();
     
           // Create a method instance.
           HttpMethod method = new GetMethod("http://www.google.de");
           
           // Provide custom retry handler is necessary
           
           method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
                    new DefaultHttpMethodRetryHandler(3, true));
     
           try {
             // Execute the method.
             int statusCode = client.executeMethod(method);
     
             if (statusCode != HttpStatus.SC_OK) {
               System.err.println("Method failed: " + method.getStatusLine());
             }
     
             // Read the response body.
             byte[] responseBody = method.getResponseBody();
     
             // Deal with the response.
             // Use caution: ensure correct character encoding and is not binary data
             text =  (new String(responseBody));
     
           } catch (HttpException e) {
             System.err.println("Fatal protocol violation: " + e.getMessage());
             e.printStackTrace();
           } catch (IOException e) {
             System.err.println("Fatal transport error: " + e.getMessage());
             e.printStackTrace();
           } finally {
             // Release the connection.
             method.releaseConnection();
           }
          
       }


    Dann mal die folgende Variante

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    public String getHttpRequest2(String url){
            GetMethod get = new GetMethod("http://www.google.de");
            // execute method and handle any error responses.
            InputStream in = null;
            try {
                in = get.getResponseBodyAsStream();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // Process the data from the input stream.
            get.releaseConnection();
            return in.toString();
        }

    und zum Schluss mal
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    
    public String getHttpRequest3(String url){
            //create a singular HttpClient object
            HttpClient client = new HttpClient();
            
            // establish a connection within 5 seconds
            client.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
            
            HttpMethod method = null;
            //create a method object
            method = new GetMethod(url);
            method.setFollowRedirects(true);
            
    //      execute the method
            String responseBody = null;
            try{
                client.executeMethod(method);
                responseBody = method.getResponseBodyAsString();
            } catch (HttpException he) {
                System.err.println("Http error connecting to '" + url + "'");
                System.err.println(he.getMessage());
                System.exit(-4);
            } catch (IOException ioe){
                System.err.println("Unable to connect to '" + url + "'");
                System.exit(-3);
            }
            
    //      write out the request headers
            System.out.println("*** Request ***");
            System.out.println("Request Path: " + method.getPath());
            System.out.println("Request Query: " + method.getQueryString());
            Header[] requestHeaders = method.getRequestHeaders();
            for (int i=0; i<requestHeaders.length; i++){
                System.out.print(requestHeaders[i]);
            }
     
            //write out the response headers
            System.out.println("*** Response ***");
            System.out.println("Status Line: " + method.getStatusLine());
            Header[] responseHeaders = method.getResponseHeaders();
            for (int i=0; i<responseHeaders.length; i++){
                System.out.print(responseHeaders[i]);
            }
     
            //write out the response body
            System.out.println("*** Response Body ***");
            System.out.println(responseBody);
     
            //clean up the connection resources
            method.releaseConnection();
            return "kein Inhalt";
        
        }

    Doch jedes mal kommt die Fehlermeldung
    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    
    WARNING: ERROR: Caughtjava.io.IOException: Server returned HTTP response code: 500 for URL: [url]http://localhost:8080/ConverterProject/services/ConverterName[/url]
    java.io.IOException: Server returned HTTP response code: 500 for URL: [url]http://localhost:8080/ConverterProject/services/ConverterName[/url]
        at sun.net.[url]www.protocol.http.HttpURLConnection.getInputStream(Unknown[/url] Source)
        at org.apache.taglibs.io.URLTag.getURLInputStream(URLTag.java:232)
        at org.apache.taglibs.io.URLTag.getURLReader(URLTag.java:217)
        at org.apache.taglibs.io.URLTag.readURL(URLTag.java:285)
        at org.apache.taglibs.io.URLTag.doEndTag(URLTag.java:139)
        at org.apache.jsp.WsClient_jsp._jspService(WsClient_jsp.java:271)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Unknown Source)
    16.08.2007 13:06:11 org.apache.catalina.core.ApplicationContext log
    SCHWERWIEGEND: Server returned HTTP response code: 500 for URL: [url]http://localhost:8080/ConverterProject/services/ConverterName[/url]
    java.io.IOException: Server returned HTTP response code: 500 for URL: [url]http://localhost:8080/ConverterProject/services/ConverterName[/url]
        at sun.net.[url]www.protocol.http.HttpURLConnection.getInputStream(Unknown[/url] Source)
        at org.apache.taglibs.io.URLTag.getURLInputStream(URLTag.java:232)
        at org.apache.taglibs.io.URLTag.getURLReader(URLTag.java:217)
        at org.apache.taglibs.io.URLTag.readURL(URLTag.java:285)
        at org.apache.taglibs.io.URLTag.doEndTag(URLTag.java:139)
        at org.apache.jsp.WsClient_jsp._jspService(WsClient_jsp.java:271)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Unknown Source)
    WARNING: Caught Exception: java.io.IOException: Server returned HTTP response code: 500 for URL: [url]http://localhost:8080/ConverterProject/services/ConverterName[/url]
    java.io.IOException: Server returned HTTP response code: 500 for URL: [url]http://localhost:8080/ConverterProject/services/ConverterName[/url]
        at sun.net.[url]www.protocol.http.HttpURLConnection.getInputStream(Unknown[/url] Source)
        at org.apache.taglibs.io.URLTag.getURLInputStream(URLTag.java:232)
        at org.apache.taglibs.io.URLTag.getURLReader(URLTag.java:217)
        at org.apache.taglibs.io.URLTag.readURL(URLTag.java:285)
        at org.apache.taglibs.io.URLTag.doEndTag(URLTag.java:139)
        at org.apache.jsp.WsClient_jsp._jspService(WsClient_jsp.java:271)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Unknown Source)
    16.08.2007 13:06:11 org.apache.catalina.core.StandardWrapperValve invoke
    SCHWERWIEGEND: Servlet.service() for servlet jsp threw exception
    javax.servlet.jsp.JspException: Server returned HTTP response code: 500 for URL: [url]http://localhost:8080/ConverterProject/services/ConverterName[/url]
        at org.apache.taglibs.io.AbstractTag.handleException(AbstractTag.java:69)
        at org.apache.taglibs.io.URLTag.doEndTag(URLTag.java:146)
        at org.apache.jsp.WsClient_jsp._jspService(WsClient_jsp.java:271)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
        at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:263)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:584)
        at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Unknown Source)
     

  8. #8
    Registriert seit
    Jun 2002
    Ort
    Saarbrücken (Saarland)
    Beiträge
    9.886
    Blog-Einträge
    29
    Hallo,

    also folgendes Funktioniert ohne Probleme:
    Code java:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    
    /**
     * 
     */
    package de.tutorials.search;
     
    import java.util.List;
     
    /**
     * @author Thomas.Darimont
     * 
     */
    public interface ISearchService {
        List<SearchResult> search(String... queryTokens);
    }

    Code java:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    
    /**
     * 
     */
    package de.tutorials.search;
     
    /**
     * @author Thomas.Darimont
     *
     */
    public class SearchResult {
        String url;
        String title;
        
        public SearchResult(){
            
        }
        
        public SearchResult(String url, String title) {
            super();
            this.url = url;
            this.title = title;
        }
        /**
         * @return the url
         */
        public String getUrl() {
            return url;
        }
        /**
         * @param url the url to set
         */
        public void setUrl(String url) {
            this.url = url;
        }
        /**
         * @return the title
         */
        public String getTitle() {
            return title;
        }
        /**
         * @param title the title to set
         */
        public void setTitle(String title) {
            this.title = title;
        }
        
        @Override
        public String toString() {
            return this.title +": " + this.url;
        }
    }

    Code java:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    
    /**
     * 
     */
    package de.tutorials.search.internal;
     
    import java.io.IOException;
    import java.io.InputStream;
    import java.text.MessageFormat;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.Scanner;
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
     
    import org.apache.commons.httpclient.HttpClient;
    import org.apache.commons.httpclient.methods.GetMethod;
     
    import de.tutorials.search.ISearchService;
    import de.tutorials.search.SearchResult;
     
    /**
     * @author Thomas.Darimont
     * 
     */
    public class GoogleBasedSearchService implements ISearchService {
     
        private static final String GOOGLE_RESULT_PATTERN = "<a href=\"([^\"]*)\" class=l>(.*?)</a>";
        public final static String GOOGLE_HOST_ADDRESS = "www.google.de";
        public final static String GOOGLE_SEARCH_URI = "/search?hl=de&q={0}";
     
        public List<SearchResult> search(String... queryTokes) {
            List<SearchResult> results = new ArrayList<SearchResult>();
        
            if (null == queryTokes || queryTokes.length == 0) {
                return results;
            }
     
            StringBuilder queryString = new StringBuilder();
            for (int i = 0; i < queryTokes.length; i++) {
                queryString.append(queryTokes[i]);
                if (i < queryTokes.length - 1) {
                    queryString.append("+");
                }
            }
     
            HttpClient client = new HttpClient();
            client.getHostConfiguration().setHost(GOOGLE_HOST_ADDRESS, 80, "http");
     
            String query = MessageFormat.format(GOOGLE_SEARCH_URI, queryString
                    .toString());
            System.out.println(query);
     
            GetMethod getMethod = new GetMethod(query);
     
            try {
                client.executeMethod(getMethod);
            } catch (Exception e) {
                e.printStackTrace();
                return results;
            }
     
            try {
                extractResultLinksFrom(getMethod.getResponseBodyAsStream(), results);
            } catch (IOException e) {
                e.printStackTrace();
            }
     
            return results;
        }
     
        private void extractResultLinksFrom(InputStream responseBodyAsStream,
                List<SearchResult> results) {
     
            Scanner scanner = new Scanner(responseBodyAsStream);
            Pattern pattern = Pattern.compile(GOOGLE_RESULT_PATTERN);
     
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                Matcher matcher = pattern.matcher(line);
     
                while (matcher.find()) {
                    String url = matcher.group(1);
                    String title = matcher.group(2);
                    results.add(new SearchResult(url, title));
                }
            }
     
            scanner.close();
     
        }
    }

    Das ist natürlich nur zu Demonstrationszwecken gedacht...

    Code :
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    
    /**
     * 
     */
    package de.tutorials.search;
     
    import java.util.List;
     
    import de.tutorials.search.internal.GoogleBasedSearchService;
     
    /**
     * @author Thomas.Darimont
     * 
     */
    public class Searcher {
     
        /**
         * @param args
         */
        public static void main(String[] args) {
            ISearchService searchService = new GoogleBasedSearchService();
            List<SearchResult> searchResults = searchService.search("tutorials",
                    "Java", "Forum");
            for (SearchResult searchResult : searchResults) {
                System.out.println(searchResult);
            }
        }
    }

    Ausgabe:
    HTML-Code:
    /search?hl=de&q=tutorials+Java+Forum
    <b>Java</b> @ <b>tutorials</b>.de: <b>Forum</b>, <b>Tutorial</b>, Anleitung, Schulung &amp; Hilfe: http://www.tutorials.de/forum/java/
    <b>Java</b> RMI - nützliches <b>Tutorial</b> - <b>Java</b> @ <b>tutorials</b>.de: <b>Forum</b> <b>...</b>: http://www.tutorials.de/forum/java/284578-java-rmi-nuetzliches-tutorial.html
    <b>java</b>-<b>forum</b>.org Index: http://www.java-forum.org/
    <b>java</b>-<b>forum</b>.org - Bücher, <b>Tutorials</b> und Links: http://www.java-forum.org/de/viewforum.php?f=12
    <b>Java Forum</b> @ javaCore.de :: Index: http://forum.javacore.de/
    <b>Java Forum</b> @ javaCore.de :: Thema anzeigen - EJB <b>Tutorial</b>: http://forum.javacore.de/viewtopic.php?p=30245
    <b>java</b>+<b>tutorials</b> | sehr beliebt | mister-wong.de: http://www.mister-wong.de/tags/java+tutorials/
    <b>java</b>, <b>forum</b>, <b>tutorials</b> ... | mister-wong.de | Social Bookmarking Tool: http://www.mister-wong.de/users/1110449/
    <b>forum</b>.yacy.de • View topic - <b>Java Tutorials</b>: http://forum.yacy-websuche.de/viewtopic.php?f=12&t=195
    <b>Java Tutorial</b> &amp; Programmier Editor auf Linus und Windows - Peter <b>...</b>: http://www.spotlight.de/zforen/jav/m/jav-1182522780-995.html
    Als Bibliotheken benötigt man hier:
    commons-httpclient.jar
    commons-logging.jar
    commons-codec.jar

    Der Fehler liegt bei dir scheinbar in einer JSP und nicht in einem Servlet... genauer gesagt, scheinst du irgendwo eine JSP zu haben welche Tags aus einer Taglib verwendet die einen HttpRequest absetzen aber die Addresse nicht stimmt und deshalb vom angepeilten Server ein 500er zurück kommt.


    Gruß Tom
     
    Java rocks!
    How to become a good Java Programmer?
    Does IT in Java and .Net
    The only valid measurement of code quality: WTFs / minute
    Blog
    Xing
    Twitter

  9. #9
    sunfy sunfy ist offline Mitglied
    Registriert seit
    Nov 2003
    Beiträge
    10
    ok, vielen Dank für deine Tipps.
    Jetzt weiß ich endlich wo ich nach meinem Fehler suchen kann.
    Werde sie gleich mal umsetzen und ausprobieren.

    Parallel dazu bin ich gerade dabei das ganze mit einer HttpURLConnection auszuprobieren. Dann brauch ich nicht unbedingt den httpClient von Apache.
    Mal schauen ob das so funktioniert, wie ich mir das denke.

    Gruß Sunfy
     

Ähnliche Themen

  1. Apache Axis
    Von DerBaron im Forum Enterprise Java (JEE, J2EE, Spring & Co.)
    Antworten: 0
    Letzter Beitrag: 05.02.08, 11:17
  2. VB + Google Search Ajax API?
    Von jimboo im Forum .NET Web und Kommunikation
    Antworten: 1
    Letzter Beitrag: 18.04.07, 14:55
  3. VB8.0 + Google Search Ajax API?
    Von jimboo im Forum Visual Basic 6.0
    Antworten: 1
    Letzter Beitrag: 15.04.07, 21:47
  4. Spass mit Google Code Search
    Von Alexander Schuc im Forum Coders Talk
    Antworten: 2
    Letzter Beitrag: 08.12.06, 19:41
  5. Google mp3 search t00l 2005 ist raus
    Von momo666 im Forum Musik & Musiker
    Antworten: 6
    Letzter Beitrag: 19.07.05, 00:45