All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.dreamhead.moco.resource.ContentResource Maven / Gradle / Ivy

Go to download

Moco is an easy setup stub framework, mainly focusing on testing and integration.

There is a newer version: 1.5.0
Show newest version
package com.github.dreamhead.moco.resource;

import com.github.dreamhead.moco.HttpRequest;
import com.github.dreamhead.moco.resource.reader.ContentResourceReader;
import com.github.dreamhead.moco.resource.reader.JsonResourceReader;
import com.google.common.base.Optional;
import com.google.common.net.MediaType;

import static com.google.common.base.Optional.absent;
import static com.google.common.base.Optional.of;

public class ContentResource extends Resource implements Content {
    public ContentResource(final Identifiable identifiable, final ResourceConfigApplier configApplier,
                           final ContentResourceReader reader) {
        super(identifiable, configApplier, reader);
    }

    @Override
    public MediaType getContentType(final HttpRequest request) {
        return reader(ContentResourceReader.class).getContentType(request);
    }

    public Optional getJsonObject() {
        try {
            return of(reader(JsonResourceReader.class).getPojo());
        } catch (Exception e) {
            return absent();
        }
    }
}