<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>mgBlog &#187; Java</title>
	<atom:link href="http://mgsimon.de/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://mgsimon.de</link>
	<description>Esc(ape), einfach ein anderes Blog über technische Spielerei ...</description>
	<lastBuildDate>Sun, 18 Dec 2011 08:52:23 +0000</lastBuildDate>
	<language>de</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Android und JSON, JSONViewer ein Beispiel</title>
		<link>http://mgsimon.de/2011/11/10/android-und-json-jsonviewer-ein-beispiel/</link>
		<comments>http://mgsimon.de/2011/11/10/android-und-json-jsonviewer-ein-beispiel/#comments</comments>
		<pubDate>Thu, 10 Nov 2011 07:47:31 +0000</pubDate>
		<dc:creator>mg</dc:creator>
				<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mobil]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[SDK]]></category>

		<guid isPermaLink="false">http://mgsimon.de/?p=3129</guid>
		<description><![CDATA[JSON wegen der Einfach- und Kompaktheit ideal f&#252;r die mobile Kommunikation, enth&#228;lt das SDK von Android einige Klassen der Referenzimplementierung. Ein kleines Beispiel kurz notiert &#8230; Kofiguration Im Manifest f&#252;r Android wird die Berechtigung f&#252;r den Zugriff auf das weltweite Netz (Zeile 7) konfiguriert. 1 2 3 4 5 6 7 8 9 10 11 [...]]]></description>
			<content:encoded><![CDATA[<p>JSON wegen der Einfach- und Kompaktheit ideal f&#252;r die mobile Kommunikation, enth&#228;lt das SDK von Android einige Klassen der Referenzimplementierung.<br />
<div id="attachment_3370" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/AndroidJSONViewer.png" alt="Android :: JSONViewer" title="Android :: JSONViewer" width="442" height="265" class="size-full wp-image-3370 stamp" /><p class="wp-caption-text">Android :: JSONViewer</p></div>Ein kleines Beispiel kurz notiert &#8230;</p>
<p><span id="more-3129"></span><div style="background-color: rgb(191, 228, 255); border:1px solid rgb(128, 201, 255); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/info.png" alt="Hinweis" title="Hinweis" width="24" height="24" style="margin: 4px 8px 0 0; float:left;"/>Das folgende Beispiel wurde unter Mac OS X 10.6.8 mit der Java Version 1.6.0_26, Eclipse EE 3.7.1 Indigo und ADT (Android Development Tools) Plugin f&#252;r Eclipse durchgef&#252;hrt. Siehe auch <a href="http://mgsimon.de/2009/12/19/hello-world-android-unter-linux/">Hello World Android unter Linux</a> …</div></p>
<p><strong>Kofiguration</strong></p>
<p>Im Manifest f&#252;r Android wird die Berechtigung f&#252;r den Zugriff auf das weltweite Netz (Zeile 7) konfiguriert.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;manifest</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">package</span>=<span style="color: #ff0000;">&quot;de.mgsimon.android.jsonviewer&quot;</span> <span style="color: #000066;">android:versionCode</span>=<span style="color: #ff0000;">&quot;1&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">android:versionName</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-sdk</span> <span style="color: #000066;">android:minSdkVersion</span>=<span style="color: #ff0000;">&quot;8&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;uses-permission</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.permission.INTERNET&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application</span> <span style="color: #000066;">android:icon</span>=<span style="color: #ff0000;">&quot;@drawable/icon&quot;</span> <span style="color: #000066;">android:label</span>=<span style="color: #ff0000;">&quot;@string/app_name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;activity</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;.JSONViewerActivity&quot;</span> <span style="color: #000066;">android:label</span>=<span style="color: #ff0000;">&quot;@string/app_name&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;intent-filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;action</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.intent.action.MAIN&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;category</span> <span style="color: #000066;">android:name</span>=<span style="color: #ff0000;">&quot;android.intent.category.LAUNCHER&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/intent-filter<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/activity<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/manifest<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p><em>JSONViewer/AndroidManifest.xml</em></p>
<p><strong>Layout</strong></p>
<p>Das Layout enth&#228;lt ein Eingabefeld (EditText) f&#252;r die URL, ein Button (ImageButton) zum abrufen der URL und ein mehrzeiliges Textfeld (TextView) zum anzeigen.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;RelativeLayout</span> <span style="color: #000066;">xmlns:android</span>=<span style="color: #ff0000;">&quot;http://schemas.android.com/apk/res/android&quot;</span></span>
<span style="color: #009900;">  <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;LinearLayout</span> <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/linearLayoutUrl&quot;</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;match_parent&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;EditText</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/editTextURL&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> <span style="color: #000066;">android:singleLine</span>=<span style="color: #ff0000;">&quot;true&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span> <span style="color: #000066;">android:layout_weight</span>=<span style="color: #ff0000;">&quot;2&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
      <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;requestFocus<span style="color: #000000; font-weight: bold;">&gt;</span></span><span style="color: #000000; font-weight: bold;">&lt;/requestFocus<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/EditText<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ImageButton</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/imageButtonLoad&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> <span style="color: #000066;">android:src</span>=<span style="color: #ff0000;">&quot;@android:drawable/ic_media_play&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;0dp&quot;</span> <span style="color: #000066;">android:layout_weight</span>=<span style="color: #ff0000;">&quot;1&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span><span style="color: #000000; font-weight: bold;">&lt;/ImageButton<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/LinearLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ScrollView</span> <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span> <span style="color: #000066;">android:layout_below</span>=<span style="color: #ff0000;">&quot;@+id/linearLayoutUrl&quot;</span></span>
<span style="color: #009900;">    <span style="color: #000066;">android:layout_margin</span>=<span style="color: #ff0000;">&quot;5dip&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;TextView</span> <span style="color: #000066;">android:id</span>=<span style="color: #ff0000;">&quot;@+id/textViewContent&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">android:layout_width</span>=<span style="color: #ff0000;">&quot;fill_parent&quot;</span> <span style="color: #000066;">android:layout_height</span>=<span style="color: #ff0000;">&quot;wrap_content&quot;</span></span>
<span style="color: #009900;">      <span style="color: #000066;">android:textAppearance</span>=<span style="color: #ff0000;">&quot;?android:attr/textAppearanceMedium&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ScrollView<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/RelativeLayout<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><em>JSONViewer/res/layout/main.xml</em></p>
<p><strong>Activity</strong></p>
<p>Die Aktivit&#228;t JSONViewerActivity erweitert Activity (Zeile 26) und initialisiert notwendige Komponenten in der &#252;berschriebene Methode onCreate (Zeile 37). Referenzen zu Elementen des UI werden &#252;ber findViewById (Zeile 41,43 und 44) gesetzt und dem ImageButton (Zeile 45) wird die aufzurufende Methode f&#252;r das Event onClick (Zeile 48) &#252;berschrieben.</p>
<p>Die Methode onClick &#8211; aufgerufen durch Klick auf dem Button &#8211; startet mit &#252;bergebener URL (Zeile 50) einen Thread (Zeile 51). Die Klasse UrlLoadTask zeigt vor (Zeile 63) dem Thread einen Status an und aktualisiert die Aktivit&#228;t nach (Zeile 94) dem Thread. </p>
<p>Die Daten werden unabh&#228;ngig des Threads f&#252;r die Benutzeroberfl&#228;che in der Methode doInBackground (Zeile 69) verarbeitet.  </p>
<div style="background-color: rgb(191, 255, 191); border:1px solid rgb(128, 255, 128); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/tip.png" alt="Tipp" title="Tipp" width="24" height="24" style="margin: 4px 8px 0 0; float:left;" />Application not responding (ANR) Meldungen werden nach etwa drei Sekunden geworfen, wenn die Benutzeroberfl&#228;che blockiert wird. Alle langl&#228;ufigen und unbekannten Laufzeiten nebenl&#228;ufig ausf&#252;hren, dann klappt es auch ohne ANR.</div>
<p>Im Hintergrund herunterladen (Zeile 71-73), JSONObject erzeugen (Zeile 74) und die TextView aktualisieren (Zeile 97).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">de.mgsimon.android.jsonviewer</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URI</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.net.URISyntaxException</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.HttpResponse</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.ParseException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.ClientProtocolException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.HttpClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.client.methods.HttpGet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.impl.client.DefaultHttpClient</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.apache.http.util.EntityUtils</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">org.json.JSONObject</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.Activity</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.app.ProgressDialog</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.AsyncTask</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.os.Bundle</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.view.View</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.EditText</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.ImageButton</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">android.widget.TextView</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> JSONViewerActivity <span style="color: #000000; font-weight: bold;">extends</span> Activity <span style="color: #009900;">&#123;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> EditText mEditTextUrl<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> ImageButton mImageButtonLoad<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> TextView mTextViewContent<span style="color: #339933;">;</span>
  <span style="color: #000000; font-weight: bold;">private</span> URI mUri<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> ProgressDialog mProgressDialog<span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #008000; font-style: italic; font-weight: bold;">/** Called when the activity is first created. */</span>
  @Override
  <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onCreate<span style="color: #009900;">&#40;</span>Bundle savedInstanceState<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000000; font-weight: bold;">super</span>.<span style="color: #006633;">onCreate</span><span style="color: #009900;">&#40;</span>savedInstanceState<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    setContentView<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">layout</span>.<span style="color: #006633;">main</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    mEditTextUrl <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>EditText<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">editTextURL</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mEditTextUrl.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;http://mgsimon.appspot.com/aboutmyrequest&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mTextViewContent <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>TextView<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">textViewContent</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mImageButtonLoad <span style="color: #339933;">=</span> <span style="color: #009900;">&#40;</span>ImageButton<span style="color: #009900;">&#41;</span> findViewById<span style="color: #009900;">&#40;</span>R.<span style="color: #006633;">id</span>.<span style="color: #006633;">imageButtonLoad</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    mImageButtonLoad.<span style="color: #006633;">setOnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #000000; font-weight: bold;">new</span> <span style="color: #003399;">View</span>.<span style="color: #006633;">OnClickListener</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
      @Override
      <span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> onClick<span style="color: #009900;">&#40;</span><span style="color: #003399;">View</span> v<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
          mUri <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> URI<span style="color: #009900;">&#40;</span>mEditTextUrl.<span style="color: #006633;">getText</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          <span style="color: #000000; font-weight: bold;">new</span> UrlLoadTask<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>mUri<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>URISyntaxException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
          e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
          mTextViewContent.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
      <span style="color: #009900;">&#125;</span>
    <span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
&nbsp;
  <span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">class</span> UrlLoadTask <span style="color: #000000; font-weight: bold;">extends</span> AsyncTask<span style="color: #339933;">&lt;</span>URI, <span style="color: #003399;">Void</span>, JSONObject<span style="color: #339933;">&gt;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPreExecute<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      mProgressDialog <span style="color: #339933;">=</span> ProgressDialog.<span style="color: #006633;">show</span><span style="color: #009900;">&#40;</span>JSONViewerActivity.<span style="color: #000000; font-weight: bold;">this</span>, <span style="color: #0000ff;">&quot;&quot;</span>,
          <span style="color: #0000ff;">&quot;Loading. Please wait...&quot;</span>, <span style="color: #000066; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> JSONObject doInBackground<span style="color: #009900;">&#40;</span>URI... <span style="color: #006633;">uris</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        HttpClient client <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> DefaultHttpClient<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        HttpGet get <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> HttpGet<span style="color: #009900;">&#40;</span>uris<span style="color: #009900;">&#91;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        HttpResponse response <span style="color: #339933;">=</span> client.<span style="color: #006633;">execute</span><span style="color: #009900;">&#40;</span>get<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        JSONObject jso <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span>EntityUtils.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span>response
            .<span style="color: #006633;">getEntity</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #009900;">&#40;</span>jso<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>ClientProtocolException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mTextViewContent.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">IOException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mTextViewContent.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span><span style="color: #003399;">ParseException</span> e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mTextViewContent.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mTextViewContent.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      <span style="color: #000000; font-weight: bold;">return</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    @Override
    <span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> onPostExecute<span style="color: #009900;">&#40;</span>JSONObject jso<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
      <span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #009900;">&#40;</span>jso <span style="color: #339933;">!=</span> <span style="color: #000066; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
          mTextViewContent.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>jso.<span style="color: #006633;">toString</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">4</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        mTextViewContent.<span style="color: #006633;">setText</span><span style="color: #009900;">&#40;</span>e.<span style="color: #006633;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
      <span style="color: #009900;">&#125;</span>
      mProgressDialog.<span style="color: #006633;">dismiss</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>JSONViewer/src/de.mgsimon.android.jsonviewer/JSONViewerActivity.java</em></p>
]]></content:encoded>
			<wfw:commentRss>http://mgsimon.de/2011/11/10/android-und-json-jsonviewer-ein-beispiel/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Google App Engine und JSON, AboutMyRequest ein Beispiel</title>
		<link>http://mgsimon.de/2011/10/30/google-app-engine-und-json-aboutmyrequest-ein-beispiel/</link>
		<comments>http://mgsimon.de/2011/10/30/google-app-engine-und-json-aboutmyrequest-ein-beispiel/#comments</comments>
		<pubDate>Sun, 30 Oct 2011 14:37:54 +0000</pubDate>
		<dc:creator>mg</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[App]]></category>
		<category><![CDATA[Engine]]></category>
		<category><![CDATA[GAE]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[Servlet]]></category>

		<guid isPermaLink="false">http://mgsimon.de/?p=3131</guid>
		<description><![CDATA[Die JavaScript Object Notation (JSON) ist ein leicht lesbares und leichtgewichtiges Protokoll, um Daten strukturiert mit wenigen Regeln verwalten zu k&#246;nnen. Viele Wege f&#252;hren nach JSON, hier ein kleines Beispiel in Java &#8230; AboutMyRequest &#8230; &#8230; oder einfach &#252;ber mein Request soll als kleines Beispiel die Informationen &#252;ber eine Anfrage zur Anwendung in der Google [...]]]></description>
			<content:encoded><![CDATA[<p>Die <a href="http://json.org/" target="_blank">JavaScript Object Notation (JSON)</a> ist ein leicht lesbares und leichtgewichtiges Protokoll, um Daten strukturiert mit wenigen Regeln verwalten zu k&#246;nnen.<br />
<div id="attachment_3262" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/GoogleAppEngineJSONAboutMyRequest.png" alt="Google App Engine JSON :: AboutMyRequest" title="Google App Engine JSON :: AboutMyRequest" width="442" height="228" class="size-full wp-image-3262 stamp" /><p class="wp-caption-text">Google App Engine JSON :: AboutMyRequest</p></div></p>
<p>Viele Wege f&#252;hren nach JSON, hier ein kleines Beispiel in Java &#8230;</p>
<p><span id="more-3131"></span><div style="background-color: rgb(191, 228, 255); border:1px solid rgb(128, 201, 255); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/info.png" alt="Hinweis" title="Hinweis" width="24" height="24" style="margin: 4px 8px 0 0; float:left;"/>Das folgende Beispiel wurde unter Mac OS X 10.6.8 mit der Java Version 1.6.0_26, Eclipse EE 3.7.1 Indigo und Google Plugin f&#252;r Eclipse 2.4.1 durchgef&#252;hrt. Siehe auch <a href="http://mgsimon.de/2011/10/25/hello-world-google-app-engine/" title="Hello World Google App Engine">Hello World Google App Engine</a> &#8230;</div></p>
<p><strong>AboutMyRequest &#8230;</strong></p>
<p>&#8230; oder einfach &#252;ber mein Request soll als kleines Beispiel die Informationen &#252;ber eine Anfrage zur Anwendung in der Google App Engine in JSON zur&#252;ck beantworten.</p>
<p><strong>JSON Referenzimplementierung</strong></p>
<p>Im SDK von der Google App Engine sind die Klassen der Referenzimplementierung zur Verarbeitung von JSON im Paket  com.google.appengine.repackaged.org.json (appengine-api-labs-1.5.4.jar) vorhanden.</p>
<div style="background-color: rgb(191, 255, 191); border:1px solid rgb(128, 255, 128); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/tip.png" alt="Tipp" title="Tipp" width="24" height="24" style="margin: 4px 8px 0 0; float:left;" />Damit die Dokumenation der Referenzimplementierung von Douglas Crockford in Eclipse verwendet werden kann, k&#246;nnen die Quellen unter <a href="https://github.com/douglascrockford/JSON-java" target="_blank">JSON-java</a> als ZIP-Archiv heruntergeladen werden und dem Projekt hinzugef&#252;gt werden.</div>
<p><strong>AboutMyRequestServlet</strong></p>
<p>Ein neues Servlet wird im Google App Engine Projekt bei selektiertem Package &#252;ber &#8220;File / New / Class&#8221; mit folgenden Einstellungen erstellt.<br />
<div id="attachment_3271" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/GoogleAppEngineJSONEclipseNewJavaClass.png" alt="Google App Engine JSON :: Eclipse New Java Class" title="Google App Engine JSON :: Eclipse New Java Class" width="442" height="528" class="size-full wp-image-3271 stamp" /><p class="wp-caption-text">Google App Engine JSON :: Eclipse New Java Class</p></div></p>
<ul>
<li>Name: AboutMyRequestServlet</li>
<li>Superclass: javax.servlet.http.HttpServlet</li>
</ul>
<p>In dem folgenden Servlet wird ein JSONObject erzeugt (Zeile 20) und die jeweiligen Header-Informationen hinzugef&#252;gt (Zeile 25). Das JSONObject wird mit dem richtigen Media Type (Zeile 27) &#252;ber Response einfach zum Client gesendet (Zeile 28).</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
</pre></td><td class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">tld.sld.my.example</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.util.Enumeration</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.ServletException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServlet</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletRequest</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.HttpServletResponse</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.appengine.repackaged.org.json.JSONException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">com.google.appengine.repackaged.org.json.JSONObject</span><span style="color: #339933;">;</span>
&nbsp;
@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;serial&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> AboutMyRequestServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #009900;">&#123;</span>
&nbsp;
	@Override
	<span style="color: #000000; font-weight: bold;">protected</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest req, HttpServletResponse resp<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> ServletException, <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		JSONObject jsonObject <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> JSONObject<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000000; font-weight: bold;">try</span> <span style="color: #009900;">&#123;</span>
			Enumeration<span style="color: #339933;">&lt;</span>String<span style="color: #339933;">&gt;</span> names <span style="color: #339933;">=</span> req.<span style="color: #006633;">getHeaderNames</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #000000; font-weight: bold;">while</span><span style="color: #009900;">&#40;</span>names.<span style="color: #006633;">hasMoreElements</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
				<span style="color: #003399;">String</span> name <span style="color: #339933;">=</span> names.<span style="color: #006633;">nextElement</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
				jsonObject.<span style="color: #006633;">put</span><span style="color: #009900;">&#40;</span>name, req.<span style="color: #006633;">getHeader</span><span style="color: #009900;">&#40;</span>name<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			<span style="color: #009900;">&#125;</span>
			resp.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;application/json&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
			resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">print</span><span style="color: #009900;">&#40;</span>jsonObject<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span> <span style="color: #000000; font-weight: bold;">catch</span> <span style="color: #009900;">&#40;</span>JSONException e<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
			e.<span style="color: #006633;">printStackTrace</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><em>AboutMyRequestServlet.java</em></p>
<p><strong>Konfiguration</strong></p>
<p>Damit das Servlet im Container bekannt ist (&lt;servlet&gt;) und &#252;ber eine URL aufl&#246;sbar ist (&lt;servlet-mapping&gt;), muss folgende Konfiguration in der Datei &#8220;war/WEB-INF/web.xml&#8221; hinzugef&#252;gt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AboutMyRequest<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>tld.sld.my.example.AboutMyRequestServlet<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-class<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>AboutMyRequest<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-name<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>/aboutmyrequest<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/url-pattern<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/servlet-mapping<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p><em>web.xml</em></p>
<p>Anschlie&#223;end kann die Webanwendung &#252;ber &#8220;Run / Run As / Web Application&#8221; gestartet werden und lokal &#252;ber <a href="http://localhost:8888/aboutmyrequest" target="_blank">http://localhost:8888/aboutmyrequest</a> getestet werden. </p>
<p><strong>Antworten</strong></p>
<p>Nach erfolgreicher Publizierung in der Google App Engine kann auf das Servlet &#252;ber http://myappid.appspot.com/aboutmyrequest wie z.B. <a href="http://mgsimon.appspot.com/aboutmyrequest" target="_blank">http://mgsimon.appspot.com/aboutmyrequest</a> zugegriffen werden.</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;Accept-Language&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;de-de,de;q=0.8,en-us;q=0.5,en;q=0.3&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;Host&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;mgsimon.appspot.com&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;Accept-Charset&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;ISO-8859-1,utf-8;q=0.7,*;q=0.7&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;X-AppEngine-Country&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;DE&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;User-Agent&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; de; rv:1.9.2.23) Gecko/20110920 Firefox/3.6.23&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;Accept&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><em>Antwort einer Anfrage durch Mozilla Firefox unter Mac OS X auf einem MacBook Pro</em></p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#123;</span>
    <span style="color: #3366CC;">&quot;Host&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;mgsimon.appspot.com&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;Referer&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;http://mgsimon.de/&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;X-AppEngine-Country&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;DE&quot;</span><span style="color: #339933;">,</span>
    <span style="color: #3366CC;">&quot;User-Agent&quot;</span><span style="color: #339933;">:</span><span style="color: #3366CC;">&quot;Mozilla/5.0 (Linux; U; Android 2.3.3; de-de; HTC_DesireZ_A7272 Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1&quot;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p><em>Antwort einer Anfrage durch Browser unter Android auf einem HTC Desire Z</em><br />
<div style="background-color: rgb(191, 228, 255); border:1px solid rgb(128, 201, 255); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/info.png" alt="Hinweis" title="Hinweis" width="24" height="24" style="margin: 4px 8px 0 0; float:left;"/>Die Anfrage wird durch die Google App Engine um zus&#228;tzliche Informationen wie z.B. die i18n Info &#8220;X-AppEngine-Country&#8221;:&#8221;DE&#8221; erweitert.</div></p>
<p><strong>Weiter &#8230;</strong></p>
<ul>
<li><a href="http://tools.ietf.org/html/rfc4627" target="_blank">rfc4627</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mgsimon.de/2011/10/30/google-app-engine-und-json-aboutmyrequest-ein-beispiel/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hello World Google App Engine</title>
		<link>http://mgsimon.de/2011/10/25/hello-world-google-app-engine/</link>
		<comments>http://mgsimon.de/2011/10/25/hello-world-google-app-engine/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 15:19:39 +0000</pubDate>
		<dc:creator>mg</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[App]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[Engine]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Servlet]]></category>

		<guid isPermaLink="false">http://mgsimon.de/?p=3132</guid>
		<description><![CDATA[Google App Engine ist eine Plattform zum Entwickeln und Hosten von Webanwendungen auf den Servern von Google. Dabei werden die Ressourcen in der Infrastruktur von Google dynamisch in Abh&#228;ngigkeit der Last zugewiesen. Ohne sich Gedanken um CPU, Bandbreite oder Speicher machen zu m&#252;ssen, werden laut Google bis zu 5 Millionen Seitenaufrufe pro Monat kostenlos und [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://code.google.com/intl/de-DE/appengine/" target="_blank">Google App Engine</a> ist eine Plattform zum Entwickeln und Hosten von Webanwendungen auf den Servern von Google.  Dabei werden die Ressourcen in der Infrastruktur von Google dynamisch in Abh&#228;ngigkeit der Last zugewiesen. Ohne sich Gedanken um CPU, Bandbreite oder Speicher machen zu m&#252;ssen, werden laut Google bis zu 5 Millionen Seitenaufrufe pro Monat kostenlos und dar&#252;ber hinaus zu <a href="http://code.google.com/intl/de-DE/appengine/docs/billing.html" target="_blank">wettbewerbsf&#228;higen Preisen</a> angeboten.<br />
<div id="attachment_3176" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/HelloWorldGoogleAppEngineMozillaFirefox.png" alt="Hello World Google App Engine :: Mozilla Firefox" title="Hello World Google App Engine :: Mozilla Firefox" width="442" height="137" class="size-full wp-image-3176 stamp" /><p class="wp-caption-text">Hello World Google App Engine :: Mozilla Firefox</p></div> Die Anwendungen k&#246;nnen in einer Umgebung f&#252;r Phyton oder Java umgesetzt werden. </p>
<p>&#8220;Hello World&#8221; in der Google App Engine, ein erstes kleines Beispiel in Java. Ab in die Cloud, schnell, schneller, am schnellsten &#8230;</p>
<p><span id="more-3132"></span><div style="background-color: rgb(191, 228, 255); border:1px solid rgb(128, 201, 255); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/info.png" alt="Hinweis" title="Hinweis" width="24" height="24" style="margin: 4px 8px 0 0; float:left;"/>Das folgende Beispiel wurde unter Mac OS X 10.6.8 mit der Java Version 1.6.0_26, Eclipse EE 3.7.1 Indigo und Google Plugin f&#252;r Eclipse 2.4.1 durchgef&#252;hrt.</div><br />
<strong>Google App Engine Account</strong></p>
<p>F&#252;r die Verwendung der Google App Engine ist ein Google-Konto und die Anmeldung unter <a href="http://appengine.google.com" target="_blank">appengine.google.com</a> notwendig. </p>
<p>Einfach mit der E-Mail und dem Passwort anmelden und auf der folgenden Seite &#252;ber &#8220;Create Application&#8221; das eigene Konto durch eine Handynummer best&#228;tigen. Eine SMS mit einem Code zur Best&#228;tigung wird unmittelbar an die angegebene Nummer gesendet. Nach der Best&#228;tigung kann die erste Anwendung erstellt werden. </p>
<p>&#8220;Application Identifier&#8221;, &#8220;Application Title, &#8220;I accept these terms.&#8221; und die Anwendung kann &#252;ber &#8220;Create Application&#8221; erstellt werden.</p>
<p><div style="background-color: rgb(191, 255, 191); border:1px solid rgb(128, 255, 128); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/tip.png" alt="Tipp" title="Tipp" width="24" height="24" style="margin: 4px 8px 0 0; float:left;" />Auf der Suche nach einem noch verf&#252;gbarem &#8220;Application Identifier&#8221; kann der Name des eigenen Google-Kontos verwendet werden, dieser sollten in der Regel f&#252;r das eigene Konto reserviert sein.</div> <div id="attachment_3155" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/HelloWorldGoogleAppEngineDashboard.png" alt="Hello World Google App Engine :: Dashboard" title="Hello World Google App Engine :: Dashboard" width="442" height="276" class="size-full wp-image-3155 stamp" /><p class="wp-caption-text">Hello World Google App Engine :: Dashboard</p></div> <strong>Entwicklungsumgebung Eclipse</strong></p>
<p>Anwendungen f&#252;r die Google App Engine k&#246;nnen mit dem <a href="http://code.google.com/intl/de-DE/appengine/downloads.html#Google_App_Engine_SDK_for_Java" target="_blank">SDK f&#252;r Java</a> manuell oder mit etwas mehr Benutzerfreundlichkeit dem <a href="http://code.google.com/intl/de-DE/appengine/downloads.html#Download_the_Google_Plugin_for_Eclipse" target="_blank">Google Plugin</a> in der IDE Eclipse erstellt werden.</p>
<p><a href="http://www.eclipse.org/downloads/" target="_blank">Eclipse herunterladen</a>, Archiv extrahieren, Eclipse starten und das Google Repository &#252;ber &#8220;Help / Install New Software&#8230; / Add&#8230;&#8221; mit folgenden Angaben hinzuf&#252;gen.</p>
<ul>
<li>Name: Google</li>
<li>Location: http://dl.google.com/eclipse/plugin/3.7</li>
</ul>
<p><div style="background-color: rgb(191, 255, 191); border:1px solid rgb(128, 255, 128); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/tip.png" alt="Tipp" title="Tipp" width="24" height="24" style="margin: 4px 8px 0 0; float:left;" />Google stellt das Plugin f&#252;r mehrere Eclipse Versionen (Galileo, Helios, Indigo &#8230;) in verschiedene Repositories bereit. Die Adressen f&#252;r die jeweilige Version sind unter <a href="http://code.google.com/intl/de-DE/eclipse/docs/download.html" target="_blank">Google Plugin f&#252;r Eclipse</a> aufgelistet.</div> Anschlie&#223;end wird das Google Plugin f&#252;r Eclipse zur Installation angeboten.</p>
<p><div id="attachment_3180" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/HelloWorldGoogleAppEngineInstallAvailableSoftware.png" alt="Hello World Google App Engine :: Install Available Software" title="Hello World Google App Engine :: Install Available Software" width="442" height="344" class="size-full wp-image-3180 stamp" /><p class="wp-caption-text">Hello World Google App Engine :: Install Available Software</p></div> Nach der Installation werden einige neue Funktionen in Eclipse durch das Google Plugin f&#252;r Eclipse angeboten.</p>
<div id="attachment_3198" class="wp-caption alignnone" style="width: 287px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/HelloWorldGoogleAppEngineEclipsePlugin.png" alt="Hello World Google App Engine :: Eclipse Plugin" title="Hello World Google App Engine :: Eclipse Plugin" width="277" height="191" class="size-full wp-image-3198 stamp" /><p class="wp-caption-text">Hello World Google App Engine :: Eclipse Plugin</p></div>
<p><strong>Hello World</strong></p>
<p>Einfach &#252;ber &#8220;File / New / Project &#8230;&#8221; ein &#8220;Google / Web Application Project&#8221; ausw&#228;hlen und durch &#8220;Next >&#8221; mit folgenden Einstellungen &#252;ber &#8220;Finish&#8221; ein neues Projekt erstellen.</p>
<ul>
<li>Project name: HelloWorldGoogleAppEngine</li>
<li>Package: tld.sld.my.example</li>
<li>Use Google Web Toolkit abw&#228;hlen</li>
</ul>
<p><div id="attachment_3173" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/HelloWorldGoogleAppEngineCreateWebApplicationProject.png" alt="Hello World Google App Engine :: Create Web Application Project" title="Hello World Google App Engine :: Create Web Application Project" width="442" height="590" class="size-full wp-image-3173 stamp" /><p class="wp-caption-text">Hello World Google App Engine :: Create Web Application Project</p></div> Die notwendige Verzeichnisstruktur und initiale Konfiguration wird mit dem folgendem Servlet durch das Plugin automatisch erstellt.</p>

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">package</span> <span style="color: #006699;">tld.sld.my.example</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">java.io.IOException</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">import</span> <span style="color: #006699;">javax.servlet.http.*</span><span style="color: #339933;">;</span>
&nbsp;
@SuppressWarnings<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;serial&quot;</span><span style="color: #009900;">&#41;</span>
<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">class</span> HelloWorldGoogleAppEngineServlet <span style="color: #000000; font-weight: bold;">extends</span> HttpServlet <span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000066; font-weight: bold;">void</span> doGet<span style="color: #009900;">&#40;</span>HttpServletRequest req, HttpServletResponse resp<span style="color: #009900;">&#41;</span>
			<span style="color: #000000; font-weight: bold;">throws</span> <span style="color: #003399;">IOException</span> <span style="color: #009900;">&#123;</span>
		resp.<span style="color: #006633;">setContentType</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;text/plain&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		resp.<span style="color: #006633;">getWriter</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>.<span style="color: #006633;">println</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Hello, world&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Das erste Servlet &#8220;Hello World Google App Engine&#8221; ohne eine Zeile selbst geschrieben zu haben &#8230; ;)</p>
<p><strong>Test</strong></p>
<p>Die Entwicklungsumgebung bietet durch das Google Plugin f&#252;r Eclipse eine lokale Simulationsumgebung an. </p>
<p>Die Google App Engine Web Anwendung wird bei selektiertem Projekt &#252;ber &#8220;Run / Run As / Web Application&#8221; lokal gestartet und im Browser kann &#252;ber die URL http://localhost:8888/ die folgende Startseite geladen werden.<br />
<div id="attachment_3204" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/HelloWorldGoogleAppEngineHelloAppEngine.png" alt="Hello World Google App Engine :: Hello App Engine" title="Hello World Google App Engine :: Hello App Engine" width="442" height="164" class="size-full wp-image-3204 stamp" /><p class="wp-caption-text">Hello World Google App Engine :: Hello App Engine</p></div> Der Quelltext der Startseite befindet sich in der Datei &#8220;/war/index.html&#8221;. Der erste Link &#8220;HelloWorldGoogleAppEngine&#8221; zeigt auf das zuvor erstellte Servlet.</p>
<p><div id="attachment_3176" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2011/10/HelloWorldGoogleAppEngineMozillaFirefox.png" alt="Hello World Google App Engine :: Mozilla Firefox" title="Hello World Google App Engine :: Mozilla Firefox" width="442" height="137" class="size-full wp-image-3176 stamp" /><p class="wp-caption-text">Hello World Google App Engine :: Mozilla Firefox</p></div> <strong>Ab in die Cloud &#8230;</strong></p>
<p>Damit das erste Beispiel im weltweiten Netz erreichbar ist, muss die Anwendung in die Cloud von Google publiziert werden. </p>
<p>In der Konfigurationsdatei appengine-web.xml unter &#8220;war/WEB-INF&#8221; die eigene zuvor erstellte Anwendungs-ID (myappid) eintragen.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;?xml</span> <span style="color: #000066;">version</span>=<span style="color: #ff0000;">&quot;1.0&quot;</span> <span style="color: #000066;">encoding</span>=<span style="color: #ff0000;">&quot;utf-8&quot;</span><span style="color: #000000; font-weight: bold;">?&gt;</span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;appengine-web-app</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://appengine.google.com/ns/1.0&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>myappid<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/application<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>1<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/version<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!--</span>
<span style="color: #808080; font-style: italic;">    By default, App Engine sends requests serially to a given web server.</span>
<span style="color: #808080; font-style: italic;">    To allow App Engine to send multiple requests in parallel specify:</span>
&nbsp;
<span style="color: #808080; font-style: italic;">      &lt;threadsafe&gt;true&lt;/threadsafe&gt;</span>
<span style="color: #808080; font-style: italic;">  --&gt;</span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- Configure java.util.logging --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;system-properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;property</span> <span style="color: #000066;">name</span>=<span style="color: #ff0000;">&quot;java.util.logging.config.file&quot;</span> <span style="color: #000066;">value</span>=<span style="color: #ff0000;">&quot;WEB-INF/logging.properties&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/system-properties<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/appengine-web-app<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Das Projekt kann &#252;ber das Kontextmen&#252; &#8220;Google / Deploy to App Engine&#8221; zur App Engine von Google &#252;bertragen werden.</p>
<p>Anschlie&#223;end kann auf die Anwendung &#252;ber http://myappid.appspot.com (myappid = zuvor erstellter Application Identifier) wie z.B. <a href="http://mgsimon.appspot.com" target="_blank">http://mgsimon.appspot.com</a> zugegriffen werden.</p>
<p>Fertig &#8230; erst einmal. ;)</p>
<p><strong>Weiter &#8230;</strong></p>
<ul>
<li><a href="http://code.google.com/intl/de-DE/appengine/" title="Google App Engine Projekt" target="_blank">Google App Engine Projekt</a></li>
<li><a href="http://code.google.com/intl/de-DE/appengine/docs/" title="Google App Engine Dokumentation" target="_blank">Google App Engine Dokumentation</a></li>
<li><a href="http://code.google.com/intl/de-DE/appengine/docs/java/javadoc/" title="Google App Engine Javadoc" target="_blank">Google App Engine Javadoc</a></li>
<li><a href="https://appengine.google.com/" title="Google App Engine Administration" target="_blank">Google App Engine Administration</a></li>
<li><a href="http://www.amazon.de/gp/product/B003DL3NT8/ref=as_li_ss_tl?ie=UTF8&#038;tag=mgs-21&#038;linkCode=as2&#038;camp=1638&#038;creative=19454&#038;creativeASIN=B003DL3NT8" title="Programming Google App Engine (Animal Guide)" target="_blank">Programming Google App Engine (Animal Guide)</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mgsimon.de/2011/10/25/hello-world-google-app-engine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Android Emulator unter Mac OS X selbst erstellen</title>
		<link>http://mgsimon.de/2010/10/08/android-emulator-unter-mac-os-x-selbst-erstellen/</link>
		<comments>http://mgsimon.de/2010/10/08/android-emulator-unter-mac-os-x-selbst-erstellen/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 04:57:12 +0000</pubDate>
		<dc:creator>mg</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Mac OS X]]></category>
		<category><![CDATA[Mobil]]></category>
		<category><![CDATA[Android]]></category>
		<category><![CDATA[MacOSX]]></category>

		<guid isPermaLink="false">http://mgsimon.de/?p=2745</guid>
		<description><![CDATA[Am Anfang war das Android-SDK, sp&#228;ter die Tiefen der Quellen und am Ende der selbst erstellte Emulator unter Mac OS X &#8230; Disk Image Disk Image &#8220;android.dmg&#8221; f&#252;r die Android-Quellen mit dem Festplatten-Dienstprogramm unter &#8220;Programme / Dienstprogramme&#8221; mit folgenden Optionen erstellen. Sichern unter: android.dmg Name: android Gr&#246;&#223;e: Eigene (10,24 GB) Format: Mac OS Extended (Gro&#223;- [...]]]></description>
			<content:encoded><![CDATA[<p>Am Anfang war das <a href="http://mgsimon.de/2009/12/19/hello-world-android-unter-linux/">Android-SDK</a>, sp&#228;ter <a href="http://mgsimon.de/2010/09/19/android-und-die-tiefen-der-quellen/">die Tiefen der Quellen</a> und am Ende der selbst erstellte Emulator unter Mac OS X &#8230;<br />
<div id="attachment_2794" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2010/10/MacOSXBootAndroidEmulator.png" alt="Mac OS X :: Boot Android Emulator" title="Mac OS X :: Boot Android Emulator" width="442" height="323" class="size-full wp-image-2794 stamp" /><p class="wp-caption-text">Mac OS X :: Boot Android Emulator</p></div><br />
<div style="background-color: rgb(191, 228, 255); border:1px solid rgb(128, 201, 255); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/info.png" alt="Hinweis" title="Hinweis" width="24" height="24" style="margin: 4px 8px 0 0; float:left;"/>Das folgende Beispiel wurde unter Mac OS X &#8211; 10.6.4 &#8211; Snow Leopard durchgef&#252;hrt.</div><span id="more-2745"></span></p>
<p><strong>Disk Image</strong></p>
<div style="background-color: rgb(191, 228, 255); border:1px solid rgb(128, 201, 255); color: rgb(0, 0, 0); margin:0 0 1.5em; overflow:auto; padding: 3px;">
<img src="/wp-content/plugins/MyShortCodes/info.png" alt="Hinweis" title="Hinweis" width="24" height="24" style="margin: 4px 8px 0 0; float:left;"/>Warum ein Disk Image?<br />
Die Quellen der Android-Plattform enthalten Dateien mit gleichen Name, welche sich lediglich durch Gro&#223;- / Kleinschreibung unterscheiden. Mac OS X unterscheidet diese im Auslieferungszustand nicht.</div>
<p>Disk Image &#8220;android.dmg&#8221; f&#252;r die Android-Quellen mit dem Festplatten-Dienstprogramm unter &#8220;Programme / Dienstprogramme&#8221; mit folgenden Optionen erstellen.</p>
<ul>
<li>Sichern unter: android.dmg</li>
<li>Name: android</li>
<li>Gr&#246;&#223;e: Eigene (10,24 GB)</li>
<li>Format: Mac OS Extended (Gro&#223;- / Kleinschreibung und Journaled)</li>
</ul>
<p><div id="attachment_2780" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2010/10/MacOSXFestplattenDienstprogrammImageErstellen.png" alt="Mac OS X :: Festplatten-Dienstprogramm Image erstellen" title="Mac OS X :: Festplatten-Dienstprogramm Image erstellen" width="442" height="307" class="size-full wp-image-2780 stamp" /><p class="wp-caption-text">Mac OS X :: Festplatten-Dienstprogramm Image erstellen</p></div><br />
<strong>Xcode &#038; MacPorts</strong></p>
<p>Die aktuellen Versionen von <a href="http://developer.apple.com/">Xcode</a> und <a href="http://www.macports.org/install.php">MacPorts</a> herunterladen, installieren und wie folgt konfigurieren.</p>
<ul>
<li>In der Datei &#8220;~/.bash_profile&#8221; die Umgebungsvariable &#8220;PATH&#8221; f&#252;r die MacPorts und &#8220;repo&#8221; (Repository-Skript) erweitern.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">PATH=/opt/local/bin:~/bin:$PATH</pre></div></div>

<ul>
<li>Zus&#228;tzliche MacPorts Pakete u.a. f&#252;r die Versionsverwaltung Git installieren.</li>
</ul>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> port <span style="color: #c20cb9; font-weight: bold;">install</span> <span style="color: #c20cb9; font-weight: bold;">gmake</span> libsdl git-core gnupg</pre></div></div>

<p><strong>Repository</strong></p>
<p>Das Repository-Skript installieren und auf dem erstellten Disk Image initialisieren. Die anschlie&#223;ende Synchronisation l&#228;dt bei einer 20 MB DSL Anbindung in ungef&#228;hr einer Stunde (64m22.741s) etwa vier GB Quellen herunter.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> ~<span style="color: #000000; font-weight: bold;">/</span>bin
$ curl http:<span style="color: #000000; font-weight: bold;">//</span>android.git.kernel.org<span style="color: #000000; font-weight: bold;">/</span>repo <span style="color: #000000; font-weight: bold;">&gt;</span> ~<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>repo
$ <span style="color: #c20cb9; font-weight: bold;">chmod</span> a+x ~<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>repo
$ <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>Volumes<span style="color: #000000; font-weight: bold;">/</span>android 
$ repo init <span style="color: #660033;">-u</span> <span style="color: #c20cb9; font-weight: bold;">git</span>:<span style="color: #000000; font-weight: bold;">//</span>android.git.kernel.org<span style="color: #000000; font-weight: bold;">/</span>platform<span style="color: #000000; font-weight: bold;">/</span>manifest.git
$ repo <span style="color: #c20cb9; font-weight: bold;">sync</span></pre></div></div>

<p><strong>Make</strong></p>
<p>Die Quellen der Android Plattform k&#246;nnen mit einem einfachen &#8220;make&#8221; (ca. zwei Stunden (114m23.836s) Mac Book Pro 2.4 GHz) &#252;bersetzt werden.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">make</span></pre></div></div>

<p><strong>Emulator</strong></p>
<p>Zu guter letzt kann der Emulator wie folgt gestartet werden.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ . build<span style="color: #000000; font-weight: bold;">/</span>envsetup.sh
$ lunch <span style="color: #000000;">1</span>
$ emulator</pre></div></div>

<div id="attachment_2787" class="wp-caption alignnone" style="width: 452px"><img src="http://mgsimon.de/wp-content/uploads/2010/10/MacOSXAndroidEmulator.png" alt="Mac OS X :: Android Emulator" title="Mac OS X :: Android Emulator" width="442" height="432" class="size-full wp-image-2787 stamp" /><p class="wp-caption-text">Mac OS X :: Android Emulator</p></div>
<p><strong>Und es l&#228;uft doch &#8230;</strong></p>
<p>Abweichend der Dokumentation auf <a href="http://source.android.com/source/download.html">source.android.com</a> k&#246;nnen die aktuellen Android Quellen auch unter Snow Leopard &#252;bersetzt werden. :-)</p>
<blockquote><p>At the moment MacOS 10.6 (&#8220;Snow Leopard&#8221;) is not supported.</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://mgsimon.de/2010/10/08/android-emulator-unter-mac-os-x-selbst-erstellen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Vorweihnachtsfreude &#8211; kostenlose eBooks</title>
		<link>http://mgsimon.de/2007/12/07/vorweihnachtsfreude-kostenlose-ebooks/</link>
		<comments>http://mgsimon.de/2007/12/07/vorweihnachtsfreude-kostenlose-ebooks/#comments</comments>
		<pubDate>Fri, 07 Dec 2007 08:58:20 +0000</pubDate>
		<dc:creator>mg</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[web2.0]]></category>
		<category><![CDATA[eBook]]></category>

		<guid isPermaLink="false">http://mgsimon.de/2007/12/07/vorweihnachtsfreude-kostenlose-ebooks/</guid>
		<description><![CDATA[entwicker.press hat einen Adventskalender mit kostenlosen elektronischen B&#252;chern. Was sich hinter den T&#252;rchen bis jetzt verbag. Java 6. Professionell einsteigen Java 6 Programmierhandbuch Das Google Web Toolkit. schnell + kompakt Managed DirectX und C#. Einstieg und professioneller Einsatz Dojo Toolkit. schnell + kompakt Visual C#]]></description>
			<content:encoded><![CDATA[<p><a href="http://entwickler-press.de/" target="_blank">entwicker.press</a> hat einen Adventskalender mit kostenlosen elektronischen B&#252;chern.</p>
<p>Was sich hinter den T&#252;rchen bis jetzt verbag.</p>
<ul>
<li> <a href="http://www.amazon.de/dp/3939084190/ref=nosim?tag=mgs-21" target="_blank">Java 6. Professionell einsteigen</a></li>
<li><a href="http://www.amazon.de/dp/3939084123/ref=nosim?tag=mgs-21" target="_blank">Java 6 Programmierhandbuch</a></li>
<li><a href="http://www.amazon.de/dp/3939084379/ref=nosim?tag=mgs-21" target="_blank">Das Google Web Toolkit. schnell + kompakt</a></li>
<li><a href="http://www.amazon.de/dp/3939084174/ref=nosim?tag=mgs-21" target="_blank">Managed DirectX und C#. Einstieg und professioneller Einsatz</a></li>
<li><a href="http://www.amazon.de/dp/3939084492/ref=nosim?tag=mgs-21" target="_blank">Dojo Toolkit. schnell + kompakt</a></li>
<li><a href="http://www.amazon.de/dp/3939084166/ref=nosim?tag=mgs-21" target="_blank">Visual C#</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://mgsimon.de/2007/12/07/vorweihnachtsfreude-kostenlose-ebooks/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaBlackBelt &#8211; Certification Community</title>
		<link>http://mgsimon.de/2007/05/15/javablackbelt-certification-community/</link>
		<comments>http://mgsimon.de/2007/05/15/javablackbelt-certification-community/#comments</comments>
		<pubDate>Tue, 15 May 2007 08:04:28 +0000</pubDate>
		<dc:creator>mg</dc:creator>
				<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://mgsimon.de/?p=19</guid>
		<description><![CDATA[JavaBlackBelt, eine online Community zum Erlernen der Sprache Java und vielen bekannten OpenSource Frameworks &#38; -Tools. Hol Dir den schwarzen G&#252;rtel in Java. Nicht nur Java sondern folgende Themen werden durch online Tests vertieft. Java 5 New Language Features Java 5 New Base Library Features Java 5 New Tools and Tool Features Java SE &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.javablackbelt.com">JavaBlackBelt</a>, eine online Community zum Erlernen der Sprache Java und vielen bekannten OpenSource Frameworks &amp; -Tools.</p>
<p style="text-align: center;"><img src="http://mgsimon.de/wp-content/uploads/2007/09/whitebelt.gif" alt="WhiteBelt" /><br />
Hol Dir den schwarzen G&#252;rtel in Java.</p>
<p>Nicht nur Java sondern folgende Themen werden durch online Tests vertieft.<br />
<span id="more-19"></span><br />
Java 5 New Language Features<br />
Java 5 New Base Library Features<br />
Java 5 New Tools and Tool Features<br />
Java SE &#8211; Basic<br />
Java SE Core &#8211; Intermed<br />
Java SE Base API &#8211; Basic<br />
Java SE Base API &#8211; Intermed<br />
Java SE Collections<br />
Java SE IO<br />
Java SE NIO<br />
Java SE Networking<br />
Java SE Reflection API<br />
Java SE Tools<br />
Java SE RegEx<br />
Java SE Concurrency &#8211; High-Level<br />
Java SE Concurrency &#8211; Low-Level<br />
Java SE &#8211; Programming Exam<br />
Java ME<br />
OO for Java &#8211; Basic<br />
OO &#8211; Intermed<br />
Servlet &#8211; Basic<br />
Servlet &#8211; Intermediate<br />
JSP &#8211; Basic<br />
JSP &#8211; Intermed<br />
Struts 1 &#8211; Basic<br />
Struts 1 &#8211; Intermed<br />
Struts Tiles<br />
JSF 1.1 &#8211; Basic<br />
Tapestry 4 &#8211; Basic<br />
EJB 2 &#8211; Basic<br />
EJB 2 &#8211; Intermed<br />
EJB 3.0 Basic<br />
JPA Exam<br />
Web Services &#8211; Basic<br />
JMS<br />
Spring Core &#8211; Basic<br />
Spring Core<br />
Spring MVC<br />
Spring DAO JDBC<br />
XML Core &#8211; Basic<br />
XML Programming &#8211; Basic<br />
XML DTD<br />
SQL &amp; RDB &#8211; Basic<br />
JDBC &#8211; Basic<br />
JDBC &#8211; Intermed<br />
Hibernate 3 Core &#8211; Basic<br />
Hibernate 3 &#8211; Core<br />
Hibernate 3 &#8211; Entity Associations and Relationships<br />
Hibernate 3 &#8211; Inheritance Strategies<br />
Hibernate 3 &#8211; Persistent Objects Retrieval<br />
Hibernate 3 &#8211; Caching<br />
Hibernate 3 &#8211; Transaction &amp; Concurrency<br />
Hibernate 3 &#8211; Advanced Lifecycle<br />
Ant &#8211; Basic<br />
JUnit &#8211; Basic<br />
JUnit &#8211; Intermed<br />
JUnit 4<br />
Websphere Application Developer (WSAD)<br />
Log4J<br />
PMD &#8211; Basic<br />
UML for Java &#8211; Basic<br />
Eclipse RCP &#8211; Basic<br />
Ruby &#8211; Basic<br />
Maven2 Standard<br />
Maven2 J2EE<br />
Maven2 Developer<br />
Swing &#8211; Basic<br />
JGoodies Forms<br />
JGoodies Bindings</p>
<p>Na dann viel Spass beim lernen (<a href="http://www.javablackbelt.com">JavaBlackBelt</a>)!</p>
]]></content:encoded>
			<wfw:commentRss>http://mgsimon.de/2007/05/15/javablackbelt-certification-community/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Roller &amp; die i18n Fehler</title>
		<link>http://mgsimon.de/2007/03/23/roller-die-i18n-fehler/</link>
		<comments>http://mgsimon.de/2007/03/23/roller-die-i18n-fehler/#comments</comments>
		<pubDate>Fri, 23 Mar 2007 05:00:18 +0000</pubDate>
		<dc:creator>mg</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Roller]]></category>

		<guid isPermaLink="false">http://mgsimon.de/?p=17</guid>
		<description><![CDATA[Die Internationalisierungsfehler insbesondere der Probleme mit der unterschiedlichen l&#228;nderspezifischen Datumsverarbeitung nerven. Die Wochentage in der Monatsnavigation werden nicht richtig dargestellt und einen zuk&#252;nftigen Eintrag zu erstellen ist nicht m&#246;glich. Vielleicht doch die aktuellest Version installieren? Die aktuelleste Version 3.1 Release Candidate 6 kann unter dieser Adresse http://people.apache.org/~snoopdave/apache-roller-3.1/ heruntergeladen werden. Die Aktualisierung von Roller 3.0 auf [...]]]></description>
			<content:encoded><![CDATA[<p>Die Internationalisierungsfehler insbesondere der Probleme mit der unterschiedlichen l&#228;nderspezifischen Datumsverarbeitung nerven.<br />
Die Wochentage in der Monatsnavigation werden nicht richtig dargestellt und einen zuk&#252;nftigen Eintrag zu erstellen ist nicht m&#246;glich.<br />
Vielleicht doch die aktuellest Version installieren?<br />
<span id="more-17"></span><br />
Die aktuelleste Version 3.1 Release Candidate 6 kann unter dieser Adresse <a href="http://people.apache.org/~snoopdave/apache-roller-3.1/">http://people.apache.org/~snoopdave/apache-roller-3.1/</a> heruntergeladen werden.<br />
Die Aktualisierung von Roller 3.0 auf 3.1-RC6 ist mit relativ wenig Aufwand verbunden.</p>
<ol>
<li>Das DDL-Skript von 300 auf 301 muss gegen&#252;ber die Datenbank ausgef&#252;hrt werden.
</li>
<li>Das Webanwendungsverzeichnis in der roller.xml angepasst werden.
</li>
<li>Die Konfiguration hat sich gegen&#252;ber 3.0 ge&#228;ndert, in einer roller-custom.properties werden zuk&#252;nftig die Einstellungen der roller.properties &#252;berschrieben (u.a. Upload- und Indexverzeichis).
</li>
</ol>
<p>Nach der Aktualisierung hatte ich ein Problem mit den zuvor hochgeladenen Dateien, da noch nicht besonders viele Dateien vorhanden waren, habe ich diese einfach erneut hochgeladen.</p>
<p>Fertig, mit der Hoffnung eine stabile Version mit Release Candidate 6 installiert zu haben. :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://mgsimon.de/2007/03/23/roller-die-i18n-fehler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Rollers JDBCException &#246;,&#228;,&#252; &#8230;</title>
		<link>http://mgsimon.de/2007/03/13/rollers-jdbcexception-oau/</link>
		<comments>http://mgsimon.de/2007/03/13/rollers-jdbcexception-oau/#comments</comments>
		<pubDate>Tue, 13 Mar 2007 05:43:50 +0000</pubDate>
		<dc:creator>mg</dc:creator>
				<category><![CDATA[Hosting]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Blog]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Roller]]></category>

		<guid isPermaLink="false">http://mgsimon.de/?p=4</guid>
		<description><![CDATA[L&#228;uft bis heute stabil? Zu fr&#252;h gefreut, Weblogeintraege mit enthaltenen Sonderzeichen wie &#246;,&#228;,&#252; k&#246;nnen nicht gespeichert werden. :-( ... JDBCExceptionReporter:logExceptions - SQL Error: 0, SQLState: 01004 JDBCExceptionReporter:logExceptions - Data truncation: Data too long for column 'summary' at row 1 ... L&#246;sung gefunden! :-) Roller ben&#246;tigt UTF-8, &#228;ltere MySQL Versionen sind auf Latin-1 voreingestellt. Die Datenbank [...]]]></description>
			<content:encoded><![CDATA[<p>L&#228;uft bis heute stabil?</p>
<p>Zu fr&#252;h gefreut, Weblogeintraege mit enthaltenen Sonderzeichen wie <span style="font-weight: bold">&#246;,&#228;,&#252;</span> k&#246;nnen nicht gespeichert werden. :-(</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">...
JDBCExceptionReporter:logExceptions - SQL Error: 0, SQLState: 01004
JDBCExceptionReporter:logExceptions - Data truncation: Data too long for column 'summary' at row 1
...</pre></div></div>

<p><strong>L&#246;sung gefunden!</strong> :-)<br />
Roller ben&#246;tigt UTF-8, &#228;ltere MySQL Versionen sind auf Latin-1 voreingestellt.</p>
<p><span id="more-4"></span></p>
<p>Die Datenbank kann wie folgt von Latin-1 nach UTF-8 konvertiert werden.<br />
Roller (bzw. Tomcat) sollte w&#228;hrend der Konvertierung heruntergefahren werden.</p>
<p>1. Dump erzeugen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysqldump DATENBANK <span style="color: #660033;">-u</span> USER <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">&gt;</span>DATEINAME</pre></div></div>

<p>2. Dump modifizieren<br />
Suchen und Ersetzen im Datenbankdump nach &#8220;latin1&#8243; durch &#8220;utf8&#8243;.<br />
Am Anfang der Datei</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;"><span style="color: #990099; font-weight: bold;">use</span> DATENBANK<span style="color: #000033;">;</span></pre></div></div>

<p>einf&#252;gen.</p>
<p>3. Dump konvertieren<br />
Mit folgendem Befehl die Datei nach UTF-8 konvertieren.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">iconv <span style="color: #660033;">-f</span> iso-<span style="color: #000000;">8859</span>-<span style="color: #000000;">1</span> <span style="color: #660033;">-t</span> utf-<span style="color: #000000;">8</span> DATEINAME</pre></div></div>

<p>4. Dump einspielen</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">mysql <span style="color: #660033;">-u</span> USER <span style="color: #660033;">-p</span> <span style="color: #000000; font-weight: bold;">&lt;</span>DATEINAME</pre></div></div>

<p>Anschlie&#223;end sollten Weblogeintr&#228;ge mit Sonderzeichen erstellt werden k&#246;nnen! :-)</p>
]]></content:encoded>
			<wfw:commentRss>http://mgsimon.de/2007/03/13/rollers-jdbcexception-oau/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

