Java tutorial
/** * OhmMarks - Simple app for displaying and notifying about new marks from * the GSO-VirtuOhm system * * Copyright (C) 2012 mojadev (www.mojadev.de) * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * @author Moja <mojadev@gmail.com> * **/ package de.mojadev.ohmmarks.virtuohm.http; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.NameValuePair; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.message.BasicNameValuePair; /** * Helper class for retrieving request parameters. * @author Moja <mojadev@gmail.com> * */ public class VirtuOhmParams { public final static String USERNAME = "BenName"; public final static String PASSWORD = "Password"; public final static String USER_ID = "in_userid"; public final static String IN_CRIMMO = "in_crimmo"; /** * Returns the POST parameters required for login * * @param username * @param password * @return * @throws UnsupportedEncodingException */ public static HttpEntity getLogin(String username, String password) throws UnsupportedEncodingException { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(USERNAME, username)); params.add(new BasicNameValuePair(PASSWORD, password)); return new UrlEncodedFormEntity(params); } /** * The GET String for registering a new session * @param in_crimmo * @param userid * @return */ public static String getSessionRegisterGETParams(String in_crimmo, String userid) { return "?" + USER_ID + "=" + userid + "&" + IN_CRIMMO + "=" + in_crimmo; } /** * Build Logout GET String * @param in_crimmo * @return */ public static String getLogout(String in_crimmo) { return "?" + IN_CRIMMO + "=" + in_crimmo; } public static HttpEntity getSessionRegisterParams(String in_crimmo, String userid) throws UnsupportedEncodingException { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(USER_ID, userid)); params.add(new BasicNameValuePair(IN_CRIMMO, in_crimmo)); return new UrlEncodedFormEntity(params); } }