Example usage for com.liferay.portal.kernel.servlet HttpMethods PUT

List of usage examples for com.liferay.portal.kernel.servlet HttpMethods PUT

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.servlet HttpMethods PUT.

Prototype

String PUT

To view the source code for com.liferay.portal.kernel.servlet HttpMethods PUT.

Click Source Link

Usage

From source file:com.liferay.server.manager.internal.servlet.ServerManagerServlet.java

License:Open Source License

protected void execute(HttpServletRequest request, JSONObject responseJSONObject, String pathInfo)
        throws Exception {

    String executorPath = getExecutorPath(pathInfo);

    Executor executor = _executorServiceRegistry.getExecutor(executorPath);

    Queue<String> arguments = getExecutorArguments(executorPath, pathInfo);

    String method = request.getMethod();

    if (StringUtil.equalsIgnoreCase(method, HttpMethods.DELETE)) {
        executor.executeDelete(request, responseJSONObject, arguments);
    } else if (StringUtil.equalsIgnoreCase(method, HttpMethods.GET)) {
        executor.executeRead(request, responseJSONObject, arguments);
    } else if (StringUtil.equalsIgnoreCase(method, HttpMethods.POST)) {
        executor.executeCreate(request, responseJSONObject, arguments);
    } else if (StringUtil.equalsIgnoreCase(method, HttpMethods.PUT)) {
        executor.executeUpdate(request, responseJSONObject, arguments);
    }/*from  w  ww  . j a  v a2 s. co m*/
}

From source file:com.liferay.servermanager.servlet.ServerManagerServlet.java

License:Open Source License

protected void execute(HttpServletRequest request, JSONObject responseJSONObject, Queue<String> arguments)
        throws Exception {

    Executor executor = _executor;

    while (true) {
        Executor nextExecutor = executor.getNextExecutor(arguments);

        if (nextExecutor == null) {
            break;
        }/*from  w  ww . j  a  va2  s.  c om*/

        executor = nextExecutor;
    }

    String method = request.getMethod();

    if (StringUtil.equalsIgnoreCase(method, HttpMethods.DELETE)) {
        executor.executeDelete(request, responseJSONObject, arguments);
    } else if (StringUtil.equalsIgnoreCase(method, HttpMethods.GET)) {
        executor.executeRead(request, responseJSONObject, arguments);
    } else if (StringUtil.equalsIgnoreCase(method, HttpMethods.POST)) {
        executor.executeCreate(request, responseJSONObject, arguments);
    } else if (StringUtil.equalsIgnoreCase(method, HttpMethods.PUT)) {
        executor.executeUpdate(request, responseJSONObject, arguments);
    }
}

From source file:it.infn.ct.indigo.futuregateway.server.FGServerManager.java

License:Apache License

/**
 * Add a new resource into the FG service.
 *
 * @param companyId The id of the instance
 * @param collection The name of the collection to post the new resource
 * @param resourceId The id of the resource to add. If provided the
 *                   resource will be overwritten
 * @param resource The resource information in JSON format
 * @param token The token of the user performing the action
 * @return The Id of the new resource//from  w  w  w.  j a  v  a  2 s  . co  m
 * @throws PortalException Cannot retrieve the server endpoint
 * @throws IOException Connect communicate with the server
 */
public final String addResource(final long companyId, final String collection, final String resourceId,
        final String resource, final String token) throws PortalException, IOException {
    log.debug("Updating/adding the resource in " + collection + ": " + resource);
    HttpURLConnection connection;
    boolean resourceExist = false;

    if (resourceId != null && !resourceId.isEmpty()) {
        resourceExist = true;
        connection = getFGConnection(companyId, collection, resourceId, token, HttpMethods.PUT,
                FutureGatewayAdminPortletKeys.FUTURE_GATEWAY_CONTENT_TYPE);
    } else {
        connection = getFGConnection(companyId, collection, null, token, HttpMethods.POST,
                FutureGatewayAdminPortletKeys.FUTURE_GATEWAY_CONTENT_TYPE);
    }
    OutputStream os = connection.getOutputStream();
    os.write(resource.getBytes());
    os.flush();
    if (resourceExist && connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
        return resourceId;
    }
    if (!resourceExist && connection.getResponseCode() != HttpURLConnection.HTTP_CREATED) {
        throw new IOException("Impossible to add the resource. " + "Server response with code: "
                + connection.getResponseCode());
    }
    StringBuilder result = new StringBuilder();
    try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
        String readLine;
        while ((readLine = br.readLine()) != null) {
            result.append(readLine);
        }
    }
    connection.disconnect();
    JSONObject jRes = JSONFactoryUtil.createJSONObject(result.toString());
    return jRes.getString(FGServerConstants.ATTRIBUTE_ID);
}