Search in sources :

Example 1 with RequestLogEntry

use of org.rstudio.core.client.jsonrpc.RequestLogEntry in project rstudio by rstudio.

the class RemoteServer method sendRequestViaMainWorkbench.

// call made from satellite -- this delegates to a native method which
// sets up a javascript callback and then calls the main workbench
private <T> void sendRequestViaMainWorkbench(String scope, String method, JSONArray params, boolean redactLog, final ServerRequestCallback<T> requestCallback) {
    JSONObject request = new JSONObject();
    request.put("method", new JSONString(method));
    if (params != null)
        request.put("params", params);
    final RequestLogEntry requestLogEntry = RequestLog.log(Integer.toString(Random.nextInt()), redactLog ? "[REDACTED]" : request.toString());
    sendRequestViaMainWorkbench(scope, method, params.getJavaScriptObject(), redactLog, new RpcResponseHandler() {

        @Override
        public void onResponseReceived(RpcResponse response) {
            String responseText = response.toString();
            requestLogEntry.logResponse(ResponseType.Normal, responseText);
            if (response.getError() != null) {
                RpcError error = response.getError();
                requestCallback.onError(new RemoteServerError(error));
            } else {
                T result = response.<T>getResult();
                requestCallback.onResponseReceived(result);
            }
        }
    });
}
Also used : JSONObject(com.google.gwt.json.client.JSONObject) RequestLogEntry(org.rstudio.core.client.jsonrpc.RequestLogEntry) GWT(com.google.gwt.core.client.GWT) RpcResponseHandler(org.rstudio.core.client.jsonrpc.RpcResponseHandler) RpcError(org.rstudio.core.client.jsonrpc.RpcError) JSONString(com.google.gwt.json.client.JSONString) JsArrayString(com.google.gwt.core.client.JsArrayString) RpcResponse(org.rstudio.core.client.jsonrpc.RpcResponse) JSONString(com.google.gwt.json.client.JSONString)

Example 2 with RequestLogEntry

use of org.rstudio.core.client.jsonrpc.RequestLogEntry in project rstudio by rstudio.

the class RequestLogVisualization method onPreviewNativeEvent.

public void onPreviewNativeEvent(NativePreviewEvent event) {
    if (event.getTypeInt() == Event.ONKEYDOWN) {
        int keyCode = event.getNativeEvent().getKeyCode();
        if (keyCode == KeyCodes.KEY_ESCAPE) {
            CloseEvent.fire(RequestLogVisualization.this, RequestLogVisualization.this);
            handlerRegistration_.removeHandler();
        } else if (keyCode == 'R' && KeyboardShortcut.getModifierValue(event.getNativeEvent()) == 0) {
            refresh(true, true);
        } else if (keyCode == 'P') {
            if (timerIsRunning_)
                timer_.cancel();
            else {
                timer_.run();
                timer_.scheduleRepeating(PERIOD_MILLIS);
            }
            timerIsRunning_ = !timerIsRunning_;
        } else if (keyCode == 'E') {
            CsvWriter writer = new CsvWriter();
            writer.writeValue(now_ + "");
            writer.endLine();
            for (RequestLogEntry entry : entries_) entry.toCsv(writer);
            TextBoxDialog dialog = new TextBoxDialog("Export", writer.getValue(), null);
            dialog.showModal();
        } else if (keyCode == 'I') {
            TextBoxDialog dialog = new TextBoxDialog("Import", "", new OperationWithInput<String>() {

                public void execute(String input) {
                    CsvReader reader = new CsvReader(input);
                    ArrayList<RequestLogEntry> entries = new ArrayList<RequestLogEntry>();
                    Iterator<String[]> it = reader.iterator();
                    String now = it.next()[0];
                    while (it.hasNext()) {
                        String[] line = it.next();
                        RequestLogEntry entry = RequestLogEntry.fromValues(line);
                        if (entry != null)
                            entries.add(entry);
                    }
                    now_ = Long.parseLong(now);
                    entries_ = entries.toArray(new RequestLogEntry[0]);
                    refresh(false, true);
                }
            });
            dialog.showModal();
        }
    } else if (event.getTypeInt() == Event.ONKEYPRESS) {
        if (event.getNativeEvent().getKeyCode() == '+') {
            scaleMillisToPixels_ *= 2.0;
            refresh(false, false);
        } else if (event.getNativeEvent().getKeyCode() == '-') {
            scaleMillisToPixels_ /= 2.0;
            refresh(false, false);
        }
    }
}
Also used : CsvReader(org.rstudio.core.client.CsvReader) CsvWriter(org.rstudio.core.client.CsvWriter) RequestLogEntry(org.rstudio.core.client.jsonrpc.RequestLogEntry) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 3 with RequestLogEntry

use of org.rstudio.core.client.jsonrpc.RequestLogEntry in project rstudio by rstudio.

the class RemoteServerAuth method updateCredentials.

