Skip to content

Instantly share code, notes, and snippets.

The World Cup Graph

Initial Data Setup

@rhart
rhart / gist:b4316b43b8323e32cf9e
Created August 2, 2014 23:01
Ratpack publishing to websocket
public class MetricsWebsocketBroadcastHandler implements Handler {
@Override
public void handle(final Context context) throws Exception {
final MetricsPublisher publisher = context.get(MetricsPublisher.class);
websocket(context, new AutoCloseWebSocketHandler<AutoCloseable>() {
@Override
public AutoCloseable onOpen(final WebSocket webSocket) throws Exception {
MetricsWebsocketSubscriber subscriber = new MetricsWebsocketSubscriber(webSocket);
import io.netty.bootstrap.Bootstrap
import io.netty.buffer.ByteBuf
import io.netty.channel.ChannelFuture
import io.netty.channel.ChannelHandlerContext
import io.netty.channel.ChannelInitializer
import io.netty.channel.ChannelPipeline
import io.netty.channel.SimpleChannelInboundHandler
import io.netty.channel.socket.SocketChannel
import io.netty.handler.codec.http.DefaultFullHttpResponse
import io.netty.handler.codec.http.HttpResponseStatus
@rhart
rhart / ratpack.groovy
Last active April 5, 2016 14:46
Ratpack SOAP web service
import static org.ratpackframework.groovy.RatpackScript.ratpack
import static org.ratpackframework.groovy.Template.groovyTemplate
ratpack {
handlers {
prefix('say-hello-service') {
soapAction('"Hello"') {
def soapRequest = new XmlSlurper().parseText(request.text)
def yourFirstName = soapRequest.Body.HelloRequest.FirstName
@rhart
rhart / Ratpack.groovy
Created December 20, 2014 23:09
Ratpack HTTP Proxy
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import ratpack.handling.Context
import ratpack.handling.Handler
import ratpack.http.client.HttpClient
import ratpack.http.client.StreamedResponse
import ratpack.http.MutableHeaders
import ratpack.http.client.RequestSpec
import static ratpack.groovy.Groovy.ratpack
public Promise<String> getBookRequest(final String isbn) {
def uri = "${config.host}/api/v2/json/${config.apikey}/book/$isbn".toURI()
httpClient
.get(uri)
.map { ReceivedResponse resp ->
if (resp.body.text.contains("Daily request limit exceeded")) {
throw new RuntimeException("ISBNDB daily request limit exceeded.")
}
resp.body.text
// Original Copyright 2012 Google, Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file in the root of the source
// tree.
// Modification Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: BSD-3-Clause
package main