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

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

Introduction

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

Prototype

public String getUrl() 

Source Link

Document

Returns the HTTP URL specified in the constructor.

Usage

From source file:org.fusesource.restygwt.client.dispatcher.CachingRetryingDispatcher.java

License:Apache License

public Request send(Method method, RequestBuilder builder) throws RequestException {

    RequestCallback outerRequestCallback = builder.getCallback();
    final CacheKey cacheKey = new CacheKey(builder);

    final Response cachedResponse = cacheStorage.getResultOrReturnNull(cacheKey);

    if (cachedResponse != null) {

        outerRequestCallback.onResponseReceived(null, cachedResponse);
        return null;

    } else {/*from  w ww . j  a v  a 2 s  . c o m*/

        RequestCallback retryingCallback = new CachingRetryingCallback(builder, outerRequestCallback);
        builder.setCallback(retryingCallback);

        GWT.log("Sending http request: " + builder.getHTTPMethod() + " " + builder.getUrl() + " ,timeout:"
                + builder.getTimeoutMillis(), null);

        String content = builder.getRequestData();

        if (content != null && content.length() > 0) {
            GWT.log(content, null);
        }

        return builder.send();
    }

}

From source file:org.fusesource.restygwt.client.dispatcher.DefaultDispatcher.java

License:Apache License

public Request send(Method method, RequestBuilder builder) throws RequestException {
    GWT.log("Sending http request: " + builder.getHTTPMethod() + " " + builder.getUrl() + " ,timeout:"
            + builder.getTimeoutMillis(), null);

    String content = builder.getRequestData();
    if (content != null && content.length() > 0) {
        GWT.log(content, null);//from  w  ww  .ja v  a 2  s .c o  m
    }
    return builder.send();
}

From source file:org.fusesource.restygwt.client.dispatcher.DefaultDispatcherFilter.java

License:Apache License

/**
 * main filter method for a dispatcherfilter.
 *
 * @return continue filtering or not/*from  www .j  a  va 2 s  . c o  m*/
 */
@Override
public boolean filter(final Method method, final RequestBuilder builder) {
    if (LogConfiguration.loggingIsEnabled()) {
        Logger.getLogger(Dispatcher.class.getName())
                .info("Sending http request: " + builder.getHTTPMethod() + " " + builder.getUrl());
    }

    builder.setCallback(callbackFactory.createCallback(method));
    return true;
}

From source file:org.fusesource.restygwt.client.dispatcher.DefaultFilterawareDispatcher.java

License:Apache License

@Override
public Request send(Method method, RequestBuilder builder) throws RequestException {
    for (DispatcherFilter f : dispatcherFilters) {
        if (!f.filter(method, builder)) {
            // filter returned false, no continue
            if (GWT.isClient() && LogConfiguration.loggingIsEnabled()) {
                Logger.getLogger(DefaultFilterawareDispatcher.class.getName())
                        .fine(f.getClass() + " told me not to continue filtering for: "
                                + builder.getHTTPMethod() + " " + builder.getUrl());
            }/*from   www  . j av a2 s  . c om*/
            return null;
        }
    }

    return builder.send();
}

From source file:org.fusesource.restygwt.client.dispatcher.FilterawareRetryingDispatcher.java

License:Apache License

public Request send(Method method, RequestBuilder builder) throws RequestException {
    for (DispatcherFilter f : dispatcherFilters) {
        if (!f.filter(method, builder)) {
            // filter returned false, no continue
            if (LogConfiguration.loggingIsEnabled()) {
                Logger.getLogger(FilterawareRetryingDispatcher.class.getName())
                        .fine(f.getClass() + " told me not to continue filtering for: "
                                + builder.getHTTPMethod() + " " + builder.getUrl());
            }//from   w ww .  java 2  s .c o  m
            return null;
        }
    }

    return builder.send();
}

From source file:org.jboss.bpm.console.client.Authentication.java

License:Open Source License

/**
 * Login using specific credentials.//from   w ww  .j  a  v a 2s  .  c o  m
 * This delegates to {@link com.google.gwt.http.client.RequestBuilder#setUser(String)}
 * and {@link com.google.gwt.http.client.RequestBuilder#setPassword(String)}
 */
private void requestAssignedRoles() {
    RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, rolesUrl);

    ConsoleLog.debug("Request roles: " + rb.getUrl());

    /*if (user != null && pass != null)
    {
      rb.setUser(user);
      rb.setPassword(pass);
            
      if (!GWT.isScript()) // hosted mode only
      {
        rb.setHeader("xtest-user", user);
        rb.setHeader("xtest-pass", pass); // NOTE: This is plaintext, use for testing only
      }
    }*/

    try {
        rb.sendRequest(null, new RequestCallback() {

            public void onResponseReceived(Request request, Response response) {
                ConsoleLog.debug("requestAssignedRoles() HTTP " + response.getStatusCode());

                // parse roles
                if (200 == response.getStatusCode()) {
                    rolesAssigned = Authentication.parseRolesAssigned(response.getText());
                    if (callback != null)
                        callback.onLoginSuccess(request, response);
                } else {
                    onError(request, new Exception(response.getText()));
                }
            }

            public void onError(Request request, Throwable t) {
                // auth failed
                // Couldn't connect to server (could be timeout, SOP violation, etc.)
                if (callback != null)
                    callback.onLoginFailed(request, t);
                else
                    throw new RuntimeException("Unknown exception upon login attempt", t);
            }
        });
    }

    catch (RequestException e1) {
        // Couldn't connect to server
        throw new RuntimeException("Unknown error upon login attempt", e1);
    }
}

From source file:org.jboss.errai.ui.shared.ServerTemplateProvider.java

License:Apache License

@Override
public void provideTemplate(final String url, final TemplateRenderingCallback renderingCallback) {
    final RequestBuilder request = new RequestBuilder(RequestBuilder.GET, url);
    request.setCallback(new RequestCallback() {
        @Override//from  w  w w .  j av  a  2s  .c om
        public void onResponseReceived(Request request, Response response) {
            if (response.getStatusCode() == Response.SC_OK) {
                renderingCallback.renderTemplate(response.getText());
            } else {
                throw new RuntimeException("Failed to retrieve template from server at " + url
                        + " (status code: " + response.getStatusCode() + ")");
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
            throw new RuntimeException("Failed to retrieve template from server at " + url, exception);
        }
    });

    try {
        request.send();
    } catch (RequestException e) {
        throw new RuntimeException("Failed to retrieve template from server at" + request.getUrl(), e);
    }
}

From source file:org.vectomatic.svg.edu.client.Main.java

License:Open Source License

public void readDots() {
    // Add a bogus query to bypass the browser cache as advised by:
    // https://developer.mozilla.org/En/Using_XMLHttpRequest#Bypassing_the_cache
    String url = getDotsUrl();/*from   w w  w  . j a  v a 2 s .c o  m*/
    url += (url.indexOf("?") == -1) ? ("?ts=" + System.currentTimeMillis())
            : ("&ts=" + +System.currentTimeMillis());
    final RequestBuilder dotsBuilder = new RequestBuilder(RequestBuilder.GET, getDotsUrl());
    dotsBuilder.setCallback(new RequestCallback() {
        /**
         * Create a blank dots structure
         */
        public void onError(Request request, Throwable exception) {
            if (mode == Mode.GAME) {
                mode = Mode.DESIGN;
                readPicture(true);
                return;
            }
            OMSVGSVGElement svg = doc.createSVGSVGElement();
            svg.setAttribute(SVGConstants.XMLNS_PREFIX, SVGConstants.SVG_NAMESPACE_URI);
            svg.setAttribute(SVGConstants.XMLNS_PREFIX + ":" + SVGConstants.XLINK_PREFIX,
                    SVGConstants.XLINK_NAMESPACE_URI);
            rootSvg.replaceChild(svg, dotSvg);
            dotSvg = svg;

            // Synchronize the the dot coordinates with the picture coordinates
            if (mode == Mode.DESIGN) {
                dotSvg.setViewBox(pictureSvg.getViewBox().getBaseVal());
            }

            // Reset the polyline
            lineGroup = doc.createSVGGElement();
            dotSvg.appendChild(lineGroup);
            polyline = doc.createSVGPolylineElement();
            polyline.setClassNameBaseVal(STYLE_LINE2);
            points = polyline.getPoints();
            lineGroup.appendChild(polyline);

            // Reset the dots
            dotGroup = doc.createSVGGElement();
            dotSvg.appendChild(dotGroup);
        }

        /**
         * Create a dots structure populated by the SVG data
         */
        private void onSuccess(Request request, Response response) {
            OMSVGSVGElement svg = OMSVGParser.parse(response.getText());
            rootSvg.replaceChild(svg, dotSvg);
            dotSvg = svg;

            // Synchronize the the dot coordinates with the picture coordinates
            if (mode == Mode.DESIGN) {
                dotSvg.setViewBox(pictureSvg.getViewBox().getBaseVal());
            }

            dotGroup = (OMSVGGElement) dotSvg.getFirstChild();
            // Reset the polyline
            lineGroup = doc.createSVGGElement();
            dotSvg.appendChild(lineGroup);
            polyline = doc.createSVGPolylineElement();
            polyline.setClassNameBaseVal(STYLE_LINE2);
            points = polyline.getPoints();
            lineGroup.appendChild(polyline);

            // Parse the dots to recreate the polyline
            OMNodeList childNodes = dotGroup.getChildNodes();
            for (int i = 0, size = childNodes.getLength(); i < size; i++) {
                OMSVGGElement g1 = (OMSVGGElement) childNodes.getItem(i);
                g1.addMouseDownHandler(Main.this);
                if (mode == Mode.DESIGN) {
                    g1.addMouseMoveHandler(Main.this);
                    g1.addMouseUpHandler(Main.this);
                }
                g1.addMouseOverHandler(Main.this);
                g1.addMouseOutHandler(Main.this);
                dots.add(g1);
                dotList.addItem(toDotName(i));
                if (mode == Mode.DESIGN) {
                    OMSVGMatrix m = g1.getTransform().getBaseVal().getItem(0).getMatrix();
                    points.appendItem(dotSvg.createSVGPoint(m.getE(), m.getF()));
                }
            }
        }

        public void onResponseReceived(Request request, Response response) {

            if (response.getStatusCode() == Response.SC_OK) {
                onSuccess(request, response);
            } else {
                if (mode == Mode.GAME) {
                    mode = Mode.DESIGN;
                    readPicture(true);
                    return;
                }
                onError(request, null);
            }

            if (mode == Mode.DESIGN) {
                pictureSvg.getStyle().setSVGProperty(SVGConstants.SVG_FILTER_ATTRIBUTE,
                        DOMHelper.toUrl(ID_ALPHA1_FILTER));
                setPictureAlpha(1f);
                showLineCheck.setValue(false);
                pictureAlphaSlider.setCurrentValue(1);
            } else {
                pictureSvg.getStyle().setVisibility(Visibility.HIDDEN);
                polyline.setClassNameBaseVal(STYLE_LINE1);
            }
            dotAlpha.setValue(1f);
            dotSvg.getStyle().setSVGProperty(SVGConstants.SVG_FILTER_ATTRIBUTE,
                    DOMHelper.toUrl(ID_ALPHA2_FILTER));
            designPanel.setVisible(mode == Mode.DESIGN);

            // Resize to the size of the window
            updatePictureSize();
            updateUI();
        }
    });
    // Send the dots request
    try {
        dotsBuilder.send();
    } catch (RequestException e) {
        GWT.log("Cannot fetch " + dotsBuilder.getUrl(), e);
    }

}