use of org.restlet.service.MetadataService in project qi4j-sdk by Qi4j.
the class ExtensionMediaTypeFilter method beforeHandle.
@Override
protected int beforeHandle(Request request, Response response) {
List<String> segments = request.getResourceRef().getSegments();
if (segments.get(segments.size() - 1).equals(""))
return Filter.CONTINUE;
String extensions = request.getResourceRef().getExtensions();
if (extensions != null) {
int idx = extensions.lastIndexOf(".");
if (idx != -1) {
extensions = extensions.substring(idx + 1);
}
MetadataService metadataService = getApplication().getMetadataService();
Metadata metadata = metadataService.getMetadata(extensions);
if (metadata != null && metadata instanceof MediaType) {
request.getClientInfo().setAcceptedMediaTypes(Collections.singletonList(new Preference<MediaType>((MediaType) metadata)));
String path = request.getResourceRef().getPath();
path = path.substring(0, path.length() - extensions.length() - 1);
request.getResourceRef().setPath(path);
}
}
return Filter.CONTINUE;
}
use of org.restlet.service.MetadataService in project qi4j-sdk by Qi4j.
the class Main method main.
public static void main(String[] args) throws Exception {
Energy4Java is = new Energy4Java();
Server server = new Server(Protocol.HTTP, 8888);
Application app = is.newApplication(new ForumAssembler(), new MetadataService());
app.activate();
ContextRestlet restlet = app.findModule("REST", "Restlet").newObject(ContextRestlet.class, new org.restlet.Context());
ChallengeAuthenticator guard = new ChallengeAuthenticator(null, ChallengeScheme.HTTP_BASIC, "testRealm");
MapVerifier mapVerifier = new MapVerifier();
mapVerifier.getLocalSecrets().put("rickard", "secret".toCharArray());
guard.setVerifier(mapVerifier);
guard.setNext(restlet);
server.setNext(restlet);
server.start();
}
use of org.restlet.service.MetadataService in project qi4j-sdk by Qi4j.
the class ExtensionMediaTypeFilter method beforeHandle.
@Override
protected int beforeHandle(Request request, Response response) {
List<String> segments = request.getResourceRef().getSegments();
if (segments.get(segments.size() - 1).equals("")) {
return Filter.CONTINUE;
}
String extensions = request.getResourceRef().getExtensions();
if (extensions != null) {
int idx = extensions.lastIndexOf(".");
if (idx != -1) {
extensions = extensions.substring(idx + 1);
}
MetadataService metadataService = getApplication().getMetadataService();
Metadata metadata = metadataService.getMetadata(extensions);
if (metadata != null && metadata instanceof MediaType) {
request.getClientInfo().setAcceptedMediaTypes(Collections.singletonList(new Preference<MediaType>((MediaType) metadata)));
String path = request.getResourceRef().getPath();
path = path.substring(0, path.length() - extensions.length() - 1);
request.getResourceRef().setPath(path);
}
}
return Filter.CONTINUE;
}
Aggregations