public void updateCredentials(final ServerRequestCallback<Integer> requestCallback) {
    // safely cleanup any previously active update credentials forms
    safeCleanupPreviousUpdateCredentials();
    // create a hidden form panel to submit the update credentials to
    // (we do this so GWT manages the trickiness associated with 
    // managing and reading the contents of a hidden iframe) 
    final FormPanel updateCredentialsForm = new FormPanel();
    updateCredentialsForm.setMethod(FormPanel.METHOD_GET);
    updateCredentialsForm.setEncoding(FormPanel.ENCODING_URLENCODED);
    // form url
    String url = remoteServer_.getApplicationURL("auth-update-credentials");
    updateCredentialsForm.setAction(url);
    // request log entry (fake up a json rpc method call to conform
    // to the data format expected by RequestLog
    String requestId = Integer.toString(Random.nextInt());
    String requestData = createRequestData();
    final RequestLogEntry logEntry = RequestLog.log(requestId, requestData);
    // form submit complete handler
    updateCredentialsForm.addSubmitCompleteHandler(new SubmitCompleteHandler() {

        public void onSubmitComplete(SubmitCompleteEvent event) {
            // parse the results
            String results = event.getResults();
            RpcResponse response = RpcResponse.parse(event.getResults());
            if (response != null) {
                logEntry.logResponse(ResponseType.Normal, results);
                // check for error
                RpcError rpcError = response.getError();
                if (rpcError != null) {
                    if (rpcError.getCode() == RpcError.METHOD_NOT_FOUND) {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_UNSUPPORTED));
                    } else {
                        requestCallback.onError(new RemoteServerError(rpcError));
                    }
                } else // must be a valid response
                {
                    Bool authenticated = response.getResult();
                    if (authenticated.getValue()) {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_SUCCESS));
                    } else {
                        requestCallback.onResponseReceived(new Integer(CREDENTIALS_UPDATE_FAILURE));
                    }
                }
            } else // error parsing results
            {
                logEntry.logResponse(ResponseType.Error, results);
                // form message
                String msg = "Error parsing results: " + (results != null ? results : "(null)");
                // we don't expect this so debug log to flag our attention
                Debug.log("UPDATE CREDENTIALS: " + msg);
                // return the error
                RpcError rpcError = RpcError.create(RpcError.PARSE_ERROR, msg);
                requestCallback.onError(new RemoteServerError(rpcError));
            }
            // remove the hidden form (from both last-ditch list and DOM)
            previousUpdateCredentialsForms_.remove(updateCredentialsForm);
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {

                public void execute() {
                    RootPanel.get().remove(updateCredentialsForm);
                }
            });
        }
    });
    // add the (hidden) form panel to the document and last ditch list
    RootPanel.get().add(updateCredentialsForm, -1000, -1000);
    previousUpdateCredentialsForms_.add(updateCredentialsForm);
    // submit the form
    updateCredentialsForm.submit();
}
Also used : FormPanel(com.google.gwt.user.client.ui.FormPanel) RequestLogEntry(org.rstudio.core.client.jsonrpc.RequestLogEntry) ScheduledCommand(com.google.gwt.core.client.Scheduler.ScheduledCommand) Bool(org.rstudio.studio.client.server.Bool) RpcError(org.rstudio.core.client.jsonrpc.RpcError) JSONString(com.google.gwt.json.client.JSONString) SubmitCompleteEvent(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent) SubmitCompleteHandler(com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler) RpcResponse(org.rstudio.core.client.jsonrpc.RpcResponse)

Example 4 with RequestLogEntry

use of org.rstudio.core.client.jsonrpc.RequestLogEntry in project rstudio by rstudio.

the class RequestLogVisualization method refresh.

private void refresh(boolean reloadEntries, boolean scrollToEnd) {
    if (reloadEntries) {
        entries_ = RequestLog.getEntries();
        now_ = System.currentTimeMillis();
    }
    overviewPanel_.clear();
    startTime_ = entries_[0].getRequestTime();
    long duration = now_ - startTime_;
    int totalWidth = (int) (duration * scaleMillisToPixels_);
    totalHeight_ = entries_.length * BAR_HEIGHT;
    overviewPanel_.setSize(totalWidth + "px", totalHeight_ + "px");
    for (int i = 0, entriesLength = entries_.length; i < entriesLength; i++) {
        RequestLogEntry entry = entries_[i];
        addEntry(i, entry);
    }
    if (scrollToEnd) {
        scrollPanel_.scrollToTop();
        scrollPanel_.scrollToRight();
    }
}
Also used : RequestLogEntry(org.rstudio.core.client.jsonrpc.RequestLogEntry)

Aggregations

RequestLogEntry (org.rstudio.core.client.jsonrpc.RequestLogEntry)4 JSONString (com.google.gwt.json.client.JSONString)2 RpcError (org.rstudio.core.client.jsonrpc.RpcError)2 RpcResponse (org.rstudio.core.client.jsonrpc.RpcResponse)2 GWT (com.google.gwt.core.client.GWT)1 JsArrayString (com.google.gwt.core.client.JsArrayString)1 ScheduledCommand (com.google.gwt.core.client.Scheduler.ScheduledCommand)1 JSONObject (com.google.gwt.json.client.JSONObject)1 FormPanel (com.google.gwt.user.client.ui.FormPanel)1 SubmitCompleteEvent (com.google.gwt.user.client.ui.FormPanel.SubmitCompleteEvent)1 SubmitCompleteHandler (com.google.gwt.user.client.ui.FormPanel.SubmitCompleteHandler)1 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 CsvReader (org.rstudio.core.client.CsvReader)1 CsvWriter (org.rstudio.core.client.CsvWriter)1 RpcResponseHandler (org.rstudio.core.client.jsonrpc.RpcResponseHandler)1 Bool (org.rstudio.studio.client.server.Bool)1