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

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

Introduction

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

Prototype

String GET

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

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 {//  w  w w. ja va 2  s . c om
        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.AlloyPortlet.java

License:Open Source License

@Override
public void init(PortletConfig portletConfig) throws PortletException {
    super.init(portletConfig);

    LiferayPortletConfig liferayPortletConfig = (LiferayPortletConfig) portletConfig;

    Portlet portlet = liferayPortletConfig.getPortlet();

    FriendlyURLMapper friendlyURLMapper = portlet.getFriendlyURLMapperInstance();

    Router router = friendlyURLMapper.getRouter();

    router.urlToParameters(HttpMethods.GET, _defaultRouteParameters);
}

From source file:com.liferay.portlet.PortletServletRequest.java

License:Open Source License

@Override
public String getMethod() {
    if (_lifecycle.equals(PortletRequest.ACTION_PHASE) || _lifecycle.equals(PortletRequest.RESOURCE_PHASE)) {

        ClientDataRequest clientDataRequest = _getClientDataRequest();

        return clientDataRequest.getMethod();
    } else if (_lifecycle.equals(PortletRequest.RENDER_PHASE)) {
        return HttpMethods.GET;
    } else {//  w w w  .j a va2 s .c  om
        EventRequest eventRequest = _getEventRequest();

        return eventRequest.getMethod();
    }
}

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  w  w .j  a  va  2s .  c  o  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 www  .  j a  v a2  s  . c  o  m*/

        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.wsrp.portlet.ConsumerPortlet.java

License:Open Source License

protected void initContexts(PortletRequest portletRequest, PortletResponse portletResponse,
        WSRPConsumerPortlet wsrpConsumerPortlet, WSRPConsumerManager wsrpConsumerManager,
        MimeRequest mimeRequest, PortletContext portletContext, RuntimeContext runtimeContext,
        UserContext userContext) throws Exception {

    PortletSession portletSession = portletRequest.getPortletSession();

    HttpServletRequest request = PortalUtil.getHttpServletRequest(portletRequest);

    ThemeDisplay themeDisplay = (ThemeDisplay) portletRequest.getAttribute(WebKeys.THEME_DISPLAY);

    // Markup params

    ClientData clientData = new ClientData();

    clientData.setRequestVerb(HttpMethods.GET);
    clientData.setUserAgent(request.getHeader(HttpHeaders.USER_AGENT));

    User user = themeDisplay.getUser();//from   www  .j  a va 2s. c  o  m

    List<MessageElement> clientAttributes = new ArrayList<MessageElement>();

    Enumeration<String> enu = request.getHeaderNames();

    while (enu.hasMoreElements()) {
        String name = enu.nextElement();

        String value = request.getHeader(name);

        ExtensionUtil.addMessageElement(clientAttributes, name, value);
    }

    ExtensionUtil.addMessageElement(clientAttributes, HttpHeaders.LIFERAY_EMAIL_ADDRESS,
            user.getEmailAddress());
    ExtensionUtil.addMessageElement(clientAttributes, HttpHeaders.LIFERAY_SCREEN_NAME, user.getScreenName());
    ExtensionUtil.addMessageElement(clientAttributes, HttpHeaders.LIFERAY_USER_ID,
            String.valueOf(user.getUserId()));

    clientData.setExtensions(ExtensionUtil.getExtensions(clientAttributes));

    mimeRequest.setClientData(clientData);

    List<Locale> locales = Collections.list(portletRequest.getLocales());

    String[] localesArray = new String[locales.size()];

    for (int i = 0; i < locales.size(); i++) {
        Locale locale = locales.get(i);

        localesArray[i] = locale.toString();
    }

    mimeRequest.setLocales(localesArray);

    mimeRequest.setMarkupCharacterSets(_CHAR_SETS);
    mimeRequest.setMimeTypes(_MIME_TYPES);
    mimeRequest.setMode(getWSRPMode(portletRequest.getPortletMode()));
    mimeRequest.setWindowState(getWSRPWindowState(portletRequest.getWindowState()));

    String[] modes = { getWSRPMode(PortletMode.EDIT), getWSRPMode(PortletMode.HELP),
            getWSRPMode(PortletMode.VIEW) };

    mimeRequest.setValidNewModes(modes);

    String[] windowStates = { getWSRPWindowState(WindowState.MAXIMIZED),
            getWSRPWindowState(WindowState.MINIMIZED), getWSRPWindowState(WindowState.NORMAL) };

    mimeRequest.setValidNewWindowStates(windowStates);

    // Navigational context

    NavigationalContext navigationalContext = new NavigationalContext();

    String navigationalState = portletRequest.getParameter("wsrp-navigationalState");

    navigationalContext.setOpaqueValue(navigationalState);

    Map<String, String[]> publicParameterMap = portletRequest.getPublicParameterMap();

    List<NamedString> publicValues = new ArrayList<NamedString>();

    for (Map.Entry<String, String[]> entry : publicParameterMap.entrySet()) {

        String name = entry.getKey();
        String[] values = entry.getValue();

        for (String value : values) {
            NamedString publicValue = new NamedString();

            publicValue.setName(name);
            publicValue.setValue(value);

            publicValues.add(publicValue);
        }
    }

    navigationalContext.setPublicValues(publicValues.toArray(new NamedString[publicValues.size()]));

    mimeRequest.setNavigationalContext(navigationalContext);

    processFormParameters(portletRequest, portletResponse, mimeRequest);

    // Portlet context

    portletContext.setPortletHandle(wsrpConsumerPortlet.getPortletHandle());

    // Runtime context

    runtimeContext.setNamespacePrefix(portletResponse.getNamespace());
    runtimeContext.setPortletInstanceKey(portletResponse.getNamespace());

    SessionContext sessionContext = (SessionContext) portletSession.getAttribute(WebKeys.SESSION_CONTEXT);

    if (sessionContext != null) {
        SessionParams sessionParams = new SessionParams();

        sessionParams.setSessionID(sessionContext.getSessionID());

        runtimeContext.setSessionParams(sessionParams);
    }

    runtimeContext.setUserAuthentication("wsrp:password");

    PortletDescription portletDescription = wsrpConsumerManager
            .getPortletDescription(wsrpConsumerPortlet.getPortletHandle());

    Boolean doesUrlTemplateProcessing = portletDescription.getDoesUrlTemplateProcessing();

    if ((doesUrlTemplateProcessing != null) && doesUrlTemplateProcessing) {
        Templates templates = new Templates();

        templates.setBlockingActionTemplate(_BLOCKING_ACTION_TEMPLATE);
        templates.setRenderTemplate(_RENDER_TEMPLATE);
        templates.setResourceTemplate(_RESOURCE_TEMPLATE);
        templates.setSecureBlockingActionTemplate(_BLOCKING_ACTION_TEMPLATE);
        templates.setSecureRenderTemplate(_RENDER_TEMPLATE);
        templates.setSecureResourceTemplate(_RESOURCE_TEMPLATE);

        runtimeContext.setTemplates(templates);
    }

    // User context

    userContext.setUserCategories(new String[] { RoleConstants.USER });
    userContext.setUserContextKey(String.valueOf(themeDisplay.getUserId()));
}

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

License:Apache License

/**
 * Retrieves a collection from the FG service.
 *
 * @param companyId The id of the instance
 * @param collection The name of the collection to post the new resource
 * @param token The authorisation token for the user
 * @return The full raw collection in json format
 * @throws PortalException Cannot retrieve the server endpoint
 * @throws IOException Connect communicate with the server
 *///from   ww  w .  ja va2  s.c om
public String getCollection(final long companyId, final String collection, final String token)
        throws PortalException, IOException {
    HttpURLConnection connection = getFGConnection(companyId, collection, null, token, HttpMethods.GET,
            FutureGatewayAdminPortletKeys.FUTURE_GATEWAY_CONTENT_TYPE);
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
        connection.disconnect();
        log.debug("FG server response code not correct: " + connection.getResponseCode());
        throw new IOException("Server response with code: " + connection.getResponseCode());
    }
    BufferedReader collIn = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String inputLine;
    StringBuilder collections = new StringBuilder();
    while ((inputLine = collIn.readLine()) != null) {
        collections.append(inputLine);
    }
    collIn.close();
    log.debug("This is the collection: " + collections.toString());
    return collections.toString();
}

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

