Package org.restlet.resource

Examples of org.restlet.resource.ResourceException


        doc.appendChild(rootElement);
        // default is XML, so no need to wrap it in a Representation
        ArtifactUsageSerializer.toXml(artifactUsers, doc, rootElement);
        return new DomRepresentation(MediaType.APPLICATION_XML, doc);
      } catch (ParserConfigurationException e) {
        throw new ResourceException(e);
      }
    }
  }
View Full Code Here


                response.setEntity( new StringRepresentation( "Event created" ) );
                response.setStatus( Status.SUCCESS_OK );
            } catch (UnitOfWorkCompletionException e)
            {
                throw new ResourceException(e);
            }
        }
View Full Code Here

                  form.set(key.toString(), jsonObject.get(key.toString()).toString());
               }
               return form;
            } catch (JSONException e)
            {
               throw new ResourceException(e);
            }
         }
      }

      return null;
View Full Code Here

            @Override
            public HandlerCommand handleResponse( Response response, ContextResourceClient client )
            {
                    if (tried)
                        throw new ResourceException( response.getStatus() );

                    tried = true;
                    client.getContextResourceClientFactory().getInfo().setUser( new User("rickard", "secret") );

                    // Try again
View Full Code Here

            if( MediaType.APPLICATION_JAVA_OBJECT.equals( response.getEntity().getMediaType() ) )
            {
                try
                {
                    Object exception = new ObjectRepresentation( response.getEntity() ).getObject();
                    throw new ResourceException( (Throwable) exception );
                }
                catch( IOException e )
                {
                    throw new ResourceException( e );
                }
                catch( ClassNotFoundException e )
                {
                    throw new ResourceException( e );
                }
            }

            throw new ResourceException( Status.SERVER_ERROR_INTERNAL, response.getEntityAsText() );
        }
        else
        {
            if( response.getEntity() != null )
            {
                String text = response.getEntityAsText();
                throw new ResourceException( response.getStatus().getCode(), response.getStatus()
                    .getName(), text, response.getRequest().getResourceRef().toUri().toString() );
            }
            else
            {
                throw new ResourceException( response.getStatus().getCode(), response.getStatus()
                    .getName(), response.getStatus().getDescription(), response.getRequest()
                    .getResourceRef()
                    .toUri()
                    .toString() );
            }
View Full Code Here

            Date lastModified = getRequest().getConditions().getModifiedSince();
            if( lastModified != null )
            {
                if( lastModified.getTime() / 1000 == entityState.lastModified() / 1000 )
                {
                    throw new ResourceException( Status.REDIRECTION_NOT_MODIFIED );
                }
            }

            // Generate the right representation according to its media type.
            if( MediaType.APPLICATION_RDF_XML.equals( variant.getMediaType() ) )
            {
                return entityHeaders( representRdfXml( entityState ), entityState );
            }
            else if( MediaType.TEXT_HTML.equals( variant.getMediaType() ) )
            {
                return entityHeaders( representHtml( entityState ), entityState );
            }
            else if( MediaType.APPLICATION_JSON.equals( variant.getMediaType() ) )
            {
                return entityHeaders( representJson( entityState ), entityState );
            }
        }
        catch( ResourceException ex )
        {
            uow.discard();
            throw ex;
        }

        throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
    }
View Full Code Here

            EntityReference entityReference = EntityReference.parseEntityReference( identity );
            entityState = unitOfWork.entityStateOf( entityReference );
        }
        catch( EntityNotFoundException e )
        {
            throw new ResourceException( Status.CLIENT_ERROR_NOT_FOUND );
        }
        return entityState;
    }
View Full Code Here

            JSONEntityState jsonState = (JSONEntityState) entityState;
            return new StringRepresentation( jsonState.state().toString(), MediaType.APPLICATION_JSON );
        }
        else
        {
            throw new ResourceException( Status.CLIENT_ERROR_NOT_ACCEPTABLE );
        }
    }
View Full Code Here

                }
            }
        }
        catch( ValueSerializationException | IllegalArgumentException e )
        {
            throw new ResourceException( Status.SERVER_ERROR_INTERNAL, e );
        }

        try
        {
            unitOfWork.applyChanges().commit();
        }
        catch( ConcurrentEntityStateModificationException e )
        {
            throw new ResourceException( Status.CLIENT_ERROR_CONFLICT );
        }
        catch( EntityNotFoundException e )
        {
            throw new ResourceException( Status.CLIENT_ERROR_GONE );
        }

        getResponse().setStatus( Status.SUCCESS_RESET_CONTENT );

        return new EmptyRepresentation();
View Full Code Here

    {
        if( resultValue != null )
        {
            if( !responseWriter.writeResponse( resultValue, Response.getCurrent() ) )
            {
                throw new ResourceException( Status.SERVER_ERROR_INTERNAL, "No result writer for type " + resultValue.getClass()
                    .getName() );
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.restlet.resource.ResourceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.