* failed to start. This ensures that the applications are started in order,
* to avoid session-id problems.
*
- * @return
*/
public void start() {
- repaintAll();
+ String jsonText = configuration.getUIDL();
+ if (jsonText == null) {
+ // inital UIDL not in DOM, request later
+ repaintAll();
+ } else {
+ // Update counter so TestBench knows something is still going on
+ incrementActiveRequests();
+
+ // initial UIDL provided in DOM, continue as if returned by request
- handleJSONText(jsonText);
++ handleJSONText(jsonText, -1);
+ }
}
private native void initializeTestbenchHooks(
if (!synchronous) {
RequestCallback requestCallback = new RequestCallback() {
public void onError(Request request, Throwable exception) {
- showCommunicationError(exception.getMessage());
+ showCommunicationError(exception.getMessage(), -1);
endRequest();
- if (!applicationRunning) {
- // start failed, let's try to start the next app
- ApplicationConfiguration.startNextApplication();
- }
}
public void onResponseReceived(Request request,
// for(;;);[realjson]
final String jsonText = response.getText().substring(9,
response.getText().length() - 1);
- handleJSONText(jsonText);
- final ValueMap json;
- try {
- json = parseJSONResponse(jsonText);
- } catch (final Exception e) {
- endRequest();
- showCommunicationError(e.getMessage()
- + " - Original JSON-text:" + jsonText,
- statusCode);
- return;
- }
-
- VConsole.log("JSON parsing took "
- + (new Date().getTime() - start.getTime()) + "ms");
- if (applicationRunning) {
- handleReceivedJSONMessage(start, jsonText, json);
- } else {
- applicationRunning = true;
- handleWhenCSSLoaded(jsonText, json);
- ApplicationConfiguration.startNextApplication();
- }
++ handleJSONText(jsonText, statusCode);
}
};
}
- private void handleJSONText(String jsonText) {
+ /**
+ * Handles received UIDL JSON text, parsing it, and passing it on to the
+ * appropriate handlers, while logging timiing information.
+ *
+ * @param jsonText
++ * @param statusCode
+ */
- + jsonText);
++ private void handleJSONText(String jsonText, int statusCode) {
+ final Date start = new Date();
+ final ValueMap json;
+ try {
+ json = parseJSONResponse(jsonText);
+ } catch (final Exception e) {
+ endRequest();
+ showCommunicationError(e.getMessage() + " - Original JSON-text:"
++ + jsonText, statusCode);
+ return;
+ }
+
+ VConsole.log("JSON parsing took "
+ + (new Date().getTime() - start.getTime()) + "ms");
+ if (applicationRunning) {
+ handleReceivedJSONMessage(start, jsonText, json);
+ } else {
+ applicationRunning = true;
+ handleWhenCSSLoaded(jsonText, json);
+ }
+ }
+
/**
* Sends an asynchronous UIDL request to the server using the given URI.
*
*
* @param details
* Optional details for debugging.
- * The http error code during the problematic request or -1 if
- * error happened before response was received.
+ * @param statusCode
++ * The status code returned for the request
++ *
*/
- protected void showCommunicationError(String details) {
+ protected void showCommunicationError(String details, int statusCode) {
- showAuthenticationError(details);
+ VConsole.error("Communication error: " + details);
+ ErrorMessage communicationError = configuration.getCommunicationError();
+ showError(details, communicationError.getCaption(),
+ communicationError.getMessage(), communicationError.getUrl());
}
/**