shrimpy's profileShrimpy`s spacePhotosBlogListsMore Tools Help

DON`T HAVE THE POWER BUT WE NEVER SAY NEVER ...

Global Domain Name

shrimpy.info



They say you`d better listen to the voice of reason
But they don't give you any choice
Cause they think that it's treason
So you had better do as you are told
You had better listen to the radi-o


Photo 1 of 12
July 03

What a amazing benifit.....

Back then, when we were still a course work student.....the printing quota was around 1K every semester......we`ve already thought that was a lot....

however...after been a research assistance........what the hell.........unbelieveable...
10G internet quota....100K black and whit printing quota and 200 colour printing quota.....

man....now..i felt a little bit regret...i should ask for a research master instead of course work at the very beginning...

damn it...howcome there are so much different.....we pay for exact the same amount of tuition fee...



June 22

A Mistake capture from MSN



ah~~~~~~~~~~~~~~~~ look at the place the read arrow is pointing.....

it should be some image AD...however.....MSN failed to parse it....must be the wrong script send from Microsoft.....

-----------------------------------------------------------------------------------------------------------------------

Ok...i have to go back to study......fighting for my last exam....

June 12

终于。。拿回了点学费。。。

来澳洲上学快两年了,花了四万多澳币交学费,
没想到最后毕业了,居然有机会赚回学校一笔,
在这里感谢一下我们的 Professor Anna... 拉了个项目,两个多月就能要回10K的学费。。哈哈

想当年出国前,给吉大的教授干了一年半,也只是跟着别人后面发了几篇文章。

唉。。。还是钱好啊。。。。





June 03

曾经的大学, 我们也疯狂过。。。

毕业的晚会。。。全班的cosplay。。。最多的掌声。。。还有最多的欢呼。。。

很快。。。我又要毕业了。。。。

(Part 1)
    
http://video.qq.com/res/qqplayerout.swf?vid=1vrM0B70QVg
(Part 2)
    
http://video.qq.com/res/qqplayerout.swf?vid=1SCJz21YGtW

May 16

Access Azure Blob Storage in Java

Microsoft is not that friendly to other language`s programer...
it is hard to find out resource how to access Azure storage in anohter language besides C#

This article is show how to access Azure Blob Storage in java, although Steve Marx has already post a artiles on his blog months ago,
but it is still hard to use for beginner.

What i am going to do in this article is that:
i have already got an container call "cantainer" under my account, i am going to put a blob call "abc" into the container.

Let`s begin:
Azure Storage is a REST base database, so i choose to use httpclient from apache, it is not a must that u have to use the same lib as mine...
       <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>4.0-beta2</version>
        </dependency>


the hard thing when comunicate with azure storage is that, we have to sign our request for authorization

There is a article from microsoft : http://msdn.microsoft.com/en-us/library/dd179428.aspx
list what we should do to sign the request,
e.g blob storage :
StringToSign = VERB + "\n" +
Content-MD5 + "\n" + //(optional)
Content-Type + "\n" +
Date + "\n" +
CanonicalizedHeaders +
CanonicalizedResource;
In Java :

    public static String ContentType = "Content-Type";
    public static String X_MS_Date = "x-ms-date";

    public static synchronized void Sign(HttpRequestBase request, String account, String key) throws Exception {
        SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
        fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
        request.setHeader(X_MS_Date, fmt.format(Calendar.getInstance().getTime()) + " GMT");

        StringBuilder sb = new StringBuilder();
        sb.append(request.getMethod().toUpperCase() + "\n\n");
        sb.append(request.getFirstHeader(ContentType).getValue() + "\n\n");
        sb.append(X_MS_Date + ":" + request.getFirstHeader("x-ms-date").getValue() + "\n");
        sb.append("/" + account + request.getURI().getPath());

        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(Base64Coder.decode(key), "HmacSHA256"));
        String finalKey = new String(Base64Coder.encode(mac.doFinal(sb.toString().getBytes("UTF-8"))));
        request.setHeader("Authorization", "SharedKey " + account + ":" + finalKey);
    }

HOWTO use it:

public static void main(String args[]) throws Exception {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPut put = new HttpPut("http://" + YOUR_ACCOUNT + ".blob.core.windows.net/container/abc");
        put.addHeader(PutBlob.ContentType, "text/plain");   // by default is binary, you should specify a qualify MINE TYPE
        put.setEntity(new StringEntity("Hello world!!", "UTF-8"));
        Sign(put, YOUR_ACCOUNT, YOUR_KEY);

        log.debug(EntityUtils.toString(httpclient.execute(put).getEntity()));
    }



====== Full Source Code Below ======
package org.unsw.eva.rest.azure;

import java.util.Calendar;
import java.util.TimeZone;
import java.text.SimpleDateFormat;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import org.apache.http.client.methods.HttpRequestBase;
import org.unsw.eva.utils.Base64Coder;
/**
 *
 * @author shrimpy
 */
public abstract class AbstractAzureStorageRestAction {

    public enum CONTENT_TYPE {

        TEXT_PLAIN("text/plain; charset=UTF-8");
        private String value;

        private CONTENT_TYPE(String value) {
            this.value = value;
        }

        public String getValue() {
            return value;
        }
    }
    public static String ACCOUNT = "YOUR ACCOUNT HERE";
    public static String KEY = "YOUR KEY HERE";
    public static String REQUEST_URI = "http://" + ACCOUNT + ".blob.core.windows.net/container/abc";
    public static String ContentType = "Content-Type";
    public static String X_MS_Date = "x-ms-date";

    public static synchronized void Sign(HttpRequestBase request, String account, String key) throws Exception {
        SimpleDateFormat fmt = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss");
        fmt.setTimeZone(TimeZone.getTimeZone("GMT"));
        request.setHeader(X_MS_Date, fmt.format(Calendar.getInstance().getTime()) + " GMT");

        StringBuilder sb = new StringBuilder();
        sb.append(request.getMethod().toUpperCase() + "\n\n");
        sb.append(request.getFirstHeader(ContentType).getValue() + "\n\n");
        sb.append(X_MS_Date + ":" + request.getFirstHeader("x-ms-date").getValue() + "\n");
        sb.append("/" + account + request.getURI().getPath());

        Mac mac = Mac.getInstance("HmacSHA256");
        mac.init(new SecretKeySpec(Base64Coder.decode(key), "HmacSHA256"));
        String finalKey = new String(Base64Coder.encode(mac.doFinal(sb.toString().getBytes("UTF-8"))));
        request.setHeader("Authorization", "SharedKey " + account + ":" + finalKey);
    }
}


package org.unsw.eva.rest.azure;

import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author shrimpy
 */
public class PutBlob extends AbstractAzureStorageRestAction {

    private static final Logger log = LoggerFactory.getLogger(PutBlob.class);

    public static void main(String args[]) throws Exception {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPut put = new HttpPut("http://" + PutBlob.ACCOUNT + ".blob.core.windows.net/container/abc");
        put.addHeader(PutBlob.ContentType, PutBlob.CONTENT_TYPE.TEXT_PLAIN.getValue());
        put.setEntity(new StringEntity("Hello world!!---", "UTF-8"));
        Sign(put, PutBlob.ACCOUNT, PutBlob.KEY);

        log.debug(EntityUtils.toString(httpclient.execute(put).getEntity()));
    }
}





Reference : http://blog.smarx.com/posts/programming-language-interoperability-in-windows-azure


 

Shrimpy`s space

Life for rent ...
走过路过,记得留下点口水。。。呵呵
Please wait...
Sorry, the comment you entered is too long. Please shorten it.
You didn't enter anything. Please try again.
Sorry, we can't add your comment right now. Please try again later.
To add a comment, you need permission from your parent. Ask for permission
Your parent has turned off comments.
Sorry, we can't delete your comment right now. Please try again later.
You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
Complete the security check below to finish leaving your comment.
The characters you type in the security check must match the characters in the picture or audio.
shrimpywrote:
啊。。太好了。。是十二月。我还以为你十一月要来。。

我到时候可以去接你。哈哈  61 0431464392 这是我手机,
shrimpywu (at) hotmail.com
我msn..哈哈。。。
Nov. 1
Jiewrote:
你有没有电话啊,我12月7号早上8点多到悉尼啊,你在不在?
Nov. 1
shrimpywrote:
To Jie :

小胖同学。。哗哈哈哈。。。。。。。。。。。。。。。。。。。。
Oct. 27
Jiewrote:
小民,你好cool....
Oct. 27
shrimpywrote:
TO Tong:

-_-!!!...啊。。。我out date了。。。 怪不得看起来怪怪的。。。。唉。。。。。。
Oct. 24

Windows Media Player