License:Apache License

/**
 * Retrieves a resource from 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 retrieve
 * @param token The authorisation token for the user
 * @return The full raw collection in json format
 * @throws PortalException Cannot retrieve the server endpoint
 * @throws IOException Connect communicate with the server
 *///from w  ww .  j a  v a  2 s.com
public String getResource(final long companyId, final String collection, final String resourceId,
        final String token) throws PortalException, IOException {
    HttpURLConnection connection = getFGConnection(companyId, collection, resourceId, token, HttpMethods.GET,
            FutureGatewayAdminPortletKeys.FUTURE_GATEWAY_CONTENT_TYPE);
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
        connection.disconnect();
        log.debug("FG server response code not correct: " + connection.getResponseCode());
        throw new IOException("Server response with code: " + connection.getResponseCode());
    }
    BufferedReader resIn = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String inputLine;
    StringBuilder resource = new StringBuilder();
    while ((inputLine = resIn.readLine()) != null) {
        resource.append(inputLine);
    }
    resIn.close();
    log.debug("This is the collection: " + resource.toString());
    return resource.toString();
}

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

License:Apache License

/**
 * Retrieves a collection from the FG service.
 *
 * @param companyId The id of the instance
 * @param collection The name of the collection to post the new resource
 * @param token The authorisation token for the user
 * @return The full raw collection in json format
 * @throws PortalException Cannot retrieve the server endpoint
 * @throws IOException Connect communicate with the server
 *//*w ww. ja  v a 2  s.  c o  m*/
public final String getCollection(final long companyId, final String collection, final String token)
        throws PortalException, IOException {
    HttpURLConnection connection = getFGConnection(companyId, collection, null, token, HttpMethods.GET,
            FutureGatewayAdminPortletKeys.FUTURE_GATEWAY_CONTENT_TYPE);
    if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
        connection.disconnect();
        log.debug("FG server response code not correct: " + connection.getResponseCode());
        throw new IOException("Server response with code: " + connection.getResponseCode());
    }
    BufferedReader collIn = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    String inputLine;
    StringBuilder collections = new StringBuilder();
    while ((inputLine = collIn.readLine()) != null) {
        collections.append(inputLine);
    }
    collIn.close();
    log.debug("This is the collection: " + collections.toString());
    return collections.toString();
}