diff options
author | Ivan Motsch | 2018-11-16 19:19:01 +0000 |
---|---|---|
committer | Ivan Motsch | 2018-11-16 19:21:48 +0000 |
commit | b1f1a3d8cc42c177c8b7d3fb449f20d71e33445d (patch) | |
tree | 1cdea30bd53754ff5b67e3f433f9f90b32911f89 | |
parent | 4081afbc146f2ef9a6b89493ec3825df3e1f37b6 (diff) | |
download | org.eclipse.scout.rt-b1f1a3d8cc42c177c8b7d3fb449f20d71e33445d.tar.gz org.eclipse.scout.rt-b1f1a3d8cc42c177c8b7d3fb449f20d71e33445d.tar.xz org.eclipse.scout.rt-b1f1a3d8cc42c177c8b7d3fb449f20d71e33445d.zip |
fix HttpServiceTunnel retryPost
accidental usage of the ByteArrayContent with retrySupported=true
fixed to the usage of the alternate ByteArrayContentEx with
retrySupported=false.
Change-Id: Ic4543f8d0ed301dfcca7707281472dff538aa252
Signed-off-by: Ivan Motsch <ivan.motsch@bsiag.com>
2 files changed, 76 insertions, 2 deletions
diff --git a/org.eclipse.scout.rt.shared/src/main/java/org/eclipse/scout/rt/shared/servicetunnel/http/ByteArrayContentEx.java b/org.eclipse.scout.rt.shared/src/main/java/org/eclipse/scout/rt/shared/servicetunnel/http/ByteArrayContentEx.java new file mode 100644 index 0000000000..7fff5dc8ad --- /dev/null +++ b/org.eclipse.scout.rt.shared/src/main/java/org/eclipse/scout/rt/shared/servicetunnel/http/ByteArrayContentEx.java @@ -0,0 +1,75 @@ +/******************************************************************************* + * Copyright (c) 2010-2018 BSI Business Systems Integration AG. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * BSI Business Systems Integration AG - initial API and implementation + ******************************************************************************/ +package org.eclipse.scout.rt.shared.servicetunnel.http; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import com.google.api.client.http.AbstractInputStreamContent; +import com.google.api.client.util.Preconditions; + +/** + * Implementation of {@link AbstractInputStreamContent} based on a byte array that is repeatable depending on the flag + * retrySupported. + * + * @since 9.0 + */ +public class ByteArrayContentEx extends AbstractInputStreamContent { + private final byte[] m_bytes; + private final int m_offset; + private final int m_length; + private boolean m_retrySupported; + + public ByteArrayContentEx(String type, byte[] array, boolean retrySupported) { + this(type, array, 0, array.length, retrySupported); + } + + public ByteArrayContentEx(String type, byte[] array, int offset, int length, boolean retrySupported) { + super(type); + Preconditions.checkArgument(offset >= 0 && length >= 0 && offset + length <= array.length, "offset %s, length %s, array length %s", offset, length, array.length); + m_bytes = Preconditions.checkNotNull(array); + m_offset = offset; + m_length = length; + m_retrySupported = retrySupported; + } + + @Override + public long getLength() { + return m_length; + } + + @Override + public boolean retrySupported() { + return m_retrySupported; + } + + @Override + public InputStream getInputStream() { + return new ByteArrayInputStream(m_bytes, m_offset, m_length); + } + + public ByteArrayContentEx setRetrySupported(boolean retrySupported) { + m_retrySupported = retrySupported; + return this; + } + + @Override + public ByteArrayContentEx setType(String type) { + super.setType(type); + return this; + } + + @Override + public ByteArrayContentEx setCloseInputStream(boolean closeInputStream) { + super.setCloseInputStream(closeInputStream); + return this; + } +} diff --git a/org.eclipse.scout.rt.shared/src/main/java/org/eclipse/scout/rt/shared/servicetunnel/http/HttpServiceTunnel.java b/org.eclipse.scout.rt.shared/src/main/java/org/eclipse/scout/rt/shared/servicetunnel/http/HttpServiceTunnel.java index 6d93fd4f04..bd2443dee1 100644 --- a/org.eclipse.scout.rt.shared/src/main/java/org/eclipse/scout/rt/shared/servicetunnel/http/HttpServiceTunnel.java +++ b/org.eclipse.scout.rt.shared/src/main/java/org/eclipse/scout/rt/shared/servicetunnel/http/HttpServiceTunnel.java @@ -34,7 +34,6 @@ import org.eclipse.scout.rt.shared.servicetunnel.IServiceTunnelContentHandler; import org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelRequest; import org.eclipse.scout.rt.shared.servicetunnel.ServiceTunnelResponse; -import com.google.api.client.http.ByteArrayContent; import com.google.api.client.http.GenericUrl; import com.google.api.client.http.HttpHeaders; import com.google.api.client.http.HttpRequest; @@ -110,7 +109,7 @@ public class HttpServiceTunnel extends AbstractServiceTunnel { } HttpRequestFactory requestFactory = getHttpTransportManager().getHttpRequestFactory(); - HttpRequest request = requestFactory.buildPostRequest(getGenericUrl(), new ByteArrayContent(null, callData)); + HttpRequest request = requestFactory.buildPostRequest(getGenericUrl(), new ByteArrayContentEx(null, callData, false)); HttpHeaders headers = request.getHeaders(); headers.setCacheControl("no-cache"); headers.setContentType("text/xml"); |