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.gwtcmis.service.policy.PolicyService.java

License:Open Source License

/**
 * Removes a specified policy from an object.
 * /*from ww  w.j a  va2 s . c om*/
 * On success response received, {@link PolicyRemovedEvent} event is fired
 * 
 * @param url url
 * @param removePolicy remove policy
 */
public void removePolicy(String url, RemovePolicy removePolicy) {
    PolicyRemovedEvent event = new PolicyRemovedEvent();
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Policy was not removed.");
    RemovePolicyMarshaller marshaller = new RemovePolicyMarshaller(removePolicy);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, null, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.X_HTTP_METHOD_OVERRIDE, HTTPMethod.DELETE)
            .data(marshaller).send(callback);
}

From source file:org.gwtcmis.service.policy.PolicyService.java

License:Open Source License

/**
 * Get all policies from repository./*from w w  w  . j  a v  a 2s.co m*/
 * 
 * On success response received, {@link AllPoliciesReceivedEvent} event is fired
 * 
 * @param url url
 * @param repositoryId repository id
 * @param searchAllVersions search all versions
 * @param includeAllowableActions include allowable actions
 * @param includeRelationships include relationships
 * @param renditionFilter rendition filter
 * @param maxItems max items
 * @param skipCount skipCount
 */
public void getAllPolicies(String url, String repositoryId, boolean searchAllVersions,
        boolean includeAllowableActions, EnumIncludeRelationships includeRelationships, String renditionFilter,
        Long maxItems, Long skipCount) {
    EntryCollection policies = new EntryCollection();
    EntryCollectionUnmarshaller unmarshaller = new EntryCollectionUnmarshaller(policies);
    AllPoliciesReceivedEvent event = new AllPoliciesReceivedEvent(policies);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Polices were not recieved.");
    /*Get all properties from repository using query*/
    String statement = "SELECT * FROM " + EnumBaseObjectTypeIds.CMIS_POLICY.value();
    Query query = new Query();
    query.setRepositoryId(repositoryId);
    query.setSearchAllVersions(searchAllVersions);
    query.setSkipCount(skipCount);
    query.setIncludeAllowableActions(includeAllowableActions);
    query.setMaxItems(maxItems);
    query.setRenditionFilter(renditionFilter);
    query.setIncludeRelationships(includeRelationships);
    query.setStatement(statement);
    QueryMarshaller marshaller = new QueryMarshaller(query);

    String params = "";
    params += (maxItems < 0) ? "" : CmisArguments.MAX_ITEMS + "=" + maxItems + "&";
    params += (skipCount < 0) ? "" : CmisArguments.SKIP_COUNT + "=" + skipCount + "&";
    params += CmisArguments.INCLUDE_RELATIONSHIPS + "=" + includeRelationships.value() + "&";
    params += (renditionFilter == null || renditionFilter.length() <= 0) ? ""
            : CmisArguments.RENDITION_FILTER + "=" + renditionFilter + "&";
    params += CmisArguments.INCLUDE_ALLOWABLE_ACTIONS + "=" + includeAllowableActions + "&";
    params += CmisArguments.ALL_VERSIONS + "=" + searchAllVersions;
    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.repository.RepositoryService.java

License:Open Source License

/**
 * Create type.//from ww  w. j a  v  a 2s  .co  m
 * 
 * On success response received, {@link TypeCreatedEvent} event is fired
 * 
 * @param url url
 * @param type type
 */
public void addType(String url, TypeDefinition createType) {
    TypeEntry type = new TypeEntry();
    TypeCreatedEvent event = new TypeCreatedEvent(type);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Type was not created.");
    TypeDefinitionUnmarshaller unmarshaller = new TypeDefinitionUnmarshaller(type);
    TypeDefinitionMarshaller marshaller = new TypeDefinitionMarshaller(createType);
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, unmarshaller, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).data(marshaller).send(callback);
}

From source file:org.gwtcmis.service.repository.RepositoryService.java

License:Open Source License

/**
 * Delete type by url./*from www .j  a  va  2 s  . c o m*/
 * 
 * On success response received, {@link TypeDeletedEvent} event is fired
 * 
 * @param url url
 */
public void deleteType(String url) {
    TypeDeletedEvent event = new TypeDeletedEvent();
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Type was not deleted.");
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.X_HTTP_METHOD_OVERRIDE, HTTPMethod.DELETE)
            .send(callback);
}

From source file:org.gwtcmis.service.versioning.VersioningService.java

License:Open Source License

/**
 * Create a private working copy of the document.
 * /*ww  w  .j  a va 2s  .c  o m*/
 * On success response received, {@link CheckoutReceivedEvent} event is fired
 * 
 * @param url url
 * @param objectId object id
 */
public void checkOut(String url, String objectId) {
    AtomEntry document = new AtomEntry();
    CheckoutReceivedEvent event = new CheckoutReceivedEvent(document);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Check-out the document failed.");
    CheckOut checkOut = new CheckOut();
    checkOut.setObjectId(objectId);
    CheckoutMarshaller marshaller = new CheckoutMarshaller(checkOut);
    EntryUnmarshaller unmarshaller = new EntryUnmarshaller(document);
    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.versioning.VersioningService.java

License:Open Source License

/**
 * Reverses the effect of a check-out. //from   w  ww.j a va2 s  . com
 * Removes the private working copy of the checked-out document, 
 * allowing other documents in the version series to be checked out again.
 * 
 * On success response received, {@link CancelCheckoutReceivedEvent} event is fired
 * 
 * @param url url
 */
public void cancelCheckout(String url) {
    CancelCheckoutReceivedEvent event = new CancelCheckoutReceivedEvent();
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Cancel check-out the document failed.");
    AsyncRequestCallback callback = new AsyncRequestCallback(eventBus, event, errorEvent);
    AsyncRequest.build(RequestBuilder.POST, url).header(HTTPHeader.X_HTTP_METHOD_OVERRIDE, HTTPMethod.DELETE)
            .send(callback);
}

From source file:org.gwtcmis.service.versioning.VersioningService.java

License:Open Source License

/**
 * Checks-in the Private Working Copy document.
 * //  w  ww  . java2 s .c o m
 * On success response received, {@link CheckinReceivedEvent} event is fired
 * 
 * @param url url
 * @param checkIn checkIn
 */
public void checkin(String url, CheckIn checkIn) {
    AtomEntry document = new AtomEntry();
    CheckinReceivedEvent event = new CheckinReceivedEvent(document);
    ExceptionThrownEvent errorEvent = new ExceptionThrownEvent("Check-in the document failed.");
    EntryUnmarshaller unmarshaller = new EntryUnmarshaller(document);

    String params = "";
    params += CmisArguments.MAJOR + "=" + checkIn.getMajor() + "&";
    params += (checkIn.getCheckinComment() == null || checkIn.getCheckinComment().length() <= 0) ? ""
            : CmisArguments.CHECKIN_COMMENT + "=" + checkIn.getCheckinComment() + "&";
    params += CmisArguments.CHECKIN + "=true";
    CheckinMarshaller marshaller = new CheckinMarshaller(checkIn);

    url = (url.contains("?")) ? (url + "&" + params) : (url + "?" + params);
    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.idwebmail.client.IDRequest.java

private void preparar(String url, final IDFunction usrFunction) {
    this.url = url;
    final IDFunction function = new IDFunction() {
        @Override//ww w. j  a  v  a2 s  . com
        public void execute(Response response) {
            try {
                JSONObject JSON = (JSONObject) JSONParser.parse(response.getText());
                usrFunction.execute(response);
            } catch (Exception e) {
                usrFunction.execute(response);
            }
        };
    };
    this.requestBuilder = new RequestBuilder(RequestBuilder.POST, url);
    this.requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded");
    this.requestBuilder.setTimeoutMillis(this.timeoutMillis);
    this.requestBuilder.setCallback(new RequestCallback() {
        @Override
        public void onResponseReceived(com.google.gwt.http.client.Request request, final Response response) {
            if (response.getStatusCode() == Response.SC_OK) {
                JSONObject JSON = null;
                try {
                    JSON = (JSONObject) JSONParser.parse(response.getText());
                    if (MainEntryPoint.getBoolean(JSON.get("STDOUT"))) {
                        final String JSONRespuesta = MainEntryPoint.getString(JSON.get("data"));
                        final Response tmp = new Response() {
                            @Override
                            public String getHeader(String arg0) {
                                return response.getHeader(arg0);
                            }

                            @Override
                            public Header[] getHeaders() {
                                return response.getHeaders();
                            }

                            @Override
                            public String getHeadersAsString() {
                                return response.getHeadersAsString();
                            }

                            @Override
                            public int getStatusCode() {
                                return response.getStatusCode();
                            }

                            @Override
                            public String getStatusText() {
                                return response.getStatusText();
                            }

                            @Override
                            public String getText() {
                                return JSONRespuesta;
                            }
                        };
                        function.execute(tmp);
                    } else
                        JSON = null;
                } catch (Exception e) {
                    function.execute(response);
                }
            }
        }

        @Override
        public void onError(Request request, Throwable exception) {
            Window.alert("Error: " + exception.getMessage());
        }
    });
}

From source file:org.idwebmail.client.IDRequest.java

public static String getAjaxData(String param) {
    final String result = "-";
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, MainEntryPoint.getURL());
    builder.setRequestData(param);/*from  w  ww. ja v  a 2 s  . c  o  m*/
    //final SynchronousQueue resultQueue = new SynchronousQueue();
    try {
        builder.sendRequest(null, new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                JSONObject json = (JSONObject) JSONParser.parse(response.getText());
                if (MainEntryPoint.getString(json.get("data")).toLowerCase().compareTo("exito") == 0) {
                    rs = MainEntryPoint.getString(json.get("modo"));
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
            }
        });
        return rs;
    } catch (RequestException ex) {
    }
    return result;
}

From source file:org.idwebmail.client.IDRequest.java

public static void getAjaxData(String param, final String campo, final Callback<String, String> callback) {
    RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, MainEntryPoint.getURL());
    builder.setHeader("Content-Type", "application/x-www-form-urlencoded");
    builder.setRequestData(param);//from  w w  w  .ja v a2s .  c  o m
    try {
        builder.sendRequest(param, new RequestCallback() {
            @Override
            public void onResponseReceived(Request request, Response response) {
                JSONObject json = (JSONObject) JSONParser.parse(response.getText());
                if (campo.isEmpty())
                    callback.onSuccess(response.getText());
                else
                    callback.onSuccess(MainEntryPoint.getString(json.get(campo)));
            }

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