diff --git a/rsocket-core/src/main/java/io/rsocket/AbstractRSocket.java b/rsocket-core/src/main/java/io/rsocket/AbstractRSocket.java deleted file mode 100644 index 7f39956dc..000000000 --- a/rsocket-core/src/main/java/io/rsocket/AbstractRSocket.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright 2015-2018 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 io.rsocket; - -import reactor.core.publisher.Mono; -import reactor.core.publisher.MonoProcessor; - -/** - * An abstract implementation of {@link RSocket}. All request handling methods emit {@link - * UnsupportedOperationException} and hence must be overridden to provide a valid implementation. - * - * @deprecated as of 1.0 in favor of implementing {@link RSocket} directly which has default - * methods. - */ -@Deprecated -public abstract class AbstractRSocket implements RSocket { - - private final MonoProcessor onClose = MonoProcessor.create(); - - @Override - public void dispose() { - onClose.onComplete(); - } - - @Override - public boolean isDisposed() { - return onClose.isDisposed(); - } - - @Override - public Mono onClose() { - return onClose; - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/ConnectionSetupPayload.java b/rsocket-core/src/main/java/io/rsocket/ConnectionSetupPayload.java index ece2aa9fa..c39e679a1 100644 --- a/rsocket-core/src/main/java/io/rsocket/ConnectionSetupPayload.java +++ b/rsocket-core/src/main/java/io/rsocket/ConnectionSetupPayload.java @@ -18,7 +18,6 @@ import io.netty.buffer.ByteBuf; import io.netty.util.AbstractReferenceCounted; -import io.rsocket.core.DefaultConnectionSetupPayload; import reactor.util.annotation.Nullable; /** @@ -57,16 +56,4 @@ public ConnectionSetupPayload retain(int increment) { @Override public abstract ConnectionSetupPayload touch(); - - /** - * Create a {@code ConnectionSetupPayload}. - * - * @deprecated as of 1.0 RC7. Please, use {@link - * DefaultConnectionSetupPayload#DefaultConnectionSetupPayload(ByteBuf) - * DefaultConnectionSetupPayload} constructor. - */ - @Deprecated - public static ConnectionSetupPayload create(final ByteBuf setupFrame) { - return new DefaultConnectionSetupPayload(setupFrame); - } } diff --git a/rsocket-core/src/main/java/io/rsocket/RSocketFactory.java b/rsocket-core/src/main/java/io/rsocket/RSocketFactory.java deleted file mode 100644 index e23bcceb2..000000000 --- a/rsocket-core/src/main/java/io/rsocket/RSocketFactory.java +++ /dev/null @@ -1,571 +0,0 @@ -/* - * Copyright 2015-2020 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 - * - * https://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 io.rsocket; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.Unpooled; -import io.rsocket.core.RSocketConnector; -import io.rsocket.core.RSocketServer; -import io.rsocket.core.Resume; -import io.rsocket.frame.decoder.PayloadDecoder; -import io.rsocket.lease.LeaseStats; -import io.rsocket.lease.Leases; -import io.rsocket.plugins.DuplexConnectionInterceptor; -import io.rsocket.plugins.RSocketInterceptor; -import io.rsocket.plugins.SocketAcceptorInterceptor; -import io.rsocket.resume.ClientResume; -import io.rsocket.resume.ResumableFramesStore; -import io.rsocket.resume.ResumeStrategy; -import io.rsocket.transport.ClientTransport; -import io.rsocket.transport.ServerTransport; -import java.time.Duration; -import java.util.function.Consumer; -import java.util.function.Function; -import java.util.function.Supplier; -import reactor.core.publisher.Mono; -import reactor.util.retry.Retry; - -/** - * Main entry point to create RSocket clients or servers as follows: - * - * - * - * @deprecated please use {@link RSocketConnector} and {@link RSocketServer}. - */ -@Deprecated -public final class RSocketFactory { - - /** - * Create a {@code ClientRSocketFactory} to connect to a remote RSocket endpoint. Internally - * delegates to {@link RSocketConnector}. - * - * @return the {@code ClientRSocketFactory} instance - */ - public static ClientRSocketFactory connect() { - return new ClientRSocketFactory(); - } - - /** - * Create a {@code ServerRSocketFactory} to accept connections from RSocket clients. Internally - * delegates to {@link RSocketServer}. - * - * @return the {@code ClientRSocketFactory} instance - */ - public static ServerRSocketFactory receive() { - return new ServerRSocketFactory(); - } - - public interface Start { - Mono start(); - } - - public interface ClientTransportAcceptor { - Start transport(Supplier transport); - - default Start transport(ClientTransport transport) { - return transport(() -> transport); - } - } - - public interface ServerTransportAcceptor { - - ServerTransport.ConnectionAcceptor toConnectionAcceptor(); - - Start transport(Supplier> transport); - - default Start transport(ServerTransport transport) { - return transport(() -> transport); - } - } - - /** Factory to create and configure an RSocket client, and connect to a server. */ - public static class ClientRSocketFactory implements ClientTransportAcceptor { - private static final ClientResume CLIENT_RESUME = - new ClientResume(Duration.ofMinutes(2), Unpooled.EMPTY_BUFFER); - - private final RSocketConnector connector; - - private Duration tickPeriod = Duration.ofSeconds(20); - private Duration ackTimeout = Duration.ofSeconds(30); - private int missedAcks = 3; - - private Resume resume; - - public ClientRSocketFactory() { - this(RSocketConnector.create()); - } - - public ClientRSocketFactory(RSocketConnector connector) { - this.connector = connector; - } - - /** - * @deprecated this method is deprecated and deliberately has no effect anymore. Right now, in - * order configure the custom {@link ByteBufAllocator} it is recommended to use the - * following setup for Reactor Netty based transport:
- * 1. For Client:
- *
{@code
-     * TcpClient.create()
-     *          ...
-     *          .bootstrap(bootstrap -> bootstrap.option(ChannelOption.ALLOCATOR, clientAllocator))
-     * }
- *
- * 2. For server:
- *
{@code
-     * TcpServer.create()
-     *          ...
-     *          .bootstrap(serverBootstrap -> serverBootstrap.childOption(ChannelOption.ALLOCATOR, serverAllocator))
-     * }
- * Or in case of local transport, to use corresponding factory method {@code - * LocalClientTransport.creat(String, ByteBufAllocator)} - * @param allocator instance of {@link ByteBufAllocator} - * @return this factory instance - */ - public ClientRSocketFactory byteBufAllocator(ByteBufAllocator allocator) { - return this; - } - - public ClientRSocketFactory addConnectionPlugin(DuplexConnectionInterceptor interceptor) { - connector.interceptors(registry -> registry.forConnection(interceptor)); - return this; - } - - /** Deprecated. Use {@link #addRequesterPlugin(RSocketInterceptor)} instead */ - @Deprecated - public ClientRSocketFactory addClientPlugin(RSocketInterceptor interceptor) { - return addRequesterPlugin(interceptor); - } - - public ClientRSocketFactory addRequesterPlugin(RSocketInterceptor interceptor) { - connector.interceptors(registry -> registry.forRequester(interceptor)); - return this; - } - - /** Deprecated. Use {@link #addResponderPlugin(RSocketInterceptor)} instead */ - @Deprecated - public ClientRSocketFactory addServerPlugin(RSocketInterceptor interceptor) { - return addResponderPlugin(interceptor); - } - - public ClientRSocketFactory addResponderPlugin(RSocketInterceptor interceptor) { - connector.interceptors(registry -> registry.forResponder(interceptor)); - return this; - } - - public ClientRSocketFactory addSocketAcceptorPlugin(SocketAcceptorInterceptor interceptor) { - connector.interceptors(registry -> registry.forSocketAcceptor(interceptor)); - return this; - } - - /** - * Deprecated without replacement as Keep-Alive is not optional according to spec - * - * @return this ClientRSocketFactory - */ - @Deprecated - public ClientRSocketFactory keepAlive() { - connector.keepAlive(tickPeriod, ackTimeout.plus(tickPeriod.multipliedBy(missedAcks))); - return this; - } - - public ClientTransportAcceptor keepAlive( - Duration tickPeriod, Duration ackTimeout, int missedAcks) { - this.tickPeriod = tickPeriod; - this.ackTimeout = ackTimeout; - this.missedAcks = missedAcks; - keepAlive(); - return this; - } - - public ClientRSocketFactory keepAliveTickPeriod(Duration tickPeriod) { - this.tickPeriod = tickPeriod; - keepAlive(); - return this; - } - - public ClientRSocketFactory keepAliveAckTimeout(Duration ackTimeout) { - this.ackTimeout = ackTimeout; - keepAlive(); - return this; - } - - public ClientRSocketFactory keepAliveMissedAcks(int missedAcks) { - this.missedAcks = missedAcks; - keepAlive(); - return this; - } - - public ClientRSocketFactory mimeType(String metadataMimeType, String dataMimeType) { - connector.metadataMimeType(metadataMimeType); - connector.dataMimeType(dataMimeType); - return this; - } - - public ClientRSocketFactory dataMimeType(String dataMimeType) { - connector.dataMimeType(dataMimeType); - return this; - } - - public ClientRSocketFactory metadataMimeType(String metadataMimeType) { - connector.metadataMimeType(metadataMimeType); - return this; - } - - public ClientRSocketFactory lease(Supplier> supplier) { - connector.lease(supplier); - return this; - } - - public ClientRSocketFactory lease() { - connector.lease(Leases::new); - return this; - } - - /** @deprecated without a replacement and no longer used. */ - @Deprecated - public ClientRSocketFactory singleSubscriberRequester() { - return this; - } - - /** - * Enables a reconnectable, shared instance of {@code Mono} so every subscriber will - * observe the same RSocket instance up on connection establishment.
- * For example: - * - *
{@code
-     * Mono sharedRSocketMono =
-     *   RSocketFactory
-     *                .connect()
-     *                .reconnect(Retry.fixedDelay(3, Duration.ofSeconds(1)))
-     *                .transport(transport)
-     *                .start();
-     *
-     *  RSocket r1 = sharedRSocketMono.block();
-     *  RSocket r2 = sharedRSocketMono.block();
-     *
-     *  assert r1 == r2;
-     *
-     * }
- * - * Apart of the shared behavior, if the connection is lost, the same {@code Mono} - * instance will transparently re-establish the connection for subsequent subscribers.
- * For example: - * - *
{@code
-     * Mono sharedRSocketMono =
-     *   RSocketFactory
-     *                .connect()
-     *                .reconnect(Retry.fixedDelay(3, Duration.ofSeconds(1)))
-     *                .transport(transport)
-     *                .start();
-     *
-     *  RSocket r1 = sharedRSocketMono.block();
-     *  RSocket r2 = sharedRSocketMono.block();
-     *
-     *  assert r1 == r2;
-     *
-     *  r1.dispose()
-     *
-     *  assert r2.isDisposed()
-     *
-     *  RSocket r3 = sharedRSocketMono.block();
-     *  RSocket r4 = sharedRSocketMono.block();
-     *
-     *
-     *  assert r1 != r3;
-     *  assert r4 == r3;
-     *
-     * }
- * - * Note, having reconnect() enabled does not eliminate the need to accompany each - * individual request with the corresponding retry logic.
- * For example: - * - *
{@code
-     * Mono sharedRSocketMono =
-     *   RSocketFactory
-     *                .connect()
-     *                .reconnect(Retry.fixedDelay(3, Duration.ofSeconds(1)))
-     *                .transport(transport)
-     *                .start();
-     *
-     *  sharedRSocket.flatMap(rSocket -> rSocket.requestResponse(...))
-     *               .retryWhen(ownRetry)
-     *               .subscribe()
-     *
-     * }
- * - * @param retrySpec a retry factory applied for {@link Mono#retryWhen(Retry)} - * @return a shared instance of {@code Mono}. - */ - public ClientRSocketFactory reconnect(Retry retrySpec) { - connector.reconnect(retrySpec); - return this; - } - - public ClientRSocketFactory resume() { - resume = resume != null ? resume : new Resume(); - connector.resume(resume); - return this; - } - - public ClientRSocketFactory resumeToken(Supplier supplier) { - resume(); - resume.token(supplier); - return this; - } - - public ClientRSocketFactory resumeStore( - Function storeFactory) { - resume(); - resume.storeFactory(storeFactory); - return this; - } - - public ClientRSocketFactory resumeSessionDuration(Duration sessionDuration) { - resume(); - resume.sessionDuration(sessionDuration); - return this; - } - - public ClientRSocketFactory resumeStreamTimeout(Duration streamTimeout) { - resume(); - resume.streamTimeout(streamTimeout); - return this; - } - - public ClientRSocketFactory resumeStrategy(Supplier strategy) { - resume(); - resume.retry( - Retry.from( - signals -> signals.flatMap(s -> strategy.get().apply(CLIENT_RESUME, s.failure())))); - return this; - } - - public ClientRSocketFactory resumeCleanupOnKeepAlive() { - resume(); - resume.cleanupStoreOnKeepAlive(); - return this; - } - - public Start transport(Supplier transport) { - return () -> connector.connect(transport); - } - - public ClientTransportAcceptor acceptor(Function acceptor) { - return acceptor(() -> acceptor); - } - - public ClientTransportAcceptor acceptor(Supplier> acceptorSupplier) { - return acceptor( - (setup, sendingSocket) -> { - acceptorSupplier.get().apply(sendingSocket); - return Mono.empty(); - }); - } - - public ClientTransportAcceptor acceptor(SocketAcceptor acceptor) { - connector.acceptor(acceptor); - return this; - } - - public ClientRSocketFactory fragment(int mtu) { - connector.fragment(mtu); - return this; - } - - /** - * @deprecated this handler is deliberately no-ops and is deprecated with no replacement. In - * order to observe errors, it is recommended to add error handler using {@code doOnError} - * on the specific logical stream. In order to observe connection, or RSocket terminal - * errors, it is recommended to hook on {@link Closeable#onClose()} handler. - */ - public ClientRSocketFactory errorConsumer(Consumer errorConsumer) { - return this; - } - - public ClientRSocketFactory setupPayload(Payload payload) { - connector.setupPayload(payload); - return this; - } - - public ClientRSocketFactory frameDecoder(PayloadDecoder payloadDecoder) { - connector.payloadDecoder(payloadDecoder); - return this; - } - } - - /** Factory to create, configure, and start an RSocket server. */ - public static class ServerRSocketFactory implements ServerTransportAcceptor { - private final RSocketServer server; - - private Resume resume; - - public ServerRSocketFactory() { - this(RSocketServer.create()); - } - - public ServerRSocketFactory(RSocketServer server) { - this.server = server; - } - - /** - * @deprecated this method is deprecated and deliberately has no effect anymore. Right now, in - * order configure the custom {@link ByteBufAllocator} it is recommended to use the - * following setup for Reactor Netty based transport:
- * 1. For Client:
- *
{@code
-     * TcpClient.create()
-     *          ...
-     *          .bootstrap(bootstrap -> bootstrap.option(ChannelOption.ALLOCATOR, clientAllocator))
-     * }
- *
- * 2. For server:
- *
{@code
-     * TcpServer.create()
-     *          ...
-     *          .bootstrap(serverBootstrap -> serverBootstrap.childOption(ChannelOption.ALLOCATOR, serverAllocator))
-     * }
- * Or in case of local transport, to use corresponding factory method {@code - * LocalClientTransport.creat(String, ByteBufAllocator)} - * @param allocator instance of {@link ByteBufAllocator} - * @return this factory instance - */ - @Deprecated - public ServerRSocketFactory byteBufAllocator(ByteBufAllocator allocator) { - return this; - } - - public ServerRSocketFactory addConnectionPlugin(DuplexConnectionInterceptor interceptor) { - server.interceptors(registry -> registry.forConnection(interceptor)); - return this; - } - /** Deprecated. Use {@link #addRequesterPlugin(RSocketInterceptor)} instead */ - @Deprecated - public ServerRSocketFactory addClientPlugin(RSocketInterceptor interceptor) { - return addRequesterPlugin(interceptor); - } - - public ServerRSocketFactory addRequesterPlugin(RSocketInterceptor interceptor) { - server.interceptors(registry -> registry.forRequester(interceptor)); - return this; - } - - /** Deprecated. Use {@link #addResponderPlugin(RSocketInterceptor)} instead */ - @Deprecated - public ServerRSocketFactory addServerPlugin(RSocketInterceptor interceptor) { - return addResponderPlugin(interceptor); - } - - public ServerRSocketFactory addResponderPlugin(RSocketInterceptor interceptor) { - server.interceptors(registry -> registry.forResponder(interceptor)); - return this; - } - - public ServerRSocketFactory addSocketAcceptorPlugin(SocketAcceptorInterceptor interceptor) { - server.interceptors(registry -> registry.forSocketAcceptor(interceptor)); - return this; - } - - public ServerTransportAcceptor acceptor(SocketAcceptor acceptor) { - server.acceptor(acceptor); - return this; - } - - public ServerRSocketFactory frameDecoder(PayloadDecoder payloadDecoder) { - server.payloadDecoder(payloadDecoder); - return this; - } - - public ServerRSocketFactory fragment(int mtu) { - server.fragment(mtu); - return this; - } - - /** - * @deprecated this handler is deliberately no-ops and is deprecated with no replacement. In - * order to observe errors, it is recommended to add error handler using {@code doOnError} - * on the specific logical stream. In order to observe connection, or RSocket terminal - * errors, it is recommended to hook on {@link Closeable#onClose()} handler. - */ - public ServerRSocketFactory errorConsumer(Consumer errorConsumer) { - return this; - } - - public ServerRSocketFactory lease(Supplier> supplier) { - server.lease(supplier); - return this; - } - - public ServerRSocketFactory lease() { - server.lease(Leases::new); - return this; - } - - /** @deprecated without a replacement and no longer used. */ - @Deprecated - public ServerRSocketFactory singleSubscriberRequester() { - return this; - } - - public ServerRSocketFactory resume() { - resume = resume != null ? resume : new Resume(); - server.resume(resume); - return this; - } - - public ServerRSocketFactory resumeStore( - Function storeFactory) { - resume(); - resume.storeFactory(storeFactory); - return this; - } - - public ServerRSocketFactory resumeSessionDuration(Duration sessionDuration) { - resume(); - resume.sessionDuration(sessionDuration); - return this; - } - - public ServerRSocketFactory resumeStreamTimeout(Duration streamTimeout) { - resume(); - resume.streamTimeout(streamTimeout); - return this; - } - - public ServerRSocketFactory resumeCleanupOnKeepAlive() { - resume(); - resume.cleanupStoreOnKeepAlive(); - return this; - } - - @Override - public ServerTransport.ConnectionAcceptor toConnectionAcceptor() { - return server.asConnectionAcceptor(); - } - - @Override - public Start transport(Supplier> transport) { - return () -> server.bind(transport.get()); - } - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/ResponderRSocket.java b/rsocket-core/src/main/java/io/rsocket/ResponderRSocket.java deleted file mode 100644 index 22697f130..000000000 --- a/rsocket-core/src/main/java/io/rsocket/ResponderRSocket.java +++ /dev/null @@ -1,28 +0,0 @@ -package io.rsocket; - -import java.util.function.BiFunction; -import org.reactivestreams.Publisher; -import reactor.core.publisher.Flux; - -/** - * Extends the {@link RSocket} that allows an implementer to peek at the first request payload of a - * channel. - * - * @deprecated as of 1.0 RC7 in favor of using {@link RSocket#requestChannel(Publisher)} with {@link - * Flux#switchOnFirst(BiFunction)} - */ -@Deprecated -public interface ResponderRSocket extends RSocket { - /** - * Implement this method to peak at the first payload of the incoming request stream without - * having to subscribe to Publish<Payload> payloads - * - * @param payload First payload in the stream - this is the same payload as the first payload in - * Publisher<Payload> payloads - * @param payloads Stream of request payloads. - * @return Stream of response payloads. - */ - default Flux requestChannel(Payload payload, Publisher payloads) { - return requestChannel(payloads); - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/core/RSocketResponder.java b/rsocket-core/src/main/java/io/rsocket/core/RSocketResponder.java index c80ecc035..de6f3d0db 100644 --- a/rsocket-core/src/main/java/io/rsocket/core/RSocketResponder.java +++ b/rsocket-core/src/main/java/io/rsocket/core/RSocketResponder.java @@ -20,7 +20,6 @@ import io.rsocket.DuplexConnection; import io.rsocket.Payload; import io.rsocket.RSocket; -import io.rsocket.ResponderRSocket; import io.rsocket.exceptions.ConnectionErrorException; import io.rsocket.frame.ErrorFrameCodec; import io.rsocket.frame.FrameHeaderCodec; @@ -52,9 +51,6 @@ class RSocketResponder extends RequesterResponderSupport implements RSocket { private final DuplexConnection connection; private final RSocket requestHandler; - @SuppressWarnings("deprecation") - private final io.rsocket.ResponderRSocket responderRSocket; - private final ResponderLeaseHandler leaseHandler; private final Disposable leaseHandlerDisposable; @@ -75,10 +71,6 @@ class RSocketResponder extends RequesterResponderSupport implements RSocket { this.connection = connection; this.requestHandler = requestHandler; - this.responderRSocket = - (requestHandler instanceof io.rsocket.ResponderRSocket) - ? (io.rsocket.ResponderRSocket) requestHandler - : null; this.leaseHandler = leaseHandler; @@ -177,12 +169,7 @@ public Flux requestChannel(Publisher payloads) { private Flux requestChannel(Payload payload, Publisher payloads) { try { if (leaseHandler.useLease()) { - final ResponderRSocket responderRSocket = this.responderRSocket; - if (responderRSocket != null) { - return responderRSocket.requestChannel(payload, payloads); - } else { - return requestHandler.requestChannel(payloads); - } + return requestHandler.requestChannel(payloads); } else { payload.release(); return Flux.error(leaseHandler.leaseError()); diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/ApplicationErrorException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/ApplicationErrorException.java index cd0d46754..40cb15dd6 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/ApplicationErrorException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/ApplicationErrorException.java @@ -16,6 +16,7 @@ package io.rsocket.exceptions; +import io.rsocket.RSocketErrorException; import io.rsocket.frame.ErrorFrameCodec; import reactor.util.annotation.Nullable; @@ -25,7 +26,7 @@ * @see Error * Codes */ -public final class ApplicationErrorException extends RSocketException { +public final class ApplicationErrorException extends RSocketErrorException { private static final long serialVersionUID = 7873267740343446585L; diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/CanceledException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/CanceledException.java index d51ba0fb7..144ef94c6 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/CanceledException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/CanceledException.java @@ -16,6 +16,7 @@ package io.rsocket.exceptions; +import io.rsocket.RSocketErrorException; import io.rsocket.frame.ErrorFrameCodec; import reactor.util.annotation.Nullable; @@ -26,7 +27,7 @@ * @see Error * Codes */ -public final class CanceledException extends RSocketException { +public final class CanceledException extends RSocketErrorException { private static final long serialVersionUID = 5074789326089722770L; diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/ConnectionCloseException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/ConnectionCloseException.java index 80324aa90..1e0167bdd 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/ConnectionCloseException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/ConnectionCloseException.java @@ -16,6 +16,7 @@ package io.rsocket.exceptions; +import io.rsocket.RSocketErrorException; import io.rsocket.frame.ErrorFrameCodec; import reactor.util.annotation.Nullable; @@ -26,7 +27,7 @@ * @see Error * Codes */ -public final class ConnectionCloseException extends RSocketException { +public final class ConnectionCloseException extends RSocketErrorException { private static final long serialVersionUID = -2214953527482377471L; diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/ConnectionErrorException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/ConnectionErrorException.java index b44714f7e..5cf7cff66 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/ConnectionErrorException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/ConnectionErrorException.java @@ -16,6 +16,7 @@ package io.rsocket.exceptions; +import io.rsocket.RSocketErrorException; import io.rsocket.frame.ErrorFrameCodec; import reactor.util.annotation.Nullable; @@ -26,7 +27,7 @@ * @see Error * Codes */ -public final class ConnectionErrorException extends RSocketException implements Retryable { +public final class ConnectionErrorException extends RSocketErrorException implements Retryable { private static final long serialVersionUID = 512325887785119744L; diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/CustomRSocketException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/CustomRSocketException.java index 079b561f9..a72c0ba3b 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/CustomRSocketException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/CustomRSocketException.java @@ -16,10 +16,11 @@ package io.rsocket.exceptions; +import io.rsocket.RSocketErrorException; import io.rsocket.frame.ErrorFrameCodec; import reactor.util.annotation.Nullable; -public class CustomRSocketException extends RSocketException { +public class CustomRSocketException extends RSocketErrorException { private static final long serialVersionUID = 7873267740343446585L; /** diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/InvalidException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/InvalidException.java index a1b77b8dd..c556423b9 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/InvalidException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/InvalidException.java @@ -16,6 +16,7 @@ package io.rsocket.exceptions; +import io.rsocket.RSocketErrorException; import io.rsocket.frame.ErrorFrameCodec; import reactor.util.annotation.Nullable; @@ -25,7 +26,7 @@ * @see Error * Codes */ -public final class InvalidException extends RSocketException { +public final class InvalidException extends RSocketErrorException { private static final long serialVersionUID = 8279420324864928243L; diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/RSocketException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/RSocketException.java deleted file mode 100644 index 2b137282f..000000000 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/RSocketException.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2015-2020 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 io.rsocket.exceptions; - -import io.rsocket.RSocketErrorException; -import io.rsocket.frame.ErrorFrameCodec; -import reactor.util.annotation.Nullable; - -/** - * The root of the RSocket exception hierarchy. - * - * @deprecated please use {@link RSocketErrorException} instead - */ -@Deprecated -public abstract class RSocketException extends RSocketErrorException { - - private static final long serialVersionUID = 2912815394105575423L; - - /** - * Constructs a new exception with the specified message and error code 0x201 (Application error). - * - * @param message the message - */ - public RSocketException(String message) { - this(message, null); - } - - /** - * Constructs a new exception with the specified message and cause and error code 0x201 - * (Application error). - * - * @param message the message - * @param cause the cause of this exception - */ - public RSocketException(String message, @Nullable Throwable cause) { - super(ErrorFrameCodec.APPLICATION_ERROR, message, cause); - } - - /** - * Constructs a new exception with the specified error code, message and cause. - * - * @param errorCode the RSocket protocol error code - * @param message the message - * @param cause the cause of this exception - */ - public RSocketException(int errorCode, String message, @Nullable Throwable cause) { - super(errorCode, message, cause); - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/RejectedException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/RejectedException.java index baed84e1b..8bc946e3d 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/RejectedException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/RejectedException.java @@ -16,6 +16,7 @@ package io.rsocket.exceptions; +import io.rsocket.RSocketErrorException; import io.rsocket.frame.ErrorFrameCodec; import reactor.util.annotation.Nullable; @@ -27,7 +28,7 @@ * @see Error * Codes */ -public class RejectedException extends RSocketException implements Retryable { +public class RejectedException extends RSocketErrorException implements Retryable { private static final long serialVersionUID = 3926231092835143715L; diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/RejectedResumeException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/RejectedResumeException.java index 8a99fcffb..44cc55710 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/RejectedResumeException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/RejectedResumeException.java @@ -16,6 +16,7 @@ package io.rsocket.exceptions; +import io.rsocket.RSocketErrorException; import io.rsocket.frame.ErrorFrameCodec; import reactor.util.annotation.Nullable; @@ -25,7 +26,7 @@ * @see Error * Codes */ -public final class RejectedResumeException extends RSocketException { +public final class RejectedResumeException extends RSocketErrorException { private static final long serialVersionUID = -873684362478544811L; diff --git a/rsocket-core/src/main/java/io/rsocket/exceptions/SetupException.java b/rsocket-core/src/main/java/io/rsocket/exceptions/SetupException.java index ed979c9e6..76dc39a59 100644 --- a/rsocket-core/src/main/java/io/rsocket/exceptions/SetupException.java +++ b/rsocket-core/src/main/java/io/rsocket/exceptions/SetupException.java @@ -16,37 +16,14 @@ package io.rsocket.exceptions; -import io.rsocket.frame.ErrorFrameCodec; +import io.rsocket.RSocketErrorException; import reactor.util.annotation.Nullable; /** The root of the setup exception hierarchy. */ -public abstract class SetupException extends RSocketException { +public abstract class SetupException extends RSocketErrorException { private static final long serialVersionUID = -2928269501877732756L; - /** - * Constructs a new exception with the specified message. - * - * @param message the message - * @deprecated please use {@link #SetupException(int, String, Throwable)} - */ - @Deprecated - public SetupException(String message) { - this(message, null); - } - - /** - * Constructs a new exception with the specified message and cause. - * - * @param message the message - * @param cause the cause of this exception - * @deprecated please use {@link #SetupException(int, String, Throwable)} - */ - @Deprecated - public SetupException(String message, @Nullable Throwable cause) { - this(ErrorFrameCodec.INVALID_SETUP, message, cause); - } - /** * Constructs a new exception with the specified error code, message and cause. * diff --git a/rsocket-core/src/main/java/io/rsocket/keepalive/KeepAliveSupport.java b/rsocket-core/src/main/java/io/rsocket/keepalive/KeepAliveSupport.java index a67226ada..6a3ab40d3 100644 --- a/rsocket-core/src/main/java/io/rsocket/keepalive/KeepAliveSupport.java +++ b/rsocket-core/src/main/java/io/rsocket/keepalive/KeepAliveSupport.java @@ -140,24 +140,6 @@ public boolean isDisposed() { return ticksDisposable.isDisposed(); } - /** - * @deprecated since it should not be used anymore and will be completely removed in 1.1. - * Keepalive is symmetric on both side and implemented as a part of RSocketRequester - */ - @Deprecated - public static final class ServerKeepAliveSupport extends KeepAliveSupport { - - public ServerKeepAliveSupport( - ByteBufAllocator allocator, int keepAlivePeriod, int keepAliveTimeout) { - super(allocator, keepAlivePeriod, keepAliveTimeout); - } - - @Override - void onIntervalTick() { - tryTimeout(); - } - } - public static final class ClientKeepAliveSupport extends KeepAliveSupport { public ClientKeepAliveSupport( diff --git a/rsocket-core/src/main/java/io/rsocket/metadata/CompositeMetadata.java b/rsocket-core/src/main/java/io/rsocket/metadata/CompositeMetadata.java index 4a48921b1..1c3ae9423 100644 --- a/rsocket-core/src/main/java/io/rsocket/metadata/CompositeMetadata.java +++ b/rsocket-core/src/main/java/io/rsocket/metadata/CompositeMetadata.java @@ -16,12 +16,12 @@ package io.rsocket.metadata; -import static io.rsocket.metadata.CompositeMetadataFlyweight.computeNextEntryIndex; -import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeAndContentBuffersSlices; -import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeIdFromMimeBuffer; -import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeTypeFromMimeBuffer; -import static io.rsocket.metadata.CompositeMetadataFlyweight.hasEntry; -import static io.rsocket.metadata.CompositeMetadataFlyweight.isWellKnownMimeType; +import static io.rsocket.metadata.CompositeMetadataCodec.computeNextEntryIndex; +import static io.rsocket.metadata.CompositeMetadataCodec.decodeMimeAndContentBuffersSlices; +import static io.rsocket.metadata.CompositeMetadataCodec.decodeMimeIdFromMimeBuffer; +import static io.rsocket.metadata.CompositeMetadataCodec.decodeMimeTypeFromMimeBuffer; +import static io.rsocket.metadata.CompositeMetadataCodec.hasEntry; +import static io.rsocket.metadata.CompositeMetadataCodec.isWellKnownMimeType; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; @@ -52,8 +52,8 @@ * ReservedMimeTypeEntry}. In this case {@link Entry#getMimeType()} will return {@code null}. The * encoded id can be retrieved using {@link ReservedMimeTypeEntry#getType()}. The byte and content * buffer should be kept around and re-encoded using {@link - * CompositeMetadataFlyweight#encodeAndAddMetadata(CompositeByteBuf, ByteBufAllocator, byte, - * ByteBuf)} in case passing that entry through is required. + * CompositeMetadataCodec#encodeAndAddMetadata(CompositeByteBuf, ByteBufAllocator, byte, ByteBuf)} + * in case passing that entry through is required. */ public final class CompositeMetadata implements Iterable { diff --git a/rsocket-core/src/main/java/io/rsocket/metadata/CompositeMetadataFlyweight.java b/rsocket-core/src/main/java/io/rsocket/metadata/CompositeMetadataFlyweight.java deleted file mode 100644 index 9916dfd3b..000000000 --- a/rsocket-core/src/main/java/io/rsocket/metadata/CompositeMetadataFlyweight.java +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright 2015-2018 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 io.rsocket.metadata; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.CompositeByteBuf; -import reactor.util.annotation.Nullable; - -/** - * A flyweight class that can be used to encode/decode composite metadata information to/from {@link - * ByteBuf}. This is intended for low-level efficient manipulation of such buffers. See {@link - * CompositeMetadata} for an Iterator-like approach to decoding entries. - * - * @deprecated in favor of {@link CompositeMetadataCodec} - */ -@Deprecated -public class CompositeMetadataFlyweight { - - private CompositeMetadataFlyweight() {} - - public static int computeNextEntryIndex( - int currentEntryIndex, ByteBuf headerSlice, ByteBuf contentSlice) { - return CompositeMetadataCodec.computeNextEntryIndex( - currentEntryIndex, headerSlice, contentSlice); - } - - /** - * Decode the next metadata entry (a mime header + content pair of {@link ByteBuf}) from a {@link - * ByteBuf} that contains at least enough bytes for one more such entry. These buffers are - * actually slices of the full metadata buffer, and this method doesn't move the full metadata - * buffer's {@link ByteBuf#readerIndex()}. As such, it requires the user to provide an {@code - * index} to read from. The next index is computed by calling {@link #computeNextEntryIndex(int, - * ByteBuf, ByteBuf)}. Size of the first buffer (the "header buffer") drives which decoding method - * should be further applied to it. - * - *

The header buffer is either: - * - *

    - *
  • made up of a single byte: this represents an encoded mime id, which can be further - * decoded using {@link #decodeMimeIdFromMimeBuffer(ByteBuf)} - *
  • made up of 2 or more bytes: this represents an encoded mime String + its length, which - * can be further decoded using {@link #decodeMimeTypeFromMimeBuffer(ByteBuf)}. Note the - * encoded length, in the first byte, is skipped by this decoding method because the - * remaining length of the buffer is that of the mime string. - *
- * - * @param compositeMetadata the source {@link ByteBuf} that originally contains one or more - * metadata entries - * @param entryIndex the {@link ByteBuf#readerIndex()} to start decoding from. original reader - * index is kept on the source buffer - * @param retainSlices should produced metadata entry buffers {@link ByteBuf#slice() slices} be - * {@link ByteBuf#retainedSlice() retained}? - * @return a {@link ByteBuf} array of length 2 containing the mime header buffer - * slice and the content buffer slice, or one of the - * zero-length error constant arrays - */ - public static ByteBuf[] decodeMimeAndContentBuffersSlices( - ByteBuf compositeMetadata, int entryIndex, boolean retainSlices) { - return CompositeMetadataCodec.decodeMimeAndContentBuffersSlices( - compositeMetadata, entryIndex, retainSlices); - } - - /** - * Decode a {@code byte} compressed mime id from a {@link ByteBuf}, assuming said buffer properly - * contains such an id. - * - *

The buffer must have exactly one readable byte, which is assumed to have been tested for - * mime id encoding via the {@link CompositeMetadataCodec#STREAM_METADATA_KNOWN_MASK} mask ({@code - * firstByte & STREAM_METADATA_KNOWN_MASK) == STREAM_METADATA_KNOWN_MASK}). - * - *

If there is no readable byte, the negative identifier of {@link - * WellKnownMimeType#UNPARSEABLE_MIME_TYPE} is returned. - * - * @param mimeBuffer the buffer that should next contain the compressed mime id byte - * @return the compressed mime id, between 0 and 127, or a negative id if the input is invalid - * @see #decodeMimeTypeFromMimeBuffer(ByteBuf) - */ - public static byte decodeMimeIdFromMimeBuffer(ByteBuf mimeBuffer) { - return CompositeMetadataCodec.decodeMimeIdFromMimeBuffer(mimeBuffer); - } - - /** - * Decode a {@link CharSequence} custome mime type from a {@link ByteBuf}, assuming said buffer - * properly contains such a mime type. - * - *

The buffer must at least have two readable bytes, which distinguishes it from the {@link - * #decodeMimeIdFromMimeBuffer(ByteBuf) compressed id} case. The first byte is a size and the - * remaining bytes must correspond to the {@link CharSequence}, encoded fully in US_ASCII. As a - * result, the first byte can simply be skipped, and the remaining of the buffer be decoded to the - * mime type. - * - *

If the mime header buffer is less than 2 bytes long, returns {@code null}. - * - * @param flyweightMimeBuffer the mime header {@link ByteBuf} that contains length + custom mime - * type - * @return the decoded custom mime type, as a {@link CharSequence}, or null if the input is - * invalid - * @see #decodeMimeIdFromMimeBuffer(ByteBuf) - */ - @Nullable - public static CharSequence decodeMimeTypeFromMimeBuffer(ByteBuf flyweightMimeBuffer) { - return CompositeMetadataCodec.decodeMimeTypeFromMimeBuffer(flyweightMimeBuffer); - } - - /** - * Encode a new sub-metadata information into a composite metadata {@link CompositeByteBuf - * buffer}, without checking if the {@link String} can be matched with a well known compressable - * mime type. Prefer using this method and {@link #encodeAndAddMetadata(CompositeByteBuf, - * ByteBufAllocator, WellKnownMimeType, ByteBuf)} if you know in advance whether or not the mime - * is well known. Otherwise use {@link #encodeAndAddMetadataWithCompression(CompositeByteBuf, - * ByteBufAllocator, String, ByteBuf)} - * - * @param compositeMetaData the buffer that will hold all composite metadata information. - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param customMimeType the custom mime type to encode. - * @param metadata the metadata value to encode. - */ - // see #encodeMetadataHeader(ByteBufAllocator, String, int) - public static void encodeAndAddMetadata( - CompositeByteBuf compositeMetaData, - ByteBufAllocator allocator, - String customMimeType, - ByteBuf metadata) { - CompositeMetadataCodec.encodeAndAddMetadata( - compositeMetaData, allocator, customMimeType, metadata); - } - - /** - * Encode a new sub-metadata information into a composite metadata {@link CompositeByteBuf - * buffer}. - * - * @param compositeMetaData the buffer that will hold all composite metadata information. - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param knownMimeType the {@link WellKnownMimeType} to encode. - * @param metadata the metadata value to encode. - */ - // see #encodeMetadataHeader(ByteBufAllocator, byte, int) - public static void encodeAndAddMetadata( - CompositeByteBuf compositeMetaData, - ByteBufAllocator allocator, - WellKnownMimeType knownMimeType, - ByteBuf metadata) { - CompositeMetadataCodec.encodeAndAddMetadata( - compositeMetaData, allocator, knownMimeType, metadata); - } - - /** - * Encode a new sub-metadata information into a composite metadata {@link CompositeByteBuf - * buffer}, first verifying if the passed {@link String} matches a {@link WellKnownMimeType} (in - * which case it will be encoded in a compressed fashion using the mime id of that type). - * - *

Prefer using {@link #encodeAndAddMetadata(CompositeByteBuf, ByteBufAllocator, String, - * ByteBuf)} if you already know that the mime type is not a {@link WellKnownMimeType}. - * - * @param compositeMetaData the buffer that will hold all composite metadata information. - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param mimeType the mime type to encode, as a {@link String}. well known mime types are - * compressed. - * @param metadata the metadata value to encode. - * @see #encodeAndAddMetadata(CompositeByteBuf, ByteBufAllocator, WellKnownMimeType, ByteBuf) - */ - // see #encodeMetadataHeader(ByteBufAllocator, String, int) - public static void encodeAndAddMetadataWithCompression( - CompositeByteBuf compositeMetaData, - ByteBufAllocator allocator, - String mimeType, - ByteBuf metadata) { - CompositeMetadataCodec.encodeAndAddMetadataWithCompression( - compositeMetaData, allocator, mimeType, metadata); - } - - /** - * Returns whether there is another entry available at a given index - * - * @param compositeMetadata the buffer to inspect - * @param entryIndex the index to check at - * @return whether there is another entry available at a given index - */ - public static boolean hasEntry(ByteBuf compositeMetadata, int entryIndex) { - return CompositeMetadataCodec.hasEntry(compositeMetadata, entryIndex); - } - - /** - * Returns whether the header represents a well-known MIME type. - * - * @param header the header to inspect - * @return whether the header represents a well-known MIME type - */ - public static boolean isWellKnownMimeType(ByteBuf header) { - return CompositeMetadataCodec.isWellKnownMimeType(header); - } - - /** - * Encode a new sub-metadata information into a composite metadata {@link CompositeByteBuf - * buffer}. - * - * @param compositeMetaData the buffer that will hold all composite metadata information. - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param unknownCompressedMimeType the id of the {@link - * WellKnownMimeType#UNKNOWN_RESERVED_MIME_TYPE} to encode. - * @param metadata the metadata value to encode. - */ - // see #encodeMetadataHeader(ByteBufAllocator, byte, int) - static void encodeAndAddMetadata( - CompositeByteBuf compositeMetaData, - ByteBufAllocator allocator, - byte unknownCompressedMimeType, - ByteBuf metadata) { - CompositeMetadataCodec.encodeAndAddMetadata( - compositeMetaData, allocator, unknownCompressedMimeType, metadata); - } - - /** - * Encode a custom mime type and a metadata value length into a newly allocated {@link ByteBuf}. - * - *

This larger representation encodes the mime type representation's length on a single byte, - * then the representation itself, then the unsigned metadata value length on 3 additional bytes. - * - * @param allocator the {@link ByteBufAllocator} to use to create the buffer. - * @param customMime a custom mime type to encode. - * @param metadataLength the metadata length to append to the buffer as an unsigned 24 bits - * integer. - * @return the encoded mime and metadata length information - */ - static ByteBuf encodeMetadataHeader( - ByteBufAllocator allocator, String customMime, int metadataLength) { - return CompositeMetadataCodec.encodeMetadataHeader(allocator, customMime, metadataLength); - } - - /** - * Encode a {@link WellKnownMimeType well known mime type} and a metadata value length into a - * newly allocated {@link ByteBuf}. - * - *

This compact representation encodes the mime type via its ID on a single byte, and the - * unsigned value length on 3 additional bytes. - * - * @param allocator the {@link ByteBufAllocator} to use to create the buffer. - * @param mimeType a byte identifier of a {@link WellKnownMimeType} to encode. - * @param metadataLength the metadata length to append to the buffer as an unsigned 24 bits - * integer. - * @return the encoded mime and metadata length information - */ - static ByteBuf encodeMetadataHeader( - ByteBufAllocator allocator, byte mimeType, int metadataLength) { - return CompositeMetadataCodec.encodeMetadataHeader(allocator, mimeType, metadataLength); - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/metadata/TaggingMetadataFlyweight.java b/rsocket-core/src/main/java/io/rsocket/metadata/TaggingMetadataFlyweight.java deleted file mode 100644 index 718528358..000000000 --- a/rsocket-core/src/main/java/io/rsocket/metadata/TaggingMetadataFlyweight.java +++ /dev/null @@ -1,62 +0,0 @@ -package io.rsocket.metadata; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; -import java.util.Collection; - -/** - * A flyweight class that can be used to encode/decode tagging metadata information to/from {@link - * ByteBuf}. This is intended for low-level efficient manipulation of such buffers. See {@link - * TaggingMetadata} for an Iterator-like approach to decoding entries. - * - * @deprecated in favor of {@link TaggingMetadataCodec} - * @author linux_china - */ -@Deprecated -public class TaggingMetadataFlyweight { - /** - * create routing metadata - * - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param tags tag values - * @return routing metadata - */ - public static RoutingMetadata createRoutingMetadata( - ByteBufAllocator allocator, Collection tags) { - return TaggingMetadataCodec.createRoutingMetadata(allocator, tags); - } - - /** - * create tagging metadata from composite metadata entry - * - * @param entry composite metadata entry - * @return tagging metadata - */ - public static TaggingMetadata createTaggingMetadata(CompositeMetadata.Entry entry) { - return TaggingMetadataCodec.createTaggingMetadata(entry); - } - - /** - * create tagging metadata - * - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param knownMimeType the {@link WellKnownMimeType} to encode. - * @param tags tag values - * @return Tagging Metadata - */ - public static TaggingMetadata createTaggingMetadata( - ByteBufAllocator allocator, String knownMimeType, Collection tags) { - return TaggingMetadataCodec.createTaggingMetadata(allocator, knownMimeType, tags); - } - - /** - * create tagging content - * - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param tags tag values - * @return tagging content - */ - public static ByteBuf createTaggingContent(ByteBufAllocator allocator, Collection tags) { - return TaggingMetadataCodec.createTaggingContent(allocator, tags); - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/metadata/security/AuthMetadataFlyweight.java b/rsocket-core/src/main/java/io/rsocket/metadata/security/AuthMetadataFlyweight.java deleted file mode 100644 index e1a8ba449..000000000 --- a/rsocket-core/src/main/java/io/rsocket/metadata/security/AuthMetadataFlyweight.java +++ /dev/null @@ -1,194 +0,0 @@ -package io.rsocket.metadata.security; - -import io.netty.buffer.ByteBuf; -import io.netty.buffer.ByteBufAllocator; -import io.netty.buffer.Unpooled; -import io.rsocket.metadata.AuthMetadataCodec; - -/** @deprecated in favor of {@link io.rsocket.metadata.AuthMetadataCodec} */ -@Deprecated -public class AuthMetadataFlyweight { - - static final int STREAM_METADATA_KNOWN_MASK = 0x80; // 1000 0000 - - private AuthMetadataFlyweight() {} - - /** - * Encode a Authentication CompositeMetadata payload using custom authentication type - * - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param customAuthType the custom mime type to encode. - * @param metadata the metadata value to encode. - * @throws IllegalArgumentException in case of {@code customAuthType} is non US_ASCII string or - * empty string or its length is greater than 128 bytes - */ - public static ByteBuf encodeMetadata( - ByteBufAllocator allocator, String customAuthType, ByteBuf metadata) { - - return AuthMetadataCodec.encodeMetadata(allocator, customAuthType, metadata); - } - - /** - * Encode a Authentication CompositeMetadata payload using custom authentication type - * - * @param allocator the {@link ByteBufAllocator} to create intermediate buffers as needed. - * @param authType the well-known mime type to encode. - * @param metadata the metadata value to encode. - * @throws IllegalArgumentException in case of {@code authType} is {@link - * WellKnownAuthType#UNPARSEABLE_AUTH_TYPE} or {@link - * WellKnownAuthType#UNKNOWN_RESERVED_AUTH_TYPE} - */ - public static ByteBuf encodeMetadata( - ByteBufAllocator allocator, WellKnownAuthType authType, ByteBuf metadata) { - - return AuthMetadataCodec.encodeMetadata(allocator, WellKnownAuthType.cast(authType), metadata); - } - - /** - * Encode a Authentication CompositeMetadata payload using Simple Authentication format - * - * @throws IllegalArgumentException if the username length is greater than 255 - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param username the char sequence which represents user name. - * @param password the char sequence which represents user password. - */ - public static ByteBuf encodeSimpleMetadata( - ByteBufAllocator allocator, char[] username, char[] password) { - return AuthMetadataCodec.encodeSimpleMetadata(allocator, username, password); - } - - /** - * Encode a Authentication CompositeMetadata payload using Bearer Authentication format - * - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param token the char sequence which represents BEARER token. - */ - public static ByteBuf encodeBearerMetadata(ByteBufAllocator allocator, char[] token) { - return AuthMetadataCodec.encodeBearerMetadata(allocator, token); - } - - /** - * Encode a new Authentication Metadata payload information, first verifying if the passed {@link - * String} matches a {@link WellKnownAuthType} (in which case it will be encoded in a compressed - * fashion using the mime id of that type). - * - *

Prefer using {@link #encodeMetadata(ByteBufAllocator, String, ByteBuf)} if you already know - * that the mime type is not a {@link WellKnownAuthType}. - * - * @param allocator the {@link ByteBufAllocator} to use to create intermediate buffers as needed. - * @param authType the mime type to encode, as a {@link String}. well known mime types are - * compressed. - * @param metadata the metadata value to encode. - * @see #encodeMetadata(ByteBufAllocator, WellKnownAuthType, ByteBuf) - * @see #encodeMetadata(ByteBufAllocator, String, ByteBuf) - */ - public static ByteBuf encodeMetadataWithCompression( - ByteBufAllocator allocator, String authType, ByteBuf metadata) { - return AuthMetadataCodec.encodeMetadataWithCompression(allocator, authType, metadata); - } - - /** - * Get the first {@code byte} from a {@link ByteBuf} and check whether it is length or {@link - * WellKnownAuthType}. Assuming said buffer properly contains such a {@code byte} - * - * @param metadata byteBuf used to get information from - */ - public static boolean isWellKnownAuthType(ByteBuf metadata) { - return AuthMetadataCodec.isWellKnownAuthType(metadata); - } - - /** - * Read first byte from the given {@code metadata} and tries to convert it's value to {@link - * WellKnownAuthType}. - * - * @param metadata given metadata buffer to read from - * @return Return on of the know Auth types or {@link WellKnownAuthType#UNPARSEABLE_AUTH_TYPE} if - * field's value is length or unknown auth type - * @throws IllegalStateException if not enough readable bytes in the given {@link ByteBuf} - */ - public static WellKnownAuthType decodeWellKnownAuthType(ByteBuf metadata) { - return WellKnownAuthType.cast(AuthMetadataCodec.readWellKnownAuthType(metadata)); - } - - /** - * Read up to 129 bytes from the given metadata in order to get the custom Auth Type - * - * @param metadata - * @return - */ - public static CharSequence decodeCustomAuthType(ByteBuf metadata) { - return AuthMetadataCodec.readCustomAuthType(metadata); - } - - /** - * Read all remaining {@code bytes} from the given {@link ByteBuf} and return sliced - * representation of a payload - * - * @param metadata metadata to get payload from. Please note, the {@code metadata#readIndex} - * should be set to the beginning of the payload bytes - * @return sliced {@link ByteBuf} or {@link Unpooled#EMPTY_BUFFER} if no bytes readable in the - * given one - */ - public static ByteBuf decodePayload(ByteBuf metadata) { - return AuthMetadataCodec.readPayload(metadata); - } - - /** - * Read up to 257 {@code bytes} from the given {@link ByteBuf} where the first byte is username - * length and the subsequent number of bytes equal to decoded length - * - * @param simpleAuthMetadata the given metadata to read username from. Please note, the {@code - * simpleAuthMetadata#readIndex} should be set to the username length byte - * @return sliced {@link ByteBuf} or {@link Unpooled#EMPTY_BUFFER} if username length is zero - */ - public static ByteBuf decodeUsername(ByteBuf simpleAuthMetadata) { - return AuthMetadataCodec.readUsername(simpleAuthMetadata); - } - - /** - * Read all the remaining {@code byte}s from the given {@link ByteBuf} which represents user's - * password - * - * @param simpleAuthMetadata the given metadata to read password from. Please note, the {@code - * simpleAuthMetadata#readIndex} should be set to the beginning of the password bytes - * @return sliced {@link ByteBuf} or {@link Unpooled#EMPTY_BUFFER} if password length is zero - */ - public static ByteBuf decodePassword(ByteBuf simpleAuthMetadata) { - return AuthMetadataCodec.readPassword(simpleAuthMetadata); - } - /** - * Read up to 257 {@code bytes} from the given {@link ByteBuf} where the first byte is username - * length and the subsequent number of bytes equal to decoded length - * - * @param simpleAuthMetadata the given metadata to read username from. Please note, the {@code - * simpleAuthMetadata#readIndex} should be set to the username length byte - * @return {@code char[]} which represents UTF-8 username - */ - public static char[] decodeUsernameAsCharArray(ByteBuf simpleAuthMetadata) { - return AuthMetadataCodec.readUsernameAsCharArray(simpleAuthMetadata); - } - - /** - * Read all the remaining {@code byte}s from the given {@link ByteBuf} which represents user's - * password - * - * @param simpleAuthMetadata the given metadata to read username from. Please note, the {@code - * simpleAuthMetadata#readIndex} should be set to the beginning of the password bytes - * @return {@code char[]} which represents UTF-8 password - */ - public static char[] decodePasswordAsCharArray(ByteBuf simpleAuthMetadata) { - return AuthMetadataCodec.readPasswordAsCharArray(simpleAuthMetadata); - } - - /** - * Read all the remaining {@code bytes} from the given {@link ByteBuf} where the first byte is - * username length and the subsequent number of bytes equal to decoded length - * - * @param bearerAuthMetadata the given metadata to read username from. Please note, the {@code - * simpleAuthMetadata#readIndex} should be set to the beginning of the password bytes - * @return {@code char[]} which represents UTF-8 password - */ - public static char[] decodeBearerTokenAsCharArray(ByteBuf bearerAuthMetadata) { - return AuthMetadataCodec.readBearerTokenAsCharArray(bearerAuthMetadata); - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/metadata/security/WellKnownAuthType.java b/rsocket-core/src/main/java/io/rsocket/metadata/security/WellKnownAuthType.java deleted file mode 100644 index 24e5ff0db..000000000 --- a/rsocket-core/src/main/java/io/rsocket/metadata/security/WellKnownAuthType.java +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright 2015-2018 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 io.rsocket.metadata.security; - -import java.util.Arrays; -import java.util.LinkedHashMap; -import java.util.Map; - -/** - * Enumeration of Well Known Auth Types, as defined in the eponymous extension. Such auth types are - * used in composite metadata (which can include routing and/or tracing metadata). Per - * specification, identifiers are between 0 and 127 (inclusive). - * - * @deprecated in favor of {@link io.rsocket.metadata.WellKnownAuthType} - */ -@Deprecated -public enum WellKnownAuthType { - UNPARSEABLE_AUTH_TYPE("UNPARSEABLE_AUTH_TYPE_DO_NOT_USE", (byte) -2), - UNKNOWN_RESERVED_AUTH_TYPE("UNKNOWN_YET_RESERVED_DO_NOT_USE", (byte) -1), - - SIMPLE("simple", (byte) 0x00), - BEARER("bearer", (byte) 0x01); - // ... reserved for future use ... - - static final WellKnownAuthType[] TYPES_BY_AUTH_ID; - static final Map TYPES_BY_AUTH_STRING; - - static { - // precompute an array of all valid auth ids, filling the blanks with the RESERVED enum - TYPES_BY_AUTH_ID = new WellKnownAuthType[128]; // 0-127 inclusive - Arrays.fill(TYPES_BY_AUTH_ID, UNKNOWN_RESERVED_AUTH_TYPE); - // also prepare a Map of the types by auth string - TYPES_BY_AUTH_STRING = new LinkedHashMap<>(128); - - for (WellKnownAuthType value : values()) { - if (value.getIdentifier() >= 0) { - TYPES_BY_AUTH_ID[value.getIdentifier()] = value; - TYPES_BY_AUTH_STRING.put(value.getString(), value); - } - } - } - - private final byte identifier; - private final String str; - - WellKnownAuthType(String str, byte identifier) { - this.str = str; - this.identifier = identifier; - } - - static io.rsocket.metadata.WellKnownAuthType cast(WellKnownAuthType wellKnownAuthType) { - byte identifier = wellKnownAuthType.identifier; - if (identifier == io.rsocket.metadata.WellKnownAuthType.UNPARSEABLE_AUTH_TYPE.getIdentifier()) { - return io.rsocket.metadata.WellKnownAuthType.UNPARSEABLE_AUTH_TYPE; - } else if (identifier - == io.rsocket.metadata.WellKnownAuthType.UNKNOWN_RESERVED_AUTH_TYPE.getIdentifier()) { - return io.rsocket.metadata.WellKnownAuthType.UNKNOWN_RESERVED_AUTH_TYPE; - } else { - return io.rsocket.metadata.WellKnownAuthType.fromIdentifier(identifier); - } - } - - static WellKnownAuthType cast(io.rsocket.metadata.WellKnownAuthType wellKnownAuthType) { - byte identifier = wellKnownAuthType.getIdentifier(); - if (identifier == WellKnownAuthType.UNPARSEABLE_AUTH_TYPE.identifier) { - return WellKnownAuthType.UNPARSEABLE_AUTH_TYPE; - } else if (identifier == WellKnownAuthType.UNKNOWN_RESERVED_AUTH_TYPE.identifier) { - return WellKnownAuthType.UNKNOWN_RESERVED_AUTH_TYPE; - } else { - return TYPES_BY_AUTH_ID[identifier]; - } - } - - /** - * Find the {@link WellKnownAuthType} for the given identifier (as an {@code int}). Valid - * identifiers are defined to be integers between 0 and 127, inclusive. Identifiers outside of - * this range will produce the {@link #UNPARSEABLE_AUTH_TYPE}. Additionally, some identifiers in - * that range are still only reserved and don't have a type associated yet: this method returns - * the {@link #UNKNOWN_RESERVED_AUTH_TYPE} when passing such an identifier, which lets call sites - * potentially detect this and keep the original representation when transmitting the associated - * metadata buffer. - * - * @param id the looked up identifier - * @return the {@link WellKnownAuthType}, or {@link #UNKNOWN_RESERVED_AUTH_TYPE} if the id is out - * of the specification's range, or {@link #UNKNOWN_RESERVED_AUTH_TYPE} if the id is one that - * is merely reserved but unknown to this implementation. - */ - public static WellKnownAuthType fromIdentifier(int id) { - if (id < 0x00 || id > 0x7F) { - return UNPARSEABLE_AUTH_TYPE; - } - return TYPES_BY_AUTH_ID[id]; - } - - /** - * Find the {@link WellKnownAuthType} for the given {@link String} representation. If the - * representation is {@code null} or doesn't match a {@link WellKnownAuthType}, the {@link - * #UNPARSEABLE_AUTH_TYPE} is returned. - * - * @param authType the looked up auth type - * @return the matching {@link WellKnownAuthType}, or {@link #UNPARSEABLE_AUTH_TYPE} if none - * matches - */ - public static WellKnownAuthType fromString(String authType) { - if (authType == null) throw new IllegalArgumentException("type must be non-null"); - - // force UNPARSEABLE if by chance UNKNOWN_RESERVED_AUTH_TYPE's text has been used - if (authType.equals(UNKNOWN_RESERVED_AUTH_TYPE.str)) { - return UNPARSEABLE_AUTH_TYPE; - } - - return TYPES_BY_AUTH_STRING.getOrDefault(authType, UNPARSEABLE_AUTH_TYPE); - } - - /** @return the byte identifier of the auth type, guaranteed to be positive or zero. */ - public byte getIdentifier() { - return identifier; - } - - /** - * @return the auth type represented as a {@link String}, which is made of US_ASCII compatible - * characters only - */ - public String getString() { - return str; - } - - /** @see #getString() */ - @Override - public String toString() { - return str; - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/resume/ExponentialBackoffResumeStrategy.java b/rsocket-core/src/main/java/io/rsocket/resume/ExponentialBackoffResumeStrategy.java deleted file mode 100644 index 461be02d2..000000000 --- a/rsocket-core/src/main/java/io/rsocket/resume/ExponentialBackoffResumeStrategy.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Copyright 2015-2019 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 io.rsocket.resume; - -import java.time.Duration; -import java.util.Objects; -import org.reactivestreams.Publisher; -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; -import reactor.util.retry.Retry; - -/** - * @deprecated as of 1.0 RC7 in favor of passing {@link Retry#backoff(long, Duration)} to {@link - * io.rsocket.core.Resume#retry(Retry)}. - */ -@Deprecated -public class ExponentialBackoffResumeStrategy implements ResumeStrategy { - private volatile Duration next; - private final Duration firstBackoff; - private final Duration maxBackoff; - private final int factor; - - public ExponentialBackoffResumeStrategy(Duration firstBackoff, Duration maxBackoff, int factor) { - this.firstBackoff = Objects.requireNonNull(firstBackoff, "firstBackoff"); - this.maxBackoff = Objects.requireNonNull(maxBackoff, "maxBackoff"); - this.factor = requirePositive(factor); - } - - @Override - public Publisher apply(ClientResume clientResume, Throwable throwable) { - return Flux.defer(() -> Mono.delay(next()).thenReturn(toString())); - } - - Duration next() { - next = - next == null - ? firstBackoff - : Duration.ofMillis(Math.min(maxBackoff.toMillis(), next.toMillis() * factor)); - return next; - } - - private static int requirePositive(int value) { - if (value <= 0) { - throw new IllegalArgumentException("Value must be positive: " + value); - } else { - return value; - } - } - - @Override - public String toString() { - return "ExponentialBackoffResumeStrategy{" - + "next=" - + next - + ", firstBackoff=" - + firstBackoff - + ", maxBackoff=" - + maxBackoff - + ", factor=" - + factor - + '}'; - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/resume/PeriodicResumeStrategy.java b/rsocket-core/src/main/java/io/rsocket/resume/PeriodicResumeStrategy.java deleted file mode 100644 index bd447c8a9..000000000 --- a/rsocket-core/src/main/java/io/rsocket/resume/PeriodicResumeStrategy.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright 2015-2019 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 io.rsocket.resume; - -import java.time.Duration; -import org.reactivestreams.Publisher; -import reactor.core.publisher.Mono; -import reactor.util.retry.Retry; - -/** - * @deprecated as of 1.0 RC7 in favor of passing {@link Retry#fixedDelay(long, Duration)} to {@link - * io.rsocket.core.Resume#retry(Retry)}. - */ -@Deprecated -public class PeriodicResumeStrategy implements ResumeStrategy { - private final Duration interval; - - public PeriodicResumeStrategy(Duration interval) { - this.interval = interval; - } - - @Override - public Publisher apply(ClientResume clientResumeConfiguration, Throwable throwable) { - return Mono.delay(interval).thenReturn(toString()); - } - - @Override - public String toString() { - return "PeriodicResumeStrategy{" + "interval=" + interval + '}'; - } -} diff --git a/rsocket-core/src/main/java/io/rsocket/resume/ResumeStrategy.java b/rsocket-core/src/main/java/io/rsocket/resume/ResumeStrategy.java deleted file mode 100644 index d9dec9f54..000000000 --- a/rsocket-core/src/main/java/io/rsocket/resume/ResumeStrategy.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2015-2020 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 io.rsocket.resume; - -import java.util.function.BiFunction; -import org.reactivestreams.Publisher; -import reactor.util.retry.Retry; - -/** - * @deprecated as of 1.0 RC7 in favor of using {@link io.rsocket.core.Resume#retry(Retry)} via - * {@link io.rsocket.core.RSocketConnector} or {@link io.rsocket.core.RSocketServer}. - */ -@Deprecated -@FunctionalInterface -public interface ResumeStrategy extends BiFunction> {} diff --git a/rsocket-core/src/main/java/io/rsocket/transport/TransportHeaderAware.java b/rsocket-core/src/main/java/io/rsocket/transport/TransportHeaderAware.java deleted file mode 100644 index 16b863d9e..000000000 --- a/rsocket-core/src/main/java/io/rsocket/transport/TransportHeaderAware.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2015-2020 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 io.rsocket.transport; - -import java.util.Map; -import java.util.function.Supplier; - -/** - * Extension interface to support Transports with headers at the transport layer, e.g. Websockets, - * Http2. - * - * @deprecated as of 1.0.1 in favor using properties on individual transports. - */ -@Deprecated -public interface TransportHeaderAware { - - /** - * Sets the transport headers - * - * @param transportHeaders the transport headers - * @throws NullPointerException if {@code transportHeaders} is {@code null} - */ - void setTransportHeaders(Supplier> transportHeaders); -} diff --git a/rsocket-core/src/test/java/io/rsocket/exceptions/RSocketExceptionTest.java b/rsocket-core/src/test/java/io/rsocket/exceptions/RSocketExceptionTest.java index ccf7649d2..9aa8fc364 100644 --- a/rsocket-core/src/test/java/io/rsocket/exceptions/RSocketExceptionTest.java +++ b/rsocket-core/src/test/java/io/rsocket/exceptions/RSocketExceptionTest.java @@ -18,10 +18,11 @@ import static org.assertj.core.api.Assertions.assertThat; +import io.rsocket.RSocketErrorException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -interface RSocketExceptionTest { +interface RSocketExceptionTest { @DisplayName("constructor does not throw NullPointerException with null message") @Test diff --git a/rsocket-core/src/test/java/io/rsocket/exceptions/TestRSocketException.java b/rsocket-core/src/test/java/io/rsocket/exceptions/TestRSocketException.java index 6c2e63730..15685aa43 100644 --- a/rsocket-core/src/test/java/io/rsocket/exceptions/TestRSocketException.java +++ b/rsocket-core/src/test/java/io/rsocket/exceptions/TestRSocketException.java @@ -1,6 +1,9 @@ package io.rsocket.exceptions; -public class TestRSocketException extends RSocketException { +import io.rsocket.RSocketErrorException; +import io.rsocket.frame.ErrorFrameCodec; + +public class TestRSocketException extends RSocketErrorException { private static final long serialVersionUID = 7873267740343446585L; private final int errorCode; @@ -14,7 +17,7 @@ public class TestRSocketException extends RSocketException { * @throws IllegalArgumentException if {@code errorCode} is out of allowed range */ public TestRSocketException(int errorCode, String message) { - super(message); + super(ErrorFrameCodec.APPLICATION_ERROR, message); this.errorCode = errorCode; } @@ -28,7 +31,7 @@ public TestRSocketException(int errorCode, String message) { * @throws IllegalArgumentException if {@code errorCode} is out of allowed range */ public TestRSocketException(int errorCode, String message, Throwable cause) { - super(message, cause); + super(ErrorFrameCodec.APPLICATION_ERROR, message, cause); this.errorCode = errorCode; } diff --git a/rsocket-core/src/test/java/io/rsocket/metadata/security/AuthMetadataFlyweightTest.java b/rsocket-core/src/test/java/io/rsocket/metadata/AuthMetadataCodecTest.java similarity index 83% rename from rsocket-core/src/test/java/io/rsocket/metadata/security/AuthMetadataFlyweightTest.java rename to rsocket-core/src/test/java/io/rsocket/metadata/AuthMetadataCodecTest.java index 13d910e15..a6ef8ea37 100644 --- a/rsocket-core/src/test/java/io/rsocket/metadata/security/AuthMetadataFlyweightTest.java +++ b/rsocket-core/src/test/java/io/rsocket/metadata/AuthMetadataCodecTest.java @@ -1,4 +1,4 @@ -package io.rsocket.metadata.security; +package io.rsocket.metadata; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; @@ -8,7 +8,7 @@ import org.assertj.core.api.Assertions; import org.junit.jupiter.api.Test; -class AuthMetadataFlyweightTest { +public class AuthMetadataCodecTest { public static final int AUTH_TYPE_ID_LENGTH = 1; public static final int USER_NAME_BYTES_LENGTH = 1; @@ -24,7 +24,7 @@ void shouldCorrectlyEncodeData() { int passwordLength = password.length(); ByteBuf byteBuf = - AuthMetadataFlyweight.encodeSimpleMetadata( + AuthMetadataCodec.encodeSimpleMetadata( ByteBufAllocator.DEFAULT, username.toCharArray(), password.toCharArray()); byteBuf.markReaderIndex(); @@ -44,7 +44,7 @@ void shouldCorrectlyEncodeData1() { int passwordLength = password.length(); ByteBuf byteBuf = - AuthMetadataFlyweight.encodeSimpleMetadata( + AuthMetadataCodec.encodeSimpleMetadata( ByteBufAllocator.DEFAULT, username.toCharArray(), password.toCharArray()); byteBuf.markReaderIndex(); @@ -64,7 +64,7 @@ void shouldCorrectlyEncodeData2() { int passwordLength = password.length(); ByteBuf byteBuf = - AuthMetadataFlyweight.encodeSimpleMetadata( + AuthMetadataCodec.encodeSimpleMetadata( ByteBufAllocator.DEFAULT, username.toCharArray(), password.toCharArray()); byteBuf.markReaderIndex(); @@ -97,18 +97,18 @@ private static void checkSimpleAuthMetadataEncodingUsingDecoders( Assertions.assertThat(byteBuf.capacity()) .isEqualTo(AUTH_TYPE_ID_LENGTH + USER_NAME_BYTES_LENGTH + usernameLength + passwordLength); - Assertions.assertThat(AuthMetadataFlyweight.decodeWellKnownAuthType(byteBuf)) + Assertions.assertThat(AuthMetadataCodec.readWellKnownAuthType(byteBuf)) .isEqualTo(WellKnownAuthType.SIMPLE); byteBuf.markReaderIndex(); - Assertions.assertThat(AuthMetadataFlyweight.decodeUsername(byteBuf).toString(CharsetUtil.UTF_8)) + Assertions.assertThat(AuthMetadataCodec.readUsername(byteBuf).toString(CharsetUtil.UTF_8)) .isEqualTo(username); - Assertions.assertThat(AuthMetadataFlyweight.decodePassword(byteBuf).toString(CharsetUtil.UTF_8)) + Assertions.assertThat(AuthMetadataCodec.readPassword(byteBuf).toString(CharsetUtil.UTF_8)) .isEqualTo(password); byteBuf.resetReaderIndex(); - Assertions.assertThat(new String(AuthMetadataFlyweight.decodeUsernameAsCharArray(byteBuf))) + Assertions.assertThat(new String(AuthMetadataCodec.readUsernameAsCharArray(byteBuf))) .isEqualTo(username); - Assertions.assertThat(new String(AuthMetadataFlyweight.decodePasswordAsCharArray(byteBuf))) + Assertions.assertThat(new String(AuthMetadataCodec.readPasswordAsCharArray(byteBuf))) .isEqualTo(password); ReferenceCountUtil.release(byteBuf); @@ -122,7 +122,7 @@ void shouldThrowExceptionIfUsernameLengthExitsAllowedBounds() { Assertions.assertThatThrownBy( () -> - AuthMetadataFlyweight.encodeSimpleMetadata( + AuthMetadataCodec.encodeSimpleMetadata( ByteBufAllocator.DEFAULT, username.toCharArray(), password.toCharArray())) .hasMessage( "Username should be shorter than or equal to 255 bytes length in UTF-8 encoding"); @@ -133,8 +133,7 @@ void shouldEncodeBearerMetadata() { String testToken = TEST_BEARER_TOKEN; ByteBuf byteBuf = - AuthMetadataFlyweight.encodeBearerMetadata( - ByteBufAllocator.DEFAULT, testToken.toCharArray()); + AuthMetadataCodec.encodeBearerMetadata(ByteBufAllocator.DEFAULT, testToken.toCharArray()); byteBuf.markReaderIndex(); checkBearerAuthMetadataEncoding(testToken, byteBuf); @@ -146,7 +145,7 @@ private static void checkBearerAuthMetadataEncoding(String testToken, ByteBuf by Assertions.assertThat(byteBuf.capacity()) .isEqualTo(testToken.getBytes(CharsetUtil.UTF_8).length + AUTH_TYPE_ID_LENGTH); Assertions.assertThat( - byteBuf.readUnsignedByte() & ~AuthMetadataFlyweight.STREAM_METADATA_KNOWN_MASK) + byteBuf.readUnsignedByte() & ~AuthMetadataCodec.STREAM_METADATA_KNOWN_MASK) .isEqualTo(WellKnownAuthType.BEARER.getIdentifier()); Assertions.assertThat(byteBuf.readSlice(byteBuf.capacity() - 1).toString(CharsetUtil.UTF_8)) .isEqualTo(testToken); @@ -156,15 +155,15 @@ private static void checkBearerAuthMetadataEncodingUsingDecoders( String testToken, ByteBuf byteBuf) { Assertions.assertThat(byteBuf.capacity()) .isEqualTo(testToken.getBytes(CharsetUtil.UTF_8).length + AUTH_TYPE_ID_LENGTH); - Assertions.assertThat(AuthMetadataFlyweight.isWellKnownAuthType(byteBuf)).isTrue(); - Assertions.assertThat(AuthMetadataFlyweight.decodeWellKnownAuthType(byteBuf)) + Assertions.assertThat(AuthMetadataCodec.isWellKnownAuthType(byteBuf)).isTrue(); + Assertions.assertThat(AuthMetadataCodec.readWellKnownAuthType(byteBuf)) .isEqualTo(WellKnownAuthType.BEARER); byteBuf.markReaderIndex(); - Assertions.assertThat(new String(AuthMetadataFlyweight.decodeBearerTokenAsCharArray(byteBuf))) + Assertions.assertThat(new String(AuthMetadataCodec.readBearerTokenAsCharArray(byteBuf))) .isEqualTo(testToken); byteBuf.resetReaderIndex(); Assertions.assertThat( - AuthMetadataFlyweight.decodePayload(byteBuf).toString(CharsetUtil.UTF_8).toString()) + AuthMetadataCodec.readPayload(byteBuf).toString(CharsetUtil.UTF_8).toString()) .isEqualTo(testToken); } @@ -176,7 +175,7 @@ void shouldEncodeCustomAuth() { String customAuthType = "myownauthtype"; ByteBuf buffer = - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, customAuthType, testSecurityPayload); checkCustomAuthMetadataEncoding(testSecurityPayload, customAuthType, buffer); @@ -204,7 +203,7 @@ void shouldThrowOnNonASCIIChars() { Assertions.assertThatThrownBy( () -> - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, customAuthType, testSecurityPayload)) .hasMessage("custom auth type must be US_ASCII characters only"); } @@ -218,7 +217,7 @@ void shouldThrowOnOutOfAllowedSizeType() { Assertions.assertThatThrownBy( () -> - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, customAuthType, testSecurityPayload)) .hasMessage( "custom auth type must have a strictly positive length that fits on 7 unsigned bits, ie 1-128"); @@ -231,7 +230,7 @@ void shouldThrowOnOutOfAllowedSizeType1() { Assertions.assertThatThrownBy( () -> - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, customAuthType, testSecurityPayload)) .hasMessage( "custom auth type must have a strictly positive length that fits on 7 unsigned bits, ie 1-128"); @@ -240,7 +239,7 @@ void shouldThrowOnOutOfAllowedSizeType1() { @Test void shouldEncodeUsingWellKnownAuthType() { ByteBuf byteBuf = - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, WellKnownAuthType.SIMPLE, ByteBufAllocator.DEFAULT.buffer(3, 3).writeByte(1).writeByte('u').writeByte('p')); @@ -251,7 +250,7 @@ void shouldEncodeUsingWellKnownAuthType() { @Test void shouldEncodeUsingWellKnownAuthType1() { ByteBuf byteBuf = - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, WellKnownAuthType.SIMPLE, ByteBufAllocator.DEFAULT.buffer().writeByte(1).writeByte('u').writeByte('p')); @@ -262,7 +261,7 @@ void shouldEncodeUsingWellKnownAuthType1() { @Test void shouldEncodeUsingWellKnownAuthType2() { ByteBuf byteBuf = - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, WellKnownAuthType.BEARER, Unpooled.copiedBuffer(TEST_BEARER_TOKEN, CharsetUtil.UTF_8)); @@ -279,13 +278,13 @@ void shouldThrowIfWellKnownAuthTypeIsUnsupportedOrUnknown() { Assertions.assertThatThrownBy( () -> - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, WellKnownAuthType.UNPARSEABLE_AUTH_TYPE, buffer)) .hasMessage("only allowed AuthType should be used"); Assertions.assertThatThrownBy( () -> - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, WellKnownAuthType.UNPARSEABLE_AUTH_TYPE, buffer)) .hasMessage("only allowed AuthType should be used"); @@ -295,7 +294,7 @@ void shouldThrowIfWellKnownAuthTypeIsUnsupportedOrUnknown() { @Test void shouldCompressMetadata() { ByteBuf byteBuf = - AuthMetadataFlyweight.encodeMetadataWithCompression( + AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "simple", ByteBufAllocator.DEFAULT.buffer().writeByte(1).writeByte('u').writeByte('p')); @@ -306,7 +305,7 @@ void shouldCompressMetadata() { @Test void shouldCompressMetadata1() { ByteBuf byteBuf = - AuthMetadataFlyweight.encodeMetadataWithCompression( + AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "bearer", Unpooled.copiedBuffer(TEST_BEARER_TOKEN, CharsetUtil.UTF_8)); @@ -323,7 +322,7 @@ void shouldNotCompressMetadata() { Unpooled.wrappedBuffer(TEST_BEARER_TOKEN.getBytes(CharsetUtil.UTF_8)); String customAuthType = "testauthtype"; ByteBuf byteBuf = - AuthMetadataFlyweight.encodeMetadataWithCompression( + AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, customAuthType, testMetadataPayload); checkCustomAuthMetadataEncoding(testMetadataPayload, customAuthType, byteBuf); @@ -332,12 +331,12 @@ void shouldNotCompressMetadata() { @Test void shouldConfirmWellKnownAuthType() { ByteBuf metadata = - AuthMetadataFlyweight.encodeMetadataWithCompression( + AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "simple", Unpooled.EMPTY_BUFFER); int initialReaderIndex = metadata.readerIndex(); - Assertions.assertThat(AuthMetadataFlyweight.isWellKnownAuthType(metadata)).isTrue(); + Assertions.assertThat(AuthMetadataCodec.isWellKnownAuthType(metadata)).isTrue(); Assertions.assertThat(metadata.readerIndex()).isEqualTo(initialReaderIndex); ReferenceCountUtil.release(metadata); @@ -346,12 +345,12 @@ void shouldConfirmWellKnownAuthType() { @Test void shouldConfirmGivenMetadataIsNotAWellKnownAuthType() { ByteBuf metadata = - AuthMetadataFlyweight.encodeMetadataWithCompression( + AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "simple/afafgafadf", Unpooled.EMPTY_BUFFER); int initialReaderIndex = metadata.readerIndex(); - Assertions.assertThat(AuthMetadataFlyweight.isWellKnownAuthType(metadata)).isFalse(); + Assertions.assertThat(AuthMetadataCodec.isWellKnownAuthType(metadata)).isFalse(); Assertions.assertThat(metadata.readerIndex()).isEqualTo(initialReaderIndex); ReferenceCountUtil.release(metadata); @@ -360,7 +359,7 @@ void shouldConfirmGivenMetadataIsNotAWellKnownAuthType() { @Test void shouldReadSimpleWellKnownAuthType() { ByteBuf metadata = - AuthMetadataFlyweight.encodeMetadataWithCompression( + AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "simple", Unpooled.EMPTY_BUFFER); WellKnownAuthType expectedType = WellKnownAuthType.SIMPLE; checkDecodeWellKnowAuthTypeCorrectly(metadata, expectedType); @@ -369,7 +368,7 @@ void shouldReadSimpleWellKnownAuthType() { @Test void shouldReadSimpleWellKnownAuthType1() { ByteBuf metadata = - AuthMetadataFlyweight.encodeMetadataWithCompression( + AuthMetadataCodec.encodeMetadataWithCompression( ByteBufAllocator.DEFAULT, "bearer", Unpooled.EMPTY_BUFFER); WellKnownAuthType expectedType = WellKnownAuthType.BEARER; checkDecodeWellKnowAuthTypeCorrectly(metadata, expectedType); @@ -380,7 +379,7 @@ void shouldReadSimpleWellKnownAuthType2() { ByteBuf metadata = ByteBufAllocator.DEFAULT .buffer() - .writeByte(3 | AuthMetadataFlyweight.STREAM_METADATA_KNOWN_MASK); + .writeByte(3 | AuthMetadataCodec.STREAM_METADATA_KNOWN_MASK); WellKnownAuthType expectedType = WellKnownAuthType.UNKNOWN_RESERVED_AUTH_TYPE; checkDecodeWellKnowAuthTypeCorrectly(metadata, expectedType); } @@ -395,7 +394,7 @@ void shouldNotReadSimpleWellKnownAuthTypeIfEncodedLength() { @Test void shouldNotReadSimpleWellKnownAuthTypeIfEncodedLength1() { ByteBuf metadata = - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, "testmetadataauthtype", Unpooled.EMPTY_BUFFER); WellKnownAuthType expectedType = WellKnownAuthType.UNPARSEABLE_AUTH_TYPE; checkDecodeWellKnowAuthTypeCorrectly(metadata, expectedType); @@ -404,7 +403,7 @@ void shouldNotReadSimpleWellKnownAuthTypeIfEncodedLength1() { @Test void shouldThrowExceptionIsNotEnoughReadableBytes() { Assertions.assertThatThrownBy( - () -> AuthMetadataFlyweight.decodeWellKnownAuthType(Unpooled.EMPTY_BUFFER)) + () -> AuthMetadataCodec.readWellKnownAuthType(Unpooled.EMPTY_BUFFER)) .hasMessage("Unable to decode Well Know Auth type. Not enough readable bytes"); } @@ -412,7 +411,7 @@ private static void checkDecodeWellKnowAuthTypeCorrectly( ByteBuf metadata, WellKnownAuthType expectedType) { int initialReaderIndex = metadata.readerIndex(); - WellKnownAuthType wellKnownAuthType = AuthMetadataFlyweight.decodeWellKnownAuthType(metadata); + WellKnownAuthType wellKnownAuthType = AuthMetadataCodec.readWellKnownAuthType(metadata); Assertions.assertThat(wellKnownAuthType).isEqualTo(expectedType); Assertions.assertThat(metadata.readerIndex()) @@ -426,15 +425,14 @@ private static void checkDecodeWellKnowAuthTypeCorrectly( void shouldReadCustomEncodedAuthType() { String testAuthType = "TestAuthType"; ByteBuf byteBuf = - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, testAuthType, Unpooled.EMPTY_BUFFER); checkDecodeCustomAuthTypeCorrectly(testAuthType, byteBuf); } @Test void shouldThrowExceptionOnEmptyMetadata() { - Assertions.assertThatThrownBy( - () -> AuthMetadataFlyweight.decodeCustomAuthType(Unpooled.EMPTY_BUFFER)) + Assertions.assertThatThrownBy(() -> AuthMetadataCodec.readCustomAuthType(Unpooled.EMPTY_BUFFER)) .hasMessage("Unable to decode custom Auth type. Not enough readable bytes"); } @@ -442,8 +440,8 @@ void shouldThrowExceptionOnEmptyMetadata() { void shouldThrowExceptionOnMalformedMetadata_wellknowninstead() { Assertions.assertThatThrownBy( () -> - AuthMetadataFlyweight.decodeCustomAuthType( - AuthMetadataFlyweight.encodeMetadata( + AuthMetadataCodec.readCustomAuthType( + AuthMetadataCodec.encodeMetadata( ByteBufAllocator.DEFAULT, WellKnownAuthType.BEARER, Unpooled.copiedBuffer(new byte[] {'a', 'b'})))) @@ -454,7 +452,7 @@ void shouldThrowExceptionOnMalformedMetadata_wellknowninstead() { void shouldThrowExceptionOnMalformedMetadata_length() { Assertions.assertThatThrownBy( () -> - AuthMetadataFlyweight.decodeCustomAuthType( + AuthMetadataCodec.readCustomAuthType( ByteBufAllocator.DEFAULT.buffer().writeByte(127).writeChar('a').writeChar('b'))) .hasMessage("Unable to decode custom Auth type. Malformed length or auth type string"); } @@ -462,7 +460,7 @@ void shouldThrowExceptionOnMalformedMetadata_length() { private static void checkDecodeCustomAuthTypeCorrectly(String testAuthType, ByteBuf byteBuf) { int initialReaderIndex = byteBuf.readerIndex(); - Assertions.assertThat(AuthMetadataFlyweight.decodeCustomAuthType(byteBuf).toString()) + Assertions.assertThat(AuthMetadataCodec.readCustomAuthType(byteBuf).toString()) .isEqualTo(testAuthType); Assertions.assertThat(byteBuf.readerIndex()) .isEqualTo(initialReaderIndex + testAuthType.length() + 1); diff --git a/rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataFlyweightTest.java b/rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataCodecTest.java similarity index 85% rename from rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataFlyweightTest.java rename to rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataCodecTest.java index bd5e4295a..3ce07729d 100644 --- a/rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataFlyweightTest.java +++ b/rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataCodecTest.java @@ -16,9 +16,9 @@ package io.rsocket.metadata; -import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeAndContentBuffersSlices; -import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeIdFromMimeBuffer; -import static io.rsocket.metadata.CompositeMetadataFlyweight.decodeMimeTypeFromMimeBuffer; +import static io.rsocket.metadata.CompositeMetadataCodec.decodeMimeAndContentBuffersSlices; +import static io.rsocket.metadata.CompositeMetadataCodec.decodeMimeIdFromMimeBuffer; +import static io.rsocket.metadata.CompositeMetadataCodec.decodeMimeTypeFromMimeBuffer; import static org.assertj.core.api.Assertions.*; import io.netty.buffer.*; @@ -27,7 +27,7 @@ import io.rsocket.util.NumberUtils; import org.junit.jupiter.api.Test; -class CompositeMetadataFlyweightTest { +class CompositeMetadataCodecTest { static String byteToBitsString(byte b) { return String.format("%8s", Integer.toBinaryString(b & 0xFF)).replace(' ', '0'); @@ -49,7 +49,7 @@ void customMimeHeaderLatin1_encodingFails() { assertThatIllegalArgumentException() .isThrownBy( () -> - CompositeMetadataFlyweight.encodeMetadataHeader( + CompositeMetadataCodec.encodeMetadataHeader( ByteBufAllocator.DEFAULT, mimeNotAscii, 0)) .withMessage("custom mime type must be US_ASCII characters only"); } @@ -58,7 +58,7 @@ void customMimeHeaderLatin1_encodingFails() { void customMimeHeaderLength0_encodingFails() { assertThatIllegalArgumentException() .isThrownBy( - () -> CompositeMetadataFlyweight.encodeMetadataHeader(ByteBufAllocator.DEFAULT, "", 0)) + () -> CompositeMetadataCodec.encodeMetadataHeader(ByteBufAllocator.DEFAULT, "", 0)) .withMessage( "custom mime type must have a strictly positive length that fits on 7 unsigned bits, ie 1-128"); } @@ -71,7 +71,7 @@ void customMimeHeaderLength127() { } String mimeString = builder.toString(); ByteBuf encoded = - CompositeMetadataFlyweight.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mimeString, 0); + CompositeMetadataCodec.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mimeString, 0); // remember actual length = encoded length + 1 assertThat(toHeaderBits(encoded)).startsWith("0").isEqualTo("01111110"); @@ -94,7 +94,7 @@ void customMimeHeaderLength127() { .hasToString(mimeString); header.resetReaderIndex(); - assertThat(CompositeMetadataFlyweight.decodeMimeTypeFromMimeBuffer(header)) + assertThat(CompositeMetadataCodec.decodeMimeTypeFromMimeBuffer(header)) .as("decoded mime string") .hasToString(mimeString); @@ -109,7 +109,7 @@ void customMimeHeaderLength128() { } String mimeString = builder.toString(); ByteBuf encoded = - CompositeMetadataFlyweight.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mimeString, 0); + CompositeMetadataCodec.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mimeString, 0); // remember actual length = encoded length + 1 assertThat(toHeaderBits(encoded)).startsWith("0").isEqualTo("01111111"); @@ -132,7 +132,7 @@ void customMimeHeaderLength128() { .hasToString(mimeString); header.resetReaderIndex(); - assertThat(CompositeMetadataFlyweight.decodeMimeTypeFromMimeBuffer(header)) + assertThat(CompositeMetadataCodec.decodeMimeTypeFromMimeBuffer(header)) .as("decoded mime string") .hasToString(mimeString); @@ -149,7 +149,7 @@ void customMimeHeaderLength129_encodingFails() { assertThatIllegalArgumentException() .isThrownBy( () -> - CompositeMetadataFlyweight.encodeMetadataHeader( + CompositeMetadataCodec.encodeMetadataHeader( ByteBufAllocator.DEFAULT, builder.toString(), 0)) .withMessage( "custom mime type must have a strictly positive length that fits on 7 unsigned bits, ie 1-128"); @@ -159,7 +159,7 @@ void customMimeHeaderLength129_encodingFails() { void customMimeHeaderLengthOne() { String mimeString = "w"; ByteBuf encoded = - CompositeMetadataFlyweight.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mimeString, 0); + CompositeMetadataCodec.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mimeString, 0); // remember actual length = encoded length + 1 assertThat(toHeaderBits(encoded)).startsWith("0").isEqualTo("00000000"); @@ -180,7 +180,7 @@ void customMimeHeaderLengthOne() { .hasToString(mimeString); header.resetReaderIndex(); - assertThat(CompositeMetadataFlyweight.decodeMimeTypeFromMimeBuffer(header)) + assertThat(CompositeMetadataCodec.decodeMimeTypeFromMimeBuffer(header)) .as("decoded mime string") .hasToString(mimeString); @@ -191,7 +191,7 @@ void customMimeHeaderLengthOne() { void customMimeHeaderLengthTwo() { String mimeString = "ww"; ByteBuf encoded = - CompositeMetadataFlyweight.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mimeString, 0); + CompositeMetadataCodec.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mimeString, 0); // remember actual length = encoded length + 1 assertThat(toHeaderBits(encoded)).startsWith("0").isEqualTo("00000001"); @@ -214,7 +214,7 @@ void customMimeHeaderLengthTwo() { .hasToString(mimeString); header.resetReaderIndex(); - assertThat(CompositeMetadataFlyweight.decodeMimeTypeFromMimeBuffer(header)) + assertThat(CompositeMetadataCodec.decodeMimeTypeFromMimeBuffer(header)) .as("decoded mime string") .hasToString(mimeString); @@ -228,7 +228,7 @@ void customMimeHeaderUtf8_encodingFails() { assertThatIllegalArgumentException() .isThrownBy( () -> - CompositeMetadataFlyweight.encodeMetadataHeader( + CompositeMetadataCodec.encodeMetadataHeader( ByteBufAllocator.DEFAULT, mimeNotAscii, 0)) .withMessage("custom mime type must be US_ASCII characters only"); } @@ -318,11 +318,11 @@ void decodeTypeSkipsFirstByte() { @Test void encodeMetadataCustomTypeDelegates() { ByteBuf expected = - CompositeMetadataFlyweight.encodeMetadataHeader(ByteBufAllocator.DEFAULT, "foo", 2); + CompositeMetadataCodec.encodeMetadataHeader(ByteBufAllocator.DEFAULT, "foo", 2); CompositeByteBuf test = ByteBufAllocator.DEFAULT.compositeBuffer(); - CompositeMetadataFlyweight.encodeAndAddMetadata( + CompositeMetadataCodec.encodeAndAddMetadata( test, ByteBufAllocator.DEFAULT, "foo", ByteBufUtils.getRandomByteBuf(2)); assertThat((Iterable) test).hasSize(2).first().isEqualTo(expected); @@ -331,14 +331,14 @@ void encodeMetadataCustomTypeDelegates() { @Test void encodeMetadataKnownTypeDelegates() { ByteBuf expected = - CompositeMetadataFlyweight.encodeMetadataHeader( + CompositeMetadataCodec.encodeMetadataHeader( ByteBufAllocator.DEFAULT, WellKnownMimeType.APPLICATION_OCTET_STREAM.getIdentifier(), 2); CompositeByteBuf test = ByteBufAllocator.DEFAULT.compositeBuffer(); - CompositeMetadataFlyweight.encodeAndAddMetadata( + CompositeMetadataCodec.encodeAndAddMetadata( test, ByteBufAllocator.DEFAULT, WellKnownMimeType.APPLICATION_OCTET_STREAM, @@ -350,11 +350,11 @@ void encodeMetadataKnownTypeDelegates() { @Test void encodeMetadataReservedTypeDelegates() { ByteBuf expected = - CompositeMetadataFlyweight.encodeMetadataHeader(ByteBufAllocator.DEFAULT, (byte) 120, 2); + CompositeMetadataCodec.encodeMetadataHeader(ByteBufAllocator.DEFAULT, (byte) 120, 2); CompositeByteBuf test = ByteBufAllocator.DEFAULT.compositeBuffer(); - CompositeMetadataFlyweight.encodeAndAddMetadata( + CompositeMetadataCodec.encodeAndAddMetadata( test, ByteBufAllocator.DEFAULT, (byte) 120, ByteBufUtils.getRandomByteBuf(2)); assertThat((Iterable) test).hasSize(2).first().isEqualTo(expected); @@ -365,7 +365,7 @@ void encodeTryCompressWithCompressableType() { ByteBuf metadata = ByteBufUtils.getRandomByteBuf(2); CompositeByteBuf target = UnpooledByteBufAllocator.DEFAULT.compositeBuffer(); - CompositeMetadataFlyweight.encodeAndAddMetadataWithCompression( + CompositeMetadataCodec.encodeAndAddMetadataWithCompression( target, UnpooledByteBufAllocator.DEFAULT, WellKnownMimeType.APPLICATION_AVRO.getString(), @@ -379,7 +379,7 @@ void encodeTryCompressWithCustomType() { ByteBuf metadata = ByteBufUtils.getRandomByteBuf(2); CompositeByteBuf target = UnpooledByteBufAllocator.DEFAULT.compositeBuffer(); - CompositeMetadataFlyweight.encodeAndAddMetadataWithCompression( + CompositeMetadataCodec.encodeAndAddMetadataWithCompression( target, UnpooledByteBufAllocator.DEFAULT, "custom/example", metadata); assertThat(target.readableBytes()).as("readableBytes 1 + 14 + 3 + 2").isEqualTo(20); @@ -393,32 +393,32 @@ void hasEntry() { Unpooled.compositeBuffer() .addComponent( true, - CompositeMetadataFlyweight.encodeMetadataHeader( + CompositeMetadataCodec.encodeMetadataHeader( ByteBufAllocator.DEFAULT, mime.getIdentifier(), 0)) .addComponent( true, - CompositeMetadataFlyweight.encodeMetadataHeader( + CompositeMetadataCodec.encodeMetadataHeader( ByteBufAllocator.DEFAULT, mime.getIdentifier(), 0)); - assertThat(CompositeMetadataFlyweight.hasEntry(buffer, 0)).isTrue(); - assertThat(CompositeMetadataFlyweight.hasEntry(buffer, 4)).isTrue(); - assertThat(CompositeMetadataFlyweight.hasEntry(buffer, 8)).isFalse(); + assertThat(CompositeMetadataCodec.hasEntry(buffer, 0)).isTrue(); + assertThat(CompositeMetadataCodec.hasEntry(buffer, 4)).isTrue(); + assertThat(CompositeMetadataCodec.hasEntry(buffer, 8)).isFalse(); } @Test void isWellKnownMimeType() { ByteBuf wellKnown = Unpooled.buffer().writeByte(0); - assertThat(CompositeMetadataFlyweight.isWellKnownMimeType(wellKnown)).isTrue(); + assertThat(CompositeMetadataCodec.isWellKnownMimeType(wellKnown)).isTrue(); ByteBuf explicit = Unpooled.buffer().writeByte(2).writeChar('a'); - assertThat(CompositeMetadataFlyweight.isWellKnownMimeType(explicit)).isFalse(); + assertThat(CompositeMetadataCodec.isWellKnownMimeType(explicit)).isFalse(); } @Test void knownMimeHeader120_reserved() { byte mime = (byte) 120; ByteBuf encoded = - CompositeMetadataFlyweight.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mime, 0); + CompositeMetadataCodec.encodeMetadataHeader(ByteBufAllocator.DEFAULT, mime, 0); assertThat(mime) .as("smoke test RESERVED_120 unsigned 7 bits representation") @@ -453,7 +453,7 @@ void knownMimeHeader127_compositeMetadata() { .isEqualTo((byte) 127) .isEqualTo((byte) 0b01111111); ByteBuf encoded = - CompositeMetadataFlyweight.encodeMetadataHeader( + CompositeMetadataCodec.encodeMetadataHeader( ByteBufAllocator.DEFAULT, mime.getIdentifier(), 0); assertThat(toHeaderBits(encoded)) @@ -490,7 +490,7 @@ void knownMimeHeaderZero_avro() { .isEqualTo((byte) 0) .isEqualTo((byte) 0b00000000); ByteBuf encoded = - CompositeMetadataFlyweight.encodeMetadataHeader( + CompositeMetadataCodec.encodeMetadataHeader( ByteBufAllocator.DEFAULT, mime.getIdentifier(), 0); assertThat(toHeaderBits(encoded)) @@ -543,8 +543,7 @@ protected ByteBuf newDirectBuffer(int initialCapacity, int maxCapacity) { } }; - assertThatCode( - () -> CompositeMetadataFlyweight.encodeMetadataHeader(allocator, "custom/type", 0)) + assertThatCode(() -> CompositeMetadataCodec.encodeMetadataHeader(allocator, "custom/type", 0)) .doesNotThrowAnyException(); assertThat(badBuf.readByte()).isEqualTo((byte) 10); diff --git a/rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataTest.java b/rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataTest.java index f06bdcc0c..0b81ab4b0 100644 --- a/rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataTest.java +++ b/rsocket-core/src/test/java/io/rsocket/metadata/CompositeMetadataTest.java @@ -108,11 +108,11 @@ void decodeThreeEntries() { metadata3.writeByte(88); CompositeByteBuf compositeMetadataBuffer = ByteBufAllocator.DEFAULT.compositeBuffer(); - CompositeMetadataFlyweight.encodeAndAddMetadata( + CompositeMetadataCodec.encodeAndAddMetadata( compositeMetadataBuffer, ByteBufAllocator.DEFAULT, mimeType1, metadata1); - CompositeMetadataFlyweight.encodeAndAddMetadata( + CompositeMetadataCodec.encodeAndAddMetadata( compositeMetadataBuffer, ByteBufAllocator.DEFAULT, mimeType2, metadata2); - CompositeMetadataFlyweight.encodeAndAddMetadata( + CompositeMetadataCodec.encodeAndAddMetadata( compositeMetadataBuffer, ByteBufAllocator.DEFAULT, reserved, metadata3); Iterator iterator = new CompositeMetadata(compositeMetadataBuffer, true).iterator(); diff --git a/rsocket-core/src/test/java/io/rsocket/metadata/TaggingMetadataTest.java b/rsocket-core/src/test/java/io/rsocket/metadata/TaggingMetadataTest.java index d1fbb50b0..b65ffafee 100644 --- a/rsocket-core/src/test/java/io/rsocket/metadata/TaggingMetadataTest.java +++ b/rsocket-core/src/test/java/io/rsocket/metadata/TaggingMetadataTest.java @@ -23,7 +23,7 @@ public void testParseTags() { Arrays.asList( "ws://localhost:8080/rsocket", String.join("", Collections.nCopies(129, "x"))); TaggingMetadata taggingMetadata = - TaggingMetadataFlyweight.createTaggingMetadata( + TaggingMetadataCodec.createTaggingMetadata( byteBufAllocator, "message/x.rsocket.routing.v0", tags); TaggingMetadata taggingMetadataCopy = new TaggingMetadata("message/x.rsocket.routing.v0", taggingMetadata.getContent()); @@ -37,7 +37,7 @@ public void testEmptyTagAndOverLengthTag() { Arrays.asList( "ws://localhost:8080/rsocket", "", String.join("", Collections.nCopies(256, "x"))); TaggingMetadata taggingMetadata = - TaggingMetadataFlyweight.createTaggingMetadata( + TaggingMetadataCodec.createTaggingMetadata( byteBufAllocator, "message/x.rsocket.routing.v0", tags); TaggingMetadata taggingMetadataCopy = new TaggingMetadata("message/x.rsocket.routing.v0", taggingMetadata.getContent()); diff --git a/rsocket-core/src/test/java/io/rsocket/resume/ResumeExpBackoffTest.java b/rsocket-core/src/test/java/io/rsocket/resume/ResumeExpBackoffTest.java deleted file mode 100644 index d86276466..000000000 --- a/rsocket-core/src/test/java/io/rsocket/resume/ResumeExpBackoffTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2015-2019 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 io.rsocket.resume; - -import static org.junit.jupiter.api.Assertions.assertThrows; - -import java.time.Duration; -import java.util.List; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Flux; - -public class ResumeExpBackoffTest { - - @Test - void backOffSeries() { - Duration firstBackoff = Duration.ofSeconds(1); - Duration maxBackoff = Duration.ofSeconds(32); - int factor = 2; - ExponentialBackoffResumeStrategy strategy = - new ExponentialBackoffResumeStrategy(firstBackoff, maxBackoff, factor); - - List expected = - Flux.just(1, 2, 4, 8, 16, 32, 32).map(Duration::ofSeconds).collectList().block(); - - List actual = Flux.range(1, 7).map(v -> strategy.next()).collectList().block(); - - Assertions.assertThat(actual).isEqualTo(expected); - } - - @Test - void nullFirstBackoff() { - assertThrows( - NullPointerException.class, - () -> { - ExponentialBackoffResumeStrategy strategy = - new ExponentialBackoffResumeStrategy(Duration.ofSeconds(1), null, 42); - }); - } - - @Test - void nullMaxBackoff() { - assertThrows( - NullPointerException.class, - () -> { - ExponentialBackoffResumeStrategy strategy = - new ExponentialBackoffResumeStrategy(null, Duration.ofSeconds(1), 42); - }); - } - - @Test - void negativeFactor() { - assertThrows( - IllegalArgumentException.class, - () -> { - ExponentialBackoffResumeStrategy strategy = - new ExponentialBackoffResumeStrategy( - Duration.ofSeconds(1), Duration.ofSeconds(32), -1); - }); - } -} diff --git a/rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/client/WebsocketClientTransport.java b/rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/client/WebsocketClientTransport.java index dd6c535db..fe66da50a 100644 --- a/rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/client/WebsocketClientTransport.java +++ b/rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/client/WebsocketClientTransport.java @@ -27,10 +27,8 @@ import java.net.InetSocketAddress; import java.net.URI; import java.util.Arrays; -import java.util.Map; import java.util.Objects; import java.util.function.Consumer; -import java.util.function.Supplier; import reactor.core.publisher.Mono; import reactor.netty.http.client.HttpClient; import reactor.netty.http.client.WebsocketClientSpec; @@ -40,9 +38,7 @@ * An implementation of {@link ClientTransport} that connects to a {@link ServerTransport} over * WebSocket. */ -@SuppressWarnings("deprecation") -public final class WebsocketClientTransport - implements ClientTransport, io.rsocket.transport.TransportHeaderAware { +public final class WebsocketClientTransport implements ClientTransport { private static final String DEFAULT_PATH = "/"; @@ -164,13 +160,6 @@ public WebsocketClientTransport webSocketSpec(Consumer> transportHeaders) { - if (transportHeaders != null) { - transportHeaders.get().forEach((name, value) -> headers.add(name, value)); - } - } - @Override public int maxFrameLength() { return specBuilder.build().maxFramePayloadLength(); diff --git a/rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/server/WebsocketServerTransport.java b/rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/server/WebsocketServerTransport.java index 4fb6417c9..81ac8dcb6 100644 --- a/rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/server/WebsocketServerTransport.java +++ b/rsocket-transport-netty/src/main/java/io/rsocket/transport/netty/server/WebsocketServerTransport.java @@ -23,9 +23,7 @@ import io.rsocket.transport.netty.WebsocketDuplexConnection; import java.net.InetSocketAddress; import java.util.Arrays; -import java.util.Map; import java.util.Objects; -import java.util.function.Supplier; import reactor.core.publisher.Mono; import reactor.netty.Connection; import reactor.netty.http.server.HttpServer; @@ -34,10 +32,8 @@ * An implementation of {@link ServerTransport} that connects to a {@link ClientTransport} via a * Websocket. */ -@SuppressWarnings("deprecation") public final class WebsocketServerTransport - extends BaseWebsocketServerTransport - implements io.rsocket.transport.TransportHeaderAware { + extends BaseWebsocketServerTransport { private final HttpServer server; @@ -111,13 +107,6 @@ public WebsocketServerTransport header(String name, String... values) { return this; } - @Override - public void setTransportHeaders(Supplier> transportHeaders) { - if (transportHeaders != null) { - transportHeaders.get().forEach((name, value) -> headers.add(name, value)); - } - } - @Override public Mono start(ConnectionAcceptor acceptor) { Objects.requireNonNull(acceptor, "acceptor must not be null"); diff --git a/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/client/WebsocketClientTransportTest.java b/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/client/WebsocketClientTransportTest.java index 944d20313..2a3670251 100644 --- a/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/client/WebsocketClientTransportTest.java +++ b/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/client/WebsocketClientTransportTest.java @@ -22,7 +22,6 @@ import io.rsocket.transport.netty.server.WebsocketServerTransport; import java.net.InetSocketAddress; import java.net.URI; -import java.util.Collections; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -150,10 +149,4 @@ void createUriPath() { .isNotNull() .hasFieldOrPropertyWithValue("path", "/test"); } - - @DisplayName("sets transport headers") - @Test - void setTransportHeader() { - WebsocketClientTransport.create(8000).setTransportHeaders(Collections::emptyMap); - } } diff --git a/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/server/WebsocketServerTransportTest.java b/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/server/WebsocketServerTransportTest.java index 3ae1b2068..b9b6201b8 100644 --- a/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/server/WebsocketServerTransportTest.java +++ b/rsocket-transport-netty/src/test/java/io/rsocket/transport/netty/server/WebsocketServerTransportTest.java @@ -22,7 +22,6 @@ import static org.mockito.ArgumentMatchers.any; import java.net.InetSocketAddress; -import java.util.Collections; import java.util.function.BiFunction; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -114,12 +113,6 @@ void createPort() { assertThat(WebsocketServerTransport.create(8000)).isNotNull(); } - @DisplayName("sets transport headers") - @Test - void setTransportHeader() { - WebsocketServerTransport.create(8000).setTransportHeaders(Collections::emptyMap); - } - @DisplayName("starts server") @Test void start() {