Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-72376

As LCS Developer I need better handling of exceptions and generics in petra JSON WS Client

    Details

      Description

      Improve
      com.liferay.petra.json.web.service.client.BaseJSONWebServiceClientHandler
      Additionally:
      protected <T> List<T> doGetToList(
      Class<T> clazz, String url, Map<String, String> parameters,
      Map<String, String> headers)
      throws JSONWebServiceInvocationException {
      String json = updateJSON(doGet(url, parameters, headers));
      if (json == null)

      { return Collections.emptyList(); }

      try

      { TypeFactory typeFactory = objectMapper.getTypeFactory(); JavaType javaType = typeFactory.constructCollectionType( List.class, clazz); return objectMapper.readValue(json, javaType); }

      catch (IOException ioe)

      { throw new JSONWebServiceInvocationException(ioe); }

      }
      JavaType javaType = typeFactory.constructCollectionType(
      List.class, clazz); should be List<T>.class to make sure generics work well! - after publish Update RemoteOSBPortlet
      This is ugly solution it has to be fixed:
      @Override
      public List<CorpProject> getUserCorpProjects(long userId)
      throws PortalException {
      String serviceURL =
      _URL_API_JSONWS_OSB_PORTLET_CORP_PROJECT +
      "/get-user-corp-projects";
      User user = userLocalService.getUser(userId);
      try {
      List<CorpProjectImpl> corpProjectImpls = doGetToList(
      CorpProjectImpl.class, serviceURL, "roleName",
      OSBPortletConstants.ROLE_OSB_CORP_LCS_USER, "userUuid",
      user.getUuid());
      List<CorpProject> corpProjects = new ArrayList<>();
      for (CorpProject corpProject : corpProjectImpls)

      { corpProjects.add(corpProject); }

      return corpProjects;
      }
      catch (Exception e)

      { processException( e, serviceURL, "roleName", OSBPortletConstants.ROLE_OSB_CORP_LCS_USER, "userUuid", user.getUuid()); throw new SystemException(e); }

      }

        Attachments

          Activity

            People

            • Assignee:
              brian.chan Brian Chan
              Reporter:
              igor.beslic Igor Beslic
              Participants of an Issue:
              Recent user:
              Csaba Turcsan
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 19 weeks, 5 days ago

                Packages

                Version Package
                7.0.0 DXP FP15
                7.0.3 CE GA4
                7.0.0 DXP SP4
                7.0.X EE
                7.1.X
                Master