001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019package org.apache.isis.viewer.restfulobjects.server.resources; 020 021import javax.ws.rs.GET; 022import javax.ws.rs.Path; 023import javax.ws.rs.Produces; 024import javax.ws.rs.core.MediaType; 025import javax.ws.rs.core.Response; 026 027import org.apache.isis.applib.annotation.Where; 028import org.apache.isis.viewer.restfulobjects.applib.JsonRepresentation; 029import org.apache.isis.viewer.restfulobjects.applib.RepresentationType; 030import org.apache.isis.viewer.restfulobjects.applib.RestfulMediaType; 031import org.apache.isis.viewer.restfulobjects.applib.client.RestfulResponse.HttpStatusCode; 032import org.apache.isis.viewer.restfulobjects.applib.homepage.HomePageResource; 033import org.apache.isis.viewer.restfulobjects.server.RestfulObjectsApplicationException; 034 035/** 036 * Implementation note: it seems to be necessary to annotate the implementation 037 * with {@link Path} rather than the interface (at least under RestEasy 1.0.2 038 * and 1.1-RC2). 039 */ 040public class HomePageResourceServerside extends ResourceAbstract implements HomePageResource { 041 042 @Override 043 @Produces({ RestfulMediaType.APPLICATION_JSON_HOME_PAGE }) 044 public Response homePage() { 045 init(RepresentationType.HOME_PAGE, Where.NOWHERE); 046 047 final HomePageReprRenderer renderer = new HomePageReprRenderer(getResourceContext(), null, JsonRepresentation.newMap()); 048 renderer.includesSelf(); 049 050 return responseOfOk(renderer, Caching.ONE_DAY).build(); 051 } 052 053 @Override 054 @GET 055 @Path("/notAuthenticated") 056 @Produces({ MediaType.APPLICATION_JSON }) 057 public Response notAuthenticated() { 058 059 throw RestfulObjectsApplicationException.create(HttpStatusCode.UNAUTHORIZED); 060 } 061 062}