This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<project> | |
<parent> | |
<groupId>com.example</groupId> | |
<artifactId>parent</artifactId> | |
<version>1.0-SNAPSHOT</version> | |
</parent> | |
<modelVersion>4.0.0</modelVersion> | |
<artifactId>rpm</artifactId> | |
<packaging>jar</packaging> | |
<name>Project :: RPM</name> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.{Color, Graphics2D} | |
import java.awt.image.BufferedImage | |
import javax.imageio.ImageIO | |
public class Main { | |
//Does not deal with double buffering, and writing on servers which are headless. | |
public BufferedImage createBlackImage(int width, int height) { | |
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); | |
Graphics2D graphics = (Graphics2D) image.getGraphics(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class QueriesTest { | |
@Test | |
public void findCreatedQuery() throws Exception { | |
Query query = Query.create(new URITemplateTarget("http://example.com{?q}"), "filter", Optional.<String>none(), Collections.singletonList(Property.template("q"))); | |
Collection collection = Collection.builder().addQuery(query).build(); | |
Query filter = collection.queryByRel("filter").get(); | |
assertThat(URI.create("http://example.com"), equalTo(filter.expand())); | |
assertThat(URI.create("http://example.com?q=faff"), equalTo(filter.expand(Collections.singletonList(Property.value("q", "faff"))))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LinkTypeExt extends Extension<Optional<String>>{ | |
@Override | |
public Optional<String> extract(ObjectNode node) { | |
return node.has("type") ? Optional.some(node.get("type").asText()) : Optional.<String>none(); | |
} | |
@Override | |
public Map<String, JsonNode> apply(Optional<String> value) { | |
if (value.isSome()) { | |
return Collections.singletonMap("type", ValueFactory.createValue(value.get()).asJson()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.http; | |
import org.apache.http.client.config.RequestConfig; | |
import org.codehaus.httpcache4j.HTTPHost; | |
public class NotRedirectingHttpClientFactory extends HttpClientFactory { | |
@Override | |
protected RequestConfig requestConfig(HTTPHost proxyHost, ConnectionConfiguration config) { | |
RequestConfig c = super.requestConfig(proxyHost, config); | |
RequestConfig.Builder builder = RequestConfig.copy(c); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"collection": { | |
"href": "http://example.com", | |
"accept-bulk": "application/vnd.collection-templates+json", | |
"template": { | |
"data": [ | |
{"name": "foo"} | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class TemplateFill { | |
public Template fill(Map<String, String> values, template: Template) { | |
Data data = template.getData(); | |
List<Property> newData = new ArrayList<>(); | |
for (Property p: data) { | |
if (values.contains(p.getName()) { | |
newData.add(p.withValue(values.get(p.getName())); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"collection": { | |
"links": [ | |
{"href": "http://example.com/events", "rel": "event collection"}, | |
{"href": "http://example.com/events?template", "rel": "event create-form"} | |
] | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package api.resource; | |
import javax.ws.rs.*; | |
import net.hamnaberg.json.*; | |
@Path("/events") | |
@Produces("application/vnd.collection+json") | |
@Consumes("application/vnd.collection+json") | |
public class EventResource{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Arrays; | |
import net.hamnaberg.json; | |
public class TemplateUse { | |
public static void main(String[] args) { | |
Template template = Template.create(Arrays.asList( | |
Property.template("faff"), | |
Property.template("foof"), | |
Property.template("feee") | |
); |