Java tutorial
/* * Copyright 2012 Johns Hopkins University * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.dataconservancy.ui.it.support; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.message.BasicNameValuePair; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; /** * */ public class ApproveRegistrationRequest { private static final String STRIPES_EVENT = "approveRegistrations"; private final UiUrlConfig config; private String emailAddress; public ApproveRegistrationRequest(UiUrlConfig config) { this.config = config; } public ApproveRegistrationRequest(UiUrlConfig config, String emailAddress) { this.config = config; this.emailAddress = emailAddress; } public String getEmailAddress() { return emailAddress; } public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } public HttpPost asHttpPost() { HttpPost form = new HttpPost(config.getAdminRegistrationUrl().toString()); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("userIdsToApprove", emailAddress)); params.add(new BasicNameValuePair(STRIPES_EVENT, "submit")); UrlEncodedFormEntity entity = null; try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } form.setEntity(entity); return form; } }