GAE な部品

とりあえず sun-java6 なパケジ入れちう。今日でどこまでデキるかは不明ですが

なあたりも含め、って考えてますが、今日はベータなソレを github に置ければシアワセかな、って思ってます。

sun-java6

sun-java5-* を remove しないとダメでした。とりあえずこの程度で良いんだから Debian は楽だわな。Sun の javaフリーソフトウェアになったお陰ではありますが。

作りはじめたんですが、org.apache なナニが無い模様。libcommons-httpclient-java なパケジを入れれば良いのかなぁ。とりあえず apt-get install したんですが、正解でありますように。

違った

org.apache.http が無い。こーゆー微妙な問題は勘弁して欲しいんですが。現時点で糸口ナシ状態だったりしてます。
で、色々 gdgd になりかけた瞬間 http://hc.apache.org/ を発見。HttpClient4.0.1 をオトして解凍してプロジェクトのプロパティから add external jar したら出てきた。とほほ杉。
まだ微妙なので HttpCore4.0.1 もオトす。

ヨシ

一つめできた。

package jp.shuri.yamanetoshi.gaeaccess;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.List;
import java.util.ArrayList;

public class GoogleAuth {
	public static String getAuthKey(HttpClient httpClient, String source, String id, String passwd) throws Exception {
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("Email", id));
        nvps.add(new BasicNameValuePair("Passwd", passwd));
        nvps.add(new BasicNameValuePair("service", "ah"));
        nvps.add(new BasicNameValuePair("source", source));
        nvps.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE"));

        //Login at Google.com
        HttpPost httpost = new HttpPost("https://www.google.com/accounts/ClientLogin");
        HttpResponse response = null;
        
        httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        response = httpClient.execute(httpost);
        
        String authKey = null;
        BufferedReader br = null;

        br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        String line = null;
        while ((line = br.readLine()) != null) {
        	String[] s = line.split("=");
        	if (s.length == 2 && s[0].equalsIgnoreCase("auth")) {
        		authKey = s[1];
        		break;
            }
        }

        if (br != null) br.close();
        
        return authKey;
	}
}

試験は後で書く。リファクタリングも後。次はアクセスしてレスポンスを戻すナニ。

package jp.shuri.yamanetoshi.gaeaccess;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;

public class AppspotAccess {
	private String URL;
	private HttpClient httpClient;
	
	AppspotAccess(String url, HttpClient httpClient) {
		this.URL = url;
		this.httpClient = httpClient;
	}
	
	public HttpResponse getContent(String authKey, String URI) throws Exception {
        HttpGet httpget = new HttpGet(URL + "/_ah/login?auth=" + authKey + "&continue=" + URI);
        return httpClient.execute(httpget);
    }
	
	public HttpResponse getContent(String URI) throws Exception {
		HttpGet httpget = new HttpGet(URL + "/" + URI);
		return httpClient.execute(httpget);
	}
}

git 方面に

投入したいんですが、どうやるんだっけ。思い出しつつ以下に控えを。

  • github にリポジトリ作る
  • ローカル側で
    • git init
    • (必要なもののみ) git add
    • git commit
    • git remote add origin git@github.com:yamanetoshi/GAEAccess.git
    • git push origin master

これで master の作成完了。次は develop で以下。

  • これもローカル側で
    • git checkout -b develop master
    • git push origin develop

あとは上記のリポジトリを clone して

$ git clone git@github.com:yamanetoshi/GAEAccess.git

develop を以下でナニ。

$ git checkout -t -b develop origin/develop

とりあえず、上記の方法でリポジトリを作成して、戻ったレスポンスを渡して json を取得する Factory も元気なら作る。

TODO

  • ant で jar を作るソレ
  • junit な単体試験

で、jar を作って eclipse 側で本当に動くのか、について確認必須。

注意

上記リポジトリはエントリ投入後に作成します。誤りがあれば別途追記します。

追記

bin ディレクトリはアレなので .gitignore にナニ。

$ echo bin/ > ./gitignore

で、git init して

$ git init
$ git add src .classpath .project
$ git add .gitignore
$ git status

で、一旦 commit して以下。

$ git remote add origin git@github.com:yamanetoshi/GAEAccess.git
$ git push origin master

カギって職場でも使えるんだったっけ。まぁいいや。とりあえずスルーで develop も作る。ローカル側で以下らしい。

$ git checkout -b develop master
$ git push origin develop

とりあえず github 側についてはこれで OK なはずなので、続きは明日。って結局日を跨いでしまいましたが。