Example usage for com.google.gwt.http.client RequestBuilder GET

List of usage examples for com.google.gwt.http.client RequestBuilder GET

Introduction

In this page you can find the example usage for com.google.gwt.http.client RequestBuilder GET.

Prototype

Method GET

To view the source code for com.google.gwt.http.client RequestBuilder GET.

Click Source Link

Document

Specifies that the HTTP GET method should be used.

Usage

From source file:org.qipki.clients.web.client.ui.widgets.ExternalResourcePanel.java

License:Open Source License

public void load(final String url, final RequestCallback callback) {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
    rb.setCallback(new RequestCallback() {

        @Override/*from   w w w  .  ja  va2  s.  c om*/
        public void onResponseReceived(final Request request, final Response response) {
            new Timer() {

                @Override
                public void run() {
                    panel.clear();
                    panel.add(new HTMLPanel(response.getText()));
                    ExternalResourcePanel.this.url = url;
                    callback.onResponseReceived(request, response);
                }

            }.schedule(2000);
        }

        @Override
        public void onError(Request request, Throwable exception) {
            panel.clear();
            panel.add(new Label("Request ERROR: " + exception.getMessage()));
            callback.onError(request, exception);
        }

    });
    panel.clear();
    if (loadingPanel != null) {
        panel.setWidget(loadingPanel);
    }
    try {
        rb.send();
    } catch (RequestException ex) {
        panel.add(new Label("Request EXCEPTION: " + ex.getMessage()));
    }
}

From source file:org.rapla.rest.gwtjsonrpc.client.impl.JsonCall20HttpGet.java

License:Apache License

@Override
protected void send() {
    requestId = ++lastRequestId;//from w w  w . j a v  a 2 s. c om
    final StringBuilder url = new StringBuilder(proxy.getServiceEntryPoint());
    url.append("?jsonrpc=2.0&method=").append(methodName);
    url.append("&params=").append(encodedRequestParams);
    url.append("&id=").append(requestId);

    final RequestBuilder rb;
    rb = new RequestBuilder(RequestBuilder.GET, url.toString());
    rb.setHeader("Content-Type", JsonConstants.JSONRPC20_REQ_CT);
    rb.setHeader("Accept", JsonConstants.JSONRPC20_ACCEPT_CTS);
    rb.setCallback(this);

    send(rb);
}

From source file:org.rebioma.client.Uploader.java

License:Apache License

/**
 * Sends a request to the server in order to get the blobstore path.
 * When the response with the session comes, it submits the form.
 *//*w  w  w . j a  v a  2 s. c o m*/
private void sendAjaxRequestToGetBlobstorePath() throws RequestException {
    RequestBuilder reqBuilder = new RequestBuilder(RequestBuilder.GET, getServletPath());//composeURL("blobstore=true"));
    reqBuilder.setTimeoutMillis(DEFAULT_AJAX_TIMEOUT);
    reqBuilder.sendRequest("blobstore", onBlobstoreReceivedCallback);
}

From source file:org.rhq.enterprise.gui.coregui.client.inventory.groups.detail.ResourceGroupContextMenu.java

License:Open Source License

