2010-03-08 3 views
5

JsonpRequestBuilder를 사용하여 시간이 초과되었습니다.GWT JsonpRequestBuilder 시간 초과 문제

는 엔트리 포인트 코드는 다음과 같이 진행됩니다

// private static final String SERVER_URL = "http://localhost:8094/data/view/"; 
private static final String SERVER_URL = "http://www.google.com/calendar/feeds/[email protected]/public/full?alt=json-in-script&callback=insertAgenda&orderby=starttime&max-results=15&singleevents=true&sortorder=ascending&futureevents=true"; 
private static final String SERVER_ERROR = "An error occurred while " 
     + "attempting to contact the server. Please check your network " 
     + "connection and try again."; 

/** 
* This is the entry point method. 
*/ 
public void onModuleLoad() { 

    JsonpRequestBuilder requestBuilder = new JsonpRequestBuilder(); 
    // requestBuilder.setTimeout(10000); 
    requestBuilder.requestObject(SERVER_URL, new Jazz10RequestCallback()); 

} 

class Jazz10RequestCallback implements AsyncCallback<Article> { 


    @Override 
    public void onFailure(Throwable caught) { 
     Window.alert("Failed to send the message: " + caught.getMessage());  
    } 

    @Override 
    public void onSuccess(Article result) { 
     // TODO Auto-generated method stub 
     Window.alert(result.toString()); 
    } 

기사 클래스는 단순히 :

import com.google.gwt.core.client.JavaScriptObject; 

public class Article extends JavaScriptObject { 


    protected Article() {}; 


} 

GWT에서 페이지, 그러나 항상 onFailure() 콜백을 명중하고이 경고를 보여줍니다

Failed to send the message. Timeout while calling <url>. 

실패

는 Eclipse 플러그인 콘솔에 아무것도를 볼 수 있습니다. 나는 URL을 시도하고 완벽하게 작동합니다. 당신이 당신의 URL에 callback=insertAgenda이 있기 때문에

답변

4

은 어쩌면 당신은 setCallbackParam를 통해 명시 적으로 콜백 함수를 설정해야합니다 기술이나 제안을 디버깅에있는 모든 팁 감사하겠습니다 - 나는 그 콜백의 이름이어야합니다 어떤 서버에 알립니다 추정 JSON을 래핑하는 함수. 또한 Firebug의 콘솔 (또는 브라우저와 비슷한 도구)을 확인하는 것이 좋습니다. GWT가 예외를보고하지 않더라도 방화범은 여전히있을 수 있습니다.

추신 : 응용 프로그램이 실제로 서버로부터 응답을 수신하는지 (예 : setCallbackParam 전화가 필요함) 방화 벽과 같은 도구를 사용하거나 실제로 뭔가 잘못된 것이 있는지 확인하는 것이 유용합니다. 서버 측 (이유가 무엇이든).

0

이 경우

<callback>(<json>); 

출력을 수정 serversite에 콜백 요청 매개 변수 (기본 callback, __gwt_jsonp__.P0.onSuccess 같은 값 뭔가를) 읽고 있어야 :

__gwt_jsonp__.P0.onSuccess(<json>); 
0

모두를 이 녀석들 중 절대적으로 정확한 것은 아니지만 여기에 그들이 말하는 것을 정확히 이해하는 데 도움이되는 구체적인 예가 있습니다.

이것은 공개 JSON API입니다. 결과에서 살펴 보자 :

http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&country=GB&maxRows=4


이 공개 API는 미리 정의 된 매개 변수 '콜백'을 통해 JSONP를 지원합니다. 기본적으로 콜백에 전달하는 모든 값은 원하는 JSON 데이터를 래핑하는 함수 이름으로 사용됩니다. 이러한 몇 가지 요청의 결과를 살펴 보자 :

http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&country=GB&maxRows=4&callback=totallyMadeUp

http://ws.geonames.org/postalCodeLookupJSON?postalcode=M1&country=GB&maxRows=4&callback=trollingWithJSONP

0

웹 서비스 호출이 JSON 객체와 반환되지만 콜백 JSONP 객체를 기대하는 것이 있기 때문에 또 다른 이유의 일이 될 수있다 (차이점이 있습니다). 당신이 구글지도 API를 다루고 있으며,이 예외를보고있다 그래서 경우

, 당신은,지도 API에 의해

final GeocoderRequest request = GeocoderRequest.create(); 
    request.setAddress(query); 
    try { 
     GWT.log("sending GeoCoderRequest"); 
     if (m_geocoder == null) { 
      m_geocoder = Geocoder.create(); 
     } 

     m_geocoder.geocode(request, new Geocoder.Callback() { 
      @Override 
      public void handle(final JsArray<GeocoderResult> results, 
        final GeocoderStatus status) { 
       handleSuccess(results, status); 
      } 
     }); 
    } catch (final Exception ex) { 
     GWT.log("GeoCoder", ex); 
    } 

같은 것을 제공하는 API로 변경해야 아니면 당신은 같이 RequestBuilder을 사용할 수 있습니다 gwt 라이브러리.