Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      there is no way how I could create CloseCode from code (integer).

      Please add CloseCodes.fromCode(int code).

        Activity

        Hide
        dannycoward added a comment -

        Hey Pavel:

        CloseReason cr = new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "bye bye");

        All the integers you should be using should be already in CloseReason.CloseCodes

        • does that cover it - d ?
        Show
        dannycoward added a comment - Hey Pavel: CloseReason cr = new CloseReason(CloseReason.CloseCodes.NORMAL_CLOSURE, "bye bye"); All the integers you should be using should be already in CloseReason.CloseCodes does that cover it - d ?
        Hide
        Pavel Bucek added a comment -

        I need to create it from incoming integer value, to create close reason which will be put as a parameter to onClose() method.

        I would expect something like what we have in TyrusEndpoint

            /**
             * Creates {@link javax.websocket.CloseReason.CloseCode} from given integer value.
             * <p/>
             * Present only for our convenience, should be removed once http://java.net/jira/browse/WEBSOCKET_SPEC-102 is
             * resolved.
             *
             * @param code close code.
             * @return {@link javax.websocket.CloseReason.CloseCode} instance corresponding to given value or newly created
             *         anonymous class if code is not present in {@link javax.websocket.CloseReason.CloseCodes} enumeration.
             * @throws IllegalArgumentException when code is smaller than 1000 (not used) or bigger than 4999. See RFC-6455,
             *                                  section 7.4 for more details.
             */
            public static CloseReason.CloseCode getCloseCode(final int code) {
                if (code < 1000 || code > 4999) {
                    throw new IllegalArgumentException();
                }
        
                switch (code) {
                    case 1000:
                        return CloseReason.CloseCodes.NORMAL_CLOSURE;
                    case 1001:
                        return CloseReason.CloseCodes.GOING_AWAY;
                    case 1002:
                        return CloseReason.CloseCodes.PROTOCOL_ERROR;
                    case 1003:
                        return CloseReason.CloseCodes.CANNOT_ACCEPT;
                    case 1004:
                        return CloseReason.CloseCodes.RESERVED;
                    case 1005:
                        return CloseReason.CloseCodes.NO_STATUS_CODE;
                    case 1006:
                        return CloseReason.CloseCodes.CLOSED_ABNORMALLY;
                    case 1007:
                        return CloseReason.CloseCodes.NOT_CONSISTENT;
                    case 1008:
                        return CloseReason.CloseCodes.VIOLATED_POLICY;
                    case 1009:
                        return CloseReason.CloseCodes.TOO_BIG;
                    case 1010:
                        return CloseReason.CloseCodes.NO_EXTENSION;
                    case 1011:
                        return CloseReason.CloseCodes.UNEXPECTED_CONDITION;
                    case 1012:
                        return CloseReason.CloseCodes.SERVICE_RESTART;
                    case 1013:
                        return CloseReason.CloseCodes.TRY_AGAIN_LATER;
                    case 1015:
                        return CloseReason.CloseCodes.TLS_HANDSHAKE_FAILURE;
                }
        
                return new CloseReason.CloseCode() {
                    @Override
                    public int getCode() {
                        return code;
                    }
                };
            }
        Show
        Pavel Bucek added a comment - I need to create it from incoming integer value, to create close reason which will be put as a parameter to onClose() method. I would expect something like what we have in TyrusEndpoint /** * Creates {@link javax.websocket.CloseReason.CloseCode} from given integer value. * <p/> * Present only for our convenience, should be removed once http: //java.net/jira/browse/WEBSOCKET_SPEC-102 is * resolved. * * @param code close code. * @ return {@link javax.websocket.CloseReason.CloseCode} instance corresponding to given value or newly created * anonymous class if code is not present in {@link javax.websocket.CloseReason.CloseCodes} enumeration. * @ throws IllegalArgumentException when code is smaller than 1000 (not used) or bigger than 4999. See RFC-6455, * section 7.4 for more details. */ public static CloseReason.CloseCode getCloseCode( final int code) { if (code < 1000 || code > 4999) { throw new IllegalArgumentException(); } switch (code) { case 1000: return CloseReason.CloseCodes.NORMAL_CLOSURE; case 1001: return CloseReason.CloseCodes.GOING_AWAY; case 1002: return CloseReason.CloseCodes.PROTOCOL_ERROR; case 1003: return CloseReason.CloseCodes.CANNOT_ACCEPT; case 1004: return CloseReason.CloseCodes.RESERVED; case 1005: return CloseReason.CloseCodes.NO_STATUS_CODE; case 1006: return CloseReason.CloseCodes.CLOSED_ABNORMALLY; case 1007: return CloseReason.CloseCodes.NOT_CONSISTENT; case 1008: return CloseReason.CloseCodes.VIOLATED_POLICY; case 1009: return CloseReason.CloseCodes.TOO_BIG; case 1010: return CloseReason.CloseCodes.NO_EXTENSION; case 1011: return CloseReason.CloseCodes.UNEXPECTED_CONDITION; case 1012: return CloseReason.CloseCodes.SERVICE_RESTART; case 1013: return CloseReason.CloseCodes.TRY_AGAIN_LATER; case 1015: return CloseReason.CloseCodes.TLS_HANDSHAKE_FAILURE; } return new CloseReason.CloseCode() { @Override public int getCode() { return code; } }; }
        Hide
        dannycoward added a comment -

        ok, got it. will add - d

        Show
        dannycoward added a comment - ok, got it. will add - d
        Hide
        dannycoward added a comment -

        fixed as suggested.

        Show
        dannycoward added a comment - fixed as suggested.

          People

          • Assignee:
            dannycoward
            Reporter:
            Pavel Bucek
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: