Skip to content

Commit

Permalink
libraries release version 1.0.64 unstable; thirdparty updates
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasWBartels committed Oct 15, 2017
1 parent b64dcfe commit 63e7670
Show file tree
Hide file tree
Showing 240 changed files with 30,221 additions and 513 deletions.
2 changes: 1 addition & 1 deletion commons/advanced/Commons_Advanced/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>net.anwiba.commons</groupId>
<artifactId>anwiba-commons-maven-advanced</artifactId>
<version>1.0.58</version>
<version>1.0.64</version>
</parent>

<scm>
Expand Down
2 changes: 1 addition & 1 deletion commons/advanced/Commons_Http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>net.anwiba.commons</groupId>
<artifactId>anwiba-commons-maven-advanced</artifactId>
<version>1.0.58</version>
<version>1.0.64</version>
</parent>

<scm>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import java.io.InputStream;
import java.io.InterruptedIOException;

import net.anwiba.commons.lang.io.NoneClosingInputStream;
import net.anwiba.commons.process.cancel.ICanceler;
import net.anwiba.commons.resource.utilities.IoUtilities;
import net.anwiba.commons.utilities.io.NoneClosingInputStream;

public class ConvertingHttpRequestExecutor implements IConvertingHttpRequestExecutor {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
Expand All @@ -26,6 +26,13 @@
import java.text.MessageFormat;
import java.util.Optional;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.ContentType;

import net.anwiba.commons.http.apache.InputStreamEntity;
import net.anwiba.commons.lang.exception.UnreachableCodeReachedException;
import net.anwiba.commons.logging.ILevel;
Expand All @@ -34,13 +41,6 @@
import net.anwiba.commons.process.cancel.ICanceler;
import net.anwiba.commons.utilities.parameter.IParameter;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.methods.RequestBuilder;
import org.apache.http.entity.ContentType;

public class HttpRequestExecutor implements IHttpRequestExecutor {

private static ILogger logger = Logging.getLogger(HttpRequestExecutor.class.getName());
Expand All @@ -66,21 +66,25 @@ private HttpUriRequest create(final IRequest request) {
switch (request.getMethodType()) {
case POST: {
final RequestBuilder requestBuilder = RequestBuilder.post(request.getUriString());
final Iterable<IParameter> parameters = request.getParameters().parameters();
for (final IParameter parameter : parameters) {
for (final IParameter parameter : request.getParameters().parameters()) {
requestBuilder.addParameter(parameter.getName(), parameter.getValue());
}
for (final IParameter parameter : request.getProperties().parameters()) {
requestBuilder.addHeader(parameter.getName(), parameter.getValue());
}
Optional.ofNullable(request.getUserAgent()).ifPresent(value -> requestBuilder.addHeader("User-Agent", value));
final HttpEntity entity = createEntity(request);
requestBuilder.setEntity(entity);
return requestBuilder.build();
}
case GET: {
final RequestBuilder requestBuilder = RequestBuilder.get(request.getUriString());
final Iterable<IParameter> parameters = request.getParameters().parameters();
for (final IParameter parameter : parameters) {
for (final IParameter parameter : request.getParameters().parameters()) {
requestBuilder.addParameter(parameter.getName(), parameter.getValue());
}
for (final IParameter parameter : request.getProperties().parameters()) {
requestBuilder.addHeader(parameter.getName(), parameter.getValue());
}
Optional.ofNullable(request.getUserAgent()).ifPresent(value -> requestBuilder.addHeader("User-Agent", value));
return requestBuilder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
Expand Down Expand Up @@ -45,4 +45,6 @@ public interface IRequest {

String getUserAgent();

IParameters getProperties();

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
Expand All @@ -37,11 +37,13 @@ public final class Request implements IRequest {
private final String encoding;
private final String mimeType;
private final String userAgent;
private final IParameters properties;

public Request(
final HttpMethodType methodType,
final String urlString,
final IParameters parameters,
final IParameters properties,
final String userAgent,
final IClosure<InputStream, IOException> inputStreamClosure,
final long contentLength,
Expand All @@ -51,6 +53,7 @@ public Request(
this.methodType = methodType;
this.urlString = urlString;
this.parameters = parameters;
this.properties = properties;
this.userAgent = userAgent;
this.inputStreamClosure = inputStreamClosure;
this.contentLength = contentLength;
Expand Down Expand Up @@ -97,4 +100,9 @@ public String getMimeType() {
public String getEncoding() {
return this.encoding;
}

@Override
public IParameters getProperties() {
return this.properties;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 2.1 of the
* License, or (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>.
Expand All @@ -38,6 +38,7 @@ public class RequestBuilder {
private HttpMethodType httpMethodType = HttpMethodType.GET;
private final String urlString;
private final List<IParameter> queryParameters = new ArrayList<>();
private final List<IParameter> headerParameters = new ArrayList<>();
IClosure<InputStream, IOException> inputStreamClosure;
private long contentLenght;
private String encoding;
Expand Down Expand Up @@ -71,6 +72,7 @@ public IRequest build() {
this.httpMethodType,
this.urlString,
new Parameters(this.queryParameters),
new Parameters(this.headerParameters),
this.userAgent,
this.inputStreamClosure,
this.contentLenght,
Expand All @@ -88,6 +90,16 @@ public RequestBuilder query(final IParameter parameter) {
return this;
}

public RequestBuilder header(final String key, final String value) {
this.headerParameters.add(new Parameter(key, value));
return this;
}

public RequestBuilder header(final IParameter parameter) {
this.headerParameters.add(parameter);
return this;
}

public RequestBuilder content(final byte[] content) {
this.contentLenght = content.length;
this.inputStreamClosure = () -> new ByteArrayInputStream(content);
Expand Down
2 changes: 1 addition & 1 deletion commons/advanced/Commons_Image/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>net.anwiba.commons</groupId>
<artifactId>anwiba-commons-maven-advanced</artifactId>
<version>1.0.58</version>
<version>1.0.64</version>
</parent>

<scm>
Expand Down
8 changes: 7 additions & 1 deletion commons/advanced/Commons_Json/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>net.anwiba.commons</groupId>
<artifactId>anwiba-commons-maven-advanced</artifactId>
<version>1.0.58</version>
<version>1.0.64</version>
</parent>

<scm>
Expand All @@ -21,6 +21,12 @@

<dependencies>

<dependency>
<groupId>net.anwiba.commons</groupId>
<artifactId>anwiba-commons-lang</artifactId>
<version>${net.anwiba.commons.version}</version>
</dependency>

<dependency>
<groupId>net.anwiba.commons</groupId>
<artifactId>anwiba-commons-reflaction</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package net.anwiba.commons.json;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

Expand All @@ -28,14 +29,12 @@ public abstract class AbstractJsonObjectUnmarshaller<T, R, E extends IOException
private final ObjectMapper mapper = new ObjectMapper();
private final IJsonObjectMarshallingExceptionFactory<R, E> exceptionFactory;
private final Class<T> clazz;
@SuppressWarnings("rawtypes")
private final Map<Class, Object> injectionValues = new HashMap<>();
private final Map<String, Object> injectionValues = new HashMap<>();

@SuppressWarnings("rawtypes")
public AbstractJsonObjectUnmarshaller(
final Class<T> clazz,
final Class<R> errorResponseClass,
final Map<Class, Object> injectionValues,
final Map<String, Object> injectionValues,
final IJsonObjectMarshallingExceptionFactory<R, E> exceptionFactory) {
super(clazz, errorResponseClass, injectionValues);
this.clazz = clazz;
Expand All @@ -45,31 +44,32 @@ public AbstractJsonObjectUnmarshaller(
}

@Override
public T unmarshal(final String body) throws IOException, E {
final T result = validate(body);
protected T _unmarshal(final InputStream stream) throws IOException, E {
stream.mark(Integer.MAX_VALUE);
final T result = validate(stream);
if (result != null) {
return result;
}
stream.reset();
stream.mark(Integer.MAX_VALUE);
try {
return read(body, this.clazz);
} catch (final JsonParseException exception) {
throw createIOException(body, exception);
} catch (final JsonMappingException exception) {
throw createIOException(body, exception);
return read(stream, this.clazz);
} catch (final JsonParseException | JsonMappingException exception) {
stream.reset();
throw createIOException(stream, exception);
}
}

private <X> X read(final String body, final Class<X> type)
private <X> X read(final InputStream stream, final Class<X> type)
throws IOException,
JsonParseException,
JsonMappingException,
JsonProcessingException {
final InjectableValues.Std injectableValues = new InjectableValues.Std();
for (@SuppressWarnings("rawtypes")
final Class key : this.injectionValues.keySet()) {
for (final String key : this.injectionValues.keySet()) {
injectableValues.addValue(key, this.injectionValues.get(key));
}
return this.mapper.readerFor(type).with(injectableValues).readValue(body);
return this.mapper.readerFor(type).with(injectableValues).readValue(stream);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package net.anwiba.commons.json;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -32,13 +33,12 @@ public abstract class AbstractJsonObjectsUnmarshaller<T, R, E extends IOExceptio
private final ObjectMapper mapper = new ObjectMapper();
private final IJsonObjectMarshallingExceptionFactory<R, E> exceptionFactory;
private final Class<T> clazz;
@SuppressWarnings("rawtypes")
private final Map<Class, Object> injectionValues = new HashMap<>();
private final Map<String, Object> injectionValues = new HashMap<>();

public AbstractJsonObjectsUnmarshaller(
final Class<T> clazz,
final Class<R> errorResponseClass,
@SuppressWarnings("rawtypes") final Map<Class, Object> injectionValues,
final Map<String, Object> injectionValues,
final IJsonObjectMarshallingExceptionFactory<R, E> exceptionFactory) {
super(clazz, errorResponseClass, injectionValues);
this.clazz = clazz;
Expand All @@ -48,21 +48,23 @@ public AbstractJsonObjectsUnmarshaller(
}

@Override
public List<T> unmarshal(final String body) throws IOException, E {
protected List<T> _unmarshal(final InputStream stream) throws IOException, E {
stream.mark(Integer.MAX_VALUE);
@SuppressWarnings("unchecked")
final List<T> result = (List<T>) validate(body);
final List<T> result = (List<T>) validate(stream);
if (result != null) {
return result;
}
stream.reset();
stream.mark(Integer.MAX_VALUE);
try {
final InjectableValues.Std injectableValues = new InjectableValues.Std();
for (@SuppressWarnings("rawtypes")
final Class key : this.injectionValues.keySet()) {
for (final String key : this.injectionValues.keySet()) {
injectableValues.addValue(key, this.injectionValues.get(key));
}

final JsonFactory f = new JsonFactory();
try (final JsonParser parser = f.createParser(body)) {
try (final JsonParser parser = f.createParser(stream)) {
final ObjectReader reader = this.mapper.readerFor(this.clazz).with(injectableValues);
final JsonToken token = parser.nextToken();
if (token != JsonToken.START_ARRAY) {
Expand All @@ -76,10 +78,9 @@ public List<T> unmarshal(final String body) throws IOException, E {
}
return results;
}
} catch (final JsonParseException exception) {
throw createIOException(body, exception);
} catch (final JsonMappingException exception) {
throw createIOException(body, exception);
} catch (final JsonParseException | JsonMappingException exception) {
stream.reset();
throw createIOException(stream, exception);
}
}

Expand Down
Loading

0 comments on commit 63e7670

Please sign in to comment.