private MenuItem buildMetricsMenu(final ResourceType type) {
    MenuItem measurements = new MenuItem(MSG.view_tree_common_contextMenu_measurements());
    final Menu measurementsSubMenu = new Menu();

    DashboardCriteria criteria = new DashboardCriteria();
    GWTServiceLookup.getDashboardService().findDashboardsByCriteria(criteria,
            new AsyncCallback<PageList<Dashboard>>() {
                public void onFailure(Throwable caught) {
                    CoreGUI.getErrorHandler()
                            .handleError(MSG.view_tree_common_contextMenu_loadFail_dashboards(), caught);
                }/* w w  w .  j a v a2 s .c o m*/

                public void onSuccess(PageList<Dashboard> result) {

                    if (type.getMetricDefinitions() != null) {
                        //sort the display items alphabetically
                        TreeSet<String> ordered = new TreeSet<String>();
                        Map<String, MeasurementDefinition> definitionMap = new HashMap<String, MeasurementDefinition>();
                        for (MeasurementDefinition m : type.getMetricDefinitions()) {
                            ordered.add(m.getDisplayName());
                            definitionMap.put(m.getDisplayName(), m);
                        }

                        for (String displayName : ordered) {
                            final MeasurementDefinition def = definitionMap.get(displayName);
                            //only add menu items for Measurement
                            if (def.getDataType().equals(DataType.MEASUREMENT)) {
                                MenuItem defItem = new MenuItem(def.getDisplayName());
                                measurementsSubMenu.addItem(defItem);
                                Menu defSubItem = new Menu();
                                defItem.setSubmenu(defSubItem);

                                for (final Dashboard d : result) {
                                    MenuItem addToDBItem = new MenuItem(
                                            MSG.view_tree_common_contextMenu_addChartToDashboard(d.getName()));
                                    defSubItem.addItem(addToDBItem);

                                    addToDBItem.addClickHandler(new ClickHandler() {
                                        public void onClick(MenuItemClickEvent menuItemClickEvent) {

                                            DashboardPortlet p = new DashboardPortlet(
                                                    MSG.view_tree_common_contextMenu_groupGraph(),
                                                    ResourceGroupGraphPortlet.KEY, 250);
                                            p.getConfiguration()
                                                    .put(new PropertySimple(
                                                            ResourceGroupGraphPortlet.CFG_RESOURCE_GROUP_ID,
                                                            group.getId()));
                                            p.getConfiguration().put(new PropertySimple(
                                                    ResourceGroupGraphPortlet.CFG_DEFINITION_ID, def.getId()));

                                            d.addPortlet(p);

                                            GWTServiceLookup.getDashboardService().storeDashboard(d,
                                                    new AsyncCallback<Dashboard>() {
                                                        public void onFailure(Throwable caught) {
                                                            CoreGUI.getErrorHandler().handleError(MSG
                                                                    .view_tree_common_contextMenu_saveChartToDashboardFailure(),
                                                                    caught);
                                                        }

                                                        public void onSuccess(Dashboard result) {
                                                            String msg = MSG
                                                                    .view_tree_common_contextMenu_saveChartToDashboardSuccessful(
                                                                            result.getName());
                                                            CoreGUI.getMessageCenter().notify(
                                                                    new Message(msg, Message.Severity.Info));
                                                        }
                                                    });

                                        }
                                    });

                                    //add new menu item for adding current graphable element to view if on Monitor/Graphs tab
                                    String currentViewPath = History.getToken();
                                    if (currentViewPath.indexOf("Monitoring/Graphs") > -1) {
                                        MenuItem addGraphItem = new MenuItem(
                                                MSG.common_title_add_graph_to_view());
                                        defSubItem.addItem(addGraphItem);

                                        addGraphItem.addClickHandler(new ClickHandler() {
                                            public void onClick(MenuItemClickEvent menuItemClickEvent) {
                                                //generate javascript to call out to.
                                                //Ex. menuLayers.hide();addMetric('${metric.resourceId},${metric.scheduleId}')
                                                String grpGraphElements = "";
                                                if (isAutoGroup) {
                                                    grpGraphElements += "ag,";
                                                } else {
                                                    grpGraphElements += "cg,";
                                                }
                                                grpGraphElements += group.getId() + "," + def.getId();
                                                if (isAutoGroup) {//need to postpend the resource type as third element
                                                    grpGraphElements += "," + group.getResourceType().getId();
                                                }
                                                //construct portal.war url to access
                                                String baseUrl = "/resource/common/monitor/visibility/IndicatorCharts.do";
                                                //No need to rebuild the autogroup url as everything handled as a compatible group now
                                                //                                                if (isAutoGroup) {
                                                //                                                    //Ex. ?parent=10001&ctype=1013&view=Default
                                                //                                                    baseUrl += "?parent=" + group.getAutoGroupParentResource().getId()
                                                //                                                        + "&ctype="
                                                //                                                        + group.getResourceType().getId();
                                                //                                                    jsCode = "ag," + group.getAutoGroupParentResource().getId() + ","
                                                //                                                        + def.getId() + ","
                                                //                                                        + group.getResourceType().getId();
                                                //                                                } else {
                                                //Ex. ?groupId=10001&view=Default
                                                baseUrl += "?groupId=" + group.getId();
                                                baseUrl += "&view=Default";
                                                baseUrl += "&action=addChart&metric=" + grpGraphElements;
                                                baseUrl += "&view=Default";
                                                final String url = baseUrl;
                                                //initiate HTTP request
                                                final RequestBuilder b = new RequestBuilder(RequestBuilder.GET,
                                                        baseUrl);

                                                try {
                                                    b.setCallback(new RequestCallback() {
                                                        public void onResponseReceived(final Request request,
                                                                final Response response) {
                                                            Log.trace(
                                                                    "Successfully submitted request to add graph to view:"
                                                                            + url);

                                                            //kick off a page reload.
                                                            String currentViewPath = History.getToken();
                                                            CoreGUI.goToView(currentViewPath, true);
                                                        }

                                                        @Override
                                                        public void onError(Request request, Throwable t) {
                                                            Log.trace("Error adding Metric:" + url, t);
                                                        }
                                                    });
                                                    b.send();
                                                } catch (RequestException e) {
                                                    Log.trace("Error adding Metric:" + url, e);
                                                }
                                            }//end of onClick definition
                                        });//end of onClick Handler definition
                                    } //end of Monitoring/Graphs view check
                                } //end of dashabord iteration
                            } //end of check for Measurement
                        } //end of metric definition iteration
                    }

                }
            });
    measurements.setSubmenu(measurementsSubMenu);
    return measurements;
}

