Package org.restlet.resource

Examples of org.restlet.resource.Representation


        this.graphApplication = newGraphApplication;
    }

    @Override
    public Representation represent(Variant variant) {
        Representation rep = null;
        try {
            graphName = getGraph();
            maxRows = getMaxRows();
            queryString = getQueryString();
            if (queryString == null) {
View Full Code Here


public class JsonRepresentationFactory implements RepresentationFactory, AnswerVisitor<Representation> {
    private MediaType mediaType;

    public Representation createRepresentation(MediaType defaultMediaType, Map<String, Object> dataModel) {
        try {
            Representation representation = Representation.createEmpty();
            final Answer answer = (Answer) dataModel.get("answer");
            if (answer != null) {
                mediaType = defaultMediaType;
                representation = answer.accept(this);
            }
View Full Code Here

public class SparqlXmlRepresentationFactory implements RepresentationFactory, AnswerVisitor<Representation> {
    private MediaType mediaType;

    public Representation createRepresentation(MediaType defaultMediaType, Map<String, Object> dataModel) {
        Representation representation = Representation.createEmpty();
        final Answer answer = (Answer) dataModel.get("answer");
        if (answer != null) {
            mediaType = defaultMediaType;
            representation = answer.accept(this);
        }
View Full Code Here

        this.graphLister = newGraphLister;
    }

    @Override
    public Representation represent(Variant variant) throws ResourceException {
        Representation rep = null;
        try {
            rep = constructRepresentation(variant);
            getResponse().setStatus(SUCCESS_OK);
        } catch (Exception e) {
            getResponse().setStatus(SERVER_ERROR_INTERNAL, e, e.getMessage().replace("\n", ""));
View Full Code Here

    @Override
    public Status sendRequest(Request request) {
        Status result = null;

        try {
            final Representation entity = request.getEntity();

            // Set the request headers
            for (final Parameter header : getRequestHeaders()) {
                getHttpMethod().addRequestHeader(header.getName(),
                        header.getValue());
            }

            // For those method that accept enclosing entities, provide it
            if ((entity != null)
                    && (getHttpMethod() instanceof EntityEnclosingMethod)) {
                final EntityEnclosingMethod eem = (EntityEnclosingMethod) getHttpMethod();
                eem.setRequestEntity(new RequestEntity() {
                    public long getContentLength() {
                        return entity.getSize();
                    }

                    public String getContentType() {
                        return (entity.getMediaType() != null) ? entity
                                .getMediaType().toString() : null;
                    }

                    public boolean isRepeatable() {
                        return !entity.isTransient();
                    }

                    public void writeRequest(OutputStream os)
                            throws IOException {
                        entity.write(os);
                    }
                });
            }

            // Ensure that the connection is active
View Full Code Here

    public Status sendRequest(Request request) {
        Status result = null;

        try {
            if (request.isEntityAvailable()) {
                Representation entity = request.getEntity();

                // These properties can only be used with Java 1.5 and upper
                // releases
                int majorVersionNumber = Engine.getJavaMajorVersion();
                int minorVersionNumber = Engine.getJavaMinorVersion();
                if ((majorVersionNumber > 1)
                        || (majorVersionNumber == 1 && minorVersionNumber >= 5)) {
                    // Adjust the streaming mode
                    if (entity.getSize() > 0) {
                        // The size of the entity is known in advance
                        getConnection().setFixedLengthStreamingMode(
                                (int) entity.getSize());
                    } else {
                        // The size of the entity is not known in advance
                        if (getHelper().getChunkLength() >= 0) {
                            // Use chunked encoding
                            getConnection().setChunkedStreamingMode(
View Full Code Here

    @Override
    public Status sendRequest(Request request) {
        Status result = null;

        try {
            final Representation entity = request.getEntity();

            // Set the request headers
            for (final Parameter header : getRequestHeaders()) {
                getHttpMethod().addRequestHeader(header.getName(),
                        header.getValue());
            }

            // For those method that accept enclosing entites, provide it
            if ((entity != null)
                    && (getHttpMethod() instanceof EntityEnclosingMethod)) {
                final EntityEnclosingMethod eem = (EntityEnclosingMethod) getHttpMethod();
                eem.setRequestEntity(new RequestEntity() {
                    public long getContentLength() {
                        return entity.getSize();
                    }

                    public String getContentType() {
                        return (entity.getMediaType() != null) ? entity
                                .getMediaType().toString() : null;
                    }

                    public boolean isRepeatable() {
                        return !entity.isTransient();
                    }

                    public void writeRequest(OutputStream os)
                            throws IOException {
                        entity.write(os);
                    }
                });
            }

            // Ensure that the connection is active
View Full Code Here

     *            The response returned.
     */
    protected void addEntityHeaders(HttpResponse response) {
        final Series<Parameter> responseHeaders = response.getHttpCall()
                .getResponseHeaders();
        final Representation entity = response.getEntity();
        addEntityHeaders(entity, responseHeaders);
    }
View Full Code Here

  {
    Reference resourceRef = new Reference(url);
    Request request = new Request(Method.GET, resourceRef);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    return sw.toString();
  }
View Full Code Here

            + "/StateModelDefs/MasterSlave";
    Reference resourceRef = new Reference(httpUrlBase);
    Request request = new Request(Method.GET, resourceRef);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    ObjectMapper mapper = new ObjectMapper();
    ZNRecord zn = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);

    Map<String, String> paraMap = new HashMap<String, String>();

    paraMap.put(JsonParameters.MANAGEMENT_COMMAND,
                ClusterSetup.addStateModelDef);

    ZNRecord r = new ZNRecord("Test");
    r.merge(zn);
    StateModelDefinition newStateModel = new StateModelDefinition(r);

    httpUrlBase =
        "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/StateModelDefs";
    resourceRef = new Reference(httpUrlBase);
    request = new Request(Method.POST, resourceRef);
    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
                          + ClusterRepresentationUtil.ObjectToJson(paraMap) + "&"
                          + JsonParameters.NEW_STATE_MODEL_DEF + "="
                          + ClusterRepresentationUtil.ZNRecordToJson(r),
                      MediaType.APPLICATION_ALL);
    client = new Client(Protocol.HTTP);
    response = client.handle(request);

    result = response.getEntity();
    sw = new StringWriter();
    result.write(sw);

    // System.out.println(sw.toString());

    AssertJUnit.assertTrue(sw.toString().contains("Test"));
  }
View Full Code Here

TOP

Related Classes of org.restlet.resource.Representation

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.