[
  {
    "path": ".gitignore",
    "content": "target/\n*.log.gz\n*.iml\n.idea/\n*.log\n*.db\n/target\ntarget\n\n*.class\n\n# Mobile Tools for Java (J2ME)\n.mtj.tmp/\n\n# Package Files #\n*.jar\n*.war\n*.ear\n\n# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml\nhs_err_pid*"
  },
  {
    "path": "LICENSE",
    "content": "                                 Apache License\n                           Version 2.0, January 2004\n                        http://www.apache.org/licenses/\n\n   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION\n\n   1. Definitions.\n\n      \"License\" shall mean the terms and conditions for use, reproduction,\n      and distribution as defined by Sections 1 through 9 of this document.\n\n      \"Licensor\" shall mean the copyright owner or entity authorized by\n      the copyright owner that is granting the License.\n\n      \"Legal Entity\" shall mean the union of the acting entity and all\n      other entities that control, are controlled by, or are under common\n      control with that entity. For the purposes of this definition,\n      \"control\" means (i) the power, direct or indirect, to cause the\n      direction or management of such entity, whether by contract or\n      otherwise, or (ii) ownership of fifty percent (50%) or more of the\n      outstanding shares, or (iii) beneficial ownership of such entity.\n\n      \"You\" (or \"Your\") shall mean an individual or Legal Entity\n      exercising permissions granted by this License.\n\n      \"Source\" form shall mean the preferred form for making modifications,\n      including but not limited to software source code, documentation\n      source, and configuration files.\n\n      \"Object\" form shall mean any form resulting from mechanical\n      transformation or translation of a Source form, including but\n      not limited to compiled object code, generated documentation,\n      and conversions to other media types.\n\n      \"Work\" shall mean the work of authorship, whether in Source or\n      Object form, made available under the License, as indicated by a\n      copyright notice that is included in or attached to the work\n      (an example is provided in the Appendix below).\n\n      \"Derivative Works\" shall mean any work, whether in Source or Object\n      form, that is based on (or derived from) the Work and for which the\n      editorial revisions, annotations, elaborations, or other modifications\n      represent, as a whole, an original work of authorship. For the purposes\n      of this License, Derivative Works shall not include works that remain\n      separable from, or merely link (or bind by name) to the interfaces of,\n      the Work and Derivative Works thereof.\n\n      \"Contribution\" shall mean any work of authorship, including\n      the original version of the Work and any modifications or additions\n      to that Work or Derivative Works thereof, that is intentionally\n      submitted to Licensor for inclusion in the Work by the copyright owner\n      or by an individual or Legal Entity authorized to submit on behalf of\n      the copyright owner. For the purposes of this definition, \"submitted\"\n      means any form of electronic, verbal, or written communication sent\n      to the Licensor or its representatives, including but not limited to\n      communication on electronic mailing lists, source code control systems,\n      and issue tracking systems that are managed by, or on behalf of, the\n      Licensor for the purpose of discussing and improving the Work, but\n      excluding communication that is conspicuously marked or otherwise\n      designated in writing by the copyright owner as \"Not a Contribution.\"\n\n      \"Contributor\" shall mean Licensor and any individual or Legal Entity\n      on behalf of whom a Contribution has been received by Licensor and\n      subsequently incorporated within the Work.\n\n   2. Grant of Copyright License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      copyright license to reproduce, prepare Derivative Works of,\n      publicly display, publicly perform, sublicense, and distribute the\n      Work and such Derivative Works in Source or Object form.\n\n   3. Grant of Patent License. Subject to the terms and conditions of\n      this License, each Contributor hereby grants to You a perpetual,\n      worldwide, non-exclusive, no-charge, royalty-free, irrevocable\n      (except as stated in this section) patent license to make, have made,\n      use, offer to sell, sell, import, and otherwise transfer the Work,\n      where such license applies only to those patent claims licensable\n      by such Contributor that are necessarily infringed by their\n      Contribution(s) alone or by combination of their Contribution(s)\n      with the Work to which such Contribution(s) was submitted. If You\n      institute patent litigation against any entity (including a\n      cross-claim or counterclaim in a lawsuit) alleging that the Work\n      or a Contribution incorporated within the Work constitutes direct\n      or contributory patent infringement, then any patent licenses\n      granted to You under this License for that Work shall terminate\n      as of the date such litigation is filed.\n\n   4. Redistribution. You may reproduce and distribute copies of the\n      Work or Derivative Works thereof in any medium, with or without\n      modifications, and in Source or Object form, provided that You\n      meet the following conditions:\n\n      (a) You must give any other recipients of the Work or\n          Derivative Works a copy of this License; and\n\n      (b) You must cause any modified files to carry prominent notices\n          stating that You changed the files; and\n\n      (c) You must retain, in the Source form of any Derivative Works\n          that You distribute, all copyright, patent, trademark, and\n          attribution notices from the Source form of the Work,\n          excluding those notices that do not pertain to any part of\n          the Derivative Works; and\n\n      (d) If the Work includes a \"NOTICE\" text file as part of its\n          distribution, then any Derivative Works that You distribute must\n          include a readable copy of the attribution notices contained\n          within such NOTICE file, excluding those notices that do not\n          pertain to any part of the Derivative Works, in at least one\n          of the following places: within a NOTICE text file distributed\n          as part of the Derivative Works; within the Source form or\n          documentation, if provided along with the Derivative Works; or,\n          within a display generated by the Derivative Works, if and\n          wherever such third-party notices normally appear. The contents\n          of the NOTICE file are for informational purposes only and\n          do not modify the License. You may add Your own attribution\n          notices within Derivative Works that You distribute, alongside\n          or as an addendum to the NOTICE text from the Work, provided\n          that such additional attribution notices cannot be construed\n          as modifying the License.\n\n      You may add Your own copyright statement to Your modifications and\n      may provide additional or different license terms and conditions\n      for use, reproduction, or distribution of Your modifications, or\n      for any such Derivative Works as a whole, provided Your use,\n      reproduction, and distribution of the Work otherwise complies with\n      the conditions stated in this License.\n\n   5. Submission of Contributions. Unless You explicitly state otherwise,\n      any Contribution intentionally submitted for inclusion in the Work\n      by You to the Licensor shall be under the terms and conditions of\n      this License, without any additional terms or conditions.\n      Notwithstanding the above, nothing herein shall supersede or modify\n      the terms of any separate license agreement you may have executed\n      with Licensor regarding such Contributions.\n\n   6. Trademarks. This License does not grant permission to use the trade\n      names, trademarks, service marks, or product names of the Licensor,\n      except as required for reasonable and customary use in describing the\n      origin of the Work and reproducing the content of the NOTICE file.\n\n   7. Disclaimer of Warranty. Unless required by applicable law or\n      agreed to in writing, Licensor provides the Work (and each\n      Contributor provides its Contributions) on an \"AS IS\" BASIS,\n      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or\n      implied, including, without limitation, any warranties or conditions\n      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A\n      PARTICULAR PURPOSE. You are solely responsible for determining the\n      appropriateness of using or redistributing the Work and assume any\n      risks associated with Your exercise of permissions under this License.\n\n   8. Limitation of Liability. In no event and under no legal theory,\n      whether in tort (including negligence), contract, or otherwise,\n      unless required by applicable law (such as deliberate and grossly\n      negligent acts) or agreed to in writing, shall any Contributor be\n      liable to You for damages, including any direct, indirect, special,\n      incidental, or consequential damages of any character arising as a\n      result of this License or out of the use or inability to use the\n      Work (including but not limited to damages for loss of goodwill,\n      work stoppage, computer failure or malfunction, or any and all\n      other commercial damages or losses), even if such Contributor\n      has been advised of the possibility of such damages.\n\n   9. Accepting Warranty or Additional Liability. While redistributing\n      the Work or Derivative Works thereof, You may choose to offer,\n      and charge a fee for, acceptance of support, warranty, indemnity,\n      or other liability obligations and/or rights consistent with this\n      License. However, in accepting such obligations, You may act only\n      on Your own behalf and on Your sole responsibility, not on behalf\n      of any other Contributor, and only if You agree to indemnify,\n      defend, and hold each Contributor harmless for any liability\n      incurred by, or claims asserted against, such Contributor by reason\n      of your accepting any such warranty or additional liability.\n\n   END OF TERMS AND CONDITIONS\n\n   APPENDIX: How to apply the Apache License to your work.\n\n      To apply the Apache License to your work, attach the following\n      boilerplate notice, with the fields enclosed by brackets \"{}\"\n      replaced with your own identifying information. (Don't include\n      the brackets!)  The text should be enclosed in the appropriate\n      comment syntax for the file format. We also recommend that a\n      file or class name and description of purpose be included on the\n      same \"printed page\" as the copyright notice for easier\n      identification within third-party archives.\n\n   Copyright {yyyy} {name of copyright owner}\n\n   Licensed under the Apache License, Version 2.0 (the \"License\");\n   you may not use this file except in compliance with the License.\n   You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n   Unless required by applicable law or agreed to in writing, software\n   distributed under the License is distributed on an \"AS IS\" BASIS,\n   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n   See the License for the specific language governing permissions and\n   limitations under the License.\n"
  },
  {
    "path": "README.md",
    "content": "# spring-cloud-netflix-zuul-websocket\nA simple library to enable Zuul reverse proxy web socket support in spring applications.\n\n## USAGE\n\nspring-cloud-netflix-zuul-websocket is available from **Maven Central**\n\n```xml\n<dependency>\n  <groupId>com.github.mthizo247</groupId>\n  <artifactId>spring-cloud-netflix-zuul-websocket</artifactId>\n  <version>1.0.0-RELEASE</version>\n</dependency>\n```\n\n### Who is this for?\n\nThis is for anyone using **Spring Netflix Zuul** to proxy requests to back-ends which supports web sockets but the proxy layer does not.\n**Netflix Zuul** does not natively support web sockets.\n\n### How do I use this?\n\nEnable it like so:\n\n```java\n@SpringBootApplication\n@EnableZuulWebSocket\n@EnableWebSocketMessageBroker\npublic class ProxyApplication {\n\tpublic static void main(String[] args) {\n\t\tSpringApplication.run(ProxyApplication.class, args);\n\t}\n}\n```\n\nThen in your spring application properties(e.g application.yml)\n\n```\nserver:\n  port: 7078\n\nzuul:\n   routes:\n    hello:\n      path: /**\n      url: http://localhost:7079\n      customSensitiveHeaders: true\n   ws:\n      brokerages:\n        hello:\n          end-points: /ws\n          brokers:  /topic\n          destination-prefixes: /app\n```\n\nWith this you should have web sockets to your back-end service working correctly.\n\n**Checkout** this [demo](https://github.com/mthizo247/zuul-websocket-support-demo)\n"
  },
  {
    "path": "eclipse-code-formatter.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n<profiles version=\"12\">\n<profile kind=\"CodeFormatterProfile\" name=\"Spring Boot Java Conventions\" version=\"12\">\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_ellipsis\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_after_imports\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.format_javadoc_comments\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indentation.size\" value=\"8\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.disabling_tag\" value=\"@formatter:off\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.continuation_indentation\" value=\"2\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_enum_constants\" value=\"0\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_before_imports\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_after_package\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_binary_operator\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.indent_root_tags\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.enabling_tag\" value=\"@formatter:on\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.compiler.problem.enumIdentifier\" value=\"error\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_statements_compare_to_block\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.line_length\" value=\"90\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.use_on_off_tags\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_method_declaration\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body\" value=\"0\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_binary_expression\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_block\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_lambda_body\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.compact_else_if\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.compiler.problem.assertIdentifier\" value=\"error\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_binary_operator\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_unary_operator\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_ellipsis\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.format_line_comments\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.align_type_members_on_columns\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_assignment\" value=\"0\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration\" value=\"0\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_conditional_expression\" value=\"80\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_block_in_case\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.format_header\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode\" value=\"enabled\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_method_declaration\" value=\"0\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.join_wrapped_lines\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_resources_in_try\" value=\"80\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.compiler.source\" value=\"1.8\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.tabulation.size\" value=\"4\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.format_source_code\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_before_field\" value=\"0\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer\" value=\"2\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_before_method\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.compiler.codegen.targetPlatform\" value=\"1.8\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_switch\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_type_annotation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.format_html\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_compact_if\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_empty_lines\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_unary_operator\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation\" value=\"0\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_label\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_before_member_type\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_semicolon\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.format_block_comments\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_lambda_arrow\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line\" value=\"false\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_statements_compare_to_body\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.alignment_for_multiple_fields\" value=\"16\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_array_initializer\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.wrap_before_binary_operator\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.compiler.compliance\" value=\"1.8\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_enum_constant\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.brace_position_for_type_declaration\" value=\"end_of_line\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_before_package\" value=\"0\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_lambda_arrow\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.join_lines_in_comments\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.comment.indent_parameter_description\" value=\"true\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement\" value=\"insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.tabulation.char\" value=\"tab\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.blank_lines_between_import_groups\" value=\"1\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.lineSplit\" value=\"90\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation\" value=\"do not insert\"/>\n<setting id=\"org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch\" value=\"insert\"/>\n</profile>\n</profiles>\n"
  },
  {
    "path": "pom.xml",
    "content": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<project xmlns=\"http://maven.apache.org/POM/4.0.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\">\n    <modelVersion>4.0.0</modelVersion>\n\n    <groupId>com.github.mthizo247</groupId>\n    <artifactId>spring-cloud-netflix-zuul-websocket</artifactId>\n    <packaging>jar</packaging>\n    <version>1.0.7.RELEASE</version>\n    <name>Spring Cloud Netflix Zuul Websocket</name>\n    <description>Spring Cloud Netflix Zuul Websocket</description>\n    <url>https://www.discovery.co.za</url>\n    <inceptionYear>2017</inceptionYear>\n\n    <licenses>\n        <license>\n            <name>The Apache Software License, Version 2.0</name>\n            <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>\n            <distribution>repo</distribution>\n        </license>\n    </licenses>\n\n    <developers>\n        <developer>\n            <id>mthizo247@gmail.com</id>\n            <name>Ronald Mthombeni</name>\n            <email>mthizo247@gmail.com</email>\n            <organization>Discovery inc.</organization>\n            <organizationUrl>http://www.discovery.co.za</organizationUrl>\n        </developer>\n        <developer>\n            <id>salmannoor74415</id>\n            <name>Salman Noor</name>\n            <email>salmannoor74415@gmail.com</email>\n            <organization>Discovery inc.</organization>\n            <organizationUrl>http://www.discovery.co.za</organizationUrl>\n        </developer>\n    </developers>\n\n    <scm>\n        <connection>scm:git:git://github.com/mthizo247/spring-cloud-netflix-zuul-websocket</connection>\n        <developerConnection>scm:git:git://github.com/mthizo247/spring-cloud-netflix-zuul-websocket\n        </developerConnection>\n        <url>https://github.com/mthizo247/spring-cloud-netflix-zuul-websocket.git</url>\n    </scm>\n\n    <issueManagement>\n        <url>https://github.com/mthizo247/spring-cloud-netflix-zuul-websocket/issues</url>\n        <system>GitHub Issues</system>\n    </issueManagement>\n\n    <parent>\n        <groupId>org.springframework.boot</groupId>\n        <artifactId>spring-boot-starter-parent</artifactId>\n        <version>1.5.10.RELEASE</version>\n        <relativePath/>\n    </parent>\n\n    <properties>\n        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>\n        <java.version>1.7</java.version>\n    </properties>\n\n    <distributionManagement>\n        <repository>\n            <id>ossrh</id>\n            <url>https://oss.sonatype.org/service/local/staging/deploy/maven2</url>\n        </repository>\n        <snapshotRepository>\n            <id>ossrh</id>\n            <url>https://oss.sonatype.org/content/repositories/snapshots</url>\n        </snapshotRepository>\n    </distributionManagement>\n\n    <dependencies>\n        <dependency>\n            <groupId>org.springframework.boot</groupId>\n            <artifactId>spring-boot-starter-websocket</artifactId>\n            <scope>provided</scope>\n        </dependency>\n        <dependency>\n            <groupId>org.springframework.cloud</groupId>\n            <artifactId>spring-cloud-starter-zuul</artifactId>\n            <version>1.1.5.RELEASE</version>\n            <scope>provided</scope>\n        </dependency>\n        <dependency>\n            <groupId>org.springframework.boot</groupId>\n            <artifactId>spring-boot-starter-security</artifactId>\n            <scope>provided</scope>\n        </dependency>\n        <dependency>\n            <groupId>org.springframework.security.oauth</groupId>\n            <artifactId>spring-security-oauth2</artifactId>\n            <scope>provided</scope>\n        </dependency>\n        <dependency>\n            <groupId>org.springframework.boot</groupId>\n            <artifactId>spring-boot-starter-test</artifactId>\n            <scope>test</scope>\n        </dependency>\n    </dependencies>\n\n    <build>\n        <pluginManagement>\n            <plugins>\n                <plugin>\n                    <groupId>org.apache.maven.plugins</groupId>\n                    <artifactId>maven-release-plugin</artifactId>\n                    <version>2.5.3</version>\n                    <configuration>\n                        <useReleaseProfile>false</useReleaseProfile>\n                        <releaseProfiles>release</releaseProfiles>\n                        <goals>deploy</goals>\n                    </configuration>\n                </plugin>\n            </plugins>\n        </pluginManagement>\n        <plugins>\n            <plugin>\n                <groupId>org.sonatype.plugins</groupId>\n                <artifactId>nexus-staging-maven-plugin</artifactId>\n                <version>1.6.3</version>\n                <extensions>true</extensions>\n                <configuration>\n                    <serverId>ossrh</serverId>\n                    <nexusUrl>https://oss.sonatype.org/</nexusUrl>\n                    <autoReleaseAfterClose>true</autoReleaseAfterClose>\n                    <stagingProfileId>5820c8da7e998d</stagingProfileId>\n                </configuration>\n            </plugin>\n        </plugins>\n    </build>\n\n    <profiles>\n        <profile>\n            <id>release</id>\n            <build>\n                <plugins>\n                    <plugin>\n                        <groupId>org.apache.maven.plugins</groupId>\n                        <artifactId>maven-release-plugin</artifactId>\n                        <version>2.5.3</version>\n                        <configuration>\n                            <skip>true</skip>\n                        </configuration>\n                    </plugin>\n                    <plugin>\n                        <groupId>org.apache.maven.plugins</groupId>\n                        <artifactId>maven-source-plugin</artifactId>\n                        <version>3.0.1</version>\n                        <executions>\n                            <execution>\n                                <id>attach-sources</id>\n                                <goals>\n                                    <goal>jar</goal>\n                                </goals>\n                            </execution>\n                        </executions>\n                    </plugin>\n                    <plugin>\n                        <groupId>org.apache.maven.plugins</groupId>\n                        <artifactId>maven-javadoc-plugin</artifactId>\n                        <version>2.10.3</version>\n                        <executions>\n                            <execution>\n                                <id>attach-javadocs</id>\n                                <goals>\n                                    <goal>jar</goal>\n                                </goals>\n                            </execution>\n                        </executions>\n                    </plugin>\n                    <plugin>\n                        <groupId>org.apache.maven.plugins</groupId>\n                        <artifactId>maven-gpg-plugin</artifactId>\n                        <version>1.5</version>\n                        <executions>\n                            <execution>\n                                <id>sign-artifacts</id>\n                                <phase>verify</phase>\n                                <goals>\n                                    <goal>sign</goal>\n                                </goals>\n                            </execution>\n                        </executions>\n                    </plugin>\n                </plugins>\n            </build>\n        </profile>\n    </profiles>\n</project>\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/authentication/AbstractHeadersCallback.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.authentication;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.socket.WebSocketHttpHeadersCallback;\nimport org.apache.commons.logging.Log;\nimport org.apache.commons.logging.LogFactory;\nimport org.springframework.web.socket.WebSocketHttpHeaders;\nimport org.springframework.web.socket.WebSocketSession;\n\n/**\n * @author Ronald Mthombeni\n */\npublic abstract class AbstractHeadersCallback implements WebSocketHttpHeadersCallback {\n    protected final Log logger = LogFactory.getLog(getClass());\n\n    @Override\n    public void applyHeaders(\n            WebSocketSession userAgentSession, WebSocketHttpHeaders headers) {\n        if (shouldApplyHeaders(userAgentSession, headers)) {\n            applyHeadersInternal(userAgentSession, headers);\n        }\n    }\n\n    protected abstract void applyHeadersInternal(WebSocketSession userAgentSession, WebSocketHttpHeaders headers);\n\n    protected abstract boolean shouldApplyHeaders(WebSocketSession userAgentSession, WebSocketHttpHeaders headers);\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/authentication/BasicAuthPrincipalHeadersCallback.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.authentication;\n\nimport org.springframework.http.HttpHeaders;\nimport org.springframework.security.core.Authentication;\nimport org.springframework.security.crypto.codec.Base64;\nimport org.springframework.web.socket.WebSocketHttpHeaders;\nimport org.springframework.web.socket.WebSocketSession;\n\nimport java.util.Collections;\n\n/**\n * @author Ronald Mthombeni\n */\npublic class BasicAuthPrincipalHeadersCallback extends AbstractHeadersCallback {\n    @Override\n    protected void applyHeadersInternal(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) {\n        Authentication authentication = (Authentication) userAgentSession.getPrincipal();\n        String usernameColonPwd = authentication.getName() + \":\"\n                + authentication.getCredentials().toString();\n        String encodedCredentials = new String(\n                Base64.encode(usernameColonPwd.getBytes()));\n        headers.put(HttpHeaders.AUTHORIZATION,\n                Collections.singletonList(\"Basic \" + encodedCredentials));\n        if (logger.isDebugEnabled()) {\n            logger.debug(\"Added basic authentication header for user \" + authentication.getName() + \" to web sockets http headers\");\n        }\n    }\n\n    @Override\n    protected boolean shouldApplyHeaders(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) {\n        return !headers.containsKey(HttpHeaders.AUTHORIZATION) && userAgentSession.getPrincipal() instanceof Authentication;\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/authentication/CompositeHeadersCallback.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.authentication;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.socket.WebSocketHttpHeadersCallback;\nimport org.springframework.web.socket.WebSocketHttpHeaders;\nimport org.springframework.web.socket.WebSocketSession;\n\nimport java.util.List;\n\n/**\n * Strategy to add different types of headers to web socket connections\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class CompositeHeadersCallback implements WebSocketHttpHeadersCallback {\n    private List<WebSocketHttpHeadersCallback> headersCallbacks;\n\n    public CompositeHeadersCallback(final List<WebSocketHttpHeadersCallback> headersCallbacks) {\n        this.headersCallbacks = headersCallbacks;\n    }\n\n\n    @Override\n    public void applyHeaders(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) {\n        for (WebSocketHttpHeadersCallback callback : headersCallbacks) {\n            callback.applyHeaders(userAgentSession, headers);\n        }\n    }\n\n    public List<WebSocketHttpHeadersCallback> getHeadersCallbacks() {\n        return headersCallbacks;\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/authentication/LoginCookieHeadersCallback.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.authentication;\n\nimport org.apache.commons.logging.Log;\nimport org.apache.commons.logging.LogFactory;\nimport org.springframework.http.HttpHeaders;\nimport org.springframework.web.socket.WebSocketHttpHeaders;\nimport org.springframework.web.socket.WebSocketSession;\n\nimport java.util.List;\n\n/**\n * @author Ronald Mthombeni\n */\npublic class LoginCookieHeadersCallback extends AbstractHeadersCallback {\n    protected final Log logger = LogFactory.getLog(getClass());\n\n    @Override\n    protected void applyHeadersInternal(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) {\n        List<String> sessionCookies = userAgentSession.getHandshakeHeaders().get(HttpHeaders.COOKIE);\n        headers.put(HttpHeaders.COOKIE, sessionCookies);\n        if (logger.isDebugEnabled()) {\n            logger.debug(\"Added cookie authentication header to web sockets http headers\");\n        }\n    }\n\n    @Override\n    protected boolean shouldApplyHeaders(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) {\n        return !headers.containsKey(HttpHeaders.COOKIE) && userAgentSession.getHandshakeHeaders().containsKey(HttpHeaders.COOKIE);\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/authentication/OAuth2BearerPrincipalHeadersCallback.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.authentication;\n\nimport org.springframework.http.HttpHeaders;\nimport org.springframework.security.oauth2.provider.OAuth2Authentication;\nimport org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationDetails;\nimport org.springframework.web.socket.WebSocketHttpHeaders;\nimport org.springframework.web.socket.WebSocketSession;\n\nimport java.util.Collections;\n\n/**\n * @author Marcin Podlodowski\n */\npublic class OAuth2BearerPrincipalHeadersCallback extends AbstractHeadersCallback {\n\n    @Override\n    protected void applyHeadersInternal(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) {\n        OAuth2Authentication oAuth2Authentication = (OAuth2Authentication) userAgentSession.getPrincipal();\n        OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) oAuth2Authentication.getDetails();\n        String accessToken = details.getTokenValue();\n        headers.put(HttpHeaders.AUTHORIZATION, Collections.singletonList(\"Bearer \" + accessToken));\n        if (logger.isDebugEnabled()) {\n            logger.debug(\"Added Oauth2 bearer token authentication header for user \" +\n                    oAuth2Authentication.getName() + \" to web sockets http headers\");\n        }\n    }\n\n    @Override\n    protected boolean shouldApplyHeaders(WebSocketSession userAgentSession, WebSocketHttpHeaders headers) {\n        return !headers.containsKey(HttpHeaders.AUTHORIZATION) && userAgentSession.getPrincipal() instanceof OAuth2Authentication;\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/filter/ProxyRedirectFilter.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.filter;\n\nimport java.util.List;\n\nimport javax.servlet.http.HttpServletRequest;\n\nimport org.springframework.cloud.netflix.zuul.filters.Route;\nimport org.springframework.cloud.netflix.zuul.filters.RouteLocator;\nimport org.springframework.web.servlet.support.ServletUriComponentsBuilder;\nimport org.springframework.web.util.UriComponents;\nimport org.springframework.web.util.UrlPathHelper;\n\nimport com.netflix.util.Pair;\nimport com.netflix.zuul.ZuulFilter;\nimport com.netflix.zuul.context.RequestContext;\n\n/**\n * @author Ronald Mthombeni\n */\npublic class ProxyRedirectFilter extends ZuulFilter {\n\tprivate static String REDIRECT_TO_URL = \"REDIRECT_TO_URL_\"\n\t\t\t+ ProxyRedirectFilter.class.getName();\n\n\tRouteLocator routeLocator;\n\tUrlPathHelper urlPathHelper;\n\n\tpublic ProxyRedirectFilter(RouteLocator routeLocator) {\n\t\tthis(routeLocator, new UrlPathHelper());\n\t}\n\n\tpublic ProxyRedirectFilter(RouteLocator routeLocator, UrlPathHelper urlPathHelper) {\n\t\tthis.routeLocator = routeLocator;\n\t\tthis.urlPathHelper = urlPathHelper;\n\t}\n\n\t@Override\n\tpublic String filterType() {\n\t\treturn \"post\";\n\t}\n\n\t@Override\n\tpublic int filterOrder() {\n\t\treturn 1;\n\t}\n\n\t@Override\n\tpublic boolean shouldFilter() {\n\t\tRequestContext ctx = RequestContext.getCurrentContext();\n\t\tboolean isRedirect = ctx.getResponseStatusCode() == 301 || ctx.getResponseStatusCode() == 302;\n\t\tif (!isRedirect)\n\t\t\treturn false;\n\n\t\tboolean hasCorrectLocation = false;\n\n\t\tList<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders();\n\t\tfor (Pair<String, String> zuulResponseHeader : zuulResponseHeaders) {\n\t\t\tif (\"Location\".equalsIgnoreCase(zuulResponseHeader.first())) {\n\t\t\t\tHttpServletRequest request = ctx.getRequest();\n\t\t\t\tString path = urlPathHelper.getPathWithinApplication(request);\n\t\t\t\tRoute route = routeLocator.getMatchingRoute(path);\n\t\t\t\tUriComponents redirectTo = ServletUriComponentsBuilder\n\t\t\t\t\t\t.fromHttpUrl(zuulResponseHeader.second()).build();\n\t\t\t\tUriComponents routeLocation = ServletUriComponentsBuilder\n\t\t\t\t\t\t.fromHttpUrl(route.getLocation()).build();\n\n\t\t\t\tif (redirectTo.getHost().equalsIgnoreCase(routeLocation.getHost())\n\t\t\t\t\t\t&& redirectTo.getPort() == routeLocation.getPort()) {\n\t\t\t\t\tString toLocation = ServletUriComponentsBuilder\n\t\t\t\t\t\t\t.fromHttpUrl(zuulResponseHeader.second())\n\t\t\t\t\t\t\t.host(request.getServerName())\n\t\t\t\t\t\t\t.port(request.getServerPort())\n\t\t\t\t\t\t\t.replacePath(\n\t\t\t\t\t\t\t\t\tbuildRoutePath(route, zuulResponseHeader.second()))\n\t\t\t\t\t\t\t.build().toUriString();\n\n\t\t\t\t\tctx.put(REDIRECT_TO_URL, toLocation);\n\t\t\t\t\thasCorrectLocation = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn hasCorrectLocation;\n\t}\n\n\t@Override\n\tpublic Object run() {\n\t\tRequestContext ctx = RequestContext.getCurrentContext();\n\t\tList<Pair<String, String>> zuulResponseHeaders = ctx.getZuulResponseHeaders();\n\t\tfor (Pair<String, String> zuulResponseHeader : zuulResponseHeaders) {\n\t\t\tif (\"Location\".equalsIgnoreCase(zuulResponseHeader.first())) {\n\t\t\t\tzuulResponseHeader.setSecond(ctx.get(REDIRECT_TO_URL).toString());\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn null;\n\t}\n\n\tprivate String buildRoutePath(Route route, String httpUrl) {\n\t\tString path = ServletUriComponentsBuilder.fromHttpUrl(httpUrl).build().getPath();\n\n\t\treturn route.getPrefix() == null ? path : route.getPrefix() + path;\n\t}\n\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/proxytarget/AbstractProxyTargetResolver.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.proxytarget;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.socket.ZuulWebSocketProperties;\nimport com.github.mthizo247.cloud.netflix.zuul.web.util.MapPropertyResolver;\nimport org.springframework.boot.bind.RelaxedPropertyResolver;\nimport org.springframework.cloud.client.ServiceInstance;\nimport org.springframework.cloud.netflix.zuul.filters.ZuulProperties;\nimport org.springframework.core.Ordered;\nimport org.springframework.util.Assert;\nimport org.springframework.web.util.UriComponentsBuilder;\n\nimport java.net.URI;\nimport java.util.HashMap;\nimport java.util.Map;\n\n/**\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic abstract class AbstractProxyTargetResolver implements ProxyTargetResolver, Ordered {\n    protected ZuulProperties zuulProperties;\n    protected int order = 0;\n\n    public AbstractProxyTargetResolver(ZuulProperties zuulProperties) {\n        Assert.notNull(zuulProperties, \"zuulProperties must not be null\");\n        this.zuulProperties = zuulProperties;\n    }\n\n    protected ZuulProperties.ZuulRoute resolveRoute(ZuulWebSocketProperties.WsBrokerage wsBrokerage) {\n\n        ZuulProperties.ZuulRoute zuulRoute = zuulProperties.getRoutes().get(wsBrokerage.getRouteId());\n        zuulRoute = zuulRoute == null ? zuulProperties.getRoutes().get(wsBrokerage.getId()) : zuulRoute;\n        return zuulRoute;\n    }\n\n    protected URI resolveUri(ServiceInstance serviceInstance) {\n        Map<String, Object> metadata = new HashMap<>();\n        for (Map.Entry<String, String> entry : serviceInstance.getMetadata().entrySet()) {\n            metadata.put(entry.getKey(), entry.getValue());\n        }\n\n        UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUri(serviceInstance.getUri());\n        RelaxedPropertyResolver propertyResolver = new RelaxedPropertyResolver(new MapPropertyResolver(metadata));\n        String configPath = propertyResolver.getProperty(\"configPath\");\n        if (configPath != null) {\n            uriBuilder.path(configPath);\n        }\n\n        return uriBuilder.build().toUri();\n    }\n\n    @Override\n    public int getOrder() {\n        return order;\n    }\n\n    public void setOrder(int order) {\n        this.order = order;\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/proxytarget/CompositeProxyTargetResolver.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.proxytarget;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.socket.ZuulWebSocketProperties;\n\nimport java.net.URI;\nimport java.util.List;\n\n/**\n * Strategy to resolve zuul proxy target using delegation pattern\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class CompositeProxyTargetResolver implements ProxyTargetResolver {\n    private List<ProxyTargetResolver> targetResolvers;\n\n    public CompositeProxyTargetResolver(final List<ProxyTargetResolver> targetResolvers) {\n        this.targetResolvers = targetResolvers;\n    }\n\n    @Override\n    public URI resolveTarget(ZuulWebSocketProperties.WsBrokerage wsBrokerage) {\n        URI target = null;\n        for (ProxyTargetResolver resolver : targetResolvers) {\n            target = resolver.resolveTarget(wsBrokerage);\n            if (target != null)\n                break;\n        }\n\n        return target;\n    }\n\n    public List<ProxyTargetResolver> getTargetResolvers() {\n        return targetResolvers;\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/proxytarget/EurekaProxyTargetResolver.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.proxytarget;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.socket.ZuulWebSocketProperties;\nimport org.springframework.cloud.client.ServiceInstance;\nimport org.springframework.cloud.client.discovery.DiscoveryClient;\nimport org.springframework.cloud.netflix.zuul.filters.ZuulProperties;\nimport org.springframework.util.Assert;\nimport org.springframework.util.CollectionUtils;\nimport org.springframework.util.StringUtils;\n\nimport java.net.URI;\nimport java.util.List;\n\n/**\n * Strategy to resolve zuul properties from route service is using eaureka service discovery\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class EurekaProxyTargetResolver extends AbstractProxyTargetResolver {\n    public static final int DEFAULT_ORDER = LoadBalancedProxyTargetResolver.DEFAULT_ORDER + 10;\n    private DiscoveryClient discoveryClient;\n\n    public EurekaProxyTargetResolver(DiscoveryClient discoveryClient, ZuulProperties zuulProperties) {\n        super(zuulProperties);\n        Assert.notNull(discoveryClient, \"discoveryClient can't be null\");\n        this.discoveryClient = discoveryClient;\n        this.order = DEFAULT_ORDER;\n    }\n\n\n    @Override\n    public URI resolveTarget(ZuulWebSocketProperties.WsBrokerage wsBrokerage) {\n        ZuulProperties.ZuulRoute zuulRoute = resolveRoute(wsBrokerage);\n        if (zuulRoute == null || StringUtils.isEmpty(zuulRoute.getServiceId())) return null;\n\n        List<ServiceInstance> instances = discoveryClient.getInstances(zuulRoute.getServiceId());\n        ServiceInstance serviceInstance = CollectionUtils.isEmpty(instances) ? null : instances.get(0);\n        return serviceInstance != null ? resolveUri(serviceInstance) : null;\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/proxytarget/LoadBalancedProxyTargetResolver.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.proxytarget;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.socket.ZuulWebSocketProperties;\nimport org.springframework.cloud.client.ServiceInstance;\nimport org.springframework.cloud.client.loadbalancer.LoadBalancerClient;\nimport org.springframework.cloud.netflix.zuul.filters.ZuulProperties;\nimport org.springframework.util.Assert;\nimport org.springframework.util.StringUtils;\n\nimport java.net.URI;\n\n/**\n * Strategy to resolve zuul proxy target from a load balanced client\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class LoadBalancedProxyTargetResolver extends AbstractProxyTargetResolver {\n    public static final int DEFAULT_ORDER = HIGHEST_PRECEDENCE + 10;\n\n    private LoadBalancerClient loadBalancerClient;\n\n    public LoadBalancedProxyTargetResolver(LoadBalancerClient loadBalancerClient, ZuulProperties zuulProperties) {\n        super(zuulProperties);\n        Assert.notNull(loadBalancerClient, \"loadBalancerClient can't be null\");\n        this.loadBalancerClient = loadBalancerClient;\n        this.order = DEFAULT_ORDER;\n    }\n\n    @Override\n    public URI resolveTarget(ZuulWebSocketProperties.WsBrokerage wsBrokerage) {\n        ZuulProperties.ZuulRoute zuulRoute = resolveRoute(wsBrokerage);\n        if (zuulRoute == null || StringUtils.isEmpty(zuulRoute.getServiceId())) return null;\n\n        ServiceInstance serviceInstance = loadBalancerClient.choose(zuulRoute.getServiceId());\n        return serviceInstance != null ? resolveUri(serviceInstance) : null;\n    }\n\n\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/proxytarget/ProxyTargetResolver.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.proxytarget;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.socket.ZuulWebSocketProperties;\n\nimport java.net.URI;\n\n/**\n * Strategy to resolve zuul proxy target\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic interface ProxyTargetResolver {\n    URI resolveTarget(ZuulWebSocketProperties.WsBrokerage wsBrokerage);\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/proxytarget/UrlProxyTargetResolver.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.proxytarget;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.socket.ZuulWebSocketProperties;\nimport org.springframework.cloud.netflix.zuul.filters.ZuulProperties;\nimport org.springframework.util.StringUtils;\n\nimport java.net.URI;\nimport java.net.URISyntaxException;\n\n/**\n * Strategy to resolve zuul proxy target from a load balanced client\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class UrlProxyTargetResolver extends AbstractProxyTargetResolver {\n    public static final int DEFAULT_ORDER = EurekaProxyTargetResolver.DEFAULT_ORDER + 10;\n\n    public UrlProxyTargetResolver(ZuulProperties zuulProperties) {\n        super(zuulProperties);\n        this.order = DEFAULT_ORDER;\n    }\n\n    @Override\n    public URI resolveTarget(ZuulWebSocketProperties.WsBrokerage wsBrokerage) {\n        ZuulProperties.ZuulRoute zuulRoute = resolveRoute(wsBrokerage);\n        if (zuulRoute == null || StringUtils.isEmpty(zuulRoute.getUrl())) return null;\n\n        try {\n            return new URI(zuulRoute.getUrl());\n        } catch (URISyntaxException e) {\n            throw new RuntimeException(e);\n        }\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/CompositeErrorHandler.java",
    "content": "package com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport org.apache.commons.logging.Log;\nimport org.apache.commons.logging.LogFactory;\n\nimport java.util.List;\n\n/**\n * Created by ronald22 on 06/04/2017.\n */\npublic class CompositeErrorHandler implements ProxyWebSocketErrorHandler {\n    protected final Log logger = LogFactory.getLog(getClass());\n    private final List<ProxyWebSocketErrorHandler> errorHandlers;\n\n    public CompositeErrorHandler(final List<ProxyWebSocketErrorHandler> handlers) {\n        this.errorHandlers = handlers;\n    }\n\n    @Override\n    public void handleError(Throwable t) {\n        for (ProxyWebSocketErrorHandler handler : errorHandlers) {\n            callErrorHandler(handler, t);\n        }\n\n    }\n\n    private void callErrorHandler(ProxyWebSocketErrorHandler handler, Throwable t) {\n        try {\n            handler.handleError(t);\n        } catch (Throwable e) {\n            logger.error(\"Error executing error handler \" + handler, e);\n        }\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/EnableZuulWebSocket.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport org.springframework.cloud.netflix.zuul.EnableZuulProxy;\nimport org.springframework.context.annotation.Import;\nimport org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;\n\nimport java.lang.annotation.Documented;\nimport java.lang.annotation.ElementType;\nimport java.lang.annotation.Retention;\nimport java.lang.annotation.RetentionPolicy;\nimport java.lang.annotation.Target;\n\n/**\n * Sets up a Zuul web socket configuration so that it can bridge web socket communication\n * to backend servers.\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\n@Target(ElementType.TYPE)\n@Retention(RetentionPolicy.RUNTIME)\n@Documented\n@EnableZuulProxy\n@EnableWebSocketMessageBroker\n@Import(ZuulWebSocketConfiguration.class)\npublic @interface EnableZuulWebSocket {\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ProxySessionException.java",
    "content": "package com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport org.springframework.messaging.simp.stomp.StompSession;\n\n/**\n * Created by ronald22 on 06/04/2017.\n */\npublic class ProxySessionException extends Exception {\n\tprivate final ProxyWebSocketConnectionManager connectionManager;\n\tprivate final StompSession session;\n\n\tpublic ProxySessionException(ProxyWebSocketConnectionManager connectionManager,\n\t\t\tStompSession session, Throwable cause) {\n\t\tsuper(cause);\n\t\tthis.connectionManager = connectionManager;\n\t\tthis.session = session;\n\t}\n\n\tpublic ProxyWebSocketConnectionManager getConnectionManager() {\n\t\treturn connectionManager;\n\t}\n\n\tpublic StompSession getSession() {\n\t\treturn session;\n\t}\n\n\t@Override\n\tpublic boolean equals(Object o) {\n\t\tif (this == o) return true;\n\t\tif (o == null || getClass() != o.getClass()) return false;\n\n\t\tProxySessionException that = (ProxySessionException) o;\n\n\t\tif (connectionManager != null ? !connectionManager.equals(that.connectionManager) : that.connectionManager != null)\n\t\t\treturn false;\n\t\treturn session != null ? session.equals(that.session) : that.session == null;\n\t}\n\n\t@Override\n\tpublic int hashCode() {\n\t\tint result = connectionManager != null ? connectionManager.hashCode() : 0;\n\t\tresult = 31 * result + (session != null ? session.hashCode() : 0);\n\t\treturn result;\n\t}\n\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ProxyWebSocketConnectionManager.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport org.springframework.messaging.simp.SimpMessagingTemplate;\nimport org.springframework.messaging.simp.stomp.StompCommand;\nimport org.springframework.messaging.simp.stomp.StompHeaders;\nimport org.springframework.messaging.simp.stomp.StompSession;\nimport org.springframework.messaging.simp.stomp.StompSessionHandler;\nimport org.springframework.util.ErrorHandler;\nimport org.springframework.web.socket.WebSocketHttpHeaders;\nimport org.springframework.web.socket.WebSocketSession;\nimport org.springframework.web.socket.client.ConnectionManagerSupport;\nimport org.springframework.web.socket.messaging.WebSocketStompClient;\n\nimport java.lang.reflect.Type;\nimport java.security.Principal;\nimport java.util.HashMap;\nimport java.util.HashSet;\nimport java.util.Map;\nimport java.util.Set;\nimport java.util.concurrent.ConcurrentHashMap;\n\n/**\n * A web socket connection manager bridge between client and backend server via zuul\n * reverse proxy\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class ProxyWebSocketConnectionManager extends ConnectionManagerSupport\n        implements StompSessionHandler {\n    private final WebSocketStompClient stompClient;\n    private final WebSocketSession userAgentSession;\n    private final WebSocketHttpHeadersCallback httpHeadersCallback;\n    private StompSession serverSession;\n    private Map<String, StompSession.Subscription> subscriptions = new ConcurrentHashMap<>();\n    private ErrorHandler errorHandler;\n    private SimpMessagingTemplate messagingTemplate;\n\n    public ProxyWebSocketConnectionManager(SimpMessagingTemplate messagingTemplate,\n                                           WebSocketStompClient stompClient, WebSocketSession userAgentSession,\n                                           WebSocketHttpHeadersCallback httpHeadersCallback, String uri) {\n        super(uri);\n        this.messagingTemplate = messagingTemplate;\n        this.stompClient = stompClient;\n        this.userAgentSession = userAgentSession;\n        this.httpHeadersCallback = httpHeadersCallback;\n    }\n\n    public void errorHandler(ErrorHandler errorHandler) {\n        this.errorHandler = errorHandler;\n    }\n\n    private WebSocketHttpHeaders buildWebSocketHttpHeaders() {\n        WebSocketHttpHeaders wsHeaders = new WebSocketHttpHeaders();\n        if (httpHeadersCallback != null) {\n            httpHeadersCallback.applyHeaders(userAgentSession, wsHeaders);\n        }\n        return wsHeaders;\n    }\n\n    @Override\n    protected void openConnection() {\n        connect();\n    }\n\n    public void connect() {\n        try {\n            serverSession = stompClient\n                    .connect(getUri().toString(), buildWebSocketHttpHeaders(), this)\n                    .get();\n        } catch (Exception e) {\n            logger.error(\"Error connecting to web socket uri \" + getUri(), e);\n            throw new RuntimeException(e);\n        }\n    }\n\n    public void reconnect(final long delay) {\n        if (delay > 0) {\n            logger.warn(\"Connection lost or refused, will attempt to reconnect after \"\n                    + delay + \" millis\");\n            try {\n                Thread.sleep(delay);\n            } catch (InterruptedException e) {\n                //\n            }\n        }\n\n        Set<String> destinations = new HashSet<>(subscriptions.keySet());\n\n        connect();\n\n        for (String destination : destinations) {\n            try {\n                subscribe(destination);\n            } catch (Exception ignored) {\n                // nothing\n            }\n        }\n    }\n\n    @Override\n    protected void closeConnection() throws Exception {\n        if (isConnected()) {\n            this.serverSession.disconnect();\n        }\n    }\n\n    @Override\n    protected boolean isConnected() {\n        return (this.serverSession != null && this.serverSession.isConnected());\n    }\n\n    @Override\n    public void afterConnected(StompSession session, StompHeaders connectedHeaders) {\n        if (logger.isDebugEnabled()) {\n            logger.debug(\"Proxied target now connected \" + session);\n        }\n    }\n\n    @Override\n    public void handleException(StompSession session, StompCommand command,\n                                StompHeaders headers, byte[] payload, Throwable ex) {\n        if (errorHandler != null) {\n            errorHandler.handleError(new ProxySessionException(this, session, ex));\n        }\n    }\n\n    @Override\n    public void handleTransportError(StompSession session, Throwable ex) {\n        if (errorHandler != null) {\n            errorHandler.handleError(new ProxySessionException(this, session, ex));\n        }\n    }\n\n    @Override\n    public Type getPayloadType(StompHeaders headers) {\n        return Object.class;\n    }\n\n    public void sendMessage(final String destination, final Object msg) {\n        if (msg instanceof String) { // in case of a json string to avoid double\n            // converstion by the converters\n            serverSession.send(destination, ((String) msg).getBytes());\n            return;\n        }\n\n        serverSession.send(destination, msg);\n    }\n\n    @Override\n    public void handleFrame(StompHeaders headers, Object payload) {\n        if (headers.getDestination() != null) {\n            String destination = headers.getDestination();\n            if (logger.isDebugEnabled()) {\n                logger.debug(\"Received \" + payload + \", To \" + headers.getDestination());\n            }\n\n            Principal principal = userAgentSession.getPrincipal();\n            String userDestinationPrefix = messagingTemplate.getUserDestinationPrefix();\n            if (principal != null && destination.startsWith(userDestinationPrefix)) {\n                destination = destination.substring(userDestinationPrefix.length());\n\n                destination = destination.startsWith(\"/\") ? destination\n                        : \"/\" + destination;\n\n                messagingTemplate.convertAndSendToUser(principal.getName(), destination,\n                        payload, copyHeaders(headers.toSingleValueMap()));\n            } else {\n                messagingTemplate.convertAndSend(destination, payload,\n                        copyHeaders(headers.toSingleValueMap()));\n            }\n        }\n    }\n\n    private Map<String, Object> copyHeaders(Map<String, String> original) {\n        Map<String, Object> copy = new HashMap<>();\n        for (String key : original.keySet()) {\n            copy.put(key, original.get(key));\n        }\n\n        return copy;\n    }\n\n    private void connectIfNecessary() {\n        if (!isConnected()) {\n            connect();\n        }\n    }\n\n    public void subscribe(String destination) throws Exception {\n        connectIfNecessary();\n        StompSession.Subscription subscription = serverSession.subscribe(destination,\n                this);\n        subscriptions.put(destination, subscription);\n    }\n\n    public void unsubscribe(String destination) {\n        StompSession.Subscription subscription = subscriptions.remove(destination);\n        if (subscription != null) {\n            connectIfNecessary();\n            subscription.unsubscribe();\n        }\n    }\n\n    public boolean isConnectedToUserAgent() {\n        return (userAgentSession != null && userAgentSession.isOpen());\n    }\n\n    public void disconnect() {\n        try {\n            closeConnection();\n        } catch (Exception e) {\n            // nothing\n        }\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ProxyWebSocketErrorHandler.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport org.springframework.util.ErrorHandler;\n\n/**\n * A simple tagging interface for pluggable web socket connection error handlers\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic interface ProxyWebSocketErrorHandler extends ErrorHandler {\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ProxyWebSocketHandler.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.proxytarget.ProxyTargetResolver;\nimport org.slf4j.Logger;\nimport org.slf4j.LoggerFactory;\nimport org.springframework.messaging.simp.SimpMessagingTemplate;\nimport org.springframework.messaging.simp.stomp.StompCommand;\nimport org.springframework.util.Assert;\nimport org.springframework.util.ErrorHandler;\nimport org.springframework.util.PatternMatchUtils;\nimport org.springframework.web.servlet.support.ServletUriComponentsBuilder;\nimport org.springframework.web.socket.CloseStatus;\nimport org.springframework.web.socket.WebSocketHandler;\nimport org.springframework.web.socket.WebSocketMessage;\nimport org.springframework.web.socket.WebSocketSession;\nimport org.springframework.web.socket.handler.WebSocketHandlerDecorator;\nimport org.springframework.web.socket.messaging.WebSocketStompClient;\nimport org.springframework.web.util.UriComponentsBuilder;\n\nimport java.net.URI;\nimport java.util.Map;\nimport java.util.concurrent.ConcurrentHashMap;\n\n/**\n * A {@link WebSocketHandlerDecorator} that adds web socket support to zuul reverse proxy.\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class ProxyWebSocketHandler extends WebSocketHandlerDecorator {\n    private final Logger logger = LoggerFactory.getLogger(ProxyWebSocketHandler.class);\n    private final WebSocketHttpHeadersCallback headersCallback;\n    private final SimpMessagingTemplate messagingTemplate;\n    private final ProxyTargetResolver proxyTargetResolver;\n    private final ZuulWebSocketProperties zuulWebSocketProperties;\n    private final WebSocketStompClient stompClient;\n    private final Map<WebSocketSession, ProxyWebSocketConnectionManager> managers = new ConcurrentHashMap<>();\n    private ErrorHandler errorHandler;\n\n    public ProxyWebSocketHandler(WebSocketHandler delegate,\n                                 WebSocketStompClient stompClient,\n                                 WebSocketHttpHeadersCallback headersCallback,\n                                 SimpMessagingTemplate messagingTemplate,\n                                 ProxyTargetResolver proxyTargetResolver,\n                                 ZuulWebSocketProperties zuulWebSocketProperties) {\n        super(delegate);\n        this.stompClient = stompClient;\n        this.headersCallback = headersCallback;\n        this.messagingTemplate = messagingTemplate;\n        this.proxyTargetResolver = proxyTargetResolver;\n        this.zuulWebSocketProperties = zuulWebSocketProperties;\n    }\n\n    public void errorHandler(ErrorHandler errorHandler) {\n        this.errorHandler = errorHandler;\n    }\n\n    private String getWebSocketServerPath(ZuulWebSocketProperties.WsBrokerage wsBrokerage,\n                                          URI uri) {\n        String path = uri.toString();\n        if (path.contains(\":\")) {\n            path = UriComponentsBuilder.fromUriString(path).build().getPath();\n        }\n\n        for (String endPoint : wsBrokerage.getEndPoints()) {\n            if (PatternMatchUtils.simpleMatch(toPattern(endPoint), path + \"/\")) {\n                return endPoint;\n            }\n        }\n\n        return null;\n    }\n\n    private ZuulWebSocketProperties.WsBrokerage getWebSocketBrokarage(URI uri) {\n        String path = uri.toString();\n        if (path.contains(\":\")) {\n            path = UriComponentsBuilder.fromUriString(path).build().getPath();\n        }\n\n        for (Map.Entry<String, ZuulWebSocketProperties.WsBrokerage> entry : zuulWebSocketProperties\n                .getBrokerages().entrySet()) {\n            ZuulWebSocketProperties.WsBrokerage wsBrokerage = entry.getValue();\n            if (wsBrokerage.isEnabled()) {\n                for (String endPoint : wsBrokerage.getEndPoints()) {\n                    if (PatternMatchUtils.simpleMatch(toPattern(endPoint), path + \"/\")) {\n                        return wsBrokerage;\n                    }\n                }\n            }\n        }\n\n        return null;\n    }\n\n    private String toPattern(String path) {\n        path = path.startsWith(\"/\") ? \"**\" + path : \"**/\" + path;\n        return path.endsWith(\"/\") ? path + \"**\" : path + \"/**\";\n    }\n\n    @Override\n    public void afterConnectionClosed(WebSocketSession session, CloseStatus closeStatus)\n            throws Exception {\n        disconnectFromProxiedTarget(session);\n        super.afterConnectionClosed(session, closeStatus);\n    }\n\n    @Override\n    public void handleMessage(WebSocketSession session, WebSocketMessage<?> message)\n            throws Exception {\n        super.handleMessage(session, message);\n        handleMessageFromClient(session, message);\n    }\n\n    private void handleMessageFromClient(WebSocketSession session,\n                                         WebSocketMessage<?> message) throws Exception {\n        boolean handled = false;\n        WebSocketMessageAccessor accessor = WebSocketMessageAccessor.create(message);\n        if (StompCommand.SEND.toString().equalsIgnoreCase(accessor.getCommand())) {\n            handled = true;\n            sendMessageToProxiedTarget(session, accessor);\n        }\n\n        if (StompCommand.SUBSCRIBE.toString().equalsIgnoreCase(accessor.getCommand())) {\n            handled = true;\n            subscribeToProxiedTarget(session, accessor);\n        }\n\n        if (StompCommand.UNSUBSCRIBE.toString().equalsIgnoreCase(accessor.getCommand())) {\n            handled = true;\n            unsubscribeFromProxiedTarget(session, accessor);\n        }\n\n        if (StompCommand.CONNECT.toString().equalsIgnoreCase(accessor.getCommand())) {\n            handled = true;\n            connectToProxiedTarget(session);\n        }\n\n        if (!handled) {\n            if (logger.isDebugEnabled()) {\n                logger.debug(\"STOMP COMMAND \" + accessor.getCommand()\n                        + \" was not explicitly handled\");\n            }\n        }\n    }\n\n    private void connectToProxiedTarget(WebSocketSession session) {\n        URI sessionUri = session.getUri();\n        ZuulWebSocketProperties.WsBrokerage wsBrokerage = getWebSocketBrokarage(\n                sessionUri);\n\n        Assert.notNull(wsBrokerage, \"wsBrokerage must not be null\");\n\n        String path = getWebSocketServerPath(wsBrokerage, sessionUri);\n        Assert.notNull(path, \"Web socket uri path must be null\");\n\n        URI routeTarget = proxyTargetResolver.resolveTarget(wsBrokerage);\n\n        Assert.notNull(routeTarget, \"routeTarget must not be null\");\n\n        String uri = ServletUriComponentsBuilder\n                .fromUri(routeTarget)\n                .path(path)\n                .replaceQuery(sessionUri.getQuery())\n                .toUriString();\n\n        ProxyWebSocketConnectionManager connectionManager = new ProxyWebSocketConnectionManager(\n                messagingTemplate, stompClient, session, headersCallback, uri);\n        connectionManager.errorHandler(this.errorHandler);\n        managers.put(session, connectionManager);\n        connectionManager.start();\n    }\n\n    private void disconnectFromProxiedTarget(WebSocketSession session) {\n        disconnectProxyManager(managers.remove(session));\n    }\n\n    private void disconnectProxyManager(ProxyWebSocketConnectionManager proxyManager) {\n        if (proxyManager != null) {\n            try {\n                proxyManager.disconnect();\n            } catch (Throwable ignored) {\n                // nothing\n            }\n        }\n    }\n\n    private void unsubscribeFromProxiedTarget(WebSocketSession session,\n                                              WebSocketMessageAccessor accessor) {\n        ProxyWebSocketConnectionManager manager = managers.get(session);\n        if (manager != null) {\n            manager.unsubscribe(accessor.getDestination());\n        }\n    }\n\n    private void sendMessageToProxiedTarget(WebSocketSession session,\n                                            WebSocketMessageAccessor accessor) {\n        ProxyWebSocketConnectionManager manager = managers.get(session);\n        manager.sendMessage(accessor.getDestination(), accessor.getPayload());\n    }\n\n    private void subscribeToProxiedTarget(WebSocketSession session,\n                                          WebSocketMessageAccessor accessor) throws Exception {\n        ProxyWebSocketConnectionManager manager = managers.get(session);\n        manager.subscribe(accessor.getDestination());\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ReconnectErrorHandler.java",
    "content": "package com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.util.ErrorAnalyzer;\nimport org.apache.commons.logging.Log;\nimport org.apache.commons.logging.LogFactory;\nimport org.springframework.messaging.simp.stomp.ConnectionLostException;\n\nimport java.io.IOException;\n\n/**\n * Created by ronald22 on 06/04/2017.\n */\npublic class ReconnectErrorHandler implements ProxyWebSocketErrorHandler {\n    private static final long CONNECTION_LOST_RECONNECT_INTERVAL = 10000;\n    private final Log logger = LogFactory\n            .getLog(ReconnectErrorHandler.class);\n    private ErrorAnalyzer errorAnalyzer;\n\n    public ReconnectErrorHandler(ErrorAnalyzer errorAnalyzer) {\n        this.errorAnalyzer = errorAnalyzer;\n    }\n\n    @Override\n    public void handleError(Throwable t) {\n        if (logger.isErrorEnabled()) {\n            logger.error(\"Proxy web socket error occurred.\", t);\n        }\n\n        if (!(t instanceof ProxySessionException))\n            return;\n\n        ProxySessionException exception = (ProxySessionException) t;\n\n        if (shouldAttemptToReconnect(exception)) {\n            executeReconnectThread(exception.getConnectionManager());\n        }\n    }\n\n    private boolean shouldAttemptToReconnect(ProxySessionException proxyException) {\n        if (!isConnectionLost(proxyException))\n            return false;\n\n        if (!proxyException.getConnectionManager().isConnectedToUserAgent())\n            return false;\n\n        return true;\n    }\n\n    private boolean isConnectionLost(ProxySessionException proxyException) {\n        Throwable cause = proxyException.getCause();\n        Throwable[] causeChain = errorAnalyzer.determineCauseChain(cause);\n        Throwable throwable = errorAnalyzer\n                .getFirstThrowableOfType(ConnectionLostException.class, causeChain);\n\n        if (throwable != null)\n            return true;\n\n        throwable = errorAnalyzer.getFirstThrowableOfType(IOException.class,\n                causeChain);\n\n        return throwable != null\n                && throwable.getMessage().toLowerCase().contains(\" refused \");\n    }\n\n    private void executeReconnectThread(\n            final ProxyWebSocketConnectionManager clientConnectionManager) {\n        Thread t = new Thread(new Runnable() {\n            @Override\n            public void run() {\n                clientConnectionManager.reconnect(CONNECTION_LOST_RECONNECT_INTERVAL);\n            }\n        });\n        t.setDaemon(true);\n        t.start();\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/WebSocketHttpHeadersCallback.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport org.springframework.web.socket.WebSocketHttpHeaders;\nimport org.springframework.web.socket.WebSocketSession;\n\n/**\n * Callback strategy to supply web socket headers to handshake requests.\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic interface WebSocketHttpHeadersCallback {\n\tvoid applyHeaders(WebSocketSession userAgentSession, WebSocketHttpHeaders headers);\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/WebSocketMessageAccessor.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport org.springframework.util.StringUtils;\nimport org.springframework.web.socket.WebSocketMessage;\n\n/**\n * An accessor to acess web socket messages before discpatching them to the backend\n * server.\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic final class WebSocketMessageAccessor {\n\tprivate String[] messageComponents;\n\n\tprivate WebSocketMessageAccessor() {\n\t}\n\n\tpublic static WebSocketMessageAccessor create(WebSocketMessage<?> message) {\n\t\tString msgPayload = message.getPayload().toString();\n\t\treturn create(msgPayload);\n\t}\n\n\tpublic static WebSocketMessageAccessor create(String message) {\n\t\tWebSocketMessageAccessor accessor = new WebSocketMessageAccessor();\n\t\taccessor.messageComponents = StringUtils.tokenizeToStringArray(message, \"\\n\");\n\t\treturn accessor;\n\t}\n\n\tpublic String getCommand() {\n\t\tif (accessible())\n\t\t\treturn messageComponents[0];\n\n\t\treturn null;\n\t}\n\n\tprivate boolean accessible() {\n\t\treturn messageComponents != null && messageComponents.length > 0;\n\t}\n\n\tpublic String getDestination() {\n\t\treturn getHeader(\"destination\");\n\t}\n\n\tpublic String getHeader(String header) {\n\t\tif (!accessible())\n\t\t\treturn null;\n\n\t\theader = header.endsWith(\":\") ? header : header + \":\";\n\t\tif (accessible()) {\n\t\t\tfor (String messageComponent : messageComponents) {\n\t\t\t\tint indx = messageComponent.indexOf(header);\n\t\t\t\tif (indx != -1) {\n\t\t\t\t\treturn messageComponent.substring(indx + header.length());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn null;\n\t}\n\n\tpublic String getPayload() {\n\t\tif (!accessible())\n\t\t\treturn null;\n\n\t\treturn messageComponents[messageComponents.length - 1];\n\t}\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ZuulWebSocketConfiguration.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport com.github.mthizo247.cloud.netflix.zuul.web.authentication.BasicAuthPrincipalHeadersCallback;\nimport com.github.mthizo247.cloud.netflix.zuul.web.authentication.CompositeHeadersCallback;\nimport com.github.mthizo247.cloud.netflix.zuul.web.authentication.LoginCookieHeadersCallback;\nimport com.github.mthizo247.cloud.netflix.zuul.web.authentication.OAuth2BearerPrincipalHeadersCallback;\nimport com.github.mthizo247.cloud.netflix.zuul.web.filter.ProxyRedirectFilter;\nimport com.github.mthizo247.cloud.netflix.zuul.web.proxytarget.CompositeProxyTargetResolver;\nimport com.github.mthizo247.cloud.netflix.zuul.web.proxytarget.EurekaProxyTargetResolver;\nimport com.github.mthizo247.cloud.netflix.zuul.web.proxytarget.LoadBalancedProxyTargetResolver;\nimport com.github.mthizo247.cloud.netflix.zuul.web.proxytarget.ProxyTargetResolver;\nimport com.github.mthizo247.cloud.netflix.zuul.web.proxytarget.UrlProxyTargetResolver;\nimport com.github.mthizo247.cloud.netflix.zuul.web.util.DefaultErrorAnalyzer;\nimport org.springframework.beans.factory.annotation.Autowired;\nimport org.springframework.beans.factory.annotation.Qualifier;\nimport org.springframework.boot.autoconfigure.AutoConfigureAfter;\nimport org.springframework.boot.autoconfigure.condition.ConditionalOnClass;\nimport org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;\nimport org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;\nimport org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;\nimport org.springframework.boot.context.properties.EnableConfigurationProperties;\nimport org.springframework.cloud.client.discovery.DiscoveryClient;\nimport org.springframework.cloud.client.loadbalancer.LoadBalancerClient;\nimport org.springframework.cloud.netflix.zuul.filters.RouteLocator;\nimport org.springframework.cloud.netflix.zuul.filters.ZuulProperties;\nimport org.springframework.context.ApplicationListener;\nimport org.springframework.context.annotation.Bean;\nimport org.springframework.context.annotation.Configuration;\nimport org.springframework.context.annotation.Primary;\nimport org.springframework.context.event.ContextRefreshedEvent;\nimport org.springframework.messaging.converter.MessageConverter;\nimport org.springframework.messaging.simp.SimpMessagingTemplate;\nimport org.springframework.messaging.simp.config.MessageBrokerRegistry;\nimport org.springframework.scheduling.TaskScheduler;\nimport org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;\nimport org.springframework.web.socket.WebSocketHandler;\nimport org.springframework.web.socket.client.WebSocketClient;\nimport org.springframework.web.socket.client.standard.StandardWebSocketClient;\nimport org.springframework.web.socket.config.annotation.AbstractWebSocketMessageBrokerConfigurer;\nimport org.springframework.web.socket.config.annotation.DelegatingWebSocketMessageBrokerConfiguration;\nimport org.springframework.web.socket.config.annotation.SockJsServiceRegistration;\nimport org.springframework.web.socket.config.annotation.StompEndpointRegistry;\nimport org.springframework.web.socket.config.annotation.WebSocketTransportRegistration;\nimport org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory;\nimport org.springframework.web.socket.messaging.WebSocketStompClient;\nimport org.springframework.web.socket.sockjs.client.SockJsClient;\nimport org.springframework.web.socket.sockjs.client.Transport;\nimport org.springframework.web.socket.sockjs.client.WebSocketTransport;\n\nimport javax.annotation.PostConstruct;\nimport java.util.ArrayList;\nimport java.util.Arrays;\nimport java.util.List;\nimport java.util.Map;\nimport java.util.UUID;\n\n/**\n * Zuul reverse proxy web socket configuration\n *\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\n@Configuration\n@ConditionalOnWebApplication\n@ConditionalOnClass(WebSocketHandler.class)\n@ConditionalOnProperty(prefix = \"zuul.ws\", name = \"enabled\", havingValue = \"true\", matchIfMissing = true)\n@EnableConfigurationProperties(ZuulWebSocketProperties.class)\n@AutoConfigureAfter(DelegatingWebSocketMessageBrokerConfiguration.class)\npublic class ZuulWebSocketConfiguration extends AbstractWebSocketMessageBrokerConfigurer\n        implements ApplicationListener<ContextRefreshedEvent> {\n    @Autowired\n    ZuulWebSocketProperties zuulWebSocketProperties;\n    @Autowired\n    SimpMessagingTemplate messagingTemplate;\n    @Autowired\n    ZuulProperties zuulProperties;\n    @Autowired\n    @Qualifier(\"compositeProxyTargetResolver\")\n    ProxyTargetResolver proxyTargetResolver;\n    @Autowired\n    ProxyWebSocketErrorHandler proxyWebSocketErrorHandler;\n    @Autowired\n    WebSocketStompClient stompClient;\n    @Autowired\n    @Qualifier(\"compositeHeadersCallback\")\n    WebSocketHttpHeadersCallback webSocketHttpHeadersCallback;\n\n    @Override\n    public void registerStompEndpoints(StompEndpointRegistry registry) {\n        boolean wsEnabled = false;\n        for (Map.Entry<String, ZuulWebSocketProperties.WsBrokerage> entry : zuulWebSocketProperties\n                .getBrokerages().entrySet()) {\n            ZuulWebSocketProperties.WsBrokerage wsBrokerage = entry.getValue();\n            if (wsBrokerage.isEnabled()) {\n                this.addStompEndpoint(registry, wsBrokerage.getEndPoints());\n                wsEnabled = true;\n            }\n        }\n\n        if (!wsEnabled)\n            this.addStompEndpoint(registry, UUID.randomUUID().toString());\n    }\n\n    @Override\n    public void configureMessageBroker(MessageBrokerRegistry config) {\n        // prefix for subscribe\n        for (Map.Entry<String, ZuulWebSocketProperties.WsBrokerage> entry : zuulWebSocketProperties\n                .getBrokerages().entrySet()) {\n            ZuulWebSocketProperties.WsBrokerage wsBrokerage = entry.getValue();\n            if (wsBrokerage.isEnabled()) {\n                config.enableSimpleBroker(\n                        mergeBrokersWithApplicationDestinationPrefixes(wsBrokerage));\n                // prefix for send\n                config.setApplicationDestinationPrefixes(\n                        wsBrokerage.getDestinationPrefixes());\n            }\n        }\n    }\n\n    private SockJsServiceRegistration addStompEndpoint(StompEndpointRegistry registry, String... endpoint) {\n        return registry.addEndpoint(endpoint)\n                // bypasses spring web security\n                .setAllowedOrigins(\"*\").withSockJS();\n    }\n\n    private String[] mergeBrokersWithApplicationDestinationPrefixes(\n            ZuulWebSocketProperties.WsBrokerage wsBrokerage) {\n        List<String> brokers = new ArrayList<>(Arrays.asList(wsBrokerage.getBrokers()));\n\n        for (String adp : wsBrokerage.getDestinationPrefixes()) {\n            if (!brokers.contains(adp)) {\n                brokers.add(adp);\n            }\n        }\n\n        return brokers.toArray(new String[brokers.size()]);\n    }\n\n    @Override\n    public void configureWebSocketTransport(WebSocketTransportRegistration registration) {\n        registration.addDecoratorFactory(new WebSocketHandlerDecoratorFactory() {\n            @Override\n            public WebSocketHandler decorate(WebSocketHandler handler) {\n                ProxyWebSocketHandler proxyWebSocketHandler = new ProxyWebSocketHandler(\n                        handler, stompClient, webSocketHttpHeadersCallback,\n                        messagingTemplate,\n                        proxyTargetResolver,\n                        zuulWebSocketProperties);\n                proxyWebSocketHandler.errorHandler(proxyWebSocketErrorHandler);\n                return proxyWebSocketHandler;\n            }\n        });\n    }\n\n    @Bean\n    @Primary\n    public WebSocketHttpHeadersCallback compositeHeadersCallback(final List<WebSocketHttpHeadersCallback> headersCallbacks) {\n        return new CompositeHeadersCallback(headersCallbacks);\n    }\n\n    @Bean\n    @ConditionalOnClass(name = \"org.springframework.security.core.Authentication\")\n    public WebSocketHttpHeadersCallback basicAuthPrincipalHeadersCallback() {\n        return new BasicAuthPrincipalHeadersCallback();\n    }\n\n    @Bean\n    @ConditionalOnClass(name = \"org.springframework.security.core.OAuth2Authentication\")\n    public WebSocketHttpHeadersCallback oauth2BearerPrincipalHeadersCallback() {\n        return new OAuth2BearerPrincipalHeadersCallback();\n    }\n\n    @Bean\n    public WebSocketHttpHeadersCallback loginCookieHeadersCallback() {\n        return new LoginCookieHeadersCallback();\n    }\n\n    @Bean\n    public ProxyTargetResolver urlProxyTargetResolver(\n            final ZuulProperties zuulProperties) {\n        return new UrlProxyTargetResolver(zuulProperties);\n    }\n\n    @Bean\n    public ProxyTargetResolver discoveryProxyTargetResolver(\n            final ZuulProperties zuulProperties, final DiscoveryClient discoveryClient) {\n        return new EurekaProxyTargetResolver(discoveryClient, zuulProperties);\n    }\n\n    @Bean\n    public ProxyTargetResolver loadBalancedProxyTargetResolver(\n            final ZuulProperties zuulProperties, final LoadBalancerClient loadBalancerClient) {\n        return new LoadBalancedProxyTargetResolver(loadBalancerClient, zuulProperties);\n    }\n\n    @Bean\n    @Primary\n    public ProxyTargetResolver compositeProxyTargetResolver(final List<ProxyTargetResolver> resolvers) {\n        return new CompositeProxyTargetResolver(resolvers);\n    }\n\n    @Bean\n    @ConditionalOnMissingBean(WebSocketStompClient.class)\n    public WebSocketStompClient stompClient(WebSocketClient webSocketClient, MessageConverter messageConverter,\n                                            @Qualifier(\"proxyStompClientTaskScheduler\") TaskScheduler taskScheduler) {\n        int bufferSizeLimit = 1024 * 1024 * 8;\n\n        WebSocketStompClient client = new WebSocketStompClient(webSocketClient);\n        client.setInboundMessageSizeLimit(bufferSizeLimit);\n        client.setMessageConverter(messageConverter);\n        client.setTaskScheduler(taskScheduler);\n        client.setDefaultHeartbeat(new long[]{0, 0});\n        return client;\n    }\n\n    @Bean\n    @ConditionalOnMissingBean(WebSocketClient.class)\n    public WebSocketClient webSocketClient() {\n        StandardWebSocketClient webSocketClient = new StandardWebSocketClient();\n        List<Transport> transports = new ArrayList<>();\n        transports.add(new WebSocketTransport(webSocketClient));\n        return new SockJsClient(transports);\n    }\n\n    @Bean\n    @Qualifier(\"proxyStompClientTaskScheduler\")\n    public TaskScheduler stompClientTaskScheduler() {\n        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();\n        scheduler.setThreadNamePrefix(\"ProxyStompClient-\");\n        scheduler.setPoolSize(Runtime.getRuntime().availableProcessors());\n        return scheduler;\n    }\n\n    @Bean\n    public ProxyWebSocketErrorHandler reconnectErrorHandler() {\n        return new ReconnectErrorHandler(new DefaultErrorAnalyzer());\n    }\n\n    @Bean\n    @Primary\n    public ProxyWebSocketErrorHandler compositeErrorHandler(final List<ProxyWebSocketErrorHandler> errorHandlers) {\n        return new CompositeErrorHandler(errorHandlers);\n    }\n\n    @Bean\n    public ProxyRedirectFilter proxyRedirectFilter(RouteLocator routeLocator) {\n        return new ProxyRedirectFilter(routeLocator);\n    }\n\n    @PostConstruct\n    public void init() {\n        ignorePattern(\"**/websocket\");\n        ignorePattern(\"**/info\");\n    }\n\n    private void ignorePattern(String ignoredPattern) {\n        for (String pattern : zuulProperties.getIgnoredPatterns()) {\n            if (pattern.toLowerCase().contains(ignoredPattern))\n                return;\n        }\n\n        zuulProperties.getIgnoredPatterns().add(ignoredPattern);\n    }\n\n    @Override\n    public void onApplicationEvent(ContextRefreshedEvent event) {\n        init();\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ZuulWebSocketProperties.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport javax.annotation.PostConstruct;\n\nimport org.springframework.boot.context.properties.ConfigurationProperties;\nimport org.springframework.util.StringUtils;\n\n/**\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\n@ConfigurationProperties(\"zuul.ws\")\npublic class ZuulWebSocketProperties {\n\tprivate boolean enabled = true;\n\tprivate Map<String, WsBrokerage> brokerages = new HashMap<>();\n\n\tpublic boolean isEnabled() {\n\t\treturn enabled;\n\t}\n\n\tpublic void setEnabled(boolean enabled) {\n\t\tthis.enabled = enabled;\n\t}\n\n\tpublic Map<String, WsBrokerage> getBrokerages() {\n\t\treturn brokerages;\n\t}\n\n\tpublic void setBrokerages(Map<String, WsBrokerage> brokerages) {\n\t\tthis.brokerages = brokerages;\n\t}\n\n\t@PostConstruct\n\tpublic void init() {\n\t\tfor (Map.Entry<String, WsBrokerage> entry : this.brokerages.entrySet()) {\n\t\t\tWsBrokerage wsBrokerage = entry.getValue();\n\t\t\tif (!StringUtils.hasText(wsBrokerage.getId())) {\n\t\t\t\twsBrokerage.id = entry.getKey();\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic static class WsBrokerage {\n\t\tprivate boolean enabled = true;\n\t\tprivate String id;\n\t\tprivate String routeId;\n\t\tprivate String[] endPoints;\n\t\tprivate String[] brokers;\n\t\tprivate String[] destinationPrefixes;\n\n\t\tpublic boolean isEnabled() {\n\t\t\treturn enabled;\n\t\t}\n\n\t\tpublic void setEnabled(boolean enabled) {\n\t\t\tthis.enabled = enabled;\n\t\t}\n\n\t\tpublic String getId() {\n\t\t\treturn id;\n\t\t}\n\n\t\tpublic void setId(String id) {\n\t\t\tthis.id = id;\n\t\t}\n\n\t\tpublic String getRouteId() {\n\t\t\treturn routeId;\n\t\t}\n\n\t\tpublic void setRouteId(String routeId) {\n\t\t\tthis.routeId = routeId;\n\t\t}\n\n\t\tpublic String[] getEndPoints() {\n\t\t\treturn endPoints;\n\t\t}\n\n\t\tpublic void setEndPoints(String[] endPoints) {\n\t\t\tthis.endPoints = endPoints;\n\t\t}\n\n\t\tpublic String[] getBrokers() {\n\t\t\treturn brokers;\n\t\t}\n\n\t\tpublic void setBrokers(String[] brokers) {\n\t\t\tthis.brokers = brokers;\n\t\t}\n\n\t\tpublic String[] getDestinationPrefixes() {\n\t\t\treturn destinationPrefixes;\n\t\t}\n\n\t\tpublic void setDestinationPrefixes(String[] destinationPrefixes) {\n\t\t\tthis.destinationPrefixes = destinationPrefixes;\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/util/DefaultErrorAnalyzer.java",
    "content": "package com.github.mthizo247.cloud.netflix.zuul.web.util;\n\nimport java.util.ArrayList;\nimport java.util.List;\n\n/**\n * Created by ronald22 on 13/02/2018.\n */\npublic class DefaultErrorAnalyzer implements ErrorAnalyzer {\n\n    @Override\n    public Throwable[] determineCauseChain(Throwable throwable) {\n        List<Throwable> chain = new ArrayList<>();\n        Throwable currentThrowable = throwable;\n\n        while (currentThrowable != null) {\n            chain.add(currentThrowable);\n            currentThrowable = currentThrowable.getCause();\n        }\n\n        return chain.toArray(new Throwable[chain.size()]);\n    }\n\n    @Override\n    public Throwable getFirstThrowableOfType(Class<? extends Throwable> throwableType, Throwable[] chain) {\n        if (chain != null) {\n            for (Throwable t : chain) {\n                if ((t != null) && throwableType.isInstance(t)) {\n                    return t;\n                }\n            }\n        }\n\n        return null;\n    }\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/util/ErrorAnalyzer.java",
    "content": "package com.github.mthizo247.cloud.netflix.zuul.web.util;\n\n/**\n * Created by ronald22 on 13/02/2018.\n */\npublic interface ErrorAnalyzer {\n    Throwable[] determineCauseChain(Throwable throwable);\n\n    Throwable getFirstThrowableOfType(Class<? extends Throwable> throwableType, Throwable[] chain);\n}\n"
  },
  {
    "path": "src/main/java/com/github/mthizo247/cloud/netflix/zuul/web/util/MapPropertyResolver.java",
    "content": "package com.github.mthizo247.cloud.netflix.zuul.web.util;\n\nimport org.springframework.core.env.AbstractPropertyResolver;\n\nimport java.util.Map;\n\n/**\n * @author Ronald Mthombeni\n */\npublic class MapPropertyResolver extends AbstractPropertyResolver {\n\n    private Map<String, Object> map;\n\n    public MapPropertyResolver(Map<String, Object> map) {\n        this.map = map;\n    }\n\n    @Override\n    protected String getPropertyAsRawString(String key) {\n        Object v = map.get(key);\n        return v != null ? v.toString() : null;\n    }\n\n    @Override\n    public <T> T getProperty(String key, Class<T> targetType) {\n        Object v = map.get(key);\n        if (v != null) {\n            return targetType.cast(v);\n        }\n        return null;\n    }\n}\n"
  },
  {
    "path": "src/test/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ProxyWebSocketConnectionManagerTests.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport org.junit.Before;\nimport org.junit.Test;\nimport org.springframework.messaging.simp.SimpMessagingTemplate;\nimport org.springframework.messaging.simp.stomp.StompCommand;\nimport org.springframework.messaging.simp.stomp.StompHeaders;\nimport org.springframework.messaging.simp.stomp.StompSession;\nimport org.springframework.util.ErrorHandler;\nimport org.springframework.util.concurrent.ListenableFuture;\nimport org.springframework.web.socket.WebSocketHttpHeaders;\nimport org.springframework.web.socket.WebSocketSession;\nimport org.springframework.web.socket.messaging.WebSocketStompClient;\n\nimport static org.mockito.Mockito.mock;\nimport static org.mockito.Mockito.verify;\nimport static org.mockito.Mockito.when;\n\n/**\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class ProxyWebSocketConnectionManagerTests {\n\n    private ProxyWebSocketConnectionManager proxyConnectionManager;\n\n    private SimpMessagingTemplate messagingTemplate = mock(SimpMessagingTemplate.class);\n    private WebSocketStompClient stompClient = mock(WebSocketStompClient.class);\n    private WebSocketSession wsSession = mock(WebSocketSession.class);\n    private WebSocketHttpHeadersCallback headersCallback = mock(\n            WebSocketHttpHeadersCallback.class);\n    private StompSession serverSession = mock(StompSession.class);\n    private ListenableFuture<StompSession> listenableFuture = (ListenableFuture<StompSession>) mock(\n            ListenableFuture.class);\n    private ErrorHandler errHandler = mock(ErrorHandler.class);\n\n    @Before\n    public void init() throws Exception {\n        String uri = \"http://example.com\";\n        proxyConnectionManager = new ProxyWebSocketConnectionManager(messagingTemplate,\n                stompClient, wsSession, headersCallback, uri);\n\n        proxyConnectionManager.errorHandler(errHandler);\n\n        when(listenableFuture.get()).thenReturn(serverSession);\n        when(stompClient.connect(uri, new WebSocketHttpHeaders(),\n                proxyConnectionManager)).thenReturn(listenableFuture);\n    }\n\n    @Test\n    public void sendStringMessageAsBytes() throws Exception {\n        String destination = \"/app/messages\";\n        String message = \"hello\";\n\n        proxyConnectionManager.start();\n\n        proxyConnectionManager.sendMessage(destination, message);\n\n        verify(serverSession).send(destination, message.getBytes());\n    }\n\n    @Test\n    public void handlesExcpetionUsingErrorHandler() throws Exception {\n        StompHeaders headers = new StompHeaders();\n        byte[] payload = new byte[0];\n        Throwable exception = new Exception(\"E\");\n        proxyConnectionManager.handleException(serverSession, StompCommand.MESSAGE,\n                headers, payload, exception);\n\n        verify(errHandler).handleError(new ProxySessionException(proxyConnectionManager, serverSession, exception));\n    }\n\n    @Test\n    public void handlesTransportErrorUsingErrorHandler() throws Exception {\n        Throwable exception = new Exception(\"E\");\n        proxyConnectionManager.handleTransportError(serverSession, exception);\n\n        verify(errHandler).handleError(new ProxySessionException(proxyConnectionManager, serverSession, exception));\n    }\n}"
  },
  {
    "path": "src/test/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/WebSocketMessageAccessorTests.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport static org.hamcrest.core.Is.is;\nimport static org.junit.Assert.assertThat;\n\nimport org.junit.Test;\n\n/**\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class WebSocketMessageAccessorTests {\n\tprivate WebSocketMessageAccessor accessor;\n\n\t@Test\n\tpublic void connect() throws Exception {\n\t\taccessor = WebSocketMessageAccessor.create(\"CONNECT\\n\"\n\t\t\t\t+ \"accept-version:1.1,1.0\\n\" + \"heart-beat:10000,10000\\n\" + \"\\n\");\n\n\t\tassertThat(accessor.getCommand(), is(\"CONNECT\"));\n\t}\n\n\t@Test\n\tpublic void subscribe() throws Exception {\n\t\taccessor = WebSocketMessageAccessor.create(\n\t\t\t\t\"SUBSCRIBE\\n\" + \"id:sub-0\\n\" + \"destination:/topic/greetings\\n\" + \"\\n\");\n\n\t\tassertThat(accessor.getCommand(), is(\"SUBSCRIBE\"));\n\t\tassertThat(accessor.getDestination(), is(\"/topic/greetings\"));\n\t}\n\n\t@Test\n\tpublic void send() throws Exception {\n\t\taccessor = WebSocketMessageAccessor.create(\"SEND\\n\" + \"destination:/app/hello\\n\"\n\t\t\t\t+ \"content-length:16\\n\" + \"\\n\" + \"{\\\"name\\\":\\\"hell9\\\"}\");\n\n\t\tassertThat(accessor.getCommand(), is(\"SEND\"));\n\t\tassertThat(accessor.getDestination(), is(\"/app/hello\"));\n\t\tassertThat(accessor.getPayload(), is(\"{\\\"name\\\":\\\"hell9\\\"}\"));\n\t}\n}"
  },
  {
    "path": "src/test/java/com/github/mthizo247/cloud/netflix/zuul/web/socket/ZuulWebSocketPropertiesTests.java",
    "content": "/*\n * Copyright 2002-2017 the original author or authors.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n *      http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\npackage com.github.mthizo247.cloud.netflix.zuul.web.socket;\n\nimport static org.hamcrest.core.Is.is;\nimport static org.junit.Assert.assertThat;\n\nimport java.util.HashMap;\nimport java.util.Map;\n\nimport org.junit.Before;\nimport org.junit.Test;\n\n/**\n * @author Ronald Mthombeni\n * @author Salman Noor\n */\npublic class ZuulWebSocketPropertiesTests {\n\tprivate ZuulWebSocketProperties properties;\n\n\t@Before\n\tpublic void setUp() throws Exception {\n\t\tproperties = new ZuulWebSocketProperties();\n\t}\n\n\t@Test\n\tpublic void brokerageIdSet() throws Exception {\n\t\tZuulWebSocketProperties.WsBrokerage brokerage = new ZuulWebSocketProperties.WsBrokerage();\n\t\tbrokerage.setId(\"bar\");\n\t\tMap<String, ZuulWebSocketProperties.WsBrokerage> brokerages = new HashMap<>();\n\t\tbrokerages.put(\"foo\", brokerage);\n\n\t\tproperties.setBrokerages(brokerages);\n\n\t\tproperties.init();\n\n\t\tassertThat(brokerage.getId(), is(\"bar\"));\n\t}\n\n\t@Test\n\tpublic void brokerageIdNotSet() throws Exception {\n\t\tZuulWebSocketProperties.WsBrokerage brokerage = new ZuulWebSocketProperties.WsBrokerage();\n\t\tMap<String, ZuulWebSocketProperties.WsBrokerage> brokerages = new HashMap<>();\n\t\tbrokerages.put(\"foo\", brokerage);\n\n\t\tproperties.setBrokerages(brokerages);\n\n\t\tproperties.init();\n\n\t\tassertThat(brokerage.getId(), is(\"foo\"));\n\t}\n}"
  }
]