From source file:org.rhq.enterprise.gui.coregui.client.inventory.resource.detail.ResourceTreeView.java

License:Open Source License

private MenuItem buildMetricsMenu(final ResourceType type, final Resource resource) {
    MenuItem measurements = new MenuItem(MSG.view_tree_common_contextMenu_measurements());
    final Menu measurementsSubMenu = new Menu();

    DashboardCriteria criteria = new DashboardCriteria();
    GWTServiceLookup.getDashboardService().findDashboardsByCriteria(criteria,
            new AsyncCallback<PageList<Dashboard>>() {

                public void onFailure(Throwable caught) {
                    CoreGUI.getErrorHandler()
                            .handleError(MSG.view_tree_common_contextMenu_loadFailed_dashboard(), caught);
                }/*from w w w . j  av a2  s .c  o m*/

                public void onSuccess(PageList<Dashboard> result) {
                    //sort the display items alphabetically
                    TreeSet<String> ordered = new TreeSet<String>();
                    Map<String, MeasurementDefinition> definitionMap = new HashMap<String, MeasurementDefinition>();
                    for (MeasurementDefinition m : type.getMetricDefinitions()) {
                        ordered.add(m.getDisplayName());
                        definitionMap.put(m.getDisplayName(), m);
                    }

                    for (String displayName : ordered) {
                        final MeasurementDefinition def = definitionMap.get(displayName);
                        //only add menu items for Measurement
                        if (def.getDataType().equals(DataType.MEASUREMENT)) {
                            MenuItem defItem = new MenuItem(def.getDisplayName());
                            measurementsSubMenu.addItem(defItem);
                            Menu defSubItem = new Menu();
                            defItem.setSubmenu(defSubItem);

                            for (final Dashboard d : result) {
                                MenuItem addToDBItem = new MenuItem(
                                        MSG.view_tree_common_contextMenu_addChartToDashboard(d.getName()));
                                defSubItem.addItem(addToDBItem);

                                addToDBItem.addClickHandler(new ClickHandler() {

                                    public void onClick(MenuItemClickEvent menuItemClickEvent) {
                                        DashboardPortlet p = new DashboardPortlet(
                                                MSG.view_tree_common_contextMenu_resourceGraph(),
                                                ResourceGraphPortlet.KEY, 250);
                                        p.getConfiguration().put(new PropertySimple(
                                                ResourceGraphPortlet.CFG_RESOURCE_ID, resource.getId()));
                                        p.getConfiguration().put(new PropertySimple(
                                                ResourceGraphPortlet.CFG_DEFINITION_ID, def.getId()));

                                        d.addPortlet(p);

                                        GWTServiceLookup.getDashboardService().storeDashboard(d,
                                                new AsyncCallback<Dashboard>() {

                                                    public void onFailure(Throwable caught) {
                                                        CoreGUI.getErrorHandler().handleError(MSG
                                                                .view_tree_common_contextMenu_saveChartToDashboardFailure(),
                                                                caught);
                                                    }

                                                    public void onSuccess(Dashboard result) {
                                                        CoreGUI.getMessageCenter().notify(new Message(MSG
                                                                .view_tree_common_contextMenu_saveChartToDashboardSuccessful(
                                                                        result.getName()),
                                                                Message.Severity.Info));
                                                    }
                                                });

                                    }
                                });
                            } //end dashboard iteration

                            //add new menu item for adding current graphable element to view if on Monitor/Graphs tab
                            String currentViewPath = History.getToken();
                            if (currentViewPath.indexOf("Monitoring/Graphs") > -1) {
                                MenuItem addGraphItem = new MenuItem(MSG.common_title_add_graph_to_view());
                                defSubItem.addItem(addGraphItem);

                                addGraphItem.addClickHandler(new ClickHandler() {
                                    public void onClick(MenuItemClickEvent menuItemClickEvent) {
                                        //generate javascript to call out to.
                                        //Ex. menuLayers.hide();addMetric('${metric.resourceId},${metric.scheduleId}')
                                        if (getScheduleDefinitionId(resource, def.getName()) > -1) {
                                            String resourceGraphElements = resource.getId() + ","
                                                    + getScheduleDefinitionId(resource, def.getName());

                                            //construct portal.war url to access
                                            String baseUrl = "/resource/common/monitor/visibility/IndicatorCharts.do";
                                            baseUrl += "?id=" + resource.getId();
                                            baseUrl += "&view=Default";
                                            baseUrl += "&action=addChart&metric=" + resourceGraphElements;
                                            baseUrl += "&view=Default";
                                            final String url = baseUrl;
                                            //initiate HTTP request
                                            final RequestBuilder b = new RequestBuilder(RequestBuilder.GET,
                                                    baseUrl);

                                            try {
                                                b.setCallback(new RequestCallback() {
                                                    public void onResponseReceived(final Request request,
                                                            final Response response) {
                                                        Log.trace(
                                                                "Successfully submitted request to add graph to view:"
                                                                        + url);

                                                        //kick off a page reload.
                                                        String currentViewPath = History.getToken();
                                                        CoreGUI.goToView(currentViewPath, true);
                                                    }

                                                    @Override
                                                    public void onError(Request request, Throwable t) {
                                                        Log.trace("Error adding Metric:" + url, t);
                                                    }
                                                });
                                                b.send();
                                            } catch (RequestException e) {
                                                Log.trace("Error adding Metric:" + url, e);
                                            }
                                        }
                                    }
                                });
                            } // end add the "add to view" menu item
                        } //end trait exclusion
                    } //end measurement def iteration

                }
            });
    measurements.setSubmenu(measurementsSubMenu);
    return measurements;
}

From source file:org.roda.wui.client.browse.BitstreamPreview.java

private void textPreview() {
    if (StringUtils.isBlank(viewers.getTextLimit()) || size <= Long.parseLong(viewers.getTextLimit())) {
        RequestBuilder request = new RequestBuilder(RequestBuilder.GET, bitstreamDownloadUri.asString());
        try {// ww  w . j av  a2  s  .  com
            request.sendRequest(null, new RequestCallback() {

                @Override
                public void onResponseReceived(Request request, Response response) {
                    if (response.getStatusCode() == HttpStatus.SC_OK) {
                        HTML html = new HTML(
                                "<pre><code>" + SafeHtmlUtils.htmlEscape(response.getText()) + "</code></pre>");
                        FlowPanel frame = new FlowPanel();
                        frame.add(html);

                        panel.add(frame);
                        frame.setStyleName("viewRepresentationTextFilePreview");
                        JavascriptUtils.runHighlighter(html.getElement());
                    } else {
                        errorPreview();
                    }
                }

                @Override
                public void onError(Request request, Throwable exception) {
                    errorPreview();
                }
            });
        } catch (RequestException e) {
            errorPreview();
        }
    } else {
        errorPreview(messages.viewRepresentationTooLargeErrorPreview());
    }
}

From source file:org.roda.wui.client.browse.BrowseAIP.java

private void getDescriptiveMetadataHTML(final String aipId, final String descId,
        final DescriptiveMetadataViewBundle bundle, final AsyncCallback<SafeHtml> callback) {
    SafeUri uri = RestUtils.createDescriptiveMetadataHTMLUri(aipId, descId);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {/*from   w  ww .ja v  a2  s  .co m*/
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                String escapedDescId = SafeHtmlUtils.htmlEscape(descId);

                if (200 == response.getStatusCode()) {
                    String html = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, escapedDescId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, escapedDescId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    // Download link
                    SafeUri downloadUri = RestUtils.createDescriptiveMetadataDownloadUri(aipId, escapedDescId);
                    String downloadLinkHtml = "<a href='" + downloadUri.asString()
                            + "' class='toolbarLink'><i class='fa fa-download'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(downloadLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataHTML'>"));
                    b.append(SafeHtmlUtils.fromTrustedString(html));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, escapedDescId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, escapedDescId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        callback.onFailure(e);
    }
}

From source file:org.roda.wui.client.browse.BrowseRepresentation.java

private void getDescriptiveMetadataHTML(final String descId, final DescriptiveMetadataViewBundle bundle,
        final AsyncCallback<SafeHtml> callback) {
    SafeUri uri = RestUtils.createRepresentationDescriptiveMetadataHTMLUri(aipId, repId, descId);
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {/*from w  ww  .  ja v  a 2 s.c o  m*/
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String html = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, repId, descId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }
                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, repId, descId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    // Download link
                    SafeUri downloadUri = RestUtils.createRepresentationDescriptiveMetadataDownloadUri(aipId,
                            repId, descId);
                    String downloadLinkHtml = "<a href='" + downloadUri.asString()
                            + "' class='toolbarLink'><i class='fa fa-download'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(downloadLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataHTML'>"));
                    b.append(SafeHtmlUtils.fromTrustedString(html));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='descriptiveMetadataLinks'>"));

                    if (bundle.hasHistory()) {
                        // History link
                        String historyLink = HistoryUtils.createHistoryHashLink(
                                DescriptiveMetadataHistory.RESOLVER, aipId, repId, descId);
                        String historyLinkHtml = "<a href='" + historyLink
                                + "' class='toolbarLink'><i class='fa fa-history'></i></a>";
                        b.append(SafeHtmlUtils.fromSafeConstant(historyLinkHtml));
                    }

                    // Edit link
                    String editLink = HistoryUtils.createHistoryHashLink(EditDescriptiveMetadata.RESOLVER,
                            aipId, repId, descId);
                    String editLinkHtml = "<a href='" + editLink
                            + "' class='toolbarLink'><i class='fa fa-edit'></i></a>";
                    b.append(SafeHtmlUtils.fromSafeConstant(editLinkHtml));

                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (RequestException e) {
        callback.onFailure(e);
    }
}

From source file:org.roda.wui.client.browse.DescriptiveMetadataHistory.java

private void getDescriptiveMetadata(final String aipId, final String representationId, final String descId,
        final String versionKey, final boolean inHTML, final AsyncCallback<SafeHtml> callback) {

    SafeUri uri;//from  w  ww  .j  a  va  2  s. c om
    if (inHTML) {
        if (representationId != null) {
            uri = RestUtils.createRepresentationDescriptiveMetadataHTMLUri(aipId, representationId, descId,
                    versionKey);
        } else {
            uri = RestUtils.createDescriptiveMetadataHTMLUri(aipId, descId, versionKey);
        }
    } else {
        if (representationId != null) {
            uri = RestUtils.createRepresentationDescriptiveMetadataDownloadUri(aipId, representationId, descId,
                    versionKey);
        } else {
            uri = RestUtils.createDescriptiveMetadataDownloadUri(aipId, descId, versionKey);
        }
    }
    RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.GET, uri.asString());
    requestBuilder.setHeader("Authorization", "Custom");
    try {
        requestBuilder.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if (200 == response.getStatusCode()) {
                    String text = response.getText();

                    SafeHtmlBuilder b = new SafeHtmlBuilder();
                    if (inHTML) {
                        b.append(SafeHtmlUtils.fromTrustedString(text));
                    } else {
                        b.append(SafeHtmlUtils.fromString(text));
                    }
                    SafeHtml safeHtml = b.toSafeHtml();

                    callback.onSuccess(safeHtml);
                } else {
                    String text = response.getText();
                    String message;
                    try {
                        RestErrorOverlayType error = (RestErrorOverlayType) JsonUtils.safeEval(text);
                        message = error.getMessage();
                    } catch (IllegalArgumentException e) {
                        message = text;
                    }

                    SafeHtmlBuilder b = new SafeHtmlBuilder();

                    // error message
                    b.append(SafeHtmlUtils.fromSafeConstant("<div class='error'>"));
                    b.append(messages.descriptiveMetadataTransformToHTMLError());
                    b.append(SafeHtmlUtils.fromSafeConstant("<pre><code>"));
                    b.append(SafeHtmlUtils.fromString(message));
                    b.append(SafeHtmlUtils.fromSafeConstant("</core></pre>"));
                    b.append(SafeHtmlUtils.fromSafeConstant("</div>"));

                    callback.onSuccess(b.toSafeHtml());
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
                callback.onFailure(exception);
            }
        });
    } catch (

    RequestException e)

    {
        callback.onFailure(e);
    }

}