-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moved and simplified CometDInput and CometDOutput.
Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
- Loading branch information
Showing
27 changed files
with
488 additions
and
512 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
146 changes: 146 additions & 0 deletions
146
...-java-server/cometd-java-server-common/src/main/java/org/cometd/server/CometDRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
/* | ||
* Copyright (c) 2008-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.cometd.server; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
import java.util.List; | ||
|
||
/** | ||
* <p>An abstraction over HTTP requests.</p> | ||
* <p>This abstraction allows CometD to be independent | ||
* from Servlet, or server-specific HTTP APIs.</p> | ||
*/ | ||
public interface CometDRequest { | ||
/** | ||
* @return the HTTP method | ||
*/ | ||
String getMethod(); | ||
|
||
/** | ||
* @return the HTTP protocol version | ||
*/ | ||
String getProtocol(); | ||
|
||
/** | ||
* @param name the query parameter name | ||
* @return the values of the given query parameter | ||
*/ | ||
String[] getParameterValues(String name); | ||
|
||
/** | ||
* @return the charset of the request body | ||
*/ | ||
String getCharacterEncoding(); | ||
|
||
/** | ||
* @return the request cookies | ||
*/ | ||
List<CometDCookie> getCookies(); | ||
|
||
/** | ||
* @return the input to read the request body from | ||
*/ | ||
Input getInput(); | ||
|
||
/** | ||
* @param name the attribute name | ||
* @return the value of the attribute with the given name, | ||
* or {@code null} if not such attribute exists | ||
*/ | ||
Object getAttribute(String name); | ||
|
||
/** | ||
* @param name the attribute name | ||
* @param value the attribute value | ||
*/ | ||
void setAttribute(String name, Object value); | ||
|
||
/** | ||
* @param name the cookie name | ||
* @param value the cookie value | ||
*/ | ||
record CometDCookie(String name, String value) { | ||
} | ||
|
||
/** | ||
* <p>The source of the request body.</p> | ||
*/ | ||
interface Input { | ||
/** | ||
* <p>Demands to invoke the given callback when request content bytes are available.</p> | ||
* | ||
* @param demandCallback the callback to invoke when request content bytes are available | ||
*/ | ||
void demand(Runnable demandCallback); | ||
|
||
/** | ||
* <p>Reads request content bytes into a {@link Chunk}.</p> | ||
* <p>The returned {@link Chunk} can be:</p> | ||
* <ul> | ||
* <li>{@code null}, if no request content bytes are available</li> | ||
* <li>a possibly empty {@link Chunk} of request content bytes</li> | ||
* </ul> | ||
* | ||
* @return a {@link Chunk} of request content bytes, | ||
* or {@code null} if no request content bytes are available | ||
* @throws IOException if the read fails | ||
*/ | ||
Chunk read() throws IOException; | ||
|
||
/** | ||
* <p>Request content bytes with the indication of whether they are the last.</p> | ||
*/ | ||
interface Chunk { | ||
/** | ||
* <p>A convenient {@link Chunk} constant indicating end-of-file.</p> | ||
*/ | ||
Chunk EOF = new Chunk() { | ||
private static final ByteBuffer EMPTY = ByteBuffer.allocate(0); | ||
|
||
@Override | ||
public ByteBuffer byteBuffer() { | ||
return EMPTY; | ||
} | ||
|
||
@Override | ||
public boolean isLast() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void release() { | ||
} | ||
}; | ||
|
||
/** | ||
* @return the {@link ByteBuffer} containing the request content bytes | ||
*/ | ||
ByteBuffer byteBuffer(); | ||
|
||
/** | ||
* @return whether this {@link Chunk} is the last | ||
*/ | ||
boolean isLast(); | ||
|
||
/** | ||
* <p>Releases this {@link Chunk} so its {@link #byteBuffer()} | ||
* can be recycled.</p> | ||
*/ | ||
void release(); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...java-server/cometd-java-server-common/src/main/java/org/cometd/server/CometDResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright (c) 2008-2022 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.cometd.server; | ||
|
||
import org.cometd.bayeux.Promise; | ||
|
||
/** | ||
* <p>An abstraction over HTTP responses.</p> | ||
* <p>This abstraction allows CometD to be independent | ||
* from Servlet, or server-specific HTTP APIs.</p> | ||
*/ | ||
public interface CometDResponse { | ||
/** | ||
* <p>Adds an HTTP header to this response.</p> | ||
* | ||
* @param name the HTTP header name | ||
* @param value the HTTP header value | ||
*/ | ||
void addHeader(String name, String value); | ||
|
||
/** | ||
* @param contentType the content type of the response body | ||
*/ | ||
void setContentType(String contentType); | ||
|
||
/** | ||
* @return the sink to write the response body to | ||
*/ | ||
Output getOutput(); | ||
|
||
/** | ||
* <p>The sink of the response body.</p> | ||
*/ | ||
interface Output { | ||
/** | ||
* <p>Writes the given response bytes, notifying the | ||
* given promise when the write operation is complete.</p> | ||
* | ||
* @param last whether the response bytes to write are the last | ||
* @param bytes the response bytes to write | ||
* @param promise the promise to notify when the write operation is complete | ||
*/ | ||
void write(boolean last, byte[] bytes, Promise<Void> promise); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
...ava-server/cometd-java-server-common/src/main/java/org/cometd/server/spi/CometDInput.java
This file was deleted.
Oops, something went wrong.
22 changes: 0 additions & 22 deletions
22
...va-server/cometd-java-server-common/src/main/java/org/cometd/server/spi/CometDOutput.java
This file was deleted.
Oops, something went wrong.
39 changes: 0 additions & 39 deletions
39
...a-server/cometd-java-server-common/src/main/java/org/cometd/server/spi/CometDRequest.java
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
...-server/cometd-java-server-common/src/main/java/org/cometd/server/spi/CometDResponse.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.