Skip to content

Commit

Permalink
'Split header parsers and entities with no dependencies on Netty out …
Browse files Browse the repository at this point in the history
…of acteur-headers and acteur-util'

Affected Checkouts
------------------

  * acteur-modules/acteur-parent
  * giulius-modules/giulius-parent
  * giulius-selenium-tests-modules/giulius-selenium-tests-parent
  * giulius-web-modules/giulius-web-parent
  * acteur-auth
  * acteur-timetracker
  * acteur-tutorial
  * blather
  * blurt
  * bunyan-java-v2
  * generic-web-api
  * giulius-settings-etcd
  * jetcd
  * netty-http-client
  * numble
  * (root)

##### Provenance

Generated by cactus: *cactus-git* version _1.5.31_.

  * Mojo:		CommitMojo
  * Generation-Time:	2022-10-19T03:41:38Z
  * Plugin-Build:	yellow rabbit
  * Plugin-Date:	2022.09.10
  * Plugin-Commit:	f32552996bf3511e8901928b6467df125bdebbd2
  * Plugin-Repo-Clean:	true
  • Loading branch information
timboudreau committed Oct 19, 2022
1 parent 80645c1 commit 54158f1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 43 deletions.
4 changes: 4 additions & 0 deletions netty-http-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jzlib</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package com.mastfrog.netty.http.client;

import com.google.common.net.MediaType;
import com.mastfrog.acteur.headers.HeaderValueType;
import com.mastfrog.mime.MimeType;
import com.mastfrog.url.Protocol;
import com.mastfrog.url.URL;
import com.mastfrog.util.thread.Receiver;
Expand Down Expand Up @@ -198,7 +198,7 @@ default HttpRequestBuilder addQueryPairs(Map<String, String> pairs) {
* @param o The body
* @return
*/
HttpRequestBuilder setBody(Object o, MediaType contentType) throws IOException;
HttpRequestBuilder setBody(Object o, MimeType contentType) throws IOException;

/**
* Add an event handler for a particular event
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
*/
package com.mastfrog.netty.http.client;

import com.google.common.net.MediaType;
import com.mastfrog.acteur.util.BasicCredentials;
import com.mastfrog.mime.MimeType;
import com.mastfrog.acteur.header.entities.BasicCredentials;
import com.mastfrog.acteur.headers.HeaderValueType;
import com.mastfrog.acteur.headers.Headers;
import com.mastfrog.acteur.headers.Method;
Expand Down Expand Up @@ -245,7 +245,7 @@ public URL toURL() {
boolean send100Continue = true;

@Override
public HttpRequestBuilder setBody(Object bodyObject, MediaType contentType) throws IOException {
public HttpRequestBuilder setBody(Object bodyObject, MimeType contentType) throws IOException {
Checks.notNull("body", bodyObject);
ByteBuf buf;
if (bodyObject instanceof ChunkedContent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
package com.mastfrog.netty.http.client;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.net.MediaType;
import com.mastfrog.marshallers.netty.NettyContentMarshallers;
import com.mastfrog.mime.MimeType;
import io.netty.buffer.ByteBuf;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.util.CharsetUtil;
Expand Down Expand Up @@ -86,10 +86,10 @@ protected void internalReceive(HttpResponseStatus status, HttpHeaders headers, B
content.release();
return;
}
MediaType mediaType = null;
MimeType mediaType = null;
if (headers.contains(HttpHeaderNames.CONTENT_TYPE)) {
try {
mediaType = MediaType.parse(headers.get(HttpHeaderNames.CONTENT_TYPE));
mediaType = MimeType.parse(headers.get(HttpHeaderNames.CONTENT_TYPE));
} catch (Exception ex) {
//do nothing
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@
*/
package com.mastfrog.netty.http.client;

import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.net.MediaType;
import com.mastfrog.acteur.headers.Headers;
import com.mastfrog.acteur.util.Connection;
import com.mastfrog.acteur.header.entities.Connection;
import com.mastfrog.mime.MimeType;
import com.mastfrog.netty.http.client.DeferredAssertions.Assertion;
import com.mastfrog.tiny.http.server.ChunkedResponse;
import com.mastfrog.tiny.http.server.Responder;
Expand Down Expand Up @@ -56,6 +54,7 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -110,7 +109,7 @@ public void testChunkedPut() throws Throwable {
final AtomicReference<String> content = new AtomicReference<>();
final AtomicReference<HttpResponseStatus> theStatus = new AtomicReference<>();
final AtomicReference<Throwable> thrown = new AtomicReference<>();
client.put().setURL("http:https://chunky.thing:" + server.httpPort() + "/").setBody(body, MediaType.PLAIN_TEXT_UTF_8)
client.put().setURL("http:https://chunky.thing:" + server.httpPort() + "/").setBody(body, MimeType.PLAIN_TEXT_UTF_8)
.onEvent(new Receiver<State<?>>() {
@Override
public void receive(State<?> state) {
Expand Down Expand Up @@ -186,7 +185,7 @@ public void exec() throws Throwable {
@Test
public void testRedirectLimit() throws Throwable {
final List<URL> redirects = new CopyOnWriteArrayList<>();
final Set<StateType> states = Sets.newConcurrentHashSet();
final Set<StateType> states = ConcurrentHashMap.newKeySet();
final AtomicBoolean errorResponse = new AtomicBoolean();
final AtomicReference<Throwable> error = new AtomicReference<>();
final AtomicBoolean received = new AtomicBoolean();
Expand Down Expand Up @@ -296,7 +295,7 @@ public void testPost() throws Throwable {
ResponseFuture f = client.post()
.setURL(ur)
.addHeader(Headers.CONNECTION, Connection.close)
.setBody("This is a test", MediaType.PLAIN_TEXT_UTF_8)
.setBody("This is a test", MimeType.PLAIN_TEXT_UTF_8)
.onEvent(new Receiver<State<?>>() {
public void receive(State<?> state) {
stateTypes.add(state.stateType());
Expand Down Expand Up @@ -342,8 +341,8 @@ public void receive(State<?> state) {

private static class AM implements ActivityMonitor {

final List<String> started = Lists.newCopyOnWriteArrayList();
final List<String> ended = Lists.newCopyOnWriteArrayList();
final List<String> started = new CopyOnWriteArrayList<>();
final List<String> ended = new CopyOnWriteArrayList<>();

@Override
public void onStartRequest(URL url) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,17 @@
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Sets;
import com.google.common.net.MediaType;
import com.google.inject.Inject;
import com.google.inject.Singleton;
import com.mastfrog.acteur.util.ErrorInterceptor;
import com.mastfrog.acteur.headers.HeaderValueType;
import com.mastfrog.acteur.headers.Headers;
import static com.mastfrog.acteur.headers.Headers.COOKIE_B;
import static com.mastfrog.acteur.headers.Headers.SET_COOKIE_B;
import com.mastfrog.acteur.headers.Method;
import com.mastfrog.acteur.util.ErrorInterceptor;
import com.mastfrog.acteur.util.Server;
import com.mastfrog.acteur.util.ServerControl;
import com.mastfrog.giulius.ShutdownHookRegistry;
import com.mastfrog.mime.MimeType;
import com.mastfrog.netty.http.client.ChunkedContent;
import com.mastfrog.netty.http.client.CookieStore;
import com.mastfrog.netty.http.client.HttpClient;
Expand All @@ -32,48 +30,50 @@
import static com.mastfrog.netty.http.client.StateType.FullContentReceived;
import static com.mastfrog.netty.http.client.StateType.HeadersReceived;
import com.mastfrog.settings.Settings;
import com.mastfrog.shutdown.hooks.ShutdownHookRegistry;
import com.mastfrog.url.Protocol;
import com.mastfrog.url.URL;
import com.mastfrog.util.net.PortFinder;
import static com.mastfrog.util.preconditions.Checks.notNull;
import com.mastfrog.util.preconditions.Exceptions;
import com.mastfrog.util.strings.Strings;
import com.mastfrog.util.thread.Receiver;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import com.mastfrog.util.preconditions.Exceptions;
import com.mastfrog.util.strings.Strings;
import com.mastfrog.util.net.PortFinder;
import io.netty.handler.codec.http.Cookie;
import io.netty.handler.codec.http.DefaultHttpHeaders;
import io.netty.handler.codec.http.HttpHeaderNames;
import io.netty.handler.codec.http.HttpHeaders;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.HttpResponseStatus;
import io.netty.handler.codec.http.cookie.DefaultCookie;
import static io.netty.util.CharsetUtil.UTF_8;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.lang.reflect.Array;
import java.nio.charset.Charset;
import java.time.Duration;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.EnumMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Function;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

/**
Expand Down Expand Up @@ -397,7 +397,7 @@ public ResponseFuture execute() {
}

@Override
public TestRequestBuilder setBody(Object o, MediaType contentType) throws IOException {
public TestRequestBuilder setBody(Object o, MimeType contentType) throws IOException {
if (o != null && !(o instanceof CharSequence) && !(o instanceof ChunkedContent)) {
// The HttpClient does not have our object mapper
o = mapper.writeValueAsString(o);
Expand Down Expand Up @@ -465,7 +465,7 @@ public HttpRequestBuilder noDateHeader() {
private static final class CallResultImpl extends Receiver<State<?>> implements CallResult, Runnable {

private final URL url;
private final Set<StateType> states = Sets.newCopyOnWriteArraySet();
private final Set<StateType> states = ConcurrentHashMap.newKeySet();
private final AtomicReference<HttpResponseStatus> status = new AtomicReference<>();
private final AtomicReference<HttpHeaders> headers = new AtomicReference<>();
private final AtomicReference<ByteBuf> content = new AtomicReference<>();
Expand Down Expand Up @@ -662,7 +662,7 @@ private String contentAsString() throws UnsupportedEncodingException {
buf.resetReaderIndex();
Charset charset = UTF_8;
if (headers.get() != null && headers.get().contains(HttpHeaderNames.CONTENT_TYPE)) {
MediaType mt = Headers.CONTENT_TYPE.toValue(headers.get().get(HttpHeaderNames.CONTENT_TYPE));
MimeType mt = Headers.CONTENT_TYPE.toValue(headers.get().get(HttpHeaderNames.CONTENT_TYPE));
if (mt != null && mt.charset().isPresent()) {
charset = mt.charset().get();
}
Expand Down

0 comments on commit 54158f1

Please sign in to comment.