@Override @GET @Path("/notAuthenticated") @Produces({ MediaType.APPLICATION_JSON }) public Response notAuthenticated() { throw RestfulObjectsApplicationException.create(HttpStatusCode.UNAUTHORIZED); }
private void fakeRuntimeExceptionIfXFail() { final HttpHeaders httpHeaders = getResourceContext().getHttpHeaders(); final List<String> requestHeader = httpHeaders.getRequestHeader("X-Fail"); if (requestHeader != null && !requestHeader.isEmpty()) { throw RestfulObjectsApplicationException.create(HttpStatusCode.METHOD_FAILURE); } }
private void ensureCompatibleAcceptHeader( final RepresentationType representationType, final List<MediaType> acceptableMediaTypes) { if(!strictAcceptChecking) { return; } if (representationType == null) { return; } // RestEasy will check the basic media types... // ... so we just need to check the profile paramter final String producedProfile = representationType.getMediaTypeProfile(); if (producedProfile == null) { return; } boolean accepted = isAccepted(producedProfile, acceptableMediaTypes); if(!accepted) { throw RestfulObjectsApplicationException.create(RestfulResponse.HttpStatusCode.NOT_ACCEPTABLE); } }
protected void init( final RepresentationType representationType, final Where where, final RepresentationService.Intent intent, final String urlUnencodedQueryString) { if (!getIsisSessionFactory().inSession()) { throw RestfulObjectsApplicationException.create(HttpStatusCode.UNAUTHORIZED); } if (getAuthenticationSession() == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.UNAUTHORIZED); } this.resourceContext = new ResourceContext( representationType, httpHeaders, providers, uriInfo, request, where, intent, urlUnencodedQueryString, httpServletRequest, httpServletResponse, securityContext, InteractionInitiatedBy.USER); }
/** * search for an accept header in form <code>application/xml;profile=urn:org.restfulobjects:repr-types/action-result;x-ro-domain-type=todoapp.dto.module.todoitem.ToDoItemDto</code> */ @Override public Response.ResponseBuilder buildResponse( final RepresentationService.Context2 renderContext2, final ObjectAndActionInvocation objectAndActionInvocation) { final RepresentationType representationType = RepresentationType.ACTION_RESULT; final MediaType mediaType = mediaTypeFrom(renderContext2, representationType); if (mediaType == null) { return null; } final Object domainObject = returnedObjectOf(objectAndActionInvocation); if(domainObject == null) { throw RestfulObjectsApplicationException.create(RestfulResponse.HttpStatusCode.NOT_FOUND); } return buildResponse(renderContext2, domainObject, representationType); }
@Override @GET @Path("/{domainType}/actions/{actionId}") @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ACTION_DESCRIPTION }) public Response typeAction(@PathParam("domainType") final String domainType, @PathParam("actionId") final String actionId) { final RepresentationType representationType = RepresentationType.ACTION_DESCRIPTION; init(representationType, Where.ANYWHERE, RepresentationService.Intent.NOT_APPLICABLE); final ObjectSpecification parentSpec = getSpecificationLoader().lookupBySpecId(ObjectSpecId.of(domainType)); if (parentSpec == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.NOT_FOUND); } final ObjectMember objectMember = parentSpec.getObjectAction(actionId); if (objectMember == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.NOT_FOUND); } final ObjectAction action = (ObjectAction) objectMember; final ActionDescriptionReprRenderer renderer = new ActionDescriptionReprRenderer(getResourceContext(), null, JsonRepresentation.newMap()); renderer.with(new ParentSpecAndAction(parentSpec, action)).includesSelf(); return Responses.ofOk(renderer, Caching.ONE_DAY).build(); }
@Override @GET @Path("/{domainType}/actions/{actionId}/params/{paramName}") @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_ACTION_PARAMETER_DESCRIPTION }) public Response typeActionParam(@PathParam("domainType") final String domainType, @PathParam("actionId") final String actionId, @PathParam("paramName") final String paramName) { final RepresentationType representationType = RepresentationType.ACTION_PARAMETER_DESCRIPTION; init(representationType, Where.ANYWHERE, RepresentationService.Intent.NOT_APPLICABLE); final ObjectSpecification parentSpec = getSpecificationLoader().lookupBySpecId(ObjectSpecId.of(domainType)); if (parentSpec == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.NOT_FOUND); } final ObjectMember objectMember = parentSpec.getObjectAction(actionId); if (objectMember == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.NOT_FOUND); } final ObjectAction parentAction = (ObjectAction) objectMember; final ObjectActionParameter actionParam = parentAction.getParameterByName(paramName); final ActionParameterDescriptionReprRenderer renderer = new ActionParameterDescriptionReprRenderer(getResourceContext(), null, JsonRepresentation.newMap()); renderer.with(new ParentSpecAndActionParam(parentSpec, actionParam)).includesSelf(); return Responses.ofOk(renderer, Caching.ONE_DAY).build(); }
@Override @GET @Path("/{domainType}/properties/{propertyId}") @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_PROPERTY_DESCRIPTION }) public Response typeProperty(@PathParam("domainType") final String domainType, @PathParam("propertyId") final String propertyId) { final RepresentationType representationType = RepresentationType.PROPERTY_DESCRIPTION; init(representationType, Where.ANYWHERE, RepresentationService.Intent.NOT_APPLICABLE); final ObjectSpecification parentSpec = getSpecificationLoader().lookupBySpecId(ObjectSpecId.of(domainType)); if (parentSpec == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.NOT_FOUND); } final ObjectMember objectMember = parentSpec.getAssociation(propertyId); if (objectMember == null || objectMember.isOneToManyAssociation()) { throw RestfulObjectsApplicationException.create(HttpStatusCode.NOT_FOUND); } final OneToOneAssociation property = (OneToOneAssociation) objectMember; final PropertyDescriptionReprRenderer renderer = new PropertyDescriptionReprRenderer(getResourceContext(), null, JsonRepresentation.newMap()); renderer.with(new ParentSpecAndProperty(parentSpec, property)).includesSelf(); return Responses.ofOk(renderer, Caching.ONE_DAY).build(); }
@Override @GET @Path("/{domainType}/collections/{collectionId}") @Produces({ MediaType.APPLICATION_JSON, RestfulMediaType.APPLICATION_JSON_COLLECTION_DESCRIPTION }) public Response typeCollection(@PathParam("domainType") final String domainType, @PathParam("collectionId") final String collectionId) { final RepresentationType representationType = RepresentationType.COLLECTION_DESCRIPTION; init(representationType, Where.ANYWHERE, RepresentationService.Intent.NOT_APPLICABLE); final ObjectSpecification parentSpec = getSpecificationLoader().lookupBySpecId(ObjectSpecId.of(domainType)); if (parentSpec == null) { throw RestfulObjectsApplicationException.create(HttpStatusCode.NOT_FOUND); } final ObjectMember objectMember = parentSpec.getAssociation(collectionId); if (objectMember == null || objectMember.isOneToOneAssociation()) { throw RestfulObjectsApplicationException.create(HttpStatusCode.NOT_FOUND); } final OneToManyAssociation collection = (OneToManyAssociation) objectMember; final CollectionDescriptionReprRenderer renderer = new CollectionDescriptionReprRenderer(getResourceContext(), null, JsonRepresentation.newMap()); renderer.with(new ParentSpecAndCollection(parentSpec, collection)).includesSelf(); return Responses.ofOk(renderer, Caching.ONE_DAY).build(); }
@Override public ResponseBuilder buildResponse( final RepresentationService.Context2 rendererContext, final ObjectAndActionInvocation objectAndActionInvocation) { final ResponseBuilder responseBuilder; final List<MediaType> acceptableMediaTypes = rendererContext.getAcceptableMediaTypes(); if(isAccepted(RepresentationType.DOMAIN_OBJECT, acceptableMediaTypes, true)) { final ObjectAdapter adapter; final Collection<ObjectAdapter> collectionAdapters = objectAdaptersFrom(objectAndActionInvocation); if(collectionAdapters != null) { final ObjectSpecification elementSpec = elementSpecFrom(objectAndActionInvocation); final String actionOwningType = actionOwningTypeFrom(objectAndActionInvocation); final String actionId = actionIdFrom(objectAndActionInvocation); final String actionArguments = actionArgumentsFrom(objectAndActionInvocation); final DomainObjectList list = domainObjectListFrom(collectionAdapters, elementSpec, actionOwningType, actionId, actionArguments); adapter = rendererContext.getPersistenceSession().adapterFor(list); } else { adapter = objectAndActionInvocation.getReturnedAdapter(); } responseBuilder = buildResponse(rendererContext, adapter); } else if(isAccepted(RepresentationType.ACTION_RESULT, acceptableMediaTypes)) { responseBuilder = buildResponseTo(rendererContext, objectAndActionInvocation, JsonRepresentation.newMap(), null); } else { throw RestfulObjectsApplicationException.create(RestfulResponse.HttpStatusCode.NOT_ACCEPTABLE); } return responseBuilder(responseBuilder); }