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

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

Introduction

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

Prototype

String POST

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

Click Source Link

Usage

From source file:com.liferay.alloy.mvc.AlloyFriendlyURLMapper.java

License:Open Source License

@Override
public String buildPath(LiferayPortletURL liferayPortletURL) {
    Map<String, String> routeParameters = new HashMap<String, String>();

    buildRouteParameters(liferayPortletURL, routeParameters);

    // Populate method parameter based on the portlet lifecycle

    String lifecycle = liferayPortletURL.getLifecycle();

    if (lifecycle.equals(PortletRequest.ACTION_PHASE)) {
        routeParameters.put("method", HttpMethods.POST);
    } else {/*from  ww  w.j av  a 2 s  .  com*/
        routeParameters.put("method", HttpMethods.GET);
    }

    // Map URL with router

    String friendlyURLPath = router.parametersToUrl(routeParameters);

    if (friendlyURLPath == null) {
        return null;
    }

    // Remove mapped parameters from URL

    addParametersIncludedInPath(liferayPortletURL, routeParameters);

    // Remove method

    int pos = friendlyURLPath.indexOf(CharPool.SLASH);

    if (pos != -1) {
        friendlyURLPath = friendlyURLPath.substring(pos);
    } else {
        friendlyURLPath = StringPool.BLANK;
    }

    // Add mapping

    friendlyURLPath = StringPool.SLASH.concat(getMapping()).concat(friendlyURLPath);

    return friendlyURLPath;
}

From source file:com.liferay.alloy.mvc.AlloyFriendlyURLMapper.java

License:Open Source License

protected String getLifecycle(HttpServletRequest request) {
    String method = request.getMethod();

    if (StringUtil.equalsIgnoreCase(method, HttpMethods.POST)) {
        return "1";
    }/*from   w w w . j a v  a 2s . c o  m*/

    return ParamUtil.getString(request, "p_p_lifecycle", "0");
}

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);
    }/*w  w w  . j  a  va  2s  .c om*/
}

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   ww  w  .  j  av  a 2 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:com.liferay.util.bridges.alloy.AlloyFriendlyURLMapper.java

License:Open Source License

protected String getLifecycle(HttpServletRequest request) {
    String method = request.getMethod();

    if (method.equalsIgnoreCase(HttpMethods.POST)) {
        return "1";
    }/*from  w w  w.  jav  a2s .  c  o  m*/

    return ParamUtil.getString(request, "p_p_lifecycle", "0");
}

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   www .  j a va  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);
}

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

License:Apache License

/**
 * Add files into a resource on FG service.
 *
 * @param companyId The id of the instance
 * @param collection The name of the collection to post the new resource
 * @param resourceId The resource requiring the files
 * @param files The files to add to the resource
 * @param token The token of the user performing the action
 * @throws PortalException Cannot retrieve the server endpoint
 * @throws IOException Connect communicate with the server
 *//*  w  ww .  j a  v a2  s .c  o m*/
public final void submitFilesResource(final long companyId, final String collection, final String resourceId,
        final Map<String, InputStream> files, final String token) throws PortalException, IOException {
    String boundary = Long.toHexString(System.currentTimeMillis());
    String crlf = "\r\n";
    log.info("Adding new files to " + collection + "/" + resourceId);

    HttpURLConnection connection = getFGConnection(companyId, collection, resourceId + "/input", token,
            HttpMethods.POST, "multipart/form-data; boundary=" + boundary);
    try (OutputStream output = connection.getOutputStream();
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8),
                    true);) {
        for (String fName : files.keySet()) {
            writer.append("--" + boundary).append(crlf);
            writer.append("Content-Disposition: form-data; " + "name=\"file[]\"; filename=\"" + fName + "\"")
                    .append(crlf);
            writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(fName)).append(crlf);
            writer.append("Content-Transfer-Encoding: binary").append(crlf);
            writer.append(crlf).flush();
            IOUtils.copy(files.get(fName), output);
            writer.append(crlf).flush();
            files.get(fName).close();
        }
        writer.append("--" + boundary + "--").append(crlf).flush();
    }
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
        throw new IOException("Impossible to post files to the resource " + collection + "/" + resourceId
                + ". Server response with code: " + connection.getResponseCode());
    }
}

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

License:Apache License

/**
 * Test getFGConnection./*from w  w w.  j a  v  a  2  s.c o m*/
 */
@Test
public final void testGetFGConnection() {
    try {
        HttpURLConnection conn = fgsm.getFGConnection(0, FGServerConstants.INFRASTRUCTURE_COLLECTION, "", "",
                HttpMethods.POST, FutureGatewayAdminPortletKeys.FUTURE_GATEWAY_CONTENT_TYPE);
        Assert.assertEquals(HttpMethods.POST, conn.getRequestMethod());
        Assert.assertEquals(FutureGatewayAdminPortletKeys.FUTURE_GATEWAY_CONTENT_TYPE,
                conn.getRequestProperty("Content-Type"));
    } catch (IllegalArgumentException | IOException | PortalException e) {
        Assert.fail(e.getMessage());
    }
}

From source file:it.infn.ct.indigo.futuregateway.server.FGServerManeger.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 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 . java  2s  . 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 resource,
        final String token) throws PortalException, IOException {
    log.debug("Adding the new " + collection + ": " + resource);
    HttpURLConnection connection = getFGConnection(companyId, collection, null, token, HttpMethods.POST,
            FutureGatewayAdminPortletKeys.FUTURE_GATEWAY_CONTENT_TYPE);
    OutputStream os = connection.getOutputStream();
    os.write(resource.getBytes());
    os.flush();
    if (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);
}

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

License:Apache License

/**
 * Add files into a resource on FG service.
 *
 * @param companyId The id of the instance
 * @param collection The name of the collection to post the new resource
 * @param resourceId The resource requiring the files
 * @param files The files to add to the resource
 * @param token The token of the user performing the action
 * @throws PortalException Cannot retrieve the server endpoint
 * @throws IOException Connect communicate with the server
 *///from   w ww . j a  va 2  s.com
public final void submitFilesResource(final long companyId, final String collection, final String resourceId,
        final Map<String, File> files, final String token) throws PortalException, IOException {
    String boundary = Long.toHexString(System.currentTimeMillis());
    String crlf = "\r\n";
    log.info("Adding new files to " + collection + "/" + resourceId);

    HttpURLConnection connection = getFGConnection(companyId, collection, resourceId + "/input", token,
            HttpMethods.POST, "multipart/form-data; boundary=" + boundary);
    try (OutputStream output = connection.getOutputStream();
            PrintWriter writer = new PrintWriter(new OutputStreamWriter(output, StandardCharsets.UTF_8),
                    true);) {
        for (String fName : files.keySet()) {
            writer.append("--" + boundary).append(crlf);
            writer.append("Content-Disposition: form-data; " + "name=\"file[]\"; filename=\"" + fName + "\"")
                    .append(crlf);
            writer.append("Content-Type: " + URLConnection.guessContentTypeFromName(fName)).append(crlf);
            writer.append("Content-Transfer-Encoding: binary").append(crlf);
            writer.append(crlf).flush();
            Files.copy(files.get(fName).toPath(), output);
            output.flush();
            writer.append(crlf).flush();
        }
        writer.append("--" + boundary + "--").append(crlf).flush();
    }
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
        throw new IOException("Impossible to post files to the resource " + collection + "/" + resourceId
                + ". Server response with code: " + connection.getResponseCode());
    }
}