Package org.restlet.data

Examples of org.restlet.data.Response


    Request request = new Request(Method.POST, resourceRef);

    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(paraMap), MediaType.APPLICATION_ALL);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);

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

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

    ObjectMapper mapper = new ObjectMapper();
    ZNRecord r = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
    AssertJUnit.assertTrue(r.getSimpleField(InstanceConfigProperty.HELIX_ENABLED.toString())
                            .equals("" + false));

    // Then enable it
    paraMap.put(JsonParameters.ENABLED, "" + true);
    request = new Request(Method.POST, resourceRef);

    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(paraMap), 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());
View Full Code Here


    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);

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

    ObjectMapper mapper = new ObjectMapper();
    ZNRecord r = mapper.readValue(new StringReader(sw.toString()), ZNRecord.class);
    String partitionName = "new-entity-12345_3";
    r.getMapFields().remove(partitionName);

    Map<String, String> paraMap = new HashMap<String, String>();
    // Add 1 instance
    paraMap.put(JsonParameters.MANAGEMENT_COMMAND, ClusterSetup.addIdealState);

    resourceRef = new Reference(httpUrlBase);

    request = new Request(Method.POST, resourceRef);
    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
                          + ClusterRepresentationUtil.ObjectToJson(paraMap) + "&"
                          + JsonParameters.NEW_IDEAL_STATE + "="
                          + 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());
View Full Code Here

  }

  private ZNRecord get(Client client, String url, ObjectMapper mapper) throws Exception
  {
    Request request = new Request(Method.GET, new Reference(url));
    Response response = client.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    String responseStr = sw.toString();
    Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
    Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
View Full Code Here

    Request request = new Request(Method.POST, new Reference(url));
    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(params), MediaType.APPLICATION_ALL);

    Response response = client.handle(request);
    Representation result = response.getEntity();
    StringWriter sw = new StringWriter();
    result.write(sw);
    String responseStr = sw.toString();
    Assert.assertTrue(responseStr.toLowerCase().indexOf("error") == -1);
    Assert.assertTrue(responseStr.toLowerCase().indexOf("exception") == -1);
View Full Code Here

    Request request = new Request(Method.POST, resourceRef);

    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(paramMap), MediaType.APPLICATION_ALL);
    Client client = new Client(Protocol.HTTP);
    Response response = client.handle(request);

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

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

    // verify pause znode exists
    String pausePath = PropertyPathConfig.getPath(PropertyType.PAUSE, clusterName);
    System.out.println("pausePath: " + pausePath);
    boolean exists = _gZkClient.exists(pausePath);
    Assert.assertTrue(exists, pausePath + " should exist");

    // Then enable it
    paramMap.put(JsonParameters.ENABLED, "" + true);
    request = new Request(Method.POST, resourceRef);

    request.setEntity(JsonParameters.JSON_PARAMETERS + "="
        + ClusterRepresentationUtil.ObjectToJson(paramMap), 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());
View Full Code Here

    protected Component createComponent() {
        Component component = null;

        // Look for the Component XML configuration file.
        Client client = createWarClient(new Context(), getServletConfig());
        Response response = client.get("war:///WEB-INF/restlet.xml");
        if (response.getStatus().isSuccess() && response.isEntityAvailable()) {
            component = new Component(response.getEntity());
        }

        // Look for the component class name specified in the web.xml file.
        if (component == null) {
            // Try to instantiate a new target component
View Full Code Here

     * @return True if the Component is the default one, false otherwise.
     */
    private boolean isDefaultComponent() {
        // The Component is provided via an XML configuration file.
        Client client = createWarClient(new Context(), getServletConfig());
        Response response = client.get("war:///WEB-INF/restlet.xml");
        if (response.getStatus().isSuccess() && response.isEntityAvailable()) {
            return false;
        }

        // The Component is provided via a context parameter in the "web.xml"
        // file.
View Full Code Here

            // Prevent the client from accessing resources in upper directories
            this.targetUri = directory.getRootRef().toString();
        }

        // Try to detect the presence of a directory
        Response contextResponse = getDispatcher().get(this.targetUri);
        if (contextResponse.getEntity() != null) {
            if (MediaType.TEXT_URI_LIST.equals(contextResponse.getEntity()
                    .getMediaType())) {
                this.targetDirectory = true;
                this.targetFile = false;
                this.directoryContent = new ReferenceList(contextResponse
                        .getEntity());
                if (!request.getResourceRef().getIdentifier().endsWith("/")) {
                    // All requests will be automatically redirected
                    this.directoryRedirection = true;
                }

                if (!this.targetUri.endsWith("/")) {
                    this.targetUri += "/";
                    this.relativePart += "/";
                }

                // Append the index name
                if (getDirectory().getIndexName() != null
                        && getDirectory().getIndexName().length() > 0) {
                    this.directoryUri = this.targetUri;
                    this.baseName = getDirectory().getIndexName();
                    this.targetUri = this.directoryUri + this.baseName;
                    this.targetIndex = true;
                } else {
                    this.directoryUri = this.targetUri;
                    this.baseName = null;
                }
            } else {
                this.targetDirectory = false;
                this.targetFile = true;
                this.fileContent = contextResponse.getEntity();
            }
        } else {
            this.targetDirectory = false;
            this.targetFile = false;
        }

        if (!this.targetDirectory) {
            int lastSlashIndex = targetUri.lastIndexOf('/');
            if (lastSlashIndex == -1) {
                this.directoryUri = "";
                this.baseName = targetUri;
            } else {
                this.directoryUri = targetUri.substring(0, lastSlashIndex + 1);
                this.baseName = targetUri.substring(lastSlashIndex + 1);
            }

            contextResponse = getDispatcher().get(this.directoryUri);
            if ((contextResponse.getEntity() != null)
                    && MediaType.TEXT_URI_LIST.equals(contextResponse
                            .getEntity().getMediaType())) {
                this.directoryContent = new ReferenceList(contextResponse
                        .getEntity());
            }
        }

        if (this.baseName != null) {
View Full Code Here

                status = new Status(Status.CLIENT_ERROR_FORBIDDEN,
                        "No modification allowed.");
            } else {
                Request contextRequest = new Request(Method.DELETE,
                        this.targetUri);
                Response contextResponse = new Response(contextRequest);

                if (targetDirectory && !targetIndex) {
                    contextRequest.setResourceRef(this.targetUri);
                    getDispatcher().handle(contextRequest, contextResponse);
                } else {
                    // Check if there is only one representation

                    // Try to get the unique representation of the resource
                    ReferenceList references = getVariantsReferences();
                    if (!references.isEmpty()) {
                        if (uniqueReference != null) {
                            contextRequest.setResourceRef(uniqueReference);
                            getDispatcher().handle(contextRequest,
                                    contextResponse);
                        } else {
                            // We found variants, but not the right one
                            contextResponse
                                    .setStatus(new Status(
                                            Status.CLIENT_ERROR_NOT_ACCEPTABLE,
                                            "Unable to process properly the request. Several variants exist but none of them suits precisely. "));
                        }
                    } else {
                        contextResponse
                                .setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                    }
                }

                status = contextResponse.getStatus();
            }

            getResponse().setStatus(status);
        }
    }
View Full Code Here

            status = new Status(Status.CLIENT_ERROR_FORBIDDEN,
                    "No modification allowed.");
        } else {
            Request contextRequest = new Request(Method.PUT, this.targetUri);
            contextRequest.setEntity(variant);
            Response contextResponse = new Response(contextRequest);
            contextRequest.setResourceRef(this.targetUri);
            getDispatcher().handle(contextRequest, contextResponse);
            status = contextResponse.getStatus();
        }

        getResponse().setStatus(status);
    }
View Full Code Here

TOP

Related Classes of org.restlet.data.Response

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.