Repository: cxf Updated Branches: refs/heads/master 1b0d3c964 -> 03cacaa47
Reintroducing a 3-callback option for NioReadEntity for now but with a no-arg completion based on the feedback from Andriy Project: http://git-wip-us.apache.org/repos/asf/cxf/repo Commit: http://git-wip-us.apache.org/repos/asf/cxf/commit/03cacaa4 Tree: http://git-wip-us.apache.org/repos/asf/cxf/tree/03cacaa4 Diff: http://git-wip-us.apache.org/repos/asf/cxf/diff/03cacaa4 Branch: refs/heads/master Commit: 03cacaa47d81f23ae51a976b65832ea50fb68d17 Parents: 1b0d3c9 Author: Sergey Beryozkin <sberyoz...@gmail.com> Authored: Wed Aug 9 17:48:52 2017 +0100 Committer: Sergey Beryozkin <sberyoz...@gmail.com> Committed: Wed Aug 9 17:48:52 2017 +0100 ---------------------------------------------------------------------- .../apache/cxf/jaxrs/nio/NioErrorHandler.java | 30 ++++++++++++++++++++ .../cxf/jaxrs/nio/NioReadCompletionHandler.java | 2 +- .../org/apache/cxf/jaxrs/nio/NioReadEntity.java | 8 +++++- .../cxf/jaxrs/nio/NioReadListenerImpl.java | 4 +-- .../apache/cxf/jaxrs/nio/NioWriteEntity.java | 6 ++-- .../cxf/jaxrs/nio/NioWriteErrorHandler.java | 30 -------------------- .../cxf/systest/jaxrs/nio/NioBookStore.java | 15 +++++----- 7 files changed, 51 insertions(+), 44 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cxf/blob/03cacaa4/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioErrorHandler.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioErrorHandler.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioErrorHandler.java new file mode 100644 index 0000000..e7a538f --- /dev/null +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioErrorHandler.java @@ -0,0 +1,30 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.cxf.jaxrs.nio; + +@FunctionalInterface +public interface NioErrorHandler { + /** + * Method called when an exception or error occurred. + * + * @param throwable the error or exception encountered. + */ + void error(Throwable throwable) throws Throwable; +} + http://git-wip-us.apache.org/repos/asf/cxf/blob/03cacaa4/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java index 2901166..97eef87 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadCompletionHandler.java @@ -20,6 +20,6 @@ package org.apache.cxf.jaxrs.nio; @FunctionalInterface public interface NioReadCompletionHandler { - void complete(NioInputStream in, Throwable t); + void complete(); } http://git-wip-us.apache.org/repos/asf/cxf/blob/03cacaa4/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java index 413b744..2dde9ae 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadEntity.java @@ -29,10 +29,12 @@ import org.apache.cxf.transport.http.AbstractHTTPDestination; public class NioReadEntity { private final NioReadHandler reader; private final NioReadCompletionHandler completion; + private final NioErrorHandler error; - public NioReadEntity(NioReadHandler reader, NioReadCompletionHandler completion) { + public NioReadEntity(NioReadHandler reader, NioReadCompletionHandler completion, NioErrorHandler error) { this.reader = reader; this.completion = completion; + this.error = error; try { final Message m = JAXRSUtils.getCurrentMessage(); @@ -54,4 +56,8 @@ public class NioReadEntity { public NioReadCompletionHandler getCompletion() { return completion; } + + public NioErrorHandler getError() { + return error; + } } http://git-wip-us.apache.org/repos/asf/cxf/blob/03cacaa4/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java index cece8b9..a090c5f 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioReadListenerImpl.java @@ -40,7 +40,7 @@ public final class NioReadListenerImpl implements ReadListener { @Override public void onError(Throwable t) { try { - entity.getCompletion().complete(null, t); + entity.getError().error(t); } catch (final Throwable ex) { LOG.warning("NIO NioReadListener error: " + ExceptionUtils.getStackTrace(ex)); } @@ -55,6 +55,6 @@ public final class NioReadListenerImpl implements ReadListener { @Override public void onAllDataRead() throws IOException { - entity.getCompletion().complete(in, null); + entity.getCompletion().complete(); } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/cxf/blob/03cacaa4/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java index af39eaa..32874e3 100644 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java +++ b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteEntity.java @@ -20,9 +20,9 @@ package org.apache.cxf.jaxrs.nio; public final class NioWriteEntity { private final NioWriteHandler writer; - private final NioWriteErrorHandler error; + private final NioErrorHandler error; - public NioWriteEntity(final NioWriteHandler writer, final NioWriteErrorHandler error) { + public NioWriteEntity(final NioWriteHandler writer, final NioErrorHandler error) { this.writer = writer; this.error = error; } @@ -31,7 +31,7 @@ public final class NioWriteEntity { return writer; } - public NioWriteErrorHandler getError() { + public NioErrorHandler getError() { return error; } } http://git-wip-us.apache.org/repos/asf/cxf/blob/03cacaa4/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteErrorHandler.java ---------------------------------------------------------------------- diff --git a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteErrorHandler.java b/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteErrorHandler.java deleted file mode 100644 index 91feb2c..0000000 --- a/rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/nio/NioWriteErrorHandler.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.cxf.jaxrs.nio; - -@FunctionalInterface -public interface NioWriteErrorHandler { - /** - * Method called when an exception or error occurred. - * - * @param throwable the error or exception encountered. - */ - void error(Throwable throwable) throws Throwable; -} - http://git-wip-us.apache.org/repos/asf/cxf/blob/03cacaa4/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java ---------------------------------------------------------------------- diff --git a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java index 7545a28..d98cfdc 100644 --- a/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java +++ b/systests/jaxrs/src/test/java/org/apache/cxf/systest/jaxrs/nio/NioBookStore.java @@ -112,12 +112,13 @@ public class NioBookStore { } }, // completion handler - (in, throwable) -> { - if (throwable != null) { - response.resume(throwable); - } else { - response.resume("Book Store uploaded: " + adder.longValue() + " bytes"); - } - }); + () -> { + response.resume("Book Store uploaded: " + adder.longValue() + " bytes"); + }, + // error handler + t -> { + response.resume(t); + } + ); } }