Package org.restlet.resource

Examples of org.restlet.resource.ClientResource


     * @param entitySubpath
     *            The path of the entity to delete
     * @throws ResourceException
     */
    public void deleteEntity(String entitySubpath) throws ResourceException {
        ClientResource resource = createResource(entitySubpath);

        try {
            resource.delete();
        } catch (ResourceException re) {
            throw new ResourceException(re.getStatus(),
                    "Can't delete this entity " + resource.getReference());
        } finally {
            this.latestRequest = resource.getRequest();
            this.latestResponse = resource.getResponse();
        }
    }
View Full Code Here


     *
     * @return The metadata document related to the current service.
     */
    protected Object getMetadata() {
        if (metadata == null) {
            ClientResource resource = createResource("$metadata");

            try {
                getLogger().log(
                        Level.INFO,
                        "Get the metadata for " + getServiceRef() + " at "
                                + resource.getReference());
                Representation rep = resource.get(MediaType.APPLICATION_XML);
                this.metadata = new Metadata(rep, resource.getReference());
            } catch (ResourceException e) {
                getLogger().log(
                        Level.SEVERE,
                        "Can't get the metadata for " + getServiceRef()
                                + " (response's status: "
                                + resource.getStatus() + ")");
            } catch (Exception e) {
                getLogger().log(Level.SEVERE,
                        "Can't get the metadata for " + getServiceRef(), e);
            } finally {
                this.latestRequest = resource.getRequest();
                this.latestResponse = resource.getResponse();
            }
        }

        return metadata;
    }
View Full Code Here

     * @return The binary representation of the given media resource.
     */
    public Representation getValue(Object entity) throws ResourceException {
        Reference ref = getValueRef(entity);
        if (ref != null) {
            ClientResource cr = createResource(ref);
            return cr.get();
        }

        return null;
    }
View Full Code Here

    public Representation getValue(Object entity,
            List<Preference<MediaType>> acceptedMediaTypes)
            throws ResourceException {
        Reference ref = getValueRef(entity);
        if (ref != null) {
            ClientResource cr = createResource(ref);
            cr.getClientInfo().setAcceptedMediaTypes(acceptedMediaTypes);
            return cr.get();
        }

        return null;
    }
View Full Code Here

     */
    public Representation getValue(Object entity, MediaType mediaType)
            throws ResourceException {
        Reference ref = getValueRef(entity);
        if (ref != null) {
            ClientResource cr = createResource(ref);
            return cr.get(mediaType);
        }

        return null;
    }
View Full Code Here

                    break;
                }
            }

            if (function != null) {
                ClientResource resource = createResource(service);
                resource.setMethod(function.getMethod());
                if (parameters != null) {
                    for (org.restlet.ext.odata.internal.edm.Parameter parameter : function
                            .getParameters()) {
                        resource.getReference().addQueryParameter(
                                parameter.getName(),
                                TypeUtils.getLiteralForm(parameters
                                        .getFirstValue(parameter.getName()),
                                        parameter.getType()));
                    }
                }

                result = resource.handle();
                this.latestRequest = resource.getRequest();
                this.latestResponse = resource.getResponse();

                if (resource.getStatus().isError()) {
                    throw new ResourceException(resource.getStatus());
                }
            }
        }

        return result;
View Full Code Here

                        "Can't set the property " + propertyName + " of "
                                + entity.getClass() + " for the service"
                                + getServiceRef(), e);
            }
        } else {
            ClientResource resource = createResource(getSubpath(entity,
                    propertyName));
            try {
                Representation rep = resource.get();

                try {
                    String value = getSimpleValue(rep, propertyName);
                    Property property = metadata.getProperty(entity,
                            propertyName);
                    ReflectUtils.setProperty(entity, property, value);
                } catch (Exception e) {
                    getLogger().log(
                            Level.WARNING,
                            "Can't set the property " + propertyName + " of "
                                    + entity.getClass() + " for the service"
                                    + getServiceRef(), e);
                }
            } catch (ResourceException e) {
                getLogger().log(
                        Level.WARNING,
                        "Can't get the following resource "
                                + resource.getReference() + " for the service"
                                + getServiceRef(), e);
            }
        }
    }
View Full Code Here

            return;
        }
        if (target != null) {
            // TODO Take into acount the case where the target does exist.
            Metadata metadata = (Metadata) getMetadata();
            ClientResource resource = createResource(metadata
                    .getSubpath(source) + "/$links/" + sourceProperty);

            try {
                // TODO Fix chunked request with net client connector
                StringBuilder sb = new StringBuilder("<uri xmlns=\"");
                sb.append(WCF_DATASERVICES_NAMESPACE);
                sb.append("\">");
                sb.append(getServiceRef().toString());
                sb.append(metadata.getSubpath(target));
                sb.append("</uri>");

                StringRepresentation r = new StringRepresentation(
                        sb.toString(), MediaType.APPLICATION_XML);
                resource.put(r);
            } catch (ResourceException re) {
                throw new ResourceException(re.getStatus(),
                        "Can't set entity to this entity set "
                                + resource.getReference());
            } finally {
                this.latestRequest = resource.getRequest();
                this.latestResponse = resource.getResponse();
            }
        } else {
            ReflectUtils.invokeSetter(source, sourceProperty, null);
            updateEntity(source);
        }
View Full Code Here

    public void setValue(Object entity, Representation blob)
            throws ResourceException {
        Reference ref = getValueEditRef(entity);

        if (ref != null) {
            ClientResource cr = createResource(ref);
            cr.put(blob);
        }
    }
View Full Code Here

        if (getMetadata() == null || entity == null) {
            return;
        }
        Entry entry = toEntry(entity);

        ClientResource resource = createResource(getSubpath(entity));

        try {
            // TODO Fix chunked request with net client connector
            ByteArrayOutputStream o = new ByteArrayOutputStream();
            entry.write(o);
            StringRepresentation r = new StringRepresentation(o.toString(),
                    MediaType.APPLICATION_ATOM);
            String tag = getTag(entity);
            if (tag != null) {
                // Add a condition
                resource.getConditions().setMatch(Arrays.asList(new Tag(tag)));
            }
            resource.put(r);
        } catch (ResourceException re) {
            throw new ResourceException(re.getStatus(),
                    "Can't update this entity " + resource.getReference());
        } finally {
            this.latestRequest = resource.getRequest();
            this.latestResponse = resource.getResponse();
        }
    }
View Full Code Here

TOP

Related Classes of org.restlet.resource.ClientResource

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.