<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>app engine &#8211; Squix &#8211; TechBlog</title>
	<atom:link href="https://blog.squix.org/tag/app-engine/feed" rel="self" type="application/rss+xml" />
	<link>https://blog.squix.org</link>
	<description></description>
	<lastBuildDate>Sun, 17 Apr 2016 07:56:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.8</generator>
<site xmlns="com-wordpress:feed-additions:1">121913304</site>	<item>
		<title>Continuous Deployment from Github to App Engine Java with CodeShip</title>
		<link>https://blog.squix.org/2014/03/continuous-deployment-from-github-to.html</link>
					<comments>https://blog.squix.org/2014/03/continuous-deployment-from-github-to.html#comments</comments>
		
		<dc:creator><![CDATA[Daniel Eichhorn]]></dc:creator>
		<pubDate>Sat, 01 Mar 2014 18:49:00 +0000</pubDate>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[app engine]]></category>
		<category><![CDATA[codeship]]></category>
		<category><![CDATA[continuous deployment]]></category>
		<category><![CDATA[GAE]]></category>
		<category><![CDATA[Google App Engine]]></category>
		<guid isPermaLink="false">http://blog.squix.org/2014/03/01/continuous-deployment-from-github-to/</guid>

					<description><![CDATA[Motivation Continuous Deployment is nice: you roll out new versions of your software all the time and not only three, four times a year with your mayor release. And everything automatically. Of course this requires a good coverage of automated unit, integration and UI tests ... <p><a class="read-more btn btn-secondary" href="https://blog.squix.org/2014/03/continuous-deployment-from-github-to.html">Read More</a></p>]]></description>
										<content:encoded><![CDATA[<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Motivation</h2>
<p>Continuous Deployment is nice: you roll out new versions of your software all the time and not only three, four times a year with your mayor release. And everything automatically. Of course this requires a good coverage of automated unit, integration and UI tests to make sure that your current version doesn&#8217;t break anything for the user.<br />
What tools can you use do achieve this for your open source project? If I&#8217;m not mistaken you get all this with an account at bit bucket from Atlassian. But since I currently host my open source projects on Github I had to find another solution. And it exists, even for free: <a href="http://codeship.io/">http://codeship.io</a><br />
Codeship already nows about many services and you only have to configure a few lines to get it up and running. For instance it supports Github as code repository and Google App Engine as deployment target. But the documentation about it is still a bit sparse. So this article describes how you can set it up</p>
<h2 style="text-align: left;">
SCM</h2>
<div>
The setup of github as a repository is fairly straight forward: you use your github account to authenticate yourself through OAuth with CodeShip. Then you create a new project and in the SCM section you pick Github as your provider. After allowing codeship to access your Github repositories you already can select the repo you want to build from.</div>
<h2 style="text-align: left;">
Tests</h2>
<div>
Currently I don&#8217;t have integration and UI tests yet for my open source project. Anyway, to make sure your build runs at least once I chose the JVM option in the &#8220;Select your technology to prepopulate basic commands&#8221; dropdown and added a</p>
</div>
<div>
<pre>mvn package
</pre>
<p></div>
<div>
in the &#8220;Modify your Setup Commands&#8221; section. I left the rest unchanged.</p>
<h2 style="text-align: left;">
Deployment</h2>
</div>
<div>
And now came the tricky part. I don&#8217;t want the build to deploy to the GAE application that is defined in the appengine-web.xml. Instead I want it to be installed to a test environment with a different name running on GAE as well. So I added a second appengine-web-testenv.xml beside the default one and changed the application id to the test environment. Then I selected the &#8220;$script&#8221; option in the CodeShip deployment tab and added a </div>
<pre>cp target/-/WEB-INF/appengine-web-testenv.xml target/-/WEB-INF/appengine-web.xml
</pre>
<p>Please replace maven.project and maven.version with the name of your maven artefact. In my case this is &#8220;extraleague-1.0-SNAPSHOT&#8221;. So this basically replaces the original appengine file with the one containing the test environment id. When appcfg.sh now tries to find the target for deployment it will find the one with the test environment.<br />
Now we add another deployment descriptor by selecting the app engine option. I think when you first do this you have to authorise CodeShip to deploy to GAE on your behalf. After that I added./target/extraleague-1.0-SNAPSHOT/ as Path and a rest service endpoint in the URL field. This URL will be checked to decide if the deployment was successful. In my first attempt I used the index.html of my angular application for this. The problem here is that static files like the index.html did get served while the Java server part had a 500 error. That&#8217;s why I think a rest point is a better choice here.</p>
<h2 style="text-align: left;">
Triggering a run and debugging</h2>
<div>
To have CodeShip do a first run you just have to commit a change to Github and there it goes. You can follow each step in the admin interface of your build and see read the log if something goes wrong. You can also change the deployment settings and rerun a previously failed build.</div>
<h2 style="text-align: left;">
Remarks</h2>
<div>
I&#8217;m really happy with this setup, but I think there should be a way to avoid setting the artefact name and version into the setting path. Probably some maven command would do the trick? As next steps I&#8217;d like to setup a UI test, maybe with PhantomJS or so&#8230; Let me know if you have improvements!</p>
<p><b>Update 2014/05/10</b><br />
Last week I had issues with app engine authentication and after that was solved it seemed that codeship used an old version of the app engine sdk to deploy which caused issues. So I started looking for an alternative to the above description and found it by adding the following script in the deployment section (no other build step required anymore, you can remove the app engine step):</p>
<pre>cp src/main/webapp/WEB-INF/appengine-web-testenv.xml  src/main/webapp/WEB-INF/appengine-web.xml
cat src/main/webapp/WEB-INF/appengine-web.xml
echo '{"credentials":{"rof":{"access_token":"XXXX","expiration_time_millis":1399667604244,"refresh_token":"XXX"}}}' &gt; ~/.appcfg_oauth2_tokens_java
mvn appengine:update
wget --retry-connrefused --no-check-certificate -T 60 http://your-test-url
</pre>
<p>
<b>Explanation</b><br />
The first line is the same as before: it copies my alternative deployment descriptor in the place of the default descriptor. The second line is used for debugging and to be sure that the task will really deploy to my test instance. The third line is the most interesting. For my own security I replaced the real tokens with XXX. How do you get this JSON object? Very simple: deploy your application locally and you can copy this JSON object from .appcfg_oauth2_tokens_java. <b>Replace your current system user with rof! </b>The next line simply deploys the application to my test environment and the last line checks if the application was deployed successfully</p>
</div>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.squix.org/2014/03/continuous-deployment-from-github-to.html/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">79</post-id>	</item>
		<item>
		<title>Google App Engine (Java) ChannelService with AngularJS</title>
		<link>https://blog.squix.org/2014/03/google-app-engine-java-channelservice.html</link>
					<comments>https://blog.squix.org/2014/03/google-app-engine-java-channelservice.html#comments</comments>
		
		<dc:creator><![CDATA[Daniel Eichhorn]]></dc:creator>
		<pubDate>Sat, 01 Mar 2014 14:04:00 +0000</pubDate>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[angularjs bootstrap]]></category>
		<category><![CDATA[app engine]]></category>
		<category><![CDATA[channel service]]></category>
		<category><![CDATA[java]]></category>
		<guid isPermaLink="false">http://blog.squix.org/2014/03/01/google-app-engine-java-channelservice/</guid>

					<description><![CDATA[Motivation I&#8217;m currently working on a foosball web app that is widely used in breaks where I work. While you track the goals made by each of the team the app running on the app engine calculates a ranking of all the players and awards ... <p><a class="read-more btn btn-secondary" href="https://blog.squix.org/2014/03/google-app-engine-java-channelservice.html">Read More</a></p>]]></description>
										<content:encoded><![CDATA[<div dir="ltr" style="text-align: left;" trbidi="on">
<h2 style="text-align: left;">
Motivation</h2>
<p>I&#8217;m currently working on a foosball web app that is widely used in breaks where I work. While you track the goals made by each of the team the app running on the app engine calculates a ranking of all the players and awards badges given special scores in a game. <br />
Now I wanted to update all the clients about goals made or if a a foosball table is currently occupied. Since I&#8217;m using AngularJS for the client my first cheap approach was to pull the information frequently. But as we all know, pulling doesn&#8217;t scale well for the server. In another project I had used the GAE ChannelService before, but there the client technology was GWT. So how would I get this to work for AngularJS? This posts describes the different components necessary and might help you achieving the same.</p>
<h2 style="text-align: left;">
Technology</h2>
<div>
Before we get into the detail a few words to the technology stack. On the server (GAE) side I&#8217;m using Java, for persistency I use&nbsp;<a href="http://code.google.com/p/objectify-appengine/">Objectify</a>&nbsp;since it comes with many nice features that go beyond JPA and JDO. <a href="http://restlet.org/">Restlet</a> together with <a href="https://github.com/FasterXML/jackson">Jackson</a>&nbsp;create the REST endpoints for AngularJS. On the client side <a href="http://getbootstrap.com/">Twitter Bootstrap</a>&nbsp;helps me to have a nice looking UI with little effort.</div>
<h2 style="text-align: left;">
The token</h2>
<div>
The GAE channel service doesn&#8217;t allow you to broadcast a message easily to all clients. You will have to implement this by yourself by sending an update message to all currently connected clients. Client connections are represented by a secret token that is first created on the server side. Once the client knows this token both parties can send messages through the channel identified by the token. For this reason I created a model to store the token:</div>
<p></p>
<pre>@Entity
@Cache
public class BrowserClient {
 
 @Id
 private Long id;

 private String token;
 
 @Index
 private Date createdDate;

        //getter/setter omitted for saving space
...
}
</pre>
<p>
The createdDate is used to remove old (and most possibly outdated) client entries from the datastore. Now how the client gets this token? With AngularJS and Restlet an obvious choice is to create a REST endpoint resource:</p>
<p></p>
<pre>public class NotificationTokenResource extends ServerResource {
 
 @Get(value = "json")
 public NotificationTokenDto execute() throws UnsupportedEncodingException {
  ChannelService channelService = ChannelServiceFactory</pre>
<pre>                     .getChannelService();
  Random random = new Random();
  String token = channelService</pre>
<pre>                     .createChannel(String.valueOf(random.nextLong()));
  BrowserClient client = new BrowserClient();
  client.setToken(token);
  ofy().save().entities(client);
  NotificationTokenDto dto = new NotificationTokenDto();
  dto.setToken(token);
  return dto;
 }
}
</pre>
<p>
So what happens here? First I get an instance of the channel service, then I have it create a token based on a random seed. In case your used is logged in you could also use the userId to create the token. This saves you the trouble to store the token in the datastore, since you always can recreate it on the server side based on the same userId. Then I store the token and fill it into a DTO to be returned as JSON to the client:</p>
<pre>{"token":"AHRl[...]ntZ"}</pre>
<h2 style="text-align: left;">
Angular Notification Service</h2>
<div>
On the client side this token has to be requested, ideally only once per session. So I created an angular service for it:
</div>
<pre>
angular.module('gaeChannelService', ['ngResource'])
 .factory('NotificationToken', ['$resource', function($resource) {
     return $resource('/rest/notificationToken');
 }])

 .factory('NotificationService', ['$rootScope', 'NotificationToken', function($rootScope, NotificationToken){
 var tokenObject = NotificationToken.get({}, function() {
  console.log("Token received");
  channel = new goog.appengine.Channel(tokenObject.token);
  socket = channel.open();
  socket.onopen = function() {
   console.log("Channel opened");
  };
  socket.onmessage = function(message) {
   console.log("Message received: " + message.data);
   var messageObject = angular.fromJson(message.data);
   $rootScope.$emit(messageObject.channel, messageObject);
  };
 });

    return {
    }
 }]);
</pre>
<p>First the REST endpoint for the token is defined and later injected into the notification service. In the callback method of the REST call the connection to the channel is opened and more callback methods are defined. The onmessage function will be called, when the server sends a new message. This message will be deserialized using the angular.fromJson method. Since all the messages contain a member called &#8220;channel&#8221; the message will be sent using the $emit function to all subscribers of that specific channel.</p>
<h2 style="text-align: left;">In the controller</h2>
<p>So what do we have now? When the page is first loaded, we request a token from the server. The NotificationService uses this token to open a channel and listens for messages. Once a message is received it is relayed on the specified broadcast channel. So now we have to add listeners in a controller:</p>
<pre>
  $rootScope.$on("UpdateOpenGames", function(event, message) {
   console.log("Received change in open games from server");
   $scope.$apply(function() {
    $scope.games = [];
    angular.forEach(message.openGames, function(key, value) {
     $scope.games.push(new OpenGames(key));
    });
   });
  });
</pre>
<p>This code listens for messages on the channel &#8220;UpdateOpenGames&#8221; for incoming messages. Once a message has been received the $scope.$apply makes sure, that everybody knows about changes of the current scope.</p>
<h2 style="text-align: left;">In the controller</h2>
<p>Now what is left is to send a message from the server:</p>
<pre>
  List clients = ofy().load().type(BrowserClient.class).list();
  ChannelService channelService = ChannelServiceFactory.getChannelService();
  ObjectMapper mapper = new ObjectMapper();
  String payload = mapper.writeValueAsString(message);
  for (BrowserClient client : clients) {
      ChannelMessage channelMessage = new ChannelMessage(client.getToken(), payload);
      channelService.sendMessage(channelMessage);
  }
</pre>
<p>This code first loads all BrowserClient objects from the datastore. Remember, the BrowserClient class contains the token we need to send a message to a specific channel. Then we serialize the message we want to send into a JSON string, convert it into a ChannelMessage and send it. We doe this for all currently active clients. If by now a client is no longer online we won&#8217;t notice here. That&#8217;s it, folks!</p>
<h2 style="text-align: left;">Remarks</h2>
<p>This is a pure broadcast and doesn&#8217;t take care much of security. If your application sends secrets over the channel you should be a bit more careful with the token. You have to treat it with care, since it can be used to impersonate your client from a possibly evil browser.
</p></div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.squix.org/2014/03/google-app-engine-java-channelservice.html/feed</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">80</post-id>	</item>
		<item>
		<title>New Features: Searching the archive</title>
		<link>https://blog.squix.org/2010/12/new-features-searching-archive.html</link>
					<comments>https://blog.squix.org/2010/12/new-features-searching-archive.html#respond</comments>
		
		<dc:creator><![CDATA[Daniel Eichhorn]]></dc:creator>
		<pubDate>Sun, 19 Dec 2010 13:50:00 +0000</pubDate>
				<category><![CDATA[Common]]></category>
		<category><![CDATA[app engine]]></category>
		<category><![CDATA[feederator]]></category>
		<category><![CDATA[full text search]]></category>
		<category><![CDATA[rss]]></category>
		<guid isPermaLink="false">http://blog.squix.org/2010/12/19/new-features-searching-archive/</guid>

					<description><![CDATA[I&#8217;m trying to improve Feederator.org. Sometimes changes are rather invisible to the end user. Sometimes new features extend the use of feederator rather dramatically. I enabled such a feature today: searching the archives with full text key words. To keep your inbox clean Feederator moves ... <p><a class="read-more btn btn-secondary" href="https://blog.squix.org/2010/12/new-features-searching-archive.html">Read More</a></p>]]></description>
										<content:encoded><![CDATA[<p>I&#8217;m trying to improve Feederator.org. Sometimes changes are rather invisible to the end user. Sometimes new features extend the use of feederator rather dramatically. I enabled such a feature today: searching the archives with full text key words.<br />
To keep your inbox clean Feederator moves items older than 3 days to the archive. Once they are in the archive you can search for them. Make sure that your most significant word comes first, otherwise it might be omitted. The search is not as good yet as Google but it is getting better. Indexed words are part of the title of a post and its categories. In addition the MIME Type of the attachment will also be indexed. Entering &#8220;2010 nzb dvdrip&#8221; will return with a list of items containing 2010 and dvdrip in the title and having a usenet enclosure.<br />
In the time of this writing there are already more than 20&#8217;000 torrent items and more than 15&#8217;000 nzb items indexed.</p>
<p>Other new features:</p>
<ul>
<li>Social bookmarking items: share items that you like with your friends in Twitter, Facebook and others</li>
<li>Drag And Drop: by dragging an item with the dotted handle to a feed label on the left you can copy that item to a new feed. This also works with search results: you can search for movies and once you found one that you like you can drag it to the feed that your downloader has subscribed to</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.squix.org/2010/12/new-features-searching-archive.html/feed</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">100</post-id>	</item>
	</channel>
</rss>
