glassfish
  1. glassfish
  2. GLASSFISH-20397

CLI prints NullPointerException when remote server returns 500 with unknown data

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 4.0_b85
    • Fix Version/s: 4.0_b86_RC2
    • Component/s: command_line_interface
    • Labels:
      None

      Description

      CLI prints NullPointerException when remote server returns 500 with unknown data. It is theoretically not possible with direct connection to GF. But can be seen when port is wrong or maybe by proxy server.

      It was identify by Bug 16553490.

        Activity

        Hide
        martin.mares added a comment -

        I have fix ready. I need to solve if I have to wait until new nucleus branch or if I can commit it into current ReleaseCandidate.

        Show
        martin.mares added a comment - I have fix ready. I need to solve if I have to wait until new nucleus branch or if I can commit it into current ReleaseCandidate.
        Hide
        martin.mares added a comment -
        Index: nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java
        ===================================================================
        --- nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java	(revision 61586)
        +++ nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java	(working copy)
        @@ -44,6 +44,7 @@
         import com.sun.enterprise.admin.remote.reader.CliActionReport;
         import com.sun.enterprise.admin.remote.reader.ProprietaryReader;
         import com.sun.enterprise.admin.remote.reader.ProprietaryReaderFactory;
        +import com.sun.enterprise.admin.remote.reader.StringProprietaryReader;
         import com.sun.enterprise.admin.remote.sse.GfSseEventReceiver;
         import com.sun.enterprise.admin.remote.sse.GfSseEventReceiverProprietaryReader;
         import com.sun.enterprise.admin.remote.sse.GfSseInboundEvent;
        @@ -815,36 +816,42 @@
                         } else {
                             ProprietaryReader<ParamsWithPayload> reader
                                     = ProprietaryReaderFactory.getReader(ParamsWithPayload.class, resultMediaType);
        -                    final InputStream is;
                             if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) {
        -                        is = urlConnection.getErrorStream();
        +                        ActionReport report;
        +                        if (reader == null) {
        +                            report = new CliActionReport();
        +                            report.setActionExitCode(ExitCode.FAILURE);
        +                            report.setMessage(urlConnection.getResponseMessage());
        +                        } else {
        +                            report = reader.readFrom(urlConnection.getErrorStream(), resultMediaType).getActionReport();
        +                        }
        +                        setActionReport(report);
                             } else {
        -                        is = urlConnection.getInputStream();
        -                    }
        -                    ParamsWithPayload pwp = reader.readFrom(is, resultMediaType);
        -                    if (pwp.getPayloadInbound() == null) {
        -                        setActionReport(pwp.getActionReport());
        -                    } else if (resultMediaType.startsWith("multipart/")) {
        -                        RestPayloadImpl.Inbound inbound = pwp.getPayloadInbound();
        -                        setActionReport(pwp.getActionReport());
        -                        if (logger.isLoggable(Level.FINER)) {
        -                            logger.log(Level.FINER, "------ PAYLOAD ------");
        -                            Iterator<Payload.Part> parts = inbound.parts();
        -                            while (parts.hasNext()) {
        -                                Payload.Part part = parts.next();
        -                                logger.log(Level.FINER, " - {0} [{1}]", new Object[]{part.getName(), part.getContentType()});
        +                        ParamsWithPayload pwp = reader.readFrom(urlConnection.getInputStream(), resultMediaType);
        +                        if (pwp.getPayloadInbound() == null) {
        +                            setActionReport(pwp.getActionReport());
        +                        } else if (resultMediaType.startsWith("multipart/")) {
        +                            RestPayloadImpl.Inbound inbound = pwp.getPayloadInbound();
        +                            setActionReport(pwp.getActionReport());
        +                            if (logger.isLoggable(Level.FINER)) {
        +                                logger.log(Level.FINER, "------ PAYLOAD ------");
        +                                Iterator<Payload.Part> parts = inbound.parts();
        +                                while (parts.hasNext()) {
        +                                    Payload.Part part = parts.next();
        +                                    logger.log(Level.FINER, " - {0} [{1}]", new Object[]{part.getName(), part.getContentType()});
        +                                }
        +                                logger.log(Level.FINER, "---- END PAYLOAD ----");
                                     }
        -                            logger.log(Level.FINER, "---- END PAYLOAD ----");
        +                            PayloadFilesManager downloadedFilesMgr =
        +                                    new PayloadFilesManager.Perm(fileOutputDir, null, logger, null);
        +                            try {
        +                                downloadedFilesMgr.processParts(inbound);
        +                            } catch (CommandException cex) {
        +                                throw cex;
        +                            } catch (Exception ex) {
        +                                throw new CommandException(ex.getMessage(), ex);
        +                            }
                                 }
        -                        PayloadFilesManager downloadedFilesMgr =
        -                                new PayloadFilesManager.Perm(fileOutputDir, null, logger, null);
        -                        try {
        -                            downloadedFilesMgr.processParts(inbound);
        -                        } catch (CommandException cex) {
        -                            throw cex;
        -                        } catch (Exception ex) {
        -                            throw new CommandException(ex.getMessage(), ex);
        -                        }
                             }
                         }
                     }
        
        Show
        martin.mares added a comment - Index: nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java =================================================================== --- nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java (revision 61586) +++ nucleus/admin/util/src/main/java/com/sun/enterprise/admin/remote/RemoteRestAdminCommand.java (working copy) @@ -44,6 +44,7 @@ import com.sun.enterprise.admin.remote.reader.CliActionReport; import com.sun.enterprise.admin.remote.reader.ProprietaryReader; import com.sun.enterprise.admin.remote.reader.ProprietaryReaderFactory; + import com.sun.enterprise.admin.remote.reader.StringProprietaryReader; import com.sun.enterprise.admin.remote.sse.GfSseEventReceiver; import com.sun.enterprise.admin.remote.sse.GfSseEventReceiverProprietaryReader; import com.sun.enterprise.admin.remote.sse.GfSseInboundEvent; @@ -815,36 +816,42 @@ } else { ProprietaryReader<ParamsWithPayload> reader = ProprietaryReaderFactory.getReader(ParamsWithPayload.class, resultMediaType); - final InputStream is; if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_INTERNAL_ERROR) { - is = urlConnection.getErrorStream(); + ActionReport report; + if (reader == null ) { + report = new CliActionReport(); + report.setActionExitCode(ExitCode.FAILURE); + report.setMessage(urlConnection.getResponseMessage()); + } else { + report = reader.readFrom(urlConnection.getErrorStream(), resultMediaType).getActionReport(); + } + setActionReport(report); } else { - is = urlConnection.getInputStream(); - } - ParamsWithPayload pwp = reader.readFrom(is, resultMediaType); - if (pwp.getPayloadInbound() == null ) { - setActionReport(pwp.getActionReport()); - } else if (resultMediaType.startsWith( "multipart/" )) { - RestPayloadImpl.Inbound inbound = pwp.getPayloadInbound(); - setActionReport(pwp.getActionReport()); - if (logger.isLoggable(Level.FINER)) { - logger.log(Level.FINER, "------ PAYLOAD ------" ); - Iterator<Payload.Part> parts = inbound.parts(); - while (parts.hasNext()) { - Payload.Part part = parts.next(); - logger.log(Level.FINER, " - {0} [{1}]" , new Object []{part.getName(), part.getContentType()}); + ParamsWithPayload pwp = reader.readFrom(urlConnection.getInputStream(), resultMediaType); + if (pwp.getPayloadInbound() == null ) { + setActionReport(pwp.getActionReport()); + } else if (resultMediaType.startsWith( "multipart/" )) { + RestPayloadImpl.Inbound inbound = pwp.getPayloadInbound(); + setActionReport(pwp.getActionReport()); + if (logger.isLoggable(Level.FINER)) { + logger.log(Level.FINER, "------ PAYLOAD ------" ); + Iterator<Payload.Part> parts = inbound.parts(); + while (parts.hasNext()) { + Payload.Part part = parts.next(); + logger.log(Level.FINER, " - {0} [{1}]" , new Object []{part.getName(), part.getContentType()}); + } + logger.log(Level.FINER, "---- END PAYLOAD ----" ); } - logger.log(Level.FINER, "---- END PAYLOAD ----" ); + PayloadFilesManager downloadedFilesMgr = + new PayloadFilesManager.Perm(fileOutputDir, null , logger, null ); + try { + downloadedFilesMgr.processParts(inbound); + } catch (CommandException cex) { + throw cex; + } catch (Exception ex) { + throw new CommandException(ex.getMessage(), ex); + } } - PayloadFilesManager downloadedFilesMgr = - new PayloadFilesManager.Perm(fileOutputDir, null , logger, null ); - try { - downloadedFilesMgr.processParts(inbound); - } catch (CommandException cex) { - throw cex; - } catch (Exception ex) { - throw new CommandException(ex.getMessage(), ex); - } } } }
        Hide
        martin.mares added a comment -

        Please, where to add this fix? Add it tu current trunk (Release candidate) or wait for branch? Thanks

        Show
        martin.mares added a comment - Please, where to add this fix? Add it tu current trunk (Release candidate) or wait for branch? Thanks
        Hide
        martin.mares added a comment -
        • What is the impact on the customer of the bug?

        CLI can print inappropriate message containing "NullPointerException" in very special situation.
        It is regression.

        • What is the cost/risk of fixing the bug?

        Very small fix. Low risk.

        • Is there an impact on documentation or message strings?

        No

        • Which tests should QA (re)run to verify the fix did not destabilize GlassFish?

        Any CLI tests are good.

        • Which is the targeted build of 4.0 for this fix?

        Nearest

        • If this an integration of a new version of a component from another project,
          what are the changes that are being brought in? This might be list of
          Jira issues from that project or a list of revision messages.

        N/A

        Show
        martin.mares added a comment - What is the impact on the customer of the bug? CLI can print inappropriate message containing "NullPointerException" in very special situation. It is regression. What is the cost/risk of fixing the bug? Very small fix. Low risk. Is there an impact on documentation or message strings? No Which tests should QA (re)run to verify the fix did not destabilize GlassFish? Any CLI tests are good. Which is the targeted build of 4.0 for this fix? Nearest If this an integration of a new version of a component from another project, what are the changes that are being brought in? This might be list of Jira issues from that project or a list of revision messages. N/A
        Hide
        Tom Mueller added a comment -

        Approved for 4.0.

        Show
        Tom Mueller added a comment - Approved for 4.0.

          People

          • Assignee:
            martin.mares
            Reporter:
            martin.mares
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: