All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.appaloosastore.client..AppaloosaClient.swp Maven / Gradle / Ivy

Go to download

Publish your mobile applications (Android, iOS, ...) to the <a href="https://www.appaloosa-store.com">appaloosa-store</a> platform.

There is a newer version: 2.0
Show newest version
b0VIM 8.1??,[O????btiOCTO-BTI.local~bti/code/appaloosa_client/src/main/java/com/appaloosastore/client/AppaloosaClient.javautf-8
3210#"! UtpXHY?l?r)??	ad?X??????S?e?
?
?
X
U

?l"??soLK6?
?
?
?
}
|
V
*
	
?	?	?	p	G		??rC??s>??u<;7???Q??<??[%"???????a??????	private String proxyPass;	private String proxyUser;	private String proxyHost;	private int waitDuration = 2000;	private int appaloosaPort = 443;	private String appaloosaUrl = "https://www.appaloosa-store.com";	private HttpClient httpClient;	private PrintStream logger;	private String storeToken;	public static int MAX_RETRIES = 30;public class AppaloosaClient { */ * @author Benoit Lafontaine * *  Store token is available on settings page. *  }                                                                  
* System.err.println("Something went wrong");
* } catch (AppaloosaDeployException e) {
* System.out.println("Archive deployed");
* "optional changelog);
* "some group | another group | also optional",
* client.deployFile("/path/to/archive", "optional description",
* try {
* AppaloosaClient client = new AppaloosaClient("my_store_token");
* * Client for appaloosa, https://www.appaloosa-store.com. Usage :
/**import org.apache.commons.lang.exception.ExceptionUtils;import org.apache.http.util.EntityUtils;import org.apache.http.message.BasicNameValuePair;import org.apache.http.impl.client.DefaultHttpClient;import org.apache.http.entity.mime.content.StringBody;import org.apache.http.entity.mime.content.FileBody;import org.apache.http.entity.mime.content.ContentBody;import org.apache.http.entity.mime.MultipartEntity;import org.apache.http.conn.params.ConnRoutePNames;import org.apache.http.client.methods.HttpPost;import org.apache.http.client.methods.HttpGet;import org.apache.http.client.entity.UrlEncodedFormEntity;import org.apache.http.client.HttpClient;import org.apache.http.client.ClientProtocolException;import org.apache.http.auth.UsernamePasswordCredentials;import org.apache.http.auth.Credentials;import org.apache.http.auth.AuthScope;import org.apache.http.ParseException;import org.apache.http.NameValuePair;import org.apache.http.HttpResponse;import org.apache.http.HttpHost;import org.apache.commons.lang.StringUtils;import org.apache.commons.io.IOUtils;import java.util.List;import java.util.ArrayList;import java.nio.charset.Charset;import java.io.UnsupportedEncodingException;import java.io.PrintStream;import java.io.IOException;import java.io.File;package com.appaloosastore.client; */ * THE SOFTWARE. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * * all copies or substantial portions of the Software. * The above copyright notice and this permission notice shall be included in * * furnished to do so, subject to the following conditions: * copies of the Software, and to permit persons to whom the Software is * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * in the Software without restriction, including without limitation the rights * of this software and associated documentation files (the "Software"), to deal * Permission is hereby granted, free of charge, to any person obtaining a copy * * Copyright (c) 2013 OCTO Technology * * The MIT License */**ad!a ?????gdca`} } this.proxyPort = proxyPort; public void setProxyPort(int proxyPort) { } this.proxyPass = proxyPass; public void setProxyPass(String proxyPass) {ad8???_^<;?????N ? ? ? ? ? [ 6 3 2 ? ? ? s 5   ? ? y 0   ? ? ? ? l 5  ? ? ? ? ? ? ? Y X  ????E???tpml?'$#??????zT???xtXD@2/.)?????yURQL?????????eA>=???????Z<985 } this.proxyUser = proxyUser; public void setProxyUser(String proxyUser) { } this.proxyHost = proxyHost; public void setProxyHost(String proxyHost) { } this.storeToken = StringUtils.trimToNull(storeToken); void setStoreToken(String storeToken) { } this.waitDuration = waitDuration; protected void setWaitDuration(int waitDuration) { } appaloosaPort = port; public void setPort(int port) { */ * @param port * * evolutions. * To change port of appaloosa server. Mostly for tests usage or for future /** } this.appaloosaUrl = appaloosaUrl; public void setBaseUrl(String appaloosaUrl) { */ * @param appaloosaUrl * * future evolutions. * To change the url of appaloosa server. Mostly for tests usage or for /** } return url; } url = url + "/"; if (!url.endsWith("/")) { } url = url + ":" + appaloosaPort; if (appaloosaPort != 443) { String url = appaloosaUrl; protected String getAppaloosaBaseUrl() { } return url; url = url + "api/upload_binary_form.json?token=" + storeToken; String url = getAppaloosaBaseUrl(); protected String newBinaryUrl() { } return url; url = url + "api/on_binary_upload"; String url = getAppaloosaBaseUrl(); protected String onBinaryUploadUrl() { } this.logger = logger; public void useLogger(PrintStream logger) { } } proxy); httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, HttpHost proxy = new HttpHost(proxyHost, proxyPort); } .setCredentials(new AuthScope(proxyHost, proxyPort), cred); ((DefaultHttpClient) httpClient).getCredentialsProvider() cred = new UsernamePasswordCredentials(proxyUser, proxyPass); if (proxyUser != null && !proxyUser.isEmpty()){ Credentials cred = null; if (proxyHost != null && !proxyHost.isEmpty() && proxyPort > 0) { httpClient = new DefaultHttpClient(); httpClient.getConnectionManager().shutdown(); if (httpClient != null) void resetHttpConnection() { } } resetHttpConnection(); } finally { + appaloosaUrl, e); "impossible to retrieve upload information from " throw new AppaloosaDeployException( log(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { throw e; } catch (AppaloosaDeployException e) { } return uploadForm; UploadBinaryForm uploadForm = UploadBinaryForm.createFormJson(json); String json = IOUtils.toString(response.getEntity().getContent()); default: throw createExceptionWithAppaloosaErrorResponse(response, ""); case 422: switch (statusCode) { int statusCode = response.getStatusLine().getStatusCode(); HttpResponse response = httpClient.execute(httpGet); try { HttpGet httpGet = new HttpGet(newBinaryUrl()); protected UploadBinaryForm getUploadForm() throws AppaloosaDeployException { } return body.substring(start, end); int end = body.indexOf(""); int start = body.indexOf("") + 9; protected String readErrorFormAmazon(String body) { } Charset.forName("UTF-8"))); entity.addPart(paramName, new StringBody(paramValue, "text/plain", String paramValue) throws UnsupportedEncodingException { protected void addParam(MultipartEntity entity, String paramName, } return httppost; httppost.setEntity(entity); HttpPost httppost = new HttpPost(uploadForm.getUrl()); entity.addPart("file", cbFile); addParam(entity, "acl", uploadForm.getAcl()); addParam(entity, "key", uploadForm.getKey()); addParam(entity, "AWSAccessKeyId", uploadForm.getAccessKey());ad ?r??kf=1???v\XUT? ? w b J >   ? ? ?  ` E 3 . $   ? ? ? ? b ? < ;   ? ? ? ? ? ~ < ;   ?  C  ????]-????QNM???{BA??a?????s4??????b0???l+?? addParam(entity, "signature", uploadForm.getSignature()); addParam(entity, "Content-Type", uploadForm.getContentType()); .getSuccessActionStatus().toString()); addParam(entity, "success_action_status", uploadForm addParam(entity, "policy", uploadForm.getPolicy()); ContentBody cbFile = new FileBody(file); MultipartEntity entity = new MultipartEntity(); throws UnsupportedEncodingException { protected HttpPost createHttpPost(UploadBinaryForm uploadForm, File file) } } resetHttpConnection(); } finally { + filePath + " : " + e.getMessage(), e); throw new AppaloosaDeployException("Error while uploading " log(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { throw e; } catch (AppaloosaDeployException e) { } + filePath + ": " + message); throw new AppaloosaDeployException("Impossible to upload file " .getEntity().getContent())); String message = readErrorFormAmazon(IOUtils.toString(response if (statusCode != uploadForm.getSuccessActionStatus()) { int statusCode = response.getStatusLine().getStatusCode(); HttpResponse response = httpClient.execute(httppost); HttpPost httppost = createHttpPost(uploadForm, file); File file = new File(filePath); try { throws AppaloosaDeployException { protected void uploadFile(String filePath, UploadBinaryForm uploadForm) } return StringUtils.replace(key, "${filename}", filename); String filename = new File(filePath).getName(); protected String constructKey(String key, String filePath) { } } resetHttpConnection(); } finally { "Error during appaloosa notification", e); throw new AppaloosaDeployException( } catch (Exception e) { throw e; } catch (AppaloosaDeployException e) { return makePublishCall(httpPost, parameters); try { parameters.add(new BasicNameValuePair("key", key)); String key = constructKey(uploadForm.getKey(), filePath); parameters.add(new BasicNameValuePair("token", storeToken)); List parameters = new ArrayList(); HttpPost httpPost = new HttpPost(onBinaryUploadUrl()); UploadBinaryForm uploadForm) throws AppaloosaDeployException { protected MobileApplicationUpdate notifyAppaloosaForFile(String filePath, } } } catch (InterruptedException e) { Thread.sleep(waitDuration); try { protected void smallWait() { } + ".json?token=" + storeToken; return getAppaloosaBaseUrl() + "mobile_application_updates/" + id protected String updateUrl(Integer id) { } return new AppaloosaDeployException(prefix + cause); } break; default: break; } cause = json; } catch (Exception e) { cause = errors.toString(); AppaloosaErrors errors = AppaloosaErrors.createFromJson(json); try { json = readBodyResponse(response); String json; case 422: break; cause = "resource not found (404)"; case 404: switch (statusCode) { String cause = ""; int statusCode = response.getStatusLine().getStatusCode(); IOException { HttpResponse response, String prefix) throws ParseException, protected AppaloosaDeployException createExceptionWithAppaloosaErrorResponse( } } resetHttpConnection(); } finally { "Error while get details for update id = " + id, e); throw new AppaloosaDeployException( log(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { throw e; } catch (AppaloosaDeployException e) { } + id + ", cause: "); "Impossible to get details for application update " throw createExceptionWithAppaloosaErrorResponse(response,ad ?l?????eD(????~{z8? ? ? ?   ? ? ? ? ? ? t ? ? ? ? ? ? ? ? ? ? 5  ? ? ? ? ? S *   ? ? i [ A = : 9 ???n2??????b=??uL???;1????}|B????urq.??????F??? } else { return MobileApplicationUpdate.createFrom(json); String json = readBodyResponse(response); if (response.getStatusLine().getStatusCode() == 200) { response = httpClient.execute(httpGet); try { HttpResponse response; HttpGet httpGet = new HttpGet(updateUrl(id)); Integer id) throws AppaloosaDeployException { public MobileApplicationUpdate getMobileApplicationUpdateDetails( } return getAppaloosaBaseUrl() + "api/publish_update.json"; protected String publishUpdateUrl() { } return EntityUtils.toString(response.getEntity(), "UTF-8"); throws ParseException, IOException { protected String readBodyResponse(HttpResponse response) } return parameters; } "mobile_application_update[group_names][]", groupName)); parameters.add(new BasicNameValuePair( for (String groupName : update.groupNames) { } parameters.add(new BasicNameValuePair("mobile_application_update[changelog]", update.changelog)); if (update.changelog != null){ } parameters.add(new BasicNameValuePair("mobile_application_update[description]", update.description)); if (update.description != null){ parameters.add(new BasicNameValuePair("id", update.id.toString())); parameters.add(new BasicNameValuePair("token", storeToken)); List parameters = new ArrayList(); MobileApplicationUpdate update) { List constructParametersFromUpdate( } return MobileApplicationUpdate.createFrom(json); String json = readBodyResponse(response); HttpResponse response = httpClient.execute(httpPost); httpPost.setEntity(new UrlEncodedFormEntity(parameters)); ClientProtocolException, AppaloosaDeployException { throws UnsupportedEncodingException, IOException, List parameters) MobileApplicationUpdate makePublishCall(HttpPost httpPost, } } resetHttpConnection(); } finally { "Error during publishing update (id=" + update.id + ")", e); throw new AppaloosaDeployException( log(ExceptionUtils.getStackTrace(e)); } catch (Exception e) { throw e; } catch (AppaloosaDeployException e) { return makePublishCall(httpPost, parameters); try { List parameters = constructParametersFromUpdate(update); HttpPost httpPost = new HttpPost(publishUpdateUrl()); throws AppaloosaDeployException { protected MobileApplicationUpdate publish(MobileApplicationUpdate update) } logger.println(string); if (logger != null) private void log(String string) { } return update; } throw new AppaloosaDeployException("Appaloosa servers seems to be down. Please retry later. Sorry for breaking your build..."); if (retries >= MAX_RETRIES) { } } retries++; }catch (Exception e) { retries = 0; update = getMobileApplicationUpdateDetails(update.id); try{ log("== Check that appaloosa has processed the uploaded file (extract useful information and do some verifications)"); smallWait(); while (!update.isProcessed() && retries < MAX_RETRIES) { int retries = 0; MobileApplicationUpdate update) throws AppaloosaDeployException { protected MobileApplicationUpdate waitForAppaloosaToProcessFile( } } update.groupNames.addAll(groupNames); if (groupNames != null) { update.groupNames.clear(); update.changelog = changelog; update.description = description; String changelog) { List groupNames, String description, void setUpdateParameters(MobileApplicationUpdate update, } } throw new AppaloosaDeployException(update.statusMessage);adG?H???????vYVU?????qSPOJ? ? ? ? Y    ? ? X B ? ? ? b [ ? ? z w v C  ? ? ? g F @ ; 7 ' $ #  ?w?f??sIB???4????mlM&??`ON"?????M9??? + update.statusMessage); log("== Impossible to publish file: " } else { log("== File deployed and published successfully"); publish(update); setUpdateParameters(update, description, groupNames, changelog); log("== Publish uploaded file"); if (update.hasError() == false) { // publish update update = waitForAppaloosaToProcessFile(update); // Wait for Appaloosa to process the file uploadForm); MobileApplicationUpdate update = notifyAppaloosaForFile(filePath, log("== Start remote processing file"); // Notify Appaloosa that the file is available uploadFile(filePath, uploadForm); log("== Upload file " + filePath); // Upload the file on Amazon UploadBinaryForm uploadForm = getUploadForm(); log("== Ask for upload information"); // Retrieve details from Appaloosa to do the upload resetHttpConnection(); log("== reseting http conn log("== Deploy file " + filePath + " to App log( log("== Appaloosa Client V1.8"); throws AppaloosaDeployException { public void deployFile(String filePath, String description, List groupNames, String changelog) * */ * when something went wrong * @throws AppaloosaDeployException * @param changelog Text changelog for this update. Can be empty. * You can also specify to publish your file to the default group "everybody", you have to use the name "everybody" even in French. * otherwise it will be published to default group "everybody". * When null or empty, the update will be publish to previous allowed groups if a previous update exists, * @param groupNames List of group names that will be allowed to see and install this update. * @param description Text description for this update. Use null if you want to use the previous description. * @param filePath physical path of the file to upload /** } return names; } } } names.add(trimedGroupName); if (!trimedGroupName.isEmpty()) { String trimedGroupName = groupName.trim(); for (String groupName : groupNames.split("\\|")) { if (groupNames != null) { ArrayList names = new ArrayList(); List parseGroupNames(String groupNames) { } deployFile(filePath, description, parseGroupNames(groupNames), changelog); throws AppaloosaDeployException { public void deployFile(String filePath, String description, String groupNames, String changelog) * */ * @throws AppaloosaDeployException * @param changelog Changelog of the update * separated by '|'. Example: "Group 1 | Group 2" * List of group names in a string format, group names should be * @param groupNames * @param description Text changelog for this update. Can be empty. * @param filePath Path to the binary * {@link #deployFile(String, String, String, String)} with groupNames as String. /** } deployFile(filePath, null, (List) null, null); public void deployFile(String filePath) throws AppaloosaDeployException { * */ * @throws AppaloosaDeployException * @param filePath Path to the binary * {@link #deployFile(String, String, List, String)} will all params set to null. /** } this.proxyPort = proxyPort; this.proxyPass = proxyPass; this.proxyUser = proxyUser; this.proxyHost = proxyHost; this(storeToken); int proxyPort, String proxyUser, String proxyPass) { public AppaloosaClient(String storeToken, String proxyHost, } setStoreToken(storeToken); this(); public AppaloosaClient(String storeToken) { } logger = System.out; public AppaloosaClient() { private int proxyPort;ad? ; ????S)??????[/? ? ? ? { z f B  ? ? ? ? Y ; + update.statusMessage); log("== Impossible to publish file: " } else { log("== File deployed and published successfully"); publish(update); setUpdateParameters(update, description, groupNames, changelog); log("== Publish uploaded file"); if (update.hasError() == false) { // publish update update = waitForAppaloosaToProcessFile(update); // Wait for Appaloosa to process the file uploadForm); MobileApplicationUpdate update = notifyAppaloosaForFile(filePath, log("== Start remote processing file"); // Notify Appaloosa that the file is available uploadFile(filePath, uploadForm); log("== Upload file " + filePath); // Upload the file on Amazon UploadBinaryForm uploadForm = getUploadForm(); log("== Ask for upload information"); // Retrieve details from Appaloosa to do the upload resetHttpConnection(); log("== reseting http connection"); log("== Deploy file " + filePath + " to Appaloosa");




© 2015 - 2025 Weber Informatics LLC | Privacy Policy