List of usage examples for com.google.gwt.http.client RequestBuilder setHeader
public void setHeader(String header, String value)
From source file:org.opentaps.gwt.crmsfa.client.Entry.java
License:Open Source License
/** * This method setup a button into subsection title at right-hand position * and allow to assign a new contact using lookup contacts window. * @param container <code>RootPanel</code> that is root container for button * @param accountContacts parent contacts list view. */// ww w. j a v a2 s. c om private void loadAssignContactToAccountWidget(RootPanel container, final ContactsSublistView accountContacts) { // create lookup window final LookupContactsWindow window = new LookupContactsWindow(true, true); window.create(); // register listener to be notified when user selects a contact window.register(new FormNotificationInterface<String>() { /** {@inheritDoc} */ public void notifySuccess(String obj) { if (obj == null) { return; } final String actionUrl = "/crmsfa/control/assignContactToAccountAJX"; // keep user's selection String contactPartyId = obj; // nothing special, just send HTTP POST request // and run crmsfa.assignContactToAccount service RequestBuilder request = new RequestBuilder(RequestBuilder.POST, actionUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData(Format.format("partyId={0}&accountPartyId={0}&contactPartyId={1}", getPartyId(), contactPartyId)); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // we don't expect anything from server, just reload the list of contacts UtilUi.logInfo("onResponseReceived, response = " + response, "", "loadAssignContactToAccountWidget"); if (!ServiceErrorReader.showErrorMessageIfAny(response, actionUrl)) { accountContacts.getStore().reload(); accountContacts.loadFirstPage(); } accountContacts.markGridNotBusy(); } }); try { accountContacts.markGridBusy(); UtilUi.logInfo("Run service crmsfa.assignContactToAccount", MODULE, "loadAssignContactToAccountWidget"); request.send(); } catch (RequestException re) { // display error message UtilUi.errorMessage(re.toString(), MODULE, "loadAssignContactToAccountWidget"); } } }); // create hyperlink as submenu button Button embedLink = new Button(UtilUi.MSG.crmAssignContact(), new ClickHandler() { public void onClick(ClickEvent event) { window.show(); } }); embedLink.setStyleName("subMenuButton"); // place [Assign Contact] button on page container.add(embedLink); }
From source file:org.opentaps.gwt.crmsfa.client.opportunities.form.OpportunityContactsSubview.java
License:Open Source License
/** * Constructor with autoLoad parameter, use this constructor if some filters need to be set prior to loading the grid data. * @param autoLoad sets the grid autoLoad parameter, set to <code>false</code> if some filters need to be set prior to loading the grid data *///from w w w . ja va 2s .co m public OpportunityContactsSubview(String accountPartyId, boolean autoLoad) { super(UtilUi.MSG.crmContactId(), UtilUi.MSG.crmFindContacts()); this.accountPartyId = accountPartyId; contactListView = new ContactListView() { /** {@inheritDoc} */ @Override public void init() { String entityViewUrl = "/crmsfa/control/viewContact?partyId={0}"; StringFieldDef idDefinition = new StringFieldDef(PartyLookupConfiguration.INOUT_PARTY_ID); makeLinkColumn(UtilUi.MSG.crmContactId(), idDefinition, entityViewUrl, true); makeLinkColumn(UtilUi.MSG.crmContactName(), idDefinition, new StringFieldDef(PartyLookupConfiguration.INOUT_FRIENDLY_PARTY_NAME), entityViewUrl, true); makeColumn(UtilUi.MSG.partyCity(), new StringFieldDef(PartyLookupConfiguration.INOUT_CITY)); makeColumn(UtilUi.MSG.crmPrimaryEmail(), new StringFieldDef(PartyLookupConfiguration.INOUT_EMAIL)); makeColumn(UtilUi.MSG.crmPrimaryPhone(), new StringFieldDef(PartyLookupConfiguration.INOUT_FORMATED_PHONE_NUMBER)); makeColumn(UtilUi.MSG.partyToName(), new StringFieldDef(PartyLookupConfiguration.INOUT_TO_NAME)); makeColumn(UtilUi.MSG.partyAttentionName(), new StringFieldDef(PartyLookupConfiguration.INOUT_ATTENTION_NAME)); makeColumn(UtilUi.MSG.partyAddressLine1(), new StringFieldDef(PartyLookupConfiguration.INOUT_ADDRESS)); makeColumn(UtilUi.MSG.partyAddressLine2(), new StringFieldDef(PartyLookupConfiguration.OUT_ADDRESS_2)); makeColumn(UtilUi.MSG.partyState(), new StringFieldDef(PartyLookupConfiguration.INOUT_STATE)); makeColumn(UtilUi.MSG.partyCountry(), new StringFieldDef(PartyLookupConfiguration.INOUT_COUNTRY)); makeColumn(UtilUi.MSG.partyPostalCode(), new StringFieldDef(PartyLookupConfiguration.INOUT_POSTAL_CODE)); makeColumn(UtilUi.MSG.crmPostalCodeExt(), new StringFieldDef(PartyLookupConfiguration.OUT_POSTAL_CODE_EXT)); deleteColumnIndex = getCurrentColumnIndex(); ColumnConfig config = makeColumn("", new Renderer() { public String render(Object value, CellMetadata cellMetadata, Record record, int rowIndex, int colNum, Store store) { return Format.format("<img width=\"15\" height=\"15\" class=\"checkbox\" src=\"{0}\"/>", UtilUi.ICON_DELETE); } }); config.setWidth(26); config.setResizable(false); config.setFixed(true); config.setSortable(false); addGridCellListener(new GridCellListenerAdapter() { private final String actionUrl = "/crmsfa/control/removeContactFromAccount"; /** {@inheritDoc} */ @Override public void onCellClick(GridPanel grid, int rowIndex, int colindex, EventObject e) { if (colindex == OpportunityContactsSubview.this.deleteColumnIndex) { String contactPartyId = getStore().getRecordAt(rowIndex).getAsString("partyId"); RequestBuilder request = new RequestBuilder(RequestBuilder.POST, actionUrl); request.setHeader("Content-type", "application/x-www-form-urlencoded"); request.setRequestData( Format.format("partyId={0}&accountPartyId={0}&contactPartyId={1}", OpportunityContactsSubview.this.accountPartyId, contactPartyId)); request.setCallback(new RequestCallback() { public void onError(Request request, Throwable exception) { // display error message markGridNotBusy(); UtilUi.errorMessage(exception.toString()); } public void onResponseReceived(Request request, Response response) { // if it is a correct response, reload the grid markGridNotBusy(); UtilUi.logInfo("onResponseReceived, response = " + response, MODULE, "ContactListView.init()"); if (!ServiceErrorReader.showErrorMessageIfAny(response, actionUrl)) { // commit store changes getStore().reload(); loadFirstPage(); } } }); try { markGridBusy(); UtilUi.logInfo("posting batch", MODULE, "ContactListView.init()"); request.send(); } catch (RequestException re) { // display error message UtilUi.errorMessage(e.toString(), MODULE, "ContactListView.init()"); } } } }); configure(PartyLookupConfiguration.URL_FIND_CONTACTS, PartyLookupConfiguration.INOUT_PARTY_ID, SortDir.ASC); // by default, hide non essential columns setColumnHidden(PartyLookupConfiguration.INOUT_PARTY_ID, true); setColumnHidden(PartyLookupConfiguration.INOUT_STATE, true); setColumnHidden(PartyLookupConfiguration.INOUT_COUNTRY, true); setColumnHidden(PartyLookupConfiguration.INOUT_TO_NAME, true); setColumnHidden(PartyLookupConfiguration.INOUT_ATTENTION_NAME, true); setColumnHidden(PartyLookupConfiguration.INOUT_ADDRESS, true); setColumnHidden(PartyLookupConfiguration.OUT_ADDRESS_2, true); setColumnHidden(PartyLookupConfiguration.INOUT_POSTAL_CODE, true); setColumnHidden(PartyLookupConfiguration.OUT_POSTAL_CODE_EXT, true); } }; contactListView.setHeader(false); contactListView.setAutoLoad(autoLoad); contactListView.init(); addListView(contactListView); }
From source file:org.otalo.ao.client.JSONRequest.java
License:Apache License
public void doPost(String fetchURL, String postData, JSONRequester requester) { this.requester = requester; // RequestBuilder used to issue HTTP GET requests. RequestBuilder requestBuilder = new RequestBuilder(RequestBuilder.POST, URL.encode(BASE_URL + fetchURL)); requestBuilder.setHeader("Content-Type", "application/x-www-form-urlencoded"); try {/* www . j a v a 2 s. com*/ requestBuilder.sendRequest(postData, new JSONResponseTextHandler()); } catch (RequestException ex) { // TODO } }
From source file:org.otalo.ao.client.JSONRequest.java
License:Apache License
public static void doPost(String url, String postData) { RequestBuilder builder = new RequestBuilder(RequestBuilder.POST, url); try {/*from w w w .jav a 2s .c om*/ builder.setHeader("Content-Type", "application/x-www-form-urlencoded"); Request response = builder.sendRequest(postData, new RequestCallback() { public void onError(Request request, Throwable exception) { // code omitted for clarity } public void onResponseReceived(Request request, Response response) { // code omitted for clarity } }); } catch (RequestException e) { } }
From source file:org.overlord.gadgets.web.client.util.RestfulInvoker.java
License:Open Source License
public static void invoke(RequestBuilder.Method method, String url, String data, Response callback) { RequestBuilder builder = new RequestBuilder(method, url); builder.setHeader("content-type", "application/json"); try {//from ww w . j a va2 s.co m builder.sendRequest(data, callback); } catch (RequestException e) { Log.error("Error on invoking the service at [" + url + "], detailed info: " + e); } }
From source file:org.ow2.proactive_grid_cloud_portal.rm.client.nodesource.serialization.CatalogRequestBuilder.java
License:Open Source License
public void sendRequestToCatalog(String endpoint, RequestCallback callback) { RequestBuilder request = new RequestBuilder(RequestBuilder.GET, this.catalogUrl + "/" + endpoint); request.setHeader(CatalogConstants.SESSION_ID_PARAM, LoginModel.getInstance().getSessionId()); request.setCallback(callback);//from w ww .j a va 2 s . co m try { request.send(); } catch (RequestException e) { this.importFromCatalogPanelFeeder.setNodeSourceWindowLabelWithError("Request sent to catalog failed", e); } }
From source file:org.ow2.proactive_grid_cloud_portal.rm.client.nodesource.serialization.export.catalog.ExportToCatalogConfirmWindow.java
License:Open Source License
private void fillBucketList() { this.bucketList.setEnabled(false); this.bucketList.addItem(SELECT_A_BUCKET_OPTION); this.bucketList .addChangeHandler(event -> requestCatalogObjectsAndRevisions(this.bucketList.getSelectedValue())); RequestBuilder request = new RequestBuilder(RequestBuilder.GET, new CatalogUrlBuilder().getCatalogUrl() + "/buckets"); request.setHeader("sessionId", LoginModel.getInstance().getSessionId()); request.setCallback(fillBucketListWithRequestCallback()); try {//from ww w . j a v a 2 s.c o m request.send(); } catch (RequestException e) { String errorMessage = "Request sent to catalog failed"; LogModel.getInstance().logCriticalMessage(errorMessage); this.windowLabel.setContents(errorMessage); } }
From source file:org.ow2.proactive_grid_cloud_portal.rm.client.nodesource.serialization.ExportToCatalogConfirmWindow.java
License:Open Source License
private void fillBucketList() { this.bucketList.setEnabled(false); this.bucketList.addItem(SELECT_A_BUCKET_OPTION); this.bucketList.addChangeHandler(event -> requestNodeSourceInBucket(this.bucketList.getSelectedValue())); RequestBuilder request = new RequestBuilder(RequestBuilder.GET, new CatalogUrlBuilder().getCatalogUrl() + "/buckets"); request.setHeader("sessionId", LoginModel.getInstance().getSessionId()); request.setCallback(fillBucketListWithRequestCallback()); try {// w ww. j a v a 2s . c om request.send(); } catch (RequestException e) { String errorMessage = "Request sent to catalog failed"; GWT.log(errorMessage, e); this.windowLabel.setContents(errorMessage); } }
From source file:org.ow2.proactive_grid_cloud_portal.rm.client.nodesource.serialization.ImportFromCatalogPanel.java
License:Open Source License
private void requestNodeSourceConfiguration() { String selectedNodeSourceInList = this.nodeSourceListBox.getSelectedValue(); if (!selectedNodeSourceInList.equals(SELECT_NODE_SOURCE_GENERIC_ENTRY)) { String nodeSourceConfigurationRequestUrl = new CatalogUrlBuilder().getCatalogUrl() + "/buckets/" + this.importFromCatalogPanelFeeder.getBucketNameForNodeSource(selectedNodeSourceInList) + "/resources/" + selectedNodeSourceInList + "/raw"; RequestBuilder nodeSourceConfigurationRequest = new RequestBuilder(RequestBuilder.GET, nodeSourceConfigurationRequestUrl); nodeSourceConfigurationRequest.setHeader(CatalogConstants.SESSION_ID_PARAM, LoginModel.getInstance().getSessionId()); nodeSourceConfigurationRequest.setCallback(getNodeSourceConfigurationRequestCallback()); try {/* w ww .j a va 2 s . c o m*/ nodeSourceConfigurationRequest.send(); } catch (RequestException e) { setNodeSourceWindowLabelWithError("Request sent to catalog failed", e); } } }
From source file:org.ow2.proactive_grid_cloud_portal.rm.client.nodesource.serialization.load.catalog.ImportFromCatalogPanel.java
License:Open Source License
private void requestNodeSourceConfiguration() { String selectedNodeSourceInList = this.nodeSourceListBox.getSelectedValue(); if (!selectedNodeSourceInList.equals(this.selectItemGenericEntry)) { String nodeSourceConfigurationRequestUrl = new CatalogUrlBuilder().getCatalogUrl() + "/buckets/" + this.importFromCatalogPanelFeeder.getBucketNameForNodeSource(selectedNodeSourceInList) + "/resources/" + selectedNodeSourceInList + "/raw"; RequestBuilder nodeSourceConfigurationRequest = new RequestBuilder(RequestBuilder.GET, nodeSourceConfigurationRequestUrl); nodeSourceConfigurationRequest.setHeader(CatalogConstants.SESSION_ID_PARAM, LoginModel.getInstance().getSessionId()); nodeSourceConfigurationRequest.setCallback(nodeSourceConfigurationRequestCallback); try {//from ww w . ja va 2 s . c o m nodeSourceConfigurationRequest.send(); } catch (RequestException e) { throw new IllegalStateException("GET " + nodeSourceConfigurationRequestUrl + " failed", e); } } }