This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new f02da06 org.apache.juneau.http tests.
f02da06 is described below
commit f02da063901ecb8f7b2260b44dbd58b9cee901cc
Author: JamesBognar <[email protected]>
AuthorDate: Sun Jul 12 12:36:45 2020 -0400
org.apache.juneau.http tests.
---
.../java/org/apache/juneau/http/BasicHeader.java | 51 +++-
.../org/apache/juneau/http/BasicHttpEntity.java | 201 ++++++++++++---
.../org/apache/juneau/http/BasicHttpResource.java | 48 +++-
.../org/apache/juneau/http/BasicNameValuePair.java | 53 +++-
.../org/apache/juneau/http/ReaderResource.java | 240 ------------------
.../juneau/http/ResolvingReaderResource.java | 281 ---------------------
.../apache/juneau/http/SerializedHttpEntity.java | 60 +++--
.../org/apache/juneau/http/StreamResource.java | 239 ------------------
.../org/apache/juneau/http/header/ContentType.java | 12 +
.../java/org/apache/juneau/svl/VarResolver.java | 11 -
.../main/ConfigurablePropertyCodeGenerator.java | 6 +-
...esource_Test.java => BasicHttpEntity_Test.java} | 80 ++++--
.../apache/juneau/http/BasicHttpResource_Test.java | 3 +
.../apache/juneau/http/ReaderResource_Test.java | 113 ---------
.../rest/client2/Remote_CommonInterfaces_Test.java | 20 +-
.../rest/client2/RestClient_BasicCalls_Test.java | 24 +-
.../juneau/rest/client2/RestClient_Body_Test.java | 164 +++++++-----
.../org/apache/juneau/rest/client2/RestClient.java | 25 +-
.../apache/juneau/rest/client2/RestRequest.java | 21 +-
.../juneau/rest/client2/RestResponseBody.java | 6 +-
.../apache/juneau/rest/mock2/MockRestClient.java | 8 +-
...esourceTest.java => BasicHttpResourceTest.java} | 30 +--
.../juneau/rest/helper/StreamResourceTest.java | 116 ---------
.../java/org/apache/juneau/rest/RestContext.java | 12 +-
.../java/org/apache/juneau/rest/RestRequest.java | 65 +----
.../org/apache/juneau/rest/annotation/Rest.java | 2 +-
.../juneau/rest/annotation/RestResource.java | 2 +-
27 files changed, 592 insertions(+), 1301 deletions(-)
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHeader.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHeader.java
index 30b9985..7c0f373 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHeader.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHeader.java
@@ -28,6 +28,22 @@ import org.apache.juneau.svl.*;
/**
* Superclass of all headers defined in this package.
+ *
+ * Provides the following features:
+ * <ul class='spaced-list'>
+ * <li>
+ * Default support for various streams and readers.
+ * <li>
+ * Content from {@link Supplier Suppliers}.
+ * <li>
+ * Caching.
+ * <li>
+ * Fluent setters.
+ * <li>
+ * Fluent assertions.
+ * <li>
+ * {@doc juneau-marshall.SimpleVariableLanguage.SvlVariables SVL
variables}.
+ * </ul>
*/
@BeanIgnore
public class BasicHeader implements Header, Cloneable, Serializable {
@@ -38,6 +54,7 @@ public class BasicHeader implements Header, Cloneable,
Serializable {
private final String name;
private final Object value;
private HeaderElement[] elements;
+ private VarResolverSession varSession;
/**
* Convenience creator.
@@ -85,9 +102,6 @@ public class BasicHeader implements Header, Cloneable,
Serializable {
* <p>
* Header value is re-evaluated on each call to {@link #getValue()}.
*
- * <p>
- * Note that you can use {@link VarResolver#supplier(String)} to create
headers with auto-resolving embedded SVL variables.
- *
* @param name The parameter name.
* @param value
* The parameter value supplier.
@@ -147,6 +161,32 @@ public class BasicHeader implements Header, Cloneable,
Serializable {
this.value = value;
}
+ /**
+ * Allows SVL variables to be resolved when calling {@link #getValue()}.
+ *
+ * @param varResolver
+ * The variable resolver to use for resolving SVL variables.
+ * @return This object (for method chaining).
+ */
+ @FluentSetter
+ public BasicHeader resolving(VarResolver varResolver) {
+ this.varSession = varResolver == null ? null :
varResolver.createSession();
+ return this;
+ }
+
+ /**
+ * Allows SVL variables to be resolved when calling {@link #getValue()}.
+ *
+ * @param varSession
+ * The variable resolver session to use for resolving SVL
variables.
+ * @return This object (for method chaining).
+ */
+ @FluentSetter
+ public BasicHeader resolving(VarResolverSession varSession) {
+ this.varSession = varSession;
+ return this;
+ }
+
@Override /* Header */
public String getName() {
return name;
@@ -154,7 +194,8 @@ public class BasicHeader implements Header, Cloneable,
Serializable {
@Override /* Header */
public String getValue() {
- return stringify(getRawValue());
+ String s = stringify(getRawValue());
+ return varSession == null ? s : varSession.resolve(s);
}
/**
@@ -232,6 +273,8 @@ public class BasicHeader implements Header, Cloneable,
Serializable {
public boolean equals(Object o) {
if (! (o instanceof Header))
return false;
+ if (varSession != null)
+ return false;
return ObjectUtils.eq(this, (Header)o, (x,y)->isEquals(x.name,
y.getName()) && isEquals(x.getValue(), y.getValue()));
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHttpEntity.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHttpEntity.java
index c2341f0..f77437d 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHttpEntity.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHttpEntity.java
@@ -16,17 +16,42 @@ import java.io.*;
import java.util.function.*;
import org.apache.http.*;
+import org.apache.juneau.assertions.*;
import org.apache.juneau.internal.*;
+import org.apache.juneau.svl.*;
/**
- * An extension of {@link org.apache.http.entity.BasicHttpEntity} with fluent
setters.
+ * An extension of {@link org.apache.http.entity.BasicHttpEntity} with
additional features.
*
- * <p>
- * Includes automatic support for a variety of content types.
+ * Provides the following features:
+ * <ul class='spaced-list'>
+ * <li>
+ * Default support for various streams and readers.
+ * <li>
+ * Content from {@link Supplier Suppliers}.
+ * <li>
+ * Caching.
+ * <li>
+ * Fluent setters.
+ * <li>
+ * Fluent assertions.
+ * <li>
+ * {@doc juneau-marshall.SimpleVariableLanguage.SvlVariables SVL
variables}.
+ * </ul>
*/
public class BasicHttpEntity extends org.apache.http.entity.BasicHttpEntity {
private Object content;
private boolean cache;
+ private VarResolverSession varSession;
+
+ /**
+ * Creator.
+ *
+ * @return A new empty {@link BasicHttpEntity} object.
+ */
+ public static BasicHttpEntity create() {
+ return new BasicHttpEntity();
+ }
/**
* Creator.
@@ -43,10 +68,10 @@ public class BasicHttpEntity extends
org.apache.http.entity.BasicHttpEntity {
* <li>A {@link Supplier} of anything on this list.
* </ul>
* </ul>
- * @return A new empty {@link ReaderResource} object.
+ * @return A new empty {@link BasicHttpEntity} object.
*/
public static BasicHttpEntity of(Object content) {
- return new BasicHttpEntity().content(content);
+ return new BasicHttpEntity(content);
}
/**
@@ -64,14 +89,15 @@ public class BasicHttpEntity extends
org.apache.http.entity.BasicHttpEntity {
* <li>A {@link Supplier} of anything on this list.
* </ul>
* </ul>
- * @return A new empty {@link ReaderResource} object.
+ * @return A new empty {@link BasicHttpEntity} object.
*/
public static BasicHttpEntity of(Supplier<?> content) {
- return new BasicHttpEntity().content(content);
+ return new BasicHttpEntity(content);
}
/**
* Creates a new basic entity.
+ *
* The content is initially missing, the content length
* is set to a negative number.
*/
@@ -80,6 +106,27 @@ public class BasicHttpEntity extends
org.apache.http.entity.BasicHttpEntity {
}
/**
+ * Creates a new basic entity.
+ *
+ * @param content
+ * The content.
+ * <br>Can be any of the following:
+ * <ul>
+ * <li><c>InputStream</c>
+ * <li><c>Reader</c> - Converted to UTF-8 bytes.
+ * <li><c>File</c>
+ * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
+ * <li><c><jk>byte</jk>[]</c>.
+ * <li>A {@link Supplier} of anything on this list.
+ * </ul>
+ * </ul>
+ */
+ public BasicHttpEntity(Object content) {
+ super();
+ content(content);
+ }
+
+ /**
* Sets the content on this entity.
*
* @param value
@@ -188,17 +235,26 @@ public class BasicHttpEntity extends
org.apache.http.entity.BasicHttpEntity {
/**
* Shortcut for calling {@link #setChunked(boolean)} with <jk>true</jk>.
*
+ * <ul class='notes'>
+ * <li>If the {@link #getContentLength()} method returns a
negative value, the HttpClient code will always
+ * use chunked encoding.
+ * </ul>
+ *
* @return This object (for method chaining).
*/
@FluentSetter
public BasicHttpEntity chunked() {
- super.setChunked(true);
- return this;
+ return chunked(true);
}
/**
* Shortcut for calling {@link #setChunked(boolean)}.
*
+ * <ul class='notes'>
+ * <li>If the {@link #getContentLength()} method returns a
negative value, the HttpClient code will always
+ * use chunked encoding.
+ * </ul>
+ *
* @param value The new value for this flag.
* @return This object (for method chaining).
*/
@@ -232,22 +288,93 @@ public class BasicHttpEntity extends
org.apache.http.entity.BasicHttpEntity {
return this;
}
+ /**
+ * Allows SVL variables to be resolved in the entity body.
+ *
+ * @param varResolver
+ * The variable resolver to use for resolving SVL variables.
+ * @return This object (for method chaining).
+ */
+ @FluentSetter
+ public BasicHttpEntity resolving(VarResolver varResolver) {
+ this.varSession = varResolver == null ? null :
varResolver.createSession();
+ return this;
+ }
+
+ /**
+ * Allows SVL variables to be resolved in the entity body.
+ *
+ * @param varSession
+ * The variable resolver session to use for resolving SVL
variables.
+ * @return This object (for method chaining).
+ */
+ @FluentSetter
+ public BasicHttpEntity resolving(VarResolverSession varSession) {
+ this.varSession = varSession;
+ return this;
+ }
+
+ /**
+ * Converts the contents of this entity as a byte array.
+ *
+ * @return The contents of this entity as a byte array.
+ * @throws IOException If a problem occurred while trying to read the
byte array.
+ */
+ public String asString() throws IOException {
+ return IOUtils.read(getRawContent());
+ }
+
+ /**
+ * Converts the contents of this entity as a byte array.
+ *
+ * @return The contents of this entity as a byte array.
+ * @throws IOException If a problem occurred while trying to read the
byte array.
+ */
+ public byte[] asBytes() throws IOException {
+ return IOUtils.readBytes(getRawContent());
+ }
+
+ /**
+ * Returns an assertion on the contents of this entity.
+ *
+ * @return A new fluent assertion.
+ * @throws IOException If a problem occurred while trying to read the
byte array.
+ */
+ public FluentStringAssertion<BasicHttpEntity> assertString() throws
IOException {
+ return new FluentStringAssertion<>(asString(), this);
+ }
+
+ /**
+ * Returns an assertion on the contents of this entity.
+ *
+ * @return A new fluent assertion.
+ * @throws IOException If a problem occurred while trying to read the
byte array.
+ */
+ public FluentByteArrayAssertion<BasicHttpEntity> assertBytes() throws
IOException {
+ return new FluentByteArrayAssertion<>(asBytes(), this);
+ }
+
@Override
public boolean isRepeatable() {
- return cache || content instanceof File || content instanceof
CharSequence || content instanceof byte[];
+ Object o = getRawContent();
+ return cache || o instanceof File || o instanceof CharSequence
|| o instanceof byte[];
}
@Override
public long getContentLength() {
+ long x = super.getContentLength();
+ if (x != -1)
+ return x;
try {
tryCache();
} catch (IOException e) {}
- if (content instanceof byte[])
- return ((byte[])content).length;
- if (content instanceof File)
- return ((File)content).length();
- if (content instanceof CharSequence)
- return ((CharSequence)content).length();
+ Object o = getRawContent();
+ if (o instanceof byte[])
+ return ((byte[])o).length;
+ if (o instanceof File)
+ return ((File)o).length();
+ if (o instanceof CharSequence)
+ return ((CharSequence)o).length();
return -1;
}
@@ -255,17 +382,18 @@ public class BasicHttpEntity extends
org.apache.http.entity.BasicHttpEntity {
public InputStream getContent() {
try {
tryCache();
- if (content == null)
+ Object o = getRawContent();
+ if (o == null)
return null;
- if (content instanceof File)
- return new FileInputStream((File)content);
- if (content instanceof byte[])
- return new
ByteArrayInputStream((byte[])content);
- if (content instanceof Reader)
- return new ReaderInputStream((Reader)content,
IOUtils.UTF8);
- if (content instanceof InputStream)
- return (InputStream)content;
- return new ReaderInputStream(new
StringReader(content.toString()),IOUtils.UTF8);
+ if (o instanceof File)
+ return new FileInputStream((File)o);
+ if (o instanceof byte[])
+ return new ByteArrayInputStream((byte[])o);
+ if (o instanceof Reader)
+ return new ReaderInputStream((Reader)o,
IOUtils.UTF8);
+ if (o instanceof InputStream)
+ return (InputStream)o;
+ return new ReaderInputStream(new
StringReader(o.toString()),IOUtils.UTF8);
} catch (Exception e) {
throw new RuntimeException(e);
}
@@ -274,14 +402,24 @@ public class BasicHttpEntity extends
org.apache.http.entity.BasicHttpEntity {
@Override
public void writeTo(OutputStream os) throws IOException {
tryCache();
- if (content != null)
- IOUtils.pipe(content, os);
+ Object o = getRawContent();
+ if (o != null) {
+ if (varSession != null) {
+ Writer osw = new OutputStreamWriter(os,
IOUtils.UTF8);
+ String s = IOUtils.read(o);
+ varSession.resolveTo(s, osw);
+ osw.flush();
+ } else {
+ IOUtils.pipe(o, os);
+ }
+ }
os.flush();
}
@Override
public boolean isStreaming() {
- return (content instanceof InputStream || content instanceof
Reader);
+ Object o = getRawContent();
+ return (o instanceof InputStream || o instanceof Reader);
}
/**
@@ -294,8 +432,9 @@ public class BasicHttpEntity extends
org.apache.http.entity.BasicHttpEntity {
}
private void tryCache() throws IOException {
- if (cache && isCacheable(content))
- content = readBytes(content);
+ Object o = getRawContent();
+ if (cache && isCacheable(o))
+ this.content = readBytes(o);
}
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHttpResource.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHttpResource.java
index 76a454a..74a12f7 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHttpResource.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicHttpResource.java
@@ -18,11 +18,28 @@ import java.util.function.*;
import org.apache.http.*;
import org.apache.juneau.collections.*;
import org.apache.juneau.internal.*;
+import org.apache.juneau.svl.*;
import org.apache.juneau.http.header.*;
import org.apache.juneau.http.header.ContentType;
/**
* An extension of an {@link HttpEntity} with support for arbitrary headers.
+ *
+ * Provides the following features:
+ * <ul class='spaced-list'>
+ * <li>
+ * Default support for various streams and readers.
+ * <li>
+ * Content from {@link Supplier Suppliers}.
+ * <li>
+ * Caching.
+ * <li>
+ * Fluent setters.
+ * <li>
+ * Fluent assertions.
+ * <li>
+ * {@doc juneau-marshall.SimpleVariableLanguage.SvlVariables SVL
variables}.
+ * </ul>
*/
public class BasicHttpResource extends BasicHttpEntity implements HttpResource
{
@@ -52,7 +69,7 @@ public class BasicHttpResource extends BasicHttpEntity
implements HttpResource {
* <li>A {@link Supplier} of anything on this list.
* </ul>
* </ul>
- * @return A new empty {@link ReaderResource} object.
+ * @return A new empty {@link BasicHttpResource} object.
*/
public static BasicHttpResource of(Object content) {
return new BasicHttpResource().content(content);
@@ -73,7 +90,7 @@ public class BasicHttpResource extends BasicHttpEntity
implements HttpResource {
* <li>A {@link Supplier} of anything on this list.
* </ul>
* </ul>
- * @return A new empty {@link ReaderResource} object.
+ * @return A new empty {@link BasicHttpResource} object.
*/
public static BasicHttpResource of(Supplier<?> content) {
return new BasicHttpResource().content(content);
@@ -88,13 +105,6 @@ public class BasicHttpResource extends BasicHttpEntity
implements HttpResource {
/**
* Constructor.
- *
- * @param contentType
- * The content type of the contents.
- * <br>Can be <jk>null</jk>.
- * @param contentEncoding
- * The content encoding of the contents.
- * <br>Can be <jk>null</jk>.
* @param content
* The content.
* <br>Can be any of the following:
@@ -107,8 +117,14 @@ public class BasicHttpResource extends BasicHttpEntity
implements HttpResource {
* <li>A {@link Supplier} of anything on this list.
* </ul>
* </ul>
+ * @param contentType
+ * The content type of the contents.
+ * <br>Can be <jk>null</jk>.
+ * @param contentEncoding
+ * The content encoding of the contents.
+ * <br>Can be <jk>null</jk>.
*/
- public BasicHttpResource(ContentType contentType, ContentEncoding
contentEncoding, Object content) {
+ public BasicHttpResource(Object content, ContentType contentType,
ContentEncoding contentEncoding) {
super();
content(content);
contentType(contentType);
@@ -273,5 +289,17 @@ public class BasicHttpResource extends BasicHttpEntity
implements HttpResource {
return this;
}
+ @Override /* GENERATED - BasicHttpEntity */
+ public BasicHttpResource resolving(VarResolver varResolver) {
+ super.resolving(varResolver);
+ return this;
+ }
+
+ @Override /* GENERATED - BasicHttpEntity */
+ public BasicHttpResource resolving(VarResolverSession varSession) {
+ super.resolving(varSession);
+ return this;
+ }
+
// </FluentSetters>
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicNameValuePair.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicNameValuePair.java
index 51f52f7..f0477d5 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicNameValuePair.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/BasicNameValuePair.java
@@ -28,14 +28,25 @@ import org.apache.juneau.svl.*;
/**
* Subclass of {@link NameValuePair} for serializing POJOs as URL-encoded form
post entries.
*
- * <p>
- * The value is serialized using {@link Object#toString()} at the point of
reading. This allows the value to be modified
- * periodically by overriding the method to return different values.
+ * Provides the following features:
+ * <ul class='spaced-list'>
+ * <li>
+ * Values from {@link Supplier Suppliers}.
+ * <li>
+ * Caching.
+ * <li>
+ * Fluent setters.
+ * <li>
+ * Fluent assertions.
+ * <li>
+ * {@doc juneau-marshall.SimpleVariableLanguage.SvlVariables SVL
variables}.
+ * </ul>
*/
@BeanIgnore
public class BasicNameValuePair implements NameValuePair, Headerable {
private final String name;
private final Object value;
+ private VarResolverSession varSession;
/**
* Convenience creator.
@@ -69,9 +80,6 @@ public class BasicNameValuePair implements NameValuePair,
Headerable {
* <p>
* Value is re-evaluated on each call to {@link #getValue()}.
*
- * <p>
- * Note that you can use {@link VarResolver#supplier(String)} to create
pair values with auto-resolving embedded SVL variables.
- *
* @param name The parameter name.
* @param value The parameter value supplier.
* @return A new {@link BasicNameValuePair} object.
@@ -125,6 +133,32 @@ public class BasicNameValuePair implements NameValuePair,
Headerable {
}
/**
+ * Allows SVL variables to be resolved when calling {@link #getValue()}.
+ *
+ * @param varResolver
+ * The variable resolver to use for resolving SVL variables.
+ * @return This object (for method chaining).
+ */
+ @FluentSetter
+ public BasicNameValuePair resolving(VarResolver varResolver) {
+ this.varSession = varResolver == null ? null :
varResolver.createSession();
+ return this;
+ }
+
+ /**
+ * Allows SVL variables to be resolved when calling {@link #getValue()}.
+ *
+ * @param varSession
+ * The variable resolver session to use for resolving SVL
variables.
+ * @return This object (for method chaining).
+ */
+ @FluentSetter
+ public BasicNameValuePair resolving(VarResolverSession varSession) {
+ this.varSession = varSession;
+ return this;
+ }
+
+ /**
* Provides an object for performing assertions against the name of
this pair.
*
* @return An object for performing assertions against the name of this
pair.
@@ -154,13 +188,18 @@ public class BasicNameValuePair implements NameValuePair,
Headerable {
@Override /* NameValuePair */
public String getValue() {
- return stringify(unwrap(value));
+ String s = stringify(unwrap(value));
+ if (varSession != null)
+ s = varSession.resolve(s);
+ return s;
}
@Override /* Object */
public boolean equals(Object o) {
if (! (o instanceof NameValuePair))
return false;
+ if (varSession != null)
+ return false;
return ObjectUtils.eq(this, (NameValuePair)o,
(x,y)->isEquals(x.name, y.getName()) && isEquals(x.getValue(), y.getValue()));
}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/ReaderResource.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/ReaderResource.java
deleted file mode 100644
index 0fda49a..0000000
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/ReaderResource.java
+++ /dev/null
@@ -1,240 +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.juneau.http;
-
-import java.io.*;
-import java.util.*;
-import java.util.function.*;
-
-import org.apache.http.Header;
-import org.apache.juneau.assertions.*;
-import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.header.*;
-import org.apache.juneau.internal.*;
-
-/**
- * Represents the contents of a text file with convenience methods for
resolving SVL variables and adding
- * HTTP response headers.
- *
- * <p>
- * <br>These objects can be returned as responses by REST methods.
- *
- * <p>
- * <l>ReaderResources</l> are meant to be thread-safe and reusable objects.
- * <br>The contents of the request passed into the constructor are immediately
converted to read-only strings.
- *
- * <ul class='seealso'>
- * <li class='link'>{@doc juneau-rest-server.RestMethod.ReaderResource}
- * </ul>
- */
-@Response
-public class ReaderResource extends BasicHttpResource {
-
- /**
- * Creator.
- *
- * @return A new empty {@link ReaderResource} object.
- */
- public static ReaderResource create() {
- return new ReaderResource();
- }
-
- /**
- * Creator.
- *
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- * @return A new empty {@link ReaderResource} object.
- */
- public static ReaderResource of(Object content) {
- return new ReaderResource().content(content);
- }
-
- /**
- * Creator.
- *
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- * @return A new empty {@link ReaderResource} object.
- */
- public static ReaderResource of(Supplier<?> content) {
- return new ReaderResource().content(content);
- }
-
- /**
- * Constructor.
- */
- public ReaderResource() {
- super();
- }
-
- /**
- * Constructor.
- *
- * @param contentType
- * The content type of the contents.
- * <br>Can be <jk>null</jk>.
- * @param contentEncoding
- * The content encoding of the contents.
- * <br>Can be <jk>null</jk>.
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- */
- public ReaderResource(ContentType contentType, ContentEncoding
contentEncoding, Object content) {
- super(contentType, contentEncoding, content);
- }
-
- /**
- * Converts the contents of this entity as a byte array.
- *
- * @return The contents of this entity as a byte array.
- * @throws IOException If a problem occurred while trying to read the
byte array.
- */
- public String asString() throws IOException {
- return IOUtils.read(getRawContent());
- }
-
- /**
- * Returns an assertion on the contents of this resource.
- *
- * @return A new fluent assertion.
- * @throws IOException If a problem occurred while trying to read the
byte array.
- */
- public FluentStringAssertion<ReaderResource> assertString() throws
IOException {
- return new FluentStringAssertion<>(asString(), this);
- }
-
- // <FluentSetters>
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource cache() {
- super.cache();
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource cache(boolean value) {
- super.cache(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource chunked() {
- super.chunked();
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource chunked(boolean value) {
- super.chunked(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource content(Object value) {
- super.content(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource content(Supplier<?> value) {
- super.content(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource contentEncoding(String value) {
- super.contentEncoding(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource contentEncoding(Header value) {
- super.contentEncoding(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource contentLength(long value) {
- super.contentLength(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource contentType(String value) {
- super.contentType(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ReaderResource contentType(Header value) {
- super.contentType(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public ReaderResource header(Header value) {
- super.header(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public ReaderResource header(String name, Object val) {
- super.header(name, val);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public ReaderResource headers(Header...headers) {
- super.headers(headers);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public ReaderResource headers(List<Header> headers) {
- super.headers(headers);
- return this;
- }
-
- // </FluentSetters>
-}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/ResolvingReaderResource.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/ResolvingReaderResource.java
deleted file mode 100644
index b7ff536..0000000
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/ResolvingReaderResource.java
+++ /dev/null
@@ -1,281 +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.juneau.http;
-
-import java.io.*;
-import java.util.*;
-import java.util.function.*;
-
-import org.apache.http.*;
-import org.apache.juneau.http.header.*;
-import org.apache.juneau.internal.*;
-import org.apache.juneau.svl.*;
-
-/**
- * An extension of {@link ReaderResource} that allows automatic resolution of
SVL variables.
- */
-public class ResolvingReaderResource extends ReaderResource {
-
- private VarResolver varResolver;
- private VarResolverSession varSession;
-
- /**
- * Creator.
- *
- * @return A new empty {@link ReaderResource} object.
- */
- public static ResolvingReaderResource create() {
- return new ResolvingReaderResource();
- }
-
- /**
- * Creator.
- *
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- * @return A new empty {@link ResolvingReaderResource} object.
- */
- public static ResolvingReaderResource of(Object content) {
- return new ResolvingReaderResource().content(content);
- }
-
- /**
- * Creator.
- *
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- * @return A new empty {@link ResolvingReaderResource} object.
- */
- public static ResolvingReaderResource of(Supplier<?> content) {
- return new ResolvingReaderResource().content(content);
- }
-
- /**
- * Constructor.
- */
- public ResolvingReaderResource() {
- super();
- }
-
- /**
- * Constructor.
- *
- * @param contentType
- * The content type of the contents.
- * <br>Can be <jk>null</jk>.
- * @param contentEncoding
- * The content encoding of the contents.
- * <br>Can be <jk>null</jk>.
- * @param varResolver
- * The var resolver for resolving SVL variables.
- * <br>Only one of <c>varResolver</c> and <c>varSession</c> needs
to be specified.
- * @param varSession
- * Var resolver session for resolving SVL variables.
- * <br>Only one of <c>varResolver</c> and <c>varSession</c> needs
to be specified.
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- */
- public ResolvingReaderResource(ContentType contentType, ContentEncoding
contentEncoding, VarResolver varResolver, VarResolverSession varSession, Object
content) {
- super(contentType, contentEncoding, content);
- this.varResolver = varResolver;
- this.varSession = varSession;
- }
-
- /**
- * Converts the contents of this entity as a byte array.
- *
- * @return The contents of this entity as a byte array.
- * @throws IOException If a problem occurred while trying to read the
byte array.
- */
- @Override
- public String asString() throws IOException {
- VarResolverSession vr = getVarSession();
- if (vr == null)
- return super.asString();
- StringWriter sw = new StringWriter();
- String s = IOUtils.read(getRawContent());
- vr.resolveTo(s, sw);
- return sw.toString();
- }
-
- @Override
- public void writeTo(OutputStream os) throws IOException {
- VarResolverSession vr = getVarSession();
- if (vr == null)
- super.writeTo(os);
- else {
- try (OutputStreamWriter osw = new
OutputStreamWriter(os, IOUtils.UTF8)) {
- String s = IOUtils.read(getRawContent());
- vr.resolveTo(s, osw);
- osw.flush();
- }
- }
- os.flush();
- }
-
- /**
- * Sets the var resolver for resolving SVL variables.
- *
- * @param varResolver - The var resolver.
- * @return This object (for method chaining).
- */
- @FluentSetter
- public ResolvingReaderResource varResolver(VarResolver varResolver) {
- this.varResolver = varResolver;
- return this;
- }
-
- /**
- * Sets the var resolver session for resolving SVL variables.
- *
- * @param varSession - The var resolver session.
- * @return This object (for method chaining).
- */
- @FluentSetter
- public ResolvingReaderResource varResolver(VarResolverSession
varSession) {
- this.varSession = varSession;
- return this;
- }
-
- private VarResolverSession getVarSession() {
- if (varSession != null)
- return varSession;
- if (varResolver != null)
- return varResolver.createSession();
- return null;
- }
-
- // <FluentSetters>
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource cache() {
- super.cache();
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource cache(boolean value) {
- super.cache(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource chunked() {
- super.chunked();
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource chunked(boolean value) {
- super.chunked(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource content(Object value) {
- super.content(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource content(Supplier<?> value) {
- super.content(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource contentEncoding(String value) {
- super.contentEncoding(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource contentEncoding(Header value) {
- super.contentEncoding(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource contentLength(long value) {
- super.contentLength(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource contentType(String value) {
- super.contentType(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public ResolvingReaderResource contentType(Header value) {
- super.contentType(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public ResolvingReaderResource header(Header value) {
- super.header(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public ResolvingReaderResource header(String name, Object val) {
- super.header(name, val);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public ResolvingReaderResource headers(Header...headers) {
- super.headers(headers);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public ResolvingReaderResource headers(List<Header> headers) {
- super.headers(headers);
- return this;
- }
-
- // </FluentSetters>
-}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/SerializedHttpEntity.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/SerializedHttpEntity.java
index 76ce356..0ea4f0e 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/SerializedHttpEntity.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/SerializedHttpEntity.java
@@ -15,8 +15,11 @@ package org.apache.juneau.http;
import static org.apache.juneau.internal.IOUtils.*;
import java.io.*;
+import java.util.function.*;
+import org.apache.http.*;
import org.apache.juneau.*;
+import org.apache.juneau.http.header.*;
import org.apache.juneau.httppart.*;
import org.apache.juneau.internal.*;
import org.apache.juneau.serializer.*;
@@ -34,26 +37,38 @@ public class SerializedHttpEntity extends BasicHttpEntity {
* Creator.
*
* @param content The POJO to serialize. Can also be a {@link Reader}
or {@link InputStream}.
+ * @param serializer The serializer to use to serialize this response.
+ * @return A new {@link SerializedHttpEntity} with uninitialized
serializer and schema.
+ */
+ public static SerializedHttpEntity of(Object content, Serializer
serializer) {
+ return new SerializedHttpEntity(content, serializer);
+ }
+
+ /**
+ * Creator.
+ *
+ * @param content The POJO to serialize. Can also be a {@link Reader}
or {@link InputStream}.
+ * @param serializer The serializer to use to serialize this response.
* @return A new {@link SerializedHttpEntity} with uninitialized
serializer and schema.
*/
- public static SerializedHttpEntity of(Object content) {
- return new SerializedHttpEntity(content, null, null, null);
+ public static SerializedHttpEntity of(Supplier<?> content, Serializer
serializer) {
+ return new SerializedHttpEntity(content, serializer);
}
/**
* Constructor.
+ */
+ public SerializedHttpEntity() {}
+
+ /**
+ * Constructor.
*
* @param content The POJO to serialize. Can also be a {@link Reader}
or {@link InputStream}.
* @param serializer The serializer to use to serialize this response.
- * @param schema The optional schema information about the serialized
part.
- * @param contentType Override the content type defined on the
serializer.
*/
- public SerializedHttpEntity(Object content, Serializer serializer,
HttpPartSchema schema, String contentType) {
- content(content);
+ public SerializedHttpEntity(Object content, Serializer serializer) {
+ super(content);
this.serializer = serializer;
- this.schema = schema;
- if (serializer != null && serializer.getResponseContentType()
!= null)
- setContentType(new BasicHeader("Content-Type",
contentType != null ? contentType :
serializer.getResponseContentType().toString()));
}
/**
@@ -89,9 +104,9 @@ public class SerializedHttpEntity extends BasicHttpEntity {
@Override /* BasicHttpEntity */
public void writeTo(OutputStream os) throws IOException {
os = new NoCloseOutputStream(os);
- Object content = getRawContent();
- if (content instanceof InputStream || content instanceof Reader
|| content instanceof File) {
- IOPipe.create(content, os).run();
+ Object o = getRawContent();
+ if (o instanceof InputStream || o instanceof Reader || o
instanceof File) {
+ IOPipe.create(o, os).run();
} else {
try {
if (serializer == null) {
@@ -101,7 +116,7 @@ public class SerializedHttpEntity extends BasicHttpEntity {
SerializerSessionArgs sArgs =
SerializerSessionArgs.create().schema(schema);
SerializerSession session =
serializer.createSession(sArgs);
try (Closeable c =
session.isWriterSerializer() ? new OutputStreamWriter(os, UTF8) : os) {
- session.serialize(content, c);
+ session.serialize(o, c);
}
}
} catch (SerializeException e) {
@@ -112,16 +127,29 @@ public class SerializedHttpEntity extends BasicHttpEntity
{
@Override /* BasicHttpEntity */
public boolean isRepeatable() {
- Object content = getRawContent();
- return (! (content instanceof InputStream || content instanceof
Reader));
+ Object o = getRawContent();
+ return (! (o instanceof InputStream || o instanceof Reader));
}
- @Override
+ @Override /* BasicHttpEntity */
public long getContentLength() {
return -1;
}
@Override /* BasicHttpEntity */
+ public Header getContentType() {
+ Header x = super.getContentType();
+ if (x != null)
+ return x;
+ Object o = getRawContent();
+ if (o instanceof InputStream || o instanceof Reader || o
instanceof File)
+ return null;
+ if (serializer != null)
+ return
ContentType.of(serializer.getResponseContentType());
+ return null;
+ }
+
+ @Override /* BasicHttpEntity */
public InputStream getContent() {
if (cache == null) {
try (ByteArrayOutputStream baos = new
ByteArrayOutputStream()) {
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/StreamResource.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/StreamResource.java
deleted file mode 100644
index 4cff804..0000000
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/StreamResource.java
+++ /dev/null
@@ -1,239 +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.juneau.http;
-
-import java.io.*;
-import java.util.*;
-import java.util.function.*;
-
-import org.apache.http.Header;
-import org.apache.juneau.assertions.*;
-import org.apache.juneau.http.annotation.*;
-import org.apache.juneau.http.header.*;
-import org.apache.juneau.internal.*;
-
-/**
- * Represents the contents of a byte stream file with convenience methods for
adding HTTP response headers.
- *
- * <p>
- * <br>These objects can to be returned as responses by REST methods.
- *
- * <p>
- * <l>StreamResources</l> are meant to be thread-safe and reusable objects.
- * <br>The contents of the request passed into the constructor are immediately
converted to read-only byte arrays.
- *
- * <ul class='seealso'>
- * <li class='link'>{@doc juneau-rest-server.RestMethod.StreamResource}
- * </ul>
- */
-@Response
-public class StreamResource extends BasicHttpResource {
-
- /**
- * Creator.
- *
- * @return A new empty {@link StreamResource} object.
- */
- public static StreamResource create() {
- return new StreamResource();
- }
-
- /**
- * Creator.
- *
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- * @return A new empty {@link StreamResource} object.
- */
- public static StreamResource of(Object content) {
- return new StreamResource().content(content);
- }
-
- /**
- * Creator.
- *
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- * @return A new empty {@link StreamResource} object.
- */
- public static StreamResource of(Supplier<?> content) {
- return new StreamResource().content(content);
- }
-
- /**
- * Constructor.
- */
- public StreamResource() {
- super();
- }
-
- /**
- * Constructor.
- *
- * @param contentType
- * The content type of the contents.
- * <br>Can be <jk>null</jk>.
- * @param contentEncoding
- * The content encoding of the contents.
- * <br>Can be <jk>null</jk>.
- * @param content
- * The content.
- * <br>Can be any of the following:
- * <ul>
- * <li><c>InputStream</c>
- * <li><c>Reader</c> - Converted to UTF-8 bytes.
- * <li><c>File</c>
- * <li><c>CharSequence</c> - Converted to UTF-8 bytes.
- * <li><c><jk>byte</jk>[]</c>.
- * <li>A {@link Supplier} of anything on this list.
- * </ul>
- * </ul>
- */
- public StreamResource(ContentType contentType, ContentEncoding
contentEncoding, Object content) {
- super(contentType, contentEncoding, content);
- }
-
- /**
- * Converts the contents of this entity as a byte array.
- *
- * @return The contents of this entity as a byte array.
- * @throws IOException If a problem occurred while trying to read the
byte array.
- */
- public byte[] asBytes() throws IOException {
- return IOUtils.readBytes(getRawContent());
- }
-
- /**
- * Returns an assertion on the contents of this resource.
- *
- * @return A new fluent assertion.
- * @throws IOException If a problem occurred while trying to read the
byte array.
- */
- public FluentByteArrayAssertion<StreamResource> assertBytes() throws
IOException {
- return new FluentByteArrayAssertion<>(asBytes(), this);
- }
-
- // <FluentSetters>
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource cache() {
- super.cache();
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource cache(boolean value) {
- super.cache(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource chunked() {
- super.chunked();
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource chunked(boolean value) {
- super.chunked(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource content(Object value) {
- super.content(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource content(Supplier<?> value) {
- super.content(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource contentEncoding(String value) {
- super.contentEncoding(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource contentEncoding(Header value) {
- super.contentEncoding(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource contentLength(long value) {
- super.contentLength(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource contentType(String value) {
- super.contentType(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpEntity */
- public StreamResource contentType(Header value) {
- super.contentType(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public StreamResource header(Header value) {
- super.header(value);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public StreamResource header(String name, Object val) {
- super.header(name, val);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public StreamResource headers(Header...headers) {
- super.headers(headers);
- return this;
- }
-
- @Override /* GENERATED - BasicHttpResource */
- public StreamResource headers(List<Header> headers) {
- super.headers(headers);
- return this;
- }
-
- // </FluentSetters>
-}
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
index 7899685..fde45c8 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/http/header/ContentType.java
@@ -72,6 +72,18 @@ public class ContentType extends BasicParameterizedHeader {
return ct;
}
+ /**
+ * Returns a parsed and cached <c>Content-Type</c> header.
+ *
+ * @param value The <c>Content-Type</c> header value.
+ * @return The parsed <c>Content-Type</c> header, or <jk>null</jk> if
the string was null.
+ */
+ public static ContentType of(MediaType value) {
+ if (value == null)
+ return null;
+ return of(value.toString());
+ }
+
private final MediaType mediaType;
/**
diff --git
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/VarResolver.java
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/VarResolver.java
index ea03dc6..675e5a2 100644
---
a/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/VarResolver.java
+++
b/juneau-core/juneau-marshall/src/main/java/org/apache/juneau/svl/VarResolver.java
@@ -14,7 +14,6 @@ package org.apache.juneau.svl;
import java.io.*;
import java.util.*;
-import java.util.function.*;
import org.apache.juneau.svl.vars.*;
@@ -179,14 +178,4 @@ public class VarResolver {
public void resolveTo(String s, Writer w) throws IOException {
createSession(null).resolveTo(s, w);
}
-
- /**
- * Returns a supplier for the specified string.
- *
- * @param s The string to resolve.
- * @return A supplier for the specified string.
- */
- public Supplier<String> supplier(String s) {
- return ()->resolve(s);
- }
}
\ No newline at end of file
diff --git
a/juneau-releng/juneau-all/src/java/main/ConfigurablePropertyCodeGenerator.java
b/juneau-releng/juneau-all/src/java/main/ConfigurablePropertyCodeGenerator.java
index 4e33cf0..4968ff1 100644
---
a/juneau-releng/juneau-all/src/java/main/ConfigurablePropertyCodeGenerator.java
+++
b/juneau-releng/juneau-all/src/java/main/ConfigurablePropertyCodeGenerator.java
@@ -186,12 +186,10 @@ public class ConfigurablePropertyCodeGenerator {
CollectionAssertion.class,
ListAssertion.class,
+ BasicHeader.class,
+ BasicNameValuePair.class,
BasicHttpEntity.class,
BasicHttpResource.class,
- StreamResource.class,
- ReaderResource.class,
- ResolvingReaderResource.class,
- ExecutableInfo.class,
ConstructorInfo.class,
MethodInfo.class
};
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/StreamResource_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/BasicHttpEntity_Test.java
similarity index 67%
rename from
juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/StreamResource_Test.java
rename to
juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/BasicHttpEntity_Test.java
index d332514..797e63c 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/StreamResource_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/BasicHttpEntity_Test.java
@@ -13,34 +13,23 @@
package org.apache.juneau.http;
import static org.apache.juneau.assertions.Assertions.*;
+import static org.apache.juneau.http.BasicHttpEntity.*;
import static org.junit.Assert.*;
-import static org.junit.runners.MethodSorters.*;
-
-import static org.apache.juneau.http.StreamResource.*;
import java.io.*;
import org.junit.*;
-@FixMethodOrder(NAME_ASCENDING)
-public class StreamResource_Test {
-
+public class BasicHttpEntity_Test {
@Test
public void a01_basic() throws Exception {
- StreamResource x = create();
- File f = File.createTempFile("test","txt");
+ BasicHttpEntity x = create();
+ File f = File.createTempFile("test", "txt");
assertNull(x.getContentType());
assertNull(x.getContent());
assertNull(x.getContentEncoding());
- assertList(x.getHeaders()).isSize(0);
- of("foo").assertBytes().string().is("foo");
- of(new StringReader("foo")).assertBytes().string().is("foo");
- of("foo".getBytes()).assertBytes().string().is("foo");
- of(new
ByteArrayInputStream("foo".getBytes())).assertBytes().string().is("foo");
- of(null).assertBytes().string().isEmpty();
- of(f).assertBytes().string().isEmpty();
x = of("foo");
assertStream(x.getContent()).string().is("foo");
@@ -72,6 +61,38 @@ public class StreamResource_Test {
assertTrue(x.isRepeatable());
assertFalse(x.isStreaming());
+
+ x = of(()->"foo");
+ assertStream(x.getContent()).string().is("foo");
+ assertTrue(x.isRepeatable());
+ assertFalse(x.isStreaming());
+
+ x = of(()->new StringReader("foo"));
+ assertStream(x.getContent()).string().is("foo");
+ assertFalse(x.isRepeatable());
+ assertTrue(x.isStreaming());
+
+ x = of(()->"foo".getBytes());
+ assertStream(x.getContent()).string().is("foo");
+ assertTrue(x.isRepeatable());
+ assertFalse(x.isStreaming());
+
+ x = of(()->new ByteArrayInputStream("foo".getBytes()));
+ assertStream(x.getContent()).string().is("foo");
+ assertFalse(x.isRepeatable());
+ assertTrue(x.isStreaming());
+
+ x = of(()->null);
+ assertStream(x.getContent()).string().doesNotExist();
+ assertFalse(x.isRepeatable());
+ assertFalse(x.isStreaming());
+
+ x = of(()->f);
+ assertStream(x.getContent()).string().isEmpty();
+ assertTrue(x.isRepeatable());
+ assertFalse(x.isStreaming());
+
+
x = of("foo").cache();
assertStream(x.getContent()).string().is("foo");
assertStream(x.getContent()).string().is("foo");
@@ -96,18 +117,31 @@ public class StreamResource_Test {
assertStream(x.getContent()).string().doesNotExist();
assertStream(x.getContent()).string().doesNotExist();
assertTrue(x.isRepeatable());
+ x.writeTo(new ByteArrayOutputStream());
+
+ x = of(f).cache();
+ assertStream(x.getContent()).string().isEmpty();
+ assertStream(x.getContent()).string().isEmpty();
+ assertTrue(x.isRepeatable());
+ x.writeTo(new ByteArrayOutputStream());
assertLong(of("foo").getContentLength()).is(3l);
assertLong(of("foo".getBytes()).getContentLength()).is(3l);
assertLong(of(f).getContentLength()).is(0l);
- x = of("foo").header("Foo","bar").header("Foo","baz");
- assertString(x.getStringHeader("Foo")).is("baz");
- assertString(x.getStringHeader("Bar")).doesNotExist();
- assertString(x.getFirstHeader("Foo").toString()).is("Foo: bar");
- assertString(x.getLastHeader("Foo").toString()).is("Foo: baz");
- assertObject(x.getFirstHeader("Bar")).doesNotExist();
- assertObject(x.getLastHeader("Bar")).doesNotExist();
- assertObject(x.getHeaders()).json().is("['Foo: bar','Foo:
baz']");
+ assertLong(of(new
StringReader("foo")).getContentLength()).is(-1l);
+ assertLong(of(new
StringReader("foo")).contentLength(3).getContentLength()).is(3l);
+
+ BasicHttpEntity x2 = new BasicHttpEntity() {
+ @Override
+ protected byte[] readBytes(Object o) throws IOException
{
+ throw new IOException("bad");
+ }
+ };
+ x2.cache().content(new StringReader("foo"));
+ assertLong(x2.getContentLength()).is(-1l);
+
+ assertThrown(()->x2.writeTo(new
ByteArrayOutputStream())).contains("bad");
+ assertThrown(()->x2.getContent()).contains("bad");
}
}
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/BasicHttpResource_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/BasicHttpResource_Test.java
index d02d777..604972c 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/BasicHttpResource_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/BasicHttpResource_Test.java
@@ -97,6 +97,9 @@ public class BasicHttpResource_Test {
assertLong(of("foo".getBytes()).getContentLength()).is(3l);
assertLong(of(f).getContentLength()).is(0l);
+ assertLong(of(new
StringReader("foo")).getContentLength()).is(-1l);
+ assertLong(of(new
StringReader("foo")).contentLength(3).getContentLength()).is(3l);
+
x =
of("foo").header("Foo","bar").header("Foo","baz").header(null,"bar").header("foo",null).header(null);
assertString(x.getStringHeader("Foo")).is("baz");
assertString(x.getStringHeader("Bar")).doesNotExist();
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/ReaderResource_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/ReaderResource_Test.java
deleted file mode 100644
index dbfcc94..0000000
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/http/ReaderResource_Test.java
+++ /dev/null
@@ -1,113 +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.juneau.http;
-
-import static org.apache.juneau.assertions.Assertions.*;
-import static org.junit.Assert.*;
-import static org.junit.runners.MethodSorters.*;
-
-import static org.apache.juneau.http.ReaderResource.*;
-
-import java.io.*;
-
-import org.junit.*;
-
-@FixMethodOrder(NAME_ASCENDING)
-public class ReaderResource_Test {
-
- @Test
- public void a01_basic() throws Exception {
- ReaderResource x = create();
- File f = File.createTempFile("test","txt");
-
- assertNull(x.getContentType());
- assertNull(x.getContent());
- assertNull(x.getContentEncoding());
- assertList(x.getHeaders()).isSize(0);
-
- of("foo").assertString().is("foo");
- of(new StringReader("foo")).assertString().is("foo");
- of("foo".getBytes()).assertString().is("foo");
- of(new
ByteArrayInputStream("foo".getBytes())).assertString().is("foo");
- of(null).assertString().doesNotExist();
- of(f).assertString().isEmpty();
-
- x = of("foo");
- assertStream(x.getContent()).string().is("foo");
- assertTrue(x.isRepeatable());
- assertFalse(x.isStreaming());
-
- x = of(new StringReader("foo"));
- assertStream(x.getContent()).string().is("foo");
- assertFalse(x.isRepeatable());
- assertTrue(x.isStreaming());
-
- x = of("foo".getBytes());
- assertStream(x.getContent()).string().is("foo");
- assertTrue(x.isRepeatable());
- assertFalse(x.isStreaming());
-
- x = of(new ByteArrayInputStream("foo".getBytes()));
- assertStream(x.getContent()).string().is("foo");
- assertFalse(x.isRepeatable());
- assertTrue(x.isStreaming());
-
- x = of(null);
- assertStream(x.getContent()).string().doesNotExist();
- assertFalse(x.isRepeatable());
- assertFalse(x.isStreaming());
-
- x = of(f);
- assertStream(x.getContent()).string().isEmpty();
- assertTrue(x.isRepeatable());
- assertFalse(x.isStreaming());
-
- x = of("foo").cache();
- assertStream(x.getContent()).string().is("foo");
- assertStream(x.getContent()).string().is("foo");
- assertTrue(x.isRepeatable());
-
- x = of(new StringReader("foo")).cache();
- assertStream(x.getContent()).string().is("foo");
- assertStream(x.getContent()).string().is("foo");
- assertTrue(x.isRepeatable());
-
- x = of("foo".getBytes()).cache();
- assertStream(x.getContent()).string().is("foo");
- assertStream(x.getContent()).string().is("foo");
- assertTrue(x.isRepeatable());
-
- x = of(new ByteArrayInputStream("foo".getBytes())).cache();
- assertStream(x.getContent()).string().is("foo");
- assertStream(x.getContent()).string().is("foo");
- assertTrue(x.isRepeatable());
-
- x = of(null).cache();
- assertStream(x.getContent()).string().doesNotExist();
- assertStream(x.getContent()).string().doesNotExist();
- assertTrue(x.isRepeatable());
-
- assertLong(of("foo").getContentLength()).is(3l);
- assertLong(of("foo".getBytes()).getContentLength()).is(3l);
- assertLong(of(f).getContentLength()).is(0l);
-
- x = of("foo").header("Foo","bar").header("Foo","baz");
- assertString(x.getStringHeader("Foo")).is("baz");
- assertString(x.getStringHeader("Bar")).doesNotExist();
- assertString(x.getFirstHeader("Foo").toString()).is("Foo: bar");
- assertString(x.getLastHeader("Foo").toString()).is("Foo: baz");
- assertObject(x.getFirstHeader("Bar")).doesNotExist();
- assertObject(x.getLastHeader("Bar")).doesNotExist();
- assertObject(x.getHeaders()).json().is("['Foo: bar','Foo:
baz']");
- }
-}
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_CommonInterfaces_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_CommonInterfaces_Test.java
index bff9079..635708a 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_CommonInterfaces_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/Remote_CommonInterfaces_Test.java
@@ -204,34 +204,24 @@ public class Remote_CommonInterfaces_Test {
@Remote
@Rest
public static interface D extends BasicSimpleJsonRest {
- StreamResource streamResource() throws IOException ;
- ReaderResource readerResource() throws IOException ;
+ BasicHttpResource httpResource() throws IOException ;
}
public static class D1 implements D {
@Override
- public StreamResource streamResource() throws IOException {
- return
StreamResource.create().contentType("text/foo").content("foo".getBytes()).header("Foo","foo").headers(ETag.of("bar"));
- }
- @Override
- public ReaderResource readerResource() throws IOException {
- return
ReaderResource.create().contentType("text/foo").content("foo".getBytes()).header("Foo","foo").headers(ETag.of("bar"));
+ public BasicHttpResource httpResource() throws IOException {
+ return
BasicHttpResource.create().contentType("text/foo").content("foo".getBytes()).header("Foo","foo").headers(ETag.of("bar"));
}
}
@Test
- public void d01_streamResource_readerResource() throws Exception {
+ public void d01_httpResource() throws Exception {
D x = MockRestClient.build(D1.class).getRemote(D.class);
- StreamResource sr = x.streamResource();
+ BasicHttpResource sr = x.httpResource();
assertEquals("foo",IOUtils.read(sr.getContent()));
assertEquals("foo",sr.getStringHeader("Foo"));
assertEquals("bar",sr.getStringHeader("ETag"));
assertEquals("text/foo",sr.getContentType().getValue().toString());
- ReaderResource rr = x.readerResource();
- assertEquals("foo",IOUtils.read(rr.getContent()));
- assertEquals("foo",rr.getStringHeader("Foo"));
- assertEquals("bar",rr.getStringHeader("ETag"));
-
assertEquals("text/foo",rr.getContentType().getValue().toString());
}
//-----------------------------------------------------------------------------------------------------------------
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_BasicCalls_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_BasicCalls_Test.java
index b1ac6bc..2ec3b24 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_BasicCalls_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_BasicCalls_Test.java
@@ -163,8 +163,7 @@ public class RestClient_BasicCalls_Test {
List<Object> bodies = AList.<Object>of(
new StringReader("{f:1}"),
new ByteArrayInputStream("{f:1}".getBytes()),
- ReaderResource.create().content("{f:1}"),
- StreamResource.create().content("{f:1}"),
+ BasicHttpResource.create().content("{f:1}"),
bean,
new StringEntity("{f:1}"),
pairs("f",1)
@@ -207,8 +206,7 @@ public class RestClient_BasicCalls_Test {
List<Object> bodies = AList.<Object>of(
new StringReader("{f:1}"),
new ByteArrayInputStream("{f:1}".getBytes()),
- ReaderResource.create().content("{f:1}"),
- StreamResource.create().content("{f:1}"),
+ BasicHttpResource.create().content("{f:1}"),
bean,
new StringEntity("{f:1}"),
pairs("f",1)
@@ -314,14 +312,10 @@ public class RestClient_BasicCalls_Test {
/*[ 3]*/ new
StringEntity("f=1",org.apache.http.entity.ContentType.APPLICATION_FORM_URLENCODED),
/*[ 4]*/ new
StringEntity("f=1",(org.apache.http.entity.ContentType)null),
/*[ 5]*/ pair("f","1"),
- /*[ 6]*/ ReaderResource.create().content("f=1"),
- /*[ 7]*/ ReaderResource.create().content("f=1"),
- /*[ 8]*/
ReaderResource.create().content("f=1").contentType("application/x-www-form-urlencoded"),
- /*[ 9]*/
ReaderResource.create().content("f=1").contentType("application/x-www-form-urlencoded"),
- /*[10]*/ StreamResource.create().content("f=1"),
- /*[11]*/ StreamResource.create().content("f=1"),
- /*[12]*/
StreamResource.create().content("f=1").contentType("application/x-www-form-urlencoded"),
- /*[13]*/
StreamResource.create().content("f=1").contentType("application/x-www-form-urlencoded"),
+ /*[ 6]*/ BasicHttpResource.create().content("f=1"),
+ /*[ 7]*/ BasicHttpResource.create().content("f=1"),
+ /*[ 8]*/
BasicHttpResource.create().content("f=1").contentType("application/x-www-form-urlencoded"),
+ /*[ 9]*/
BasicHttpResource.create().content("f=1").contentType("application/x-www-form-urlencoded"),
/*[14]*/ s1,
/*[15]*/ s2
);
@@ -352,8 +346,7 @@ public class RestClient_BasicCalls_Test {
List<Object> bodies = AList.<Object>of(
new StringReader("{f:1}"),
new ByteArrayInputStream("{f:1}".getBytes()),
- ReaderResource.create().content("{f:1}"),
- StreamResource.create().content("{f:1}"),
+ BasicHttpResource.create().content("{f:1}"),
bean,
new StringEntity("{f:1}"),
pairs("f",1)
@@ -390,8 +383,7 @@ public class RestClient_BasicCalls_Test {
List<Object> bodies = AList.<Object>of(
new StringReader("{f:1}"),
new ByteArrayInputStream("{f:1}".getBytes()),
- ReaderResource.create().content("{f:1}"),
- StreamResource.create().content("{f:1}"),
+ BasicHttpResource.create().content("{f:1}"),
bean,
new StringEntity("{f:1}"),
pairs("f",1)
diff --git
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Body_Test.java
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Body_Test.java
index 99a8bd3..1cced7d 100644
---
a/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Body_Test.java
+++
b/juneau-rest/juneau-rest-client-utest/src/test/java/org/apache/juneau/rest/client2/RestClient_Body_Test.java
@@ -20,9 +20,12 @@ import java.util.*;
import org.apache.http.*;
import org.apache.juneau.http.*;
import org.apache.juneau.http.header.*;
+import org.apache.juneau.json.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.annotation.*;
import org.apache.juneau.rest.mock2.*;
+import org.apache.juneau.serializer.*;
+import org.apache.juneau.testutils.pojos.*;
import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
@@ -31,8 +34,12 @@ public class RestClient_Body_Test {
@Rest
public static class A extends BasicRest {
@RestMethod
- public Reader post(org.apache.juneau.rest.RestRequest req)
throws IOException {
- return new StringReader(req.toString());
+ public Reader post(org.apache.juneau.rest.RestRequest req,
org.apache.juneau.rest.RestResponse res) throws IOException {
+ for (Map.Entry<String,String[]> e :
req.getHeaders().entrySet()) {
+ for (String v : e.getValue())
+ res.addHeader("X-" + e.getKey(), v);
+ }
+ return req.getReader();
}
}
@@ -41,97 +48,130 @@ public class RestClient_Body_Test {
//------------------------------------------------------------------------------------------------------------------
@Test
- public void a01_ReaderResource() throws Exception {
- ReaderResource x1 = ReaderResource.create().content("foo");
+ public void a01_BasicHttpResource() throws Exception {
+ BasicHttpResource x1 = httpResource("foo");
client().build().post("/", x1).run()
- .getBody().assertString().contains("foo",
"Content-Length: 3")
-
.getBody().assertString().doesNotContain("Content-Encoding","Content-Type","Transfer-Encoding")
+ .assertIntegerHeader("X-Content-Length").is(3)
+ .assertHeader("X-Content-Encoding").doesNotExist()
+ .assertHeader("X-Content-Type").doesNotExist()
+ .assertHeader("X-Transfer-Encoding").doesNotExist()
;
- ReaderResource x2 =
ReaderResource.create().content("foo").contentType("text/plain").contentEncoding("identity");
+ BasicHttpResource x2 =
httpResource("foo").contentType("text/plain").contentEncoding("identity");
client().build().post("/",x2).run()
-
.getBody().assertString().contains("foo","Content-Length: 3","Content-Encoding:
identity","Content-Type: text/plain")
+ .assertIntegerHeader("X-Content-Length").is(3)
+ .assertHeader("X-Content-Encoding").is("identity")
+ .assertHeader("X-Content-Type").is("text/plain")
+ .assertHeader("X-Transfer-Encoding").doesNotExist()
;
- ReaderResource x3 =
ReaderResource.create().content("foo").contentType(contentType("text/plain")).contentEncoding(contentEncoding("identity")).chunked();
+ BasicHttpResource x3 =
httpResource("foo").contentType(contentType("text/plain")).contentEncoding(contentEncoding("identity")).chunked();
client().build().post("/",x3).run()
-
.getBody().assertString().contains("foo","Content-Encoding:
identity","Content-Type: text/plain","Transfer-Encoding: chunked")
+ .assertIntegerHeader("X-Content-Length").doesNotExist()
// Missing when chunked.
+ .assertHeader("X-Content-Encoding").is("identity")
+ .assertHeader("X-Content-Type").is("text/plain")
+ .assertHeader("X-Transfer-Encoding").is("chunked")
;
- ReaderResource x4 = new
ReaderResource(contentType("text/plain"), contentEncoding("identity"), "foo");
+ BasicHttpResource x4 = new BasicHttpResource("foo",
contentType("text/plain"), contentEncoding("identity"));
client().build().post("/",x4).run()
-
.getBody().assertString().contains("foo","Content-Length: 3","Content-Encoding:
identity","Content-Type: text/plain")
+ .assertIntegerHeader("X-Content-Length").is(3)
+ .assertHeader("X-Content-Encoding").is("identity")
+ .assertHeader("X-Content-Type").is("text/plain")
+ .assertHeader("X-Transfer-Encoding").doesNotExist()
;
- ReaderResource x5 =
ReaderResource.of("foo").header("Foo","bar").header(header("Baz","qux"));
+ BasicHttpResource x5 =
httpResource("foo").header("Foo","bar").header(header("Baz","qux"));
client().build().post("/",x5).run()
- .getBody().assertString().contains("Foo: bar","Baz:
qux")
+ .assertHeader("X-Foo").is("bar")
+ .assertHeader("X-Baz").is("qux")
;
- ReaderResource x6 =
ReaderResource.of("foo").headers(Arrays.asList(header("Foo","bar"),header("Baz","qux")));
+ BasicHttpResource x6 =
httpResource("foo").headers(Arrays.asList(header("Foo","bar"),header("Baz","qux")));
client().build().post("/",x6).run()
- .getBody().assertString().contains("Foo: bar","Baz:
qux")
+ .assertHeader("X-Foo").is("bar")
+ .assertHeader("X-Baz").is("qux")
;
- ReaderResource x7 = ReaderResource.of(new StringReader("foo"));
-
client().build().post("/",x7).run().getBody().assertString().contains("foo");
+ BasicHttpResource x7 = httpResource(new StringReader("foo"));
+
client().build().post("/",x7).run().getBody().assertString().is("foo");
- ReaderResource x8 = ReaderResource.of(new
StringReader("foo")).cache();
-
client().build().post("/",x8).run().getBody().assertString().contains("foo");
-
client().build().post("/",x8).run().getBody().assertString().contains("foo");
+ BasicHttpResource x8 = httpResource(new
StringReader("foo")).cache();
+
client().build().post("/",x8).run().getBody().assertString().is("foo");
+
client().build().post("/",x8).run().getBody().assertString().is("foo");
- ReaderResource x9 = ReaderResource.of(null);
-
client().build().post("/",x9).run().getBody().assertString().contains("HTTP
POST");
+ BasicHttpResource x9 = httpResource(null);
+
client().build().post("/",x9).run().getBody().assertString().isEmpty();
}
@Test
- public void a02_StreamResource() throws Exception {
- StreamResource x1 = StreamResource.create().content("foo");
- client().build().post("/", x1).run()
- .getBody().assertString().contains("foo",
"Content-Length: 3")
-
.getBody().assertString().doesNotContain("Content-Encoding","Content-Type","Transfer-Encoding")
- ;
-
- StreamResource x2 =
StreamResource.create().content("foo").contentType("text/plain").contentEncoding("identity");
- client().build().post("/",x2).run()
-
.getBody().assertString().contains("foo","Content-Length: 3","Content-Encoding:
identity","Content-Type: text/plain")
- ;
-
- StreamResource x3 =
StreamResource.create().content("foo").contentType(contentType("text/plain")).contentEncoding(contentEncoding("identity")).chunked();
- client().build().post("/",x3).run()
-
.getBody().assertString().contains("foo","Content-Encoding:
identity","Content-Type: text/plain","Transfer-Encoding: chunked")
- ;
-
- StreamResource x4 = new
StreamResource(contentType("text/plain"), contentEncoding("identity"), "foo");
- client().build().post("/",x4).run()
-
.getBody().assertString().contains("foo","Content-Length: 3","Content-Encoding:
identity","Content-Type: text/plain")
- ;
-
- StreamResource x5 =
StreamResource.of("foo").header("Foo","bar").header(header("Baz","qux"));
- client().build().post("/",x5).run()
- .getBody().assertString().contains("Foo: bar","Baz:
qux")
- ;
-
- StreamResource x6 =
StreamResource.of("foo").headers(Arrays.asList(header("Foo","bar"),header("Baz","qux")));
- client().build().post("/",x6).run()
- .getBody().assertString().contains("Foo: bar","Baz:
qux")
+ public void a03_SerializedHttpEntity() throws Exception {
+ Serializer js = JsonSerializer.DEFAULT;
+ File f = File.createTempFile("test", "txt");
+
+ SerializedHttpEntity x = serializedHttpEntity(ABean.get(),null);
+ client().debug().build().post("/",x).run()
+ .assertHeader("X-Content-Length").doesNotExist()
+ .assertHeader("X-Content-Encoding").doesNotExist()
+ .assertHeader("X-Content-Type").doesNotExist()
+ .assertHeader("X-Transfer-Encoding").is("chunked") //
Because content length is -1.
;
- StreamResource x7 = StreamResource.of(new StringReader("foo"));
-
client().build().post("/",x7).run().getBody().assertString().contains("foo");
-
- StreamResource x8 = StreamResource.of(new
StringReader("foo")).cache();
-
client().build().post("/",x8).run().getBody().assertString().contains("foo");
-
client().build().post("/",x8).run().getBody().assertString().contains("foo");
-
- StreamResource x9 = StreamResource.of(null);
-
client().build().post("/",x9).run().getBody().assertString().contains("HTTP
POST");
+ x.serializer(js);
+ client().build().post("/",x).run()
+ .assertHeader("X-Content-Length").doesNotExist()
+ .assertHeader("X-Content-Encoding").doesNotExist()
+ .assertHeader("X-Content-Type").is("application/json")
+
.getBody().assertObject(ABean.class).json().is("{a:1,b:'foo'}");
+
+ x = serializedHttpEntity(ABean.get(),js);
+ client().build().post("/",x).run()
+ .assertHeader("X-Content-Length").doesNotExist()
+ .assertHeader("X-Content-Encoding").doesNotExist()
+ .assertHeader("X-Content-Type").is("application/json")
+
.getBody().assertObject(ABean.class).json().is("{a:1,b:'foo'}");
+
+ x = SerializedHttpEntity.of(()->ABean.get(),js);
+ client().build().post("/",x).run()
+ .assertHeader("X-Content-Length").doesNotExist()
+ .assertHeader("X-Content-Encoding").doesNotExist()
+ .assertHeader("X-Content-Type").is("application/json")
+
.getBody().assertObject(ABean.class).json().is("{a:1,b:'foo'}");
+
+ x = serializedHttpEntity(new
StringReader("{a:1,b:'foo'}"),null);
+ client().build().post("/",x).run()
+ .assertHeader("X-Content-Length").doesNotExist()
+ .assertHeader("X-Content-Encoding").doesNotExist()
+ .assertHeader("X-Content-Type").doesNotExist()
+
.getBody().assertObject(ABean.class).json().is("{a:1,b:'foo'}");
+
+ x = serializedHttpEntity(new
ByteArrayInputStream("{a:1,b:'foo'}".getBytes()),null);
+ client().build().post("/",x).run()
+ .assertHeader("X-Content-Length").doesNotExist()
+ .assertHeader("X-Content-Encoding").doesNotExist()
+ .assertHeader("X-Content-Type").doesNotExist()
+
.getBody().assertObject(ABean.class).json().is("{a:1,b:'foo'}");
+
+ x = serializedHttpEntity(f,null);
+ client().build().post("/",x).run()
+ .assertHeader("X-Content-Length").doesNotExist()
+ .assertHeader("X-Content-Encoding").doesNotExist()
+ .assertHeader("X-Content-Type").doesNotExist()
+ .getBody().assertObject(ABean.class).json().is("{a:0}");
}
//------------------------------------------------------------------------------------------------------------------
// Helper methods.
//------------------------------------------------------------------------------------------------------------------
+ private static BasicHttpResource httpResource(Object val) {
+ return BasicHttpResource.of(val);
+ }
+
+ private static SerializedHttpEntity serializedHttpEntity(Object val,
Serializer s) {
+ return SerializedHttpEntity.of(val, s);
+ }
+
private static RestClientBuilder client() {
return MockRestClient.create(A.class).simpleJson();
}
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
index 954408e..0e01976 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestClient.java
@@ -41,6 +41,7 @@ import org.apache.http.client.methods.*;
import org.apache.http.client.utils.*;
import org.apache.http.conn.*;
import org.apache.http.entity.*;
+import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.impl.client.*;
import org.apache.http.params.*;
import org.apache.http.protocol.*;
@@ -487,11 +488,9 @@ import org.apache.juneau.utils.*;
* <li class='jc'>
* {@link InputStream} - Raw contents of {@code
InputStream} will be serialized to remote resource.
* <li class='jc'>
- * {@link ReaderResource} - Raw contents of {@code Reader}
will be serialized to remote resource. Additional headers and media type will
be set on request.
+ * {@link HttpResource}/{@link BasicHttpResource} - Raw
contents will be serialized to remote resource. Additional headers and media
type will be set on request.
* <li class='jc'>
- * {@link StreamResource} - Raw contents of {@code
InputStream} will be serialized to remote resource. Additional headers and
media type will be set on request.
- * <li class='jc'>
- * {@link HttpEntity} - Bypass Juneau serialization and
pass HttpEntity directly to HttpClient.
+ * {@link HttpEntity}/{@link BasicHttpEntity} - Bypass
Juneau serialization and pass HttpEntity directly to HttpClient.
* <li class='jc'>
* {@link NameValuePairSupplier} - Converted to a
URL-encoded FORM post.
* <li class='jc'>
@@ -2483,8 +2482,8 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
* <li>{@link NameValuePair} array - URL-encoded as name
value pairs.
* <li>{@link NameValuePairSupplier} - URL-encoded as name
value pairs.
* <li>{@link Reader}/{@link InputStream}- Streamed
directly and <l>Content-Type</l> set to
<js>"application/x-www-form-urlencoded"</js>
- * <li>{@link ReaderResource}/{@link StreamResource}-
Streamed directly and <l>Content-Type</l> set to
<js>"application/x-www-form-urlencoded"</js> if not already specified on the
entity.
- * <li>{@link HttpEntity}- Streamed directly and
<l>Content-Type</l> set to <js>"application/x-www-form-urlencoded"</js> if not
already specified on the entity.
+ * <li>{@link HttpResource}/{@link BasicHttpResource} -
Raw contents will be serialized to remote resource. Additional headers and
media type will be set on request.
+ * <li>{@link HttpEntity}/{@link BasicHttpEntity} - Bypass
Juneau serialization and pass HttpEntity directly to HttpClient.
* <li>{@link Object} - Converted to a {@link
SerializedHttpEntity} using {@link UrlEncodingSerializer} to serialize.
* <li>{@link Supplier} - A supplier of anything on this
list.
* </ul>
@@ -2516,7 +2515,7 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
}
if (body instanceof Reader || body instanceof
InputStream)
return
req.contentType("application/x-www-form-urlencoded").body(body);
- return req.body(new SerializedHttpEntity(body,
urlEncodingSerializer, null, null));
+ return req.body(SerializedHttpEntity.of(body,
urlEncodingSerializer));
} catch (IOException e) {
throw new RestCallException(null, e, "Could not read
form post body.");
}
@@ -2593,15 +2592,13 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
* <li>
* {@link InputStream} - Raw contents of {@code
InputStream} will be serialized to remote resource.
* <li>
- * {@link ReaderResource} - Raw contents of {@code
Reader} will be serialized to remote resource. Additional headers and media
type will be set on request.
+ * {@link HttpResource}/{@link BasicHttpResource}
- Raw contents will be serialized to remote resource. Additional headers and
media type will be set on request.
* <li>
- * {@link StreamResource} - Raw contents of {@code
InputStream} will be serialized to remote resource. Additional headers and
media type will be set on request.
+ * {@link HttpEntity}/{@link BasicHttpEntity} -
Bypass Juneau serialization and pass HttpEntity directly to HttpClient.
* <li>
* {@link Object} - POJO to be converted to text
using the {@link Serializer} registered with the
* {@link RestClient}.
* <li>
- * {@link HttpEntity} - Bypass Juneau
serialization and pass HttpEntity directly to HttpClient.
- * <li>
* {@link NameValuePairSupplier} - Converted to a
URL-encoded FORM post.
* <li>
* {@link Supplier} - A supplier of anything on
this list.
@@ -2779,15 +2776,13 @@ public class RestClient extends BeanContext implements
HttpClient, Closeable, Re
* <li>
* {@link InputStream} - Raw contents of {@code
InputStream} will be serialized to remote resource.
* <li>
- * {@link ReaderResource} - Raw contents of {@code
Reader} will be serialized to remote resource. Additional headers and media
type will be set on request.
+ * {@link HttpResource}/{@link BasicHttpResource}
- Raw contents will be serialized to remote resource. Additional headers and
media type will be set on request.
* <li>
- * {@link StreamResource} - Raw contents of {@code
InputStream} will be serialized to remote resource. Additional headers and
media type will be set on request.
+ * {@link HttpEntity}/{@link BasicHttpEntity} -
Bypass Juneau serialization and pass HttpEntity directly to HttpClient.
* <li>
* {@link Object} - POJO to be converted to text
using the {@link Serializer} registered with the
* {@link RestClient}.
* <li>
- * {@link HttpEntity} - Bypass Juneau
serialization and pass HttpEntity directly to HttpClient.
- * <li>
* {@link NameValuePairSupplier} - Converted to a
URL-encoded FORM post.
* <li>
* {@link Supplier} - A supplier of anything on
this list.
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
index 43f5e51..cf1340d 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestRequest.java
@@ -33,6 +33,7 @@ import org.apache.http.client.methods.*;
import org.apache.http.client.utils.*;
import org.apache.http.concurrent.*;
import org.apache.http.entity.*;
+import org.apache.http.entity.BasicHttpEntity;
import org.apache.http.entity.ContentType;
import org.apache.http.params.*;
import org.apache.http.protocol.*;
@@ -1761,15 +1762,13 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* <li>
* {@link InputStream} - Raw contents of {@code
InputStream} will be serialized to remote resource.
* <li>
- * {@link ReaderResource} - Raw contents of {@code
Reader} will be serialized to remote resource. Additional headers and media
type will be set on request.
+ * {@link HttpResource}/{@link BasicHttpResource}
- Raw contents will be serialized to remote resource. Additional headers and
media type will be set on request.
* <li>
- * {@link StreamResource} - Raw contents of {@code
InputStream} will be serialized to remote resource. Additional headers and
media type will be set on request.
+ * {@link HttpEntity}/{@link BasicHttpEntity} -
Bypass Juneau serialization and pass HttpEntity directly to HttpClient.
* <li>
* {@link Object} - POJO to be converted to text
using the {@link Serializer} registered with the
* {@link RestClient}.
* <li>
- * {@link HttpEntity} - Bypass Juneau
serialization and pass HttpEntity directly to HttpClient.
- * <li>
* {@link NameValuePairSupplier} - Converted to a
URL-encoded FORM post.
* </ul>
* @return This object (for method chaining).
@@ -1853,15 +1852,13 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* <li>
* {@link InputStream} - Raw contents of {@code
InputStream} will be serialized to remote resource.
* <li>
- * {@link ReaderResource} - Raw contents of {@code
Reader} will be serialized to remote resource. Additional headers and media
type will be set on request.
+ * {@link HttpResource}/{@link BasicHttpResource}
- Raw contents will be serialized to remote resource. Additional headers and
media type will be set on request.
* <li>
- * {@link StreamResource} - Raw contents of {@code
InputStream} will be serialized to remote resource. Additional headers and
media type will be set on request.
+ * {@link HttpEntity}/{@link BasicHttpEntity} -
Bypass Juneau serialization and pass HttpEntity directly to HttpClient.
* <li>
* {@link Object} - POJO to be converted to text
using the {@link Serializer} registered with the
* {@link RestClient}.
* <li>
- * {@link HttpEntity} - Bypass Juneau
serialization and pass HttpEntity directly to HttpClient.
- * <li>
* {@link NameValuePairSupplier} - Converted to a
URL-encoded FORM post.
* <li>
* A {@link Supplier} of anything on this list.
@@ -1923,15 +1920,13 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
* <li>
* {@link InputStream} - Raw contents of {@code
InputStream} will be serialized to remote resource.
* <li>
- * {@link ReaderResource} - Raw contents of {@code
Reader} will be serialized to remote resource. Additional headers and media
type will be set on request.
+ * {@link HttpResource}/{@link BasicHttpResource}
- Raw contents will be serialized to remote resource. Additional headers and
media type will be set on request.
* <li>
- * {@link StreamResource} - Raw contents of {@code
InputStream} will be serialized to remote resource. Additional headers and
media type will be set on request.
+ * {@link HttpEntity}/{@link BasicHttpEntity} -
Bypass Juneau serialization and pass HttpEntity directly to HttpClient.
* <li>
* {@link Object} - POJO to be converted to text
using the {@link Serializer} registered with the
* {@link RestClient}.
* <li>
- * {@link HttpEntity} - Bypass Juneau
serialization and pass HttpEntity directly to HttpClient.
- * <li>
* {@link NameValuePairSupplier} - Converted to a
URL-encoded FORM post.
* <li>
* A {@link Supplier} of anything on this list.
@@ -2863,7 +2858,7 @@ public class RestRequest extends BeanSession implements
HttpUriRequest, Configur
else if (input2 instanceof InputStream)
entity = new
InputStreamEntity((InputStream)input2,
getRequestContentType(ContentType.APPLICATION_OCTET_STREAM));
else if (serializer != null)
- entity = new
SerializedHttpEntity(input2, serializer, requestBodySchema, contentType);
+ entity =
SerializedHttpEntity.of(input2,
serializer).schema(requestBodySchema).contentType(contentType);
else {
if (input2 == null)
input2 = "";
diff --git
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBody.java
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBody.java
index 94df46d..7243a0e 100644
---
a/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBody.java
+++
b/juneau-rest/juneau-rest-client/src/main/java/org/apache/juneau/rest/client2/RestResponseBody.java
@@ -513,8 +513,7 @@ public class RestResponseBody implements HttpEntity {
* <li>{@link RestResponseBody}/{@link HttpEntity}
- Returns access to this object.
* <li>{@link Reader} - Returns access to the raw
reader of the response.
* <li>{@link InputStream} - Returns access to the
raw input stream of the response.
- * <li>{@link ReaderResource} - Returns access as
a reader wrapped in a reader resource.
- * <li>{@link StreamResource} - Returns access as
an input stream wrapped in a stream resource.
+ * <li>{@link BasicHttpResource} - Raw contents
will be serialized to remote resource. Additional headers and media type will
be set on request.
* </ul>
* <li>
* If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
@@ -625,8 +624,7 @@ public class RestResponseBody implements HttpEntity {
* <li>{@link RestResponseBody}/{@link HttpEntity}
- Returns access to this object.
* <li>{@link Reader} - Returns access to the raw
reader of the response.
* <li>{@link InputStream} - Returns access to the
raw input stream of the response.
- * <li>{@link ReaderResource} - Returns access as
a reader wrapped in a reader resource.
- * <li>{@link StreamResource} - Returns access as
an input stream wrapped in a stream resource.
+ * <li>{@link BasicHttpResource} - Raw contents
will be serialized to remote resource. Additional headers and media type will
be set on request.
* </ul>
* <li>
* If {@link #cache()} or {@link RestResponse#cacheBody()}
has been called, this method can be can be called multiple times and/or
combined with
diff --git
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
index 9765c17..b70358c 100644
---
a/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
+++
b/juneau-rest/juneau-rest-mock/src/main/java/org/apache/juneau/rest/mock2/MockRestClient.java
@@ -29,7 +29,6 @@ import org.apache.http.entity.*;
import org.apache.http.message.*;
import org.apache.juneau.*;
import org.apache.juneau.http.remote.*;
-import org.apache.juneau.internal.*;
import org.apache.juneau.parser.*;
import org.apache.juneau.rest.*;
import org.apache.juneau.rest.RestCallHandler;
@@ -742,10 +741,9 @@ public class MockRestClient extends RestClient implements
HttpClientConnection {
long length = entity.getContentLength();
if (length < 0)
length = 1024;
- try (InputStream is = entity.getContent()) {
- if (is != null)
- body = IOUtils.readBytes(is,
(int)Math.min(length, 1024));
- }
+ ByteArrayOutputStream baos = new
ByteArrayOutputStream((int)Math.min(length, 1024));
+ entity.writeTo(baos);
+ body = baos.toByteArray();
}
sreq.get().body(body);
}
diff --git
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/ReaderResourceTest.java
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/BasicHttpResourceTest.java
similarity index 75%
rename from
juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/ReaderResourceTest.java
rename to
juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/BasicHttpResourceTest.java
index 9397ed9..ae64926 100644
---
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/ReaderResourceTest.java
+++
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/BasicHttpResourceTest.java
@@ -23,44 +23,44 @@ import org.apache.juneau.rest.mock2.*;
import org.junit.*;
@FixMethodOrder(NAME_ASCENDING)
-public class ReaderResourceTest {
+public class BasicHttpResourceTest {
@Rest
public static class A {
@RestMethod
- public ReaderResource a01() throws Exception {
- return ReaderResource.create().content("foo");
+ public BasicHttpResource a01() throws Exception {
+ return BasicHttpResource.create().content("foo");
}
@RestMethod
- public ReaderResource a02() throws Exception {
- return ReaderResource.create().header("Foo", "Bar");
+ public BasicHttpResource a02() throws Exception {
+ return BasicHttpResource.create().header("Foo", "Bar");
}
@RestMethod
- public ReaderResource a03() throws Exception {
- return
ReaderResource.create().contentType("application/json");
+ public BasicHttpResource a03() throws Exception {
+ return
BasicHttpResource.create().contentType("application/json");
}
@RestMethod
- public ReaderResource a04(RestRequest req) throws Exception {
- return
ResolvingReaderResource.create().varResolver(req.getVarResolverSession()).content("$RQ{foo}");
+ public BasicHttpResource a04(RestRequest req) throws Exception {
+ return
BasicHttpResource.create().resolving(req.getVarResolverSession()).content("$RQ{foo}");
}
@RestMethod
- public ReaderResource a05() throws Exception {
- return ReaderResource.create().content(new
ByteArrayInputStream("foo".getBytes()));
+ public BasicHttpResource a05() throws Exception {
+ return BasicHttpResource.create().content(new
ByteArrayInputStream("foo".getBytes()));
}
@RestMethod
- public ReaderResource a06() throws Exception {
- return ReaderResource.create().content(new
StringReader("foo"));
+ public BasicHttpResource a06() throws Exception {
+ return BasicHttpResource.create().content(new
StringReader("foo"));
}
@RestMethod
- public ReaderResource a07() throws Exception {
- return ReaderResource.create().content(new
StringBuilder("foo"));
+ public BasicHttpResource a07() throws Exception {
+ return BasicHttpResource.create().content(new
StringBuilder("foo"));
}
}
diff --git
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/StreamResourceTest.java
b/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/StreamResourceTest.java
deleted file mode 100644
index 8e74e97..0000000
---
a/juneau-rest/juneau-rest-server-utest/src/test/java/org/apache/juneau/rest/helper/StreamResourceTest.java
+++ /dev/null
@@ -1,116 +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.juneau.rest.helper;
-
-import static org.junit.runners.MethodSorters.*;
-
-import java.io.*;
-
-import org.apache.juneau.http.StreamResource;
-import org.apache.juneau.rest.annotation.*;
-import org.apache.juneau.rest.mock2.*;
-import org.junit.*;
-
-@FixMethodOrder(NAME_ASCENDING)
-public class StreamResourceTest {
-
- @Rest
- public static class A {
-
- @RestMethod
- public StreamResource a01() throws Exception {
- return StreamResource.create().content("foo");
- }
-
- @RestMethod
- public StreamResource a02() throws Exception {
- return StreamResource.create().header("Foo", "Bar");
- }
-
- @RestMethod
- public StreamResource a03() throws Exception {
- return
StreamResource.create().contentType("application/json");
- }
-
- @RestMethod
- public StreamResource a04() throws Exception {
- return
StreamResource.create().content("foo".getBytes());
- }
-
- @RestMethod
- public StreamResource a05() throws Exception {
- return StreamResource.create().content(new
ByteArrayInputStream("foo".getBytes()));
- }
-
- @RestMethod
- public StreamResource a06() throws Exception {
- return StreamResource.create().content(new
StringReader("foo"));
- }
-
- @RestMethod
- public StreamResource a07() throws Exception {
- return StreamResource.create().content(new
StringBuilder("foo"));
- }
- }
-
- static MockRestClient a = MockRestClient.build(A.class);
-
- @Test
- public void a01_basic() throws Exception {
- a.get("/a01")
- .run()
- .assertBody().is("foo");
- }
-
- @Test
- public void a02_headers() throws Exception {
- a.get("/a02")
- .run()
- .assertHeader("Foo").is("Bar");
- }
-
- @Test
- public void a03_contentType() throws Exception {
- a.get("/a03")
- .run()
- .assertHeader("Content-Type").is("application/json");
- }
-
- @Test
- public void a04_byteArray() throws Exception {
- a.get("/a04")
- .run()
- .assertBody().is("foo");
- }
-
- @Test
- public void a05_inputStream() throws Exception {
- a.get("/a05")
- .run()
- .assertBody().is("foo");
- }
-
- @Test
- public void a06_reader() throws Exception {
- a.get("/a06")
- .run()
- .assertBody().is("foo");
- }
-
- @Test
- public void a07_charSequence() throws Exception {
- a.get("/a07")
- .run()
- .assertBody().is("foo");
- }
-}
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
index 770d66c..dcbd72f 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestContext.java
@@ -808,9 +808,9 @@ public final class RestContext extends BeanContext {
* </ul>
* <li class='jc'>{@link RestRequest}
* <ul>
- * <li class='jm'>{@link
RestRequest#getClasspathReaderResource(String)
getClasspathReaderResource(String)}
- * <li class='jm'>{@link
RestRequest#getClasspathReaderResource(String,boolean)
getClasspathReaderResource(String,boolean)}
- * <li class='jm'>{@link
RestRequest#getClasspathReaderResource(String,boolean,MediaType,boolean)
getClasspathReaderResource(String,boolean,MediaType,boolean)}
+ * <li class='jm'>{@link
RestRequest#getClasspathHttpResource(String) getClasspathHttpResource(String)}
+ * <li class='jm'>{@link
RestRequest#getClasspathHttpResource(String,boolean)
getClasspathHttpResource(String,boolean)}
+ * <li class='jm'>{@link
RestRequest#getClasspathHttpResource(String,boolean,MediaType,boolean)
getClasspathHttpResource(String,boolean,MediaType,boolean)}
* </ul>
* </ul>
*
@@ -1664,9 +1664,9 @@ public final class RestContext extends BeanContext {
* Used for specifying the content type on file resources retrieved
through the following methods:
* <ul class='javatree'>
* <li class='jm'>{@link RestContext#resolveStaticFile(String)
RestContext.resolveStaticFile(String)}
- * <li class='jm'>{@link
RestRequest#getClasspathReaderResource(String,boolean,MediaType,boolean)}
- * <li class='jm'>{@link
RestRequest#getClasspathReaderResource(String,boolean)}
- * <li class='jm'>{@link
RestRequest#getClasspathReaderResource(String)}
+ * <li class='jm'>{@link
RestRequest#getClasspathHttpResource(String,boolean,MediaType,boolean)}
+ * <li class='jm'>{@link
RestRequest#getClasspathHttpResource(String,boolean)}
+ * <li class='jm'>{@link
RestRequest#getClasspathHttpResource(String)}
* </ul>
*
* <p>
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
index a3c8d16..fba70ca 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/RestRequest.java
@@ -1416,7 +1416,7 @@ public final class RestRequest extends
HttpServletRequestWrapper {
}
/**
- * Returns an instance of a {@link ReaderResource} that represents the
contents of a resource text file from the
+ * Returns an instance of a {@link BasicHttpResource} that represents
the contents of a resource text file from the
* classpath.
*
* <p>
@@ -1432,8 +1432,8 @@ public final class RestRequest extends
HttpServletRequestWrapper {
*
* <ul class='seealso'>
* <li class='jf'>{@link
org.apache.juneau.rest.RestContext#REST_classpathResourceFinder}
- * <li class='jm'>{@link
org.apache.juneau.rest.RestRequest#getClasspathReaderResource(String, boolean)}
- * <li class='jm'>{@link
org.apache.juneau.rest.RestRequest#getClasspathReaderResource(String)}
+ * <li class='jm'>{@link
org.apache.juneau.rest.RestRequest#getClasspathHttpResource(String, boolean)}
+ * <li class='jm'>{@link
org.apache.juneau.rest.RestRequest#getClasspathHttpResource(String)}
* </ul>
*
* @param name The name of the resource (i.e. the value normally passed
to {@link Class#getResourceAsStream(String)}.
@@ -1446,16 +1446,16 @@ public final class RestRequest extends
HttpServletRequestWrapper {
* @return A new reader resource, or <jk>null</jk> if resource could
not be found.
* @throws IOException Thrown by underlying stream.
*/
- public ReaderResource getClasspathReaderResource(String name, boolean
resolveVars, MediaType mediaType, boolean cached) throws IOException {
+ public BasicHttpResource getClasspathHttpResource(String name, boolean
resolveVars, MediaType mediaType, boolean cached) throws IOException {
String s = context.getClasspathResourceAsString(name,
getLocale());
if (s == null)
return null;
- ResolvingReaderResource b = ResolvingReaderResource
+ BasicHttpResource b = BasicHttpResource
.create()
.content(s)
.contentType(mediaType == null ? null :
ContentType.of(mediaType.toString()));
if (resolveVars)
- b.varResolver(getVarResolverSession());
+ b.resolving(getVarResolverSession());
if (cached)
b.cache();
return b;
@@ -1488,7 +1488,7 @@ public final class RestRequest extends
HttpServletRequestWrapper {
}
/**
- * Same as {@link #getClasspathReaderResource(String, boolean,
MediaType, boolean)} except uses the resource mime-type map
+ * Same as {@link #getClasspathHttpResource(String, boolean, MediaType,
boolean)} except uses the resource mime-type map
* constructed using {@link RestContextBuilder#mimeTypes(String...)} to
determine the media type.
*
* @param name The name of the resource (i.e. the value normally passed
to {@link Class#getResourceAsStream(String)}.
@@ -1499,60 +1499,19 @@ public final class RestRequest extends
HttpServletRequestWrapper {
* @return A new reader resource, or <jk>null</jk> if resource could
not be found.
* @throws IOException Thrown by underlying stream.
*/
- public ReaderResource getClasspathReaderResource(String name, boolean
resolveVars) throws IOException {
- return getClasspathReaderResource(name, resolveVars,
MediaType.forString(context.getMediaTypeForName(name)), false);
+ public BasicHttpResource getClasspathHttpResource(String name, boolean
resolveVars) throws IOException {
+ return getClasspathHttpResource(name, resolveVars,
MediaType.forString(context.getMediaTypeForName(name)), false);
}
/**
- * Same as {@link #getClasspathReaderResource(String, boolean)} with
<code>resolveVars == <jk>false</jk></code>
+ * Same as {@link #getClasspathHttpResource(String, boolean)} with
<code>resolveVars == <jk>false</jk></code>
*
* @param name The name of the resource (i.e. the value normally passed
to {@link Class#getResourceAsStream(String)}.
* @return A new reader resource, or <jk>null</jk> if resource could
not be found.
* @throws IOException Thrown by underlying stream.
*/
- public ReaderResource getClasspathReaderResource(String name) throws
IOException {
- return getClasspathReaderResource(name, false,
MediaType.forString(context.getMediaTypeForName(name)), false);
- }
-
- /**
- * Returns an instance of a {@link StreamResource} that represents the
contents of a resource binary file from the
- * classpath.
- *
- * <ul class='seealso'>
- * <li class='jf'>{@link
org.apache.juneau.rest.RestContext#REST_classpathResourceFinder}
- * <li class='jm'>{@link
org.apache.juneau.rest.RestRequest#getClasspathStreamResource(String)}
- * </ul>
- *
- * @param name The name of the resource (i.e. the value normally passed
to {@link Class#getResourceAsStream(String)}.
- * @param mediaType The value to set as the <js>"Content-Type"</js>
header for this object.
- * @param cached If <jk>true</jk>, the resource will be read into a
byte array for fast serialization.
- * @return A new stream resource, or <jk>null</jk> if resource could
not be found.
- * @throws IOException Thrown by underlying stream.
- */
- @SuppressWarnings("resource")
- public StreamResource getClasspathStreamResource(String name, MediaType
mediaType, boolean cached) throws IOException {
- InputStream is = context.getClasspathResource(name,
getLocale());
- if (is == null)
- return null;
- StreamResource b = StreamResource
- .create()
- .content(is)
- .contentType(mediaType == null ? null :
ContentType.of(mediaType.toString()));
- if (cached)
- b.cache();
- return b;
- }
-
- /**
- * Same as {@link #getClasspathStreamResource(String, MediaType,
boolean)} except uses the resource mime-type map
- * constructed using {@link RestContextBuilder#mimeTypes(String...)} to
determine the media type.
- *
- * @param name The name of the resource (i.e. the value normally passed
to {@link Class#getResourceAsStream(String)}.
- * @return A new stream resource, or <jk>null</jk> if resource could
not be found.
- * @throws IOException Thrown by underlying stream.
- */
- public StreamResource getClasspathStreamResource(String name) throws
IOException {
- return getClasspathStreamResource(name,
MediaType.forString(context.getMediaTypeForName(name)), false);
+ public BasicHttpResource getClasspathHttpResource(String name) throws
IOException {
+ return getClasspathHttpResource(name, false,
MediaType.forString(context.getMediaTypeForName(name)), false);
}
/**
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Rest.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Rest.java
index 5a06ab0..a210eab 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Rest.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/Rest.java
@@ -1490,7 +1490,7 @@ public @interface Rest {
* Configuration property: Use classpath resource caching.
*
* <p>
- * When enabled, resources retrieved via {@link
RestRequest#getClasspathReaderResource(String, boolean)} (and related
+ * When enabled, resources retrieved via {@link
RestRequest#getClasspathHttpResource(String, boolean)} (and related
* methods) will be cached in memory to speed subsequent lookups.
*
* <ul class='notes'>
diff --git
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
index 5607e14..c4ce990 100644
---
a/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
+++
b/juneau-rest/juneau-rest-server/src/main/java/org/apache/juneau/rest/annotation/RestResource.java
@@ -1339,7 +1339,7 @@ public @interface RestResource {
* Configuration property: Use classpath resource caching.
*
* <p>
- * When enabled, resources retrieved via {@link
RestRequest#getClasspathReaderResource(String, boolean)} (and related
+ * When enabled, resources retrieved via {@link
RestRequest#getClasspathHttpResource(String, boolean)} (and related
* methods) will be cached in memory to speed subsequent lookups.
*
* <ul class='notes'>