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

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

Introduction

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

Prototype

Method POST

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

Click Source Link

Document

Specifies that the HTTP POST method should be used.

Usage

From source file:org.geosdi.geoplatform.gui.client.form.GPPrintWidget.java

License:Open Source License

@Override
public void execute() {
    if (formPanel.isValid()) {
        layerList = buildLayerList();/*from  w  ww.  j a v a 2s  . c  o m*/
        if (layerList.isEmpty()) {
            GeoPlatformMessage.alertMessage(INSTANCE.GPPrintWidget_warningMessageLayersEmptyListText(),
                    INSTANCE.GPPrintWidget_warningMessageLayersEmptyListText());
            return;
        }

        logger.log(Level.FINEST, "Execute ......");
        // Center on correct ViewPort
        LonLat center = printExtent.getDataExtent().getCenterLonLat();
        if (GPApplicationMap.getInstance().getApplicationMap().getMap().getProjection()
                .equals(GPCoordinateReferenceSystem.WGS_84.getCode())) {
            center.transform(GPCoordinateReferenceSystem.WGS_84.getCode(),
                    GPCoordinateReferenceSystem.GOOGLE_MERCATOR.getCode());
        }

        String specJson = "";

        specJson = "{\"layout\":\"" + comboTemplate.getValue().getTemplate() + "\""
                + ",\"srs\":\"EPSG:3857\",\"units\": \"m\",\"geodetic\":true,\"outputFilename\":\"gp-map\", \"outputFormat\":\"pdf\",";

        //            String layers = "{\"title\":\"" + title.getValue() + "\",\"pages\":[{\"center\":["
        //                    + center.lon() + ","
        //                    + center.lat()
        //                    + "],\"scale\":" + getCurrentScale()
        //                    + ",\"rotation\":0,\"mapTitle\":\"" + mapTitle.getValue()
        //                    + "\",\"comment\":\"" + comments.getValue() + "\"}],\"layers\":[";
        specJson = specJson.concat(buildBaseLayerJson());

        String pagesJson = "\"pages\": [" + "{" + "\"center\": [" + center.lon() + "," + center.lat() + "],"
                + "\"scale\": " + getCurrentScale() + "," + "\"dpi\": " + comboDPI.getValue().getDpi() + ","
                + "\"mapTitle\": \"" + mapTitle.getValue() + "\"," + "\"title\": \"" + title.getValue() + "\","
                + "\"comment\": \"" + comments.getValue() + "\"" + "}" + "],\n";

        String legendJson = "\"legends\": [";
        String legendLayers = buildLegendLayerJson();
        String legendEnd = "]}";

        specJson = specJson.concat(pagesJson + legendJson + legendLayers + legendEnd);

        String url = GWT.getHostPageBaseURL() + GWT.getModuleName() + "/pdf/create.json";

        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url);

        String jsonData = "spec=" + specJson;

        builder.setHeader("Content-Type", "application/x-www-form-urlencoded");
        try {
            Info.display(INSTANCE.printText(), INSTANCE.GPPrintWidget_infoStartPringBodyText());
            logger.log(Level.INFO, jsonData);
            Request response = builder.sendRequest(jsonData, new RequestCallback() {

                @Override
                public void onError(Request request, Throwable exception) {
                    Window.alert(exception.getLocalizedMessage());
                }

                @Override
                public void onResponseReceived(Request request, Response response) {
                    Info.display(INSTANCE.printText(), INSTANCE.GPPrintWidget_infoFinishPrintBodyText());
                    String downloadURL = response.getText().substring(11,
                            response.getText().indexOf("printout") + 8);

                    Window.open(downloadURL, "_blank", "");

                }
            });
        } catch (RequestException ex) {
            Logger.getLogger(GPPrintWidget.class.getName()).log(Level.SEVERE, null, ex);
        }

        this.hide();
    }

}

From source file:org.gss_project.gss.web.client.rest.MultiplePostCommand.java

License:Open Source License

public MultiplePostCommand(String[] pathToDelete, String data, final int okStatusCode, boolean showLoading) {
    setShowLoadingIndicator(showLoading);
    if (isShowLoadingIndicator())
        GSS.get().showLoadingIndicator("Updating " + pathToDelete.length + " items", null);
    paths = pathToDelete;/*  w  w  w.  j a  v  a  2s. c o m*/
    for (final String pathg : pathToDelete) {
        GWT.log("[DEL]" + pathg, null);
        RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, pathg);

        try {
            handleHeaders(builder, pathg);
            builder.sendRequest(data, new RequestCallback() {

                @Override
                public void onError(Request arg0, Throwable arg1) {
                    errors.put(pathg, arg1);
                }

                @Override
                public void onResponseReceived(Request arg0, Response arg1) {
                    if (arg1.getStatusCode() == okStatusCode)
                        successPaths.add(pathg);
                    else if (arg1.getStatusCode() == 403)
                        sessionExpired();
                    else if (arg1.getStatusCode() == 405)
                        errors.put(pathg, new InsufficientPermissionsException(
                                "You don't have permissions to delete this resource"));
                    else
                        errors.put(pathg, new RestException(pathg, arg1.getStatusCode(), arg1.getStatusText(),
                                arg1.getText()));
                }

            });
        } catch (Exception ex) {
            errors.put(pathg, ex);
        }
    }
}

From source file:org.gss_project.gss.web.client.rest.PostCommand.java

License:Open Source License

public PostCommand(final String path, String data, final int okStatusCode, boolean showLoading) {
    setShowLoadingIndicator(showLoading);
    if (isShowLoadingIndicator())
        GSS.get().showLoadingIndicator("Updating ", path);

    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, path);

    try {/*from   ww  w . ja  v  a 2  s  .  c  o m*/
        handleHeaders(builder, path);
        builder.sendRequest(data, new RequestCallback() {

            @Override
            public void onError(Request arg0, Throwable arg1) {
                complete = true;
                PostCommand.this.onError(arg1);
            }

            @Override
            public void onResponseReceived(Request req, Response resp) {
                complete = true;
                int status = resp.getStatusCode();
                // Normalize IE status 1223 to a regular 204.
                if (status == 1223)
                    status = 204;

                if (status == okStatusCode) {
                    postBody = resp.getText();
                    onComplete();
                } else if (status == 403)
                    sessionExpired();
                else
                    PostCommand.this
                            .onError(new RestException(path, status, resp.getStatusText(), resp.getText()));
            }

        });
    } catch (Exception ex) {
        complete = true;
        onError(ex);
    }
}

From source file:org.gwtcmis.service.acl.ACLService.java

License:Open Source License

/**
 * Adds or removes the given ACEs to or from the ACL of document or folder object pointed by url.
 * //  w ww.j av  a2s.  c  o m
 * On success response received {@link ACLAppliedEvent} 
 * 
 * @param url url
 * @param applyACL applyACL
 */
public void applyACL(String url, ApplyACL applyACL) {
    ACLAppliedEvent event = new ACLAppliedEvent();
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("ACL was not applied.");
    ApplyACLMarshaller marshaller = new ApplyACLMarshaller(applyACL);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.X_HTTP_METHOD_OVERRIDE, HTTPMethod.PUT)
            .header(HTTPHeader.CONTENT_TYPE, "application/atom+xml;type=entry").data(marshaller).send(callback);
}

From source file:org.gwtcmis.service.discovery.DiscoveryService.java

License:Open Source License

/**
 * The Discovery Services (query) are used to search for query-able objects within the Repository.
 * /*from   w w w.  j ava  2  s.  co  m*/
 * On success results received, {@link QueryResultReceivedEvent} is fired
 * 
 * @param url url
 * @param query query
 */
public void query(String url, Query query) {
    EntryCollection entryCollection = new EntryCollection();
    QueryResultReceivedEvent event = new QueryResultReceivedEvent(entryCollection);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Query was performed with errors.");
    EntryCollectionUnmarshaller unmarshaller = new EntryCollectionUnmarshaller(entryCollection);

    QueryMarshaller marshaller = new QueryMarshaller(query);

    String params = "";
    params += (query.getIncludeRelationships() == null) ? ""
            : CmisArguments.INCLUDE_RELATIONSHIPS + "=" + query.getIncludeRelationships().value() + "&";
    params += (query.getRenditionFilter() == null || query.getRenditionFilter().length() <= 0) ? ""
            : CmisArguments.RENDITION_FILTER + "=" + query.getRenditionFilter() + "&";
    params += CmisArguments.INCLUDE_ALLOWABLE_ACTIONS + "=" + query.getIncludeAllowableActions() + "&";
    params += (query.getMaxItems() == null || query.getMaxItems() < 0) ? ""
            : CmisArguments.MAX_ITEMS + "=" + query.getMaxItems() + "&";
    params += (query.getSkipCount() == null || query.getSkipCount() < 0) ? ""
            : CmisArguments.SKIP_COUNT + "=" + query.getSkipCount() + "&";
    url = (url.contains("?")) ? (url + "&" + params) : (url + "?" + params);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, unmarshaller, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.CONTENT_TYPE, CmisMediaTypes.QUERY_DOCUMENT)
            .data(marshaller).send(callback);
}

From source file:org.gwtcmis.service.object.ObjectService.java

License:Open Source License

/**
 * Creates a document object of the specified type (given by the cmis:objectTypeId property) 
 * in the (optionally) specified location.
 * /*from  w  w w.j a va2  s.c  o  m*/
 * On success response received, {@link DocumentCreatedEvent} event is fired.
 * 
 * @param url url
 * @param createDocument createDocument
 */
public void createDocument(String url, CreateDocument createDocument) {
    AtomEntry document = new AtomEntry();
    DocumentCreatedEvent event = new DocumentCreatedEvent(document);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Document was not created.");
    EntryUnmarshaller unmarshaller = new EntryUnmarshaller(document);
    CreateDocumentMarshaller marshaller = new CreateDocumentMarshaller(createDocument);
    String params = (createDocument.getVersioningState() == null) ? ""
            : CmisArguments.VERSIONING_STATE + "=" + createDocument.getVersioningState().value();
    url = (url.contains("?")) ? (url + "&" + params) : (url + "?" + params);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, unmarshaller, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.CONTENT_TYPE, CmisMediaTypes.ATOM_ENTRY)
            .data(marshaller).send(callback);
}

From source file:org.gwtcmis.service.object.ObjectService.java

License:Open Source License

/**
 * @param url// ww  w  .  ja  va2s .  c o m
 * @param createDocument
 * @param sourceUrl
 * @param contentType
 */
public void createDocument(String url, CreateDocument createDocument, String sourceUrl) {
    AtomEntry document = new AtomEntry();
    DocumentCreatedEvent event = new DocumentCreatedEvent(document);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Document was not created.");
    EntryUnmarshaller unmarshaller = new EntryUnmarshaller(document);
    CreateDocumentMarshaller marshaller = new CreateDocumentMarshaller(createDocument, sourceUrl);
    String params = (createDocument.getVersioningState() == null) ? ""
            : CmisArguments.VERSIONING_STATE + "=" + createDocument.getVersioningState().value();
    url = (url.contains("?")) ? (url + "&" + params) : (url + "?" + params);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, unmarshaller, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.CONTENT_TYPE, CmisMediaTypes.ATOM_ENTRY)
            .data(marshaller).send(callback);
}

From source file:org.gwtcmis.service.object.ObjectService.java

License:Open Source License

/**
 * Updating document's content stream copying by url pointed in second parameter.
 * //from   www . java  2  s . co m
 * @param url document location
 * @param sourceUrl location of source for content stream
 */
public void updateDocumentContent(String url, String sourceUrl) {
    AtomEntry document = new AtomEntry();
    DocumentContentUpdatedEvent event = new DocumentContentUpdatedEvent(document);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Document's content was not updated.");
    EntryUnmarshaller unmarshaller = new EntryUnmarshaller(document);
    UpdateDocumentContentMarshaller marshaller = new UpdateDocumentContentMarshaller(sourceUrl);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, unmarshaller, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.X_HTTP_METHOD_OVERRIDE, HTTPMethod.PUT)
            .header(HTTPHeader.CONTENT_TYPE, CmisMediaTypes.ATOM_ENTRY).data(marshaller).send(callback);
}

From source file:org.gwtcmis.service.object.ObjectService.java

License:Open Source License

/**
 * On success response received, {@link EmptyDocumentCreatedEvent} event is fired.
 * /*from  w  w w . j a  v a  2s  .  co m*/
 * @param url url
 * @param createDocument createDocument
 */
public void createEmptyDocument(String url, CreateDocument createDocument) {
    AtomEntry document = new AtomEntry();
    EmptyDocumentCreatedEvent event = new EmptyDocumentCreatedEvent(document);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Document was not created.");
    EntryUnmarshaller unmarshaller = new EntryUnmarshaller(document);
    CreateDocumentMarshaller marshaller = new CreateDocumentMarshaller(createDocument);
    String params = (createDocument.getVersioningState() == null) ? ""
            : CmisArguments.VERSIONING_STATE + "=" + createDocument.getVersioningState().value();
    url = (url.contains("?")) ? (url + "&" + params) : (url + "?" + params);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, unmarshaller, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.CONTENT_TYPE, CmisMediaTypes.ATOM_ENTRY)
            .data(marshaller).send(callback);
}

From source file:org.gwtcmis.service.object.ObjectService.java

License:Open Source License

/**
 * Creates a document object as a copy of the given source document in the (optionally) 
 * specified location./*from w  ww.  j a va  2 s  .  c  om*/
 * 
 * * On success response received, {@link DocumentFromSourceCreatedEvent} event is fired.
 * 
 * @param url url
 * @param createDocumentFromSource createDocumentFromSource
 */
public void createDocumentFromSource(String url, CreateDocumentFromSource createDocumentFromSource) {
    AtomEntry document = new AtomEntry();
    DocumentFromSourceCreatedEvent event = new DocumentFromSourceCreatedEvent(document);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Document was not created.");
    EntryUnmarshaller unmarshaller = new EntryUnmarshaller(document);
    CreateDocumentFromSourceMarshaller marshaller = new CreateDocumentFromSourceMarshaller(
            createDocumentFromSource);

    String params = (createDocumentFromSource.getVersioningState() == null) ? ""
            : CmisArguments.VERSIONING_STATE + "=" + createDocumentFromSource.getVersioningState().value();
    url = (url.contains("?")) ? (url + "&" + params) : (url + "?" + params);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, unmarshaller, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.CONTENT_TYPE, CmisMediaTypes.ATOM_ENTRY)
            .data(marshaller).send(callback);
}