Advertisement
Guest User

Patch

a guest
Apr 7th, 2020
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.79 KB | None | 0 0
  1. --- a/java/org/apache/catalina/connector/Connector.java
  2. +++ b/java/org/apache/catalina/connector/Connector.java
  3. @@ -35,7 +35,6 @@
  4. import org.apache.coyote.Adapter;
  5. import org.apache.coyote.ProtocolHandler;
  6. import org.apache.coyote.UpgradeProtocol;
  7. -import org.apache.coyote.ajp.AbstractAjpProtocol;
  8. import org.apache.coyote.http11.AbstractHttp11JsseProtocol;
  9. import org.apache.juli.logging.Log;
  10. import org.apache.juli.logging.LogFactory;
  11. @@ -64,40 +63,48 @@
  12.  
  13. // ------------------------------------------------------------ Constructor
  14.  
  15. +
  16. /**
  17. * Defaults to using HTTP/1.1 NIO implementation.
  18. */
  19. public Connector() {
  20. - this("org.apache.coyote.http11.Http11NioProtocol");
  21. + this("HTTP/1.1");
  22. }
  23.  
  24.  
  25. public Connector(String protocol) {
  26. if ("HTTP/1.1".equals(protocol) || protocol == null) {
  27. - protocolHandlerClassName = "org.apache.coyote.http11.Http11NioProtocol";
  28. + protocolHandlerClassName = org.apache.coyote.http11.Http11NioProtocol.class.getName();
  29. + this.protocolHandler = new org.apache.coyote.http11.Http11NioProtocol();
  30. } else if ("AJP/1.3".equals(protocol)) {
  31. - protocolHandlerClassName = "org.apache.coyote.ajp.AjpNioProtocol";
  32. + protocolHandlerClassName = org.apache.coyote.ajp.AjpNioProtocol.class.getName();
  33. + this.protocolHandler = new org.apache.coyote.ajp.AjpNioProtocol();
  34. } else {
  35. protocolHandlerClassName = protocol;
  36. + // Instantiate protocol handler
  37. + ProtocolHandler p = null;
  38. + try {
  39. + Class<?> clazz = Class.forName(protocolHandlerClassName);
  40. + p = (ProtocolHandler) clazz.getConstructor().newInstance();
  41. + } catch (Exception e) {
  42. + log.error(sm.getString(
  43. + "coyoteConnector.protocolHandlerInstantiationFailed"), e);
  44. + } finally {
  45. + this.protocolHandler = p;
  46. + }
  47. }
  48. -
  49. - // Instantiate protocol handler
  50. - ProtocolHandler p = null;
  51. - try {
  52. - Class<?> clazz = Class.forName(protocolHandlerClassName);
  53. - p = (ProtocolHandler) clazz.getConstructor().newInstance();
  54. - } catch (Exception e) {
  55. - log.error(sm.getString(
  56. - "coyoteConnector.protocolHandlerInstantiationFailed"), e);
  57. - } finally {
  58. - this.protocolHandler = p;
  59. - }
  60. -
  61. // Default for Connector depends on this system property
  62. setThrowOnFailure(Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"));
  63. }
  64.  
  65.  
  66. + public Connector(ProtocolHandler protocolHandler) {
  67. + protocolHandlerClassName = protocolHandler.getClass().getName();
  68. + this.protocolHandler = protocolHandler;
  69. + // Default for Connector depends on this system property
  70. + setThrowOnFailure(Boolean.getBoolean("org.apache.catalina.startup.EXIT_ON_INIT_FAILURE"));
  71. + }
  72. +
  73. // ----------------------------------------------------- Instance Variables
  74.  
  75.  
  76. @@ -946,9 +953,9 @@
  77. * @return a new Servlet response object
  78. */
  79. public Response createResponse() {
  80. - if (protocolHandler instanceof AbstractAjpProtocol<?>) {
  81. - int packetSize = ((AbstractAjpProtocol<?>) protocolHandler).getPacketSize();
  82. - return new Response(packetSize - org.apache.coyote.ajp.Constants.SEND_HEAD_LEN);
  83. + int size = protocolHandler.getDesiredBufferSize();
  84. + if (size > 0) {
  85. + return new Response(size);
  86. } else {
  87. return new Response();
  88. }
  89. diff --git a/java/org/apache/coyote/ProtocolHandler.java b/java/org/apache/coyote/ProtocolHandler.java
  90. index b467558..ce40d74 100644
  91. --- a/java/org/apache/coyote/ProtocolHandler.java
  92. +++ b/java/org/apache/coyote/ProtocolHandler.java
  93. @@ -179,4 +179,16 @@
  94. * @return the protocols
  95. */
  96. public UpgradeProtocol[] findUpgradeProtocols();
  97. +
  98. +
  99. + /**
  100. + * Some protocols, like AJP, have a packet length that
  101. + * shouldn't be exceeded, and this can be used to adjust the buffering
  102. + * used by the application layer.
  103. + * @return the desired buffer size, or -1 if not relevant
  104. + */
  105. + public default int getDesiredBufferSize() {
  106. + return -1;
  107. + }
  108. +
  109. }
  110. diff --git a/java/org/apache/coyote/ajp/AbstractAjpProtocol.java b/java/org/apache/coyote/ajp/AbstractAjpProtocol.java
  111. index abf8e60..93f0bab 100644
  112. --- a/java/org/apache/coyote/ajp/AbstractAjpProtocol.java
  113. +++ b/java/org/apache/coyote/ajp/AbstractAjpProtocol.java
  114. @@ -207,7 +207,7 @@
  115. private int packetSize = Constants.MAX_PACKET_SIZE;
  116. public int getPacketSize() { return packetSize; }
  117. public void setPacketSize(int packetSize) {
  118. - if(packetSize < Constants.MAX_PACKET_SIZE) {
  119. + if (packetSize < Constants.MAX_PACKET_SIZE) {
  120. this.packetSize = Constants.MAX_PACKET_SIZE;
  121. } else {
  122. this.packetSize = packetSize;
  123. @@ -215,6 +215,12 @@
  124. }
  125.  
  126.  
  127. + @Override
  128. + public int getDesiredBufferSize() {
  129. + return getPacketSize() - Constants.SEND_HEAD_LEN;
  130. + }
  131. +
  132. +
  133. // --------------------------------------------- SSL is not supported in AJP
  134.  
  135. @Override
  136. diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml
  137. index 02bda5e..ab27bb6 100644
  138. --- a/webapps/docs/changelog.xml
  139. +++ b/webapps/docs/changelog.xml
  140. @@ -62,6 +62,10 @@
  141. <code>Loader</code> interface as it is duplicated on the
  142. <code>Context</code> interface. (markt)
  143. </scode>
  144. + <fix>
  145. + Reduce reflection use and remove AJP specific code in the Connector.
  146. + (remm/markt/fhanik)
  147. + </fix>
  148. </changelog>
  149. </subsection>
  150. <subsection name="Coyote">
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement