Skip to content

Commit

Permalink
v3.1.4 (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
scx567888 authored Oct 3, 2024
1 parent 153416b commit 7fbad36
Show file tree
Hide file tree
Showing 39 changed files with 447 additions and 186 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<artifactId>scx</artifactId>
<packaging>pom</packaging>
<version>3.1.3</version>
<version>3.1.4</version>

<name>SCX</name>
<url>https://github.com/scx567888/scx</url>
Expand Down
2 changes: 1 addition & 1 deletion scx-ansi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-ansi</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-common</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-config/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-config</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-core/src/main/java/cool/scx/core/ScxVersion.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ScxVersion {
/**
* SCX 版本号
*/
public static final String SCX_VERSION = "3.1.3";
public static final String SCX_VERSION = "3.1.4";

/**
* 在控制台上打印 banner
Expand Down
2 changes: 1 addition & 1 deletion scx-data-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-data-jdbc</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-data-mysql-x/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-data-mysql-x</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-data/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-data</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-ext/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-ext</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-ffm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-ffm</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion scx-http-helidon/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-http-helidon</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import cool.scx.http.ScxHttpHeaders;
import cool.scx.http.ScxHttpHeadersWritable;
import cool.scx.reflect.ReflectFactory;
import io.helidon.http.*;
import io.helidon.http.Header;
import io.helidon.http.Headers;
import io.helidon.http.PathMatchers;
import io.helidon.webserver.websocket.WsRoute;
import io.helidon.webserver.websocket.WsRouting;
import io.helidon.websocket.WsListener;
Expand Down Expand Up @@ -41,11 +43,4 @@ public static ScxHttpHeadersWritable convertHeaders(Headers o) {
return h;
}

public static void updateHeaders(ScxHttpHeaders o, ServerResponseHeaders u) {
u.clear();
for (var header : o) {
u.add(HeaderNames.create(header.getKey().value()), header.getValue().toArray(String[]::new));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package cool.scx.http.helidon.test;

public record Apple(String color, String name, int weight) {

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package cool.scx.http.helidon.test;

import cool.scx.http.MediaType;
import cool.scx.http.ScxHttpServerOptions;
import cool.scx.http.helidon.HelidonHttpClient;
import cool.scx.http.helidon.HelidonHttpServer;
import cool.scx.http.media.form_params.FormParams;

import java.io.IOException;

import static cool.scx.http.HttpFieldName.ACCEPT;

public class ClientTest {

public static void main(String[] args) throws IOException, InterruptedException {
Expand All @@ -18,7 +22,8 @@ public static void test1() throws IOException, InterruptedException {
var httpServer = new HelidonHttpServer(new ScxHttpServerOptions().setPort(8990));
httpServer.requestHandler(c -> {
System.out.println(c.uri());
c.response().send("Hi Client !!!");
System.out.println(c.body().asFormParams());
c.response().send(new Apple("red", "red apple", 99));
});
httpServer.webSocketHandler(c -> {
System.out.println(c.uri());
Expand All @@ -32,7 +37,7 @@ public static void test1() throws IOException, InterruptedException {

public static void test2() {
var httpClient = new HelidonHttpClient();
var webSocketBuilder = httpClient.webSocket().uri("http://localhost:8990/中:文|路径/ddd?查询=🎈🎈|🎈");
var webSocketBuilder = httpClient.webSocket().uri("http://localhost:8990/中:文|路@径/ddd?查询=🎈🎈|🎈#🎃🎃");
webSocketBuilder.onConnect(webSocket -> {
webSocket.onTextMessage(t -> {
System.out.println(t);
Expand All @@ -45,9 +50,17 @@ public static void test2() {
public static void test3() {
var httpClient = new HelidonHttpClient();
var response = httpClient.request()
.uri("http://localhost:8990/中:文|路径/ddd?查询=🎈🎈|🎈")
.send();
//支持 ACCEPT
.addHeader(ACCEPT, MediaType.APPLICATION_XML.value())
.uri("http://localhost:8990/中:文|路@径/ddd?查询=🎈🎈|🎈#🎃🎃")
.send(new FormParams()
.add("中文|||/ |||===", "嘎 嘎 嘎🧶🧶🛒")
.add("🏓🏓🏓", "!@#%^%&*%%")
);
//可以用不同的方式重复读取
var apple = response.body().asObject(Apple.class);
var string = response.body().asString();
var jsonNode = response.body().asJsonNode();
System.out.println(string);
}

Expand Down
2 changes: 1 addition & 1 deletion scx-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>cool.scx</groupId>
<artifactId>scx</artifactId>
<version>3.1.3</version>
<version>3.1.4</version>
</parent>

<artifactId>scx-http</artifactId>
Expand Down
12 changes: 11 additions & 1 deletion scx-http/src/main/java/cool/scx/http/ScxHttpBody.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cool.scx.http;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.JsonNode;
import cool.scx.http.media.MediaReader;
import cool.scx.http.media.form_params.FormParams;
import cool.scx.http.media.multi_part.MultiPart;
Expand All @@ -16,6 +17,7 @@

import static cool.scx.http.media.byte_array.ByteArrayReader.BYTE_ARRAY_READER;
import static cool.scx.http.media.form_params.FormParamsReader.FORM_PARAMS_READER;
import static cool.scx.http.media.json_node.JsonNodeReader.JSON_NODE_READER;
import static cool.scx.http.media.multi_part.MultiPartStreamCachedReader.MULTI_PART_READER_CACHED;
import static cool.scx.http.media.multi_part.MultiPartStreamReader.MULTI_PART_READER;
import static cool.scx.http.media.string.StringReader.STRING_READER;
Expand All @@ -27,7 +29,11 @@ public interface ScxHttpBody {

InputStream inputStream();

<T> T as(MediaReader<T> t);
ScxHttpHeaders headers();

default <T> T as(MediaReader<T> t) {
return t.read(inputStream(), headers());
}

default byte[] asBytes() {
return as(BYTE_ARRAY_READER);
Expand Down Expand Up @@ -61,6 +67,10 @@ default Path asPath(Path path, OpenOption... options) {
return as(new PathReader(path, options));
}

default JsonNode asJsonNode() {
return as(JSON_NODE_READER);
}

default <T> T asObject(Class<T> c) {
return as(new ObjectReader<>(c));
}
Expand Down
30 changes: 17 additions & 13 deletions scx-http/src/main/java/cool/scx/http/ScxHttpBodyImpl.java
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
package cool.scx.http;

import cool.scx.http.media.MediaReader;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

public class ScxHttpBodyImpl implements ScxHttpBody {

private final InputStream inputStream;
private final ScxHttpHeaders headers;

// 简单做一个缓存
private String cacheString;
// InputStream 的缓存
private final BufferedInputStream bufferedInputStream;

public ScxHttpBodyImpl(InputStream inputStream, ScxHttpHeaders headers) {
this.inputStream = inputStream;
this.bufferedInputStream = new BufferedInputStream(inputStream);
this.headers = headers;
this.bufferedInputStream.mark(0);
}

@Override
public InputStream inputStream() {
return inputStream;
public ScxHttpHeaders headers() {
return headers;
}

@Override
public <T> T as(MediaReader<T> t) {
return t.read(inputStream, headers);
public InputStream inputStream() {
try {
bufferedInputStream.reset();
} catch (IOException e) {
throw new RuntimeException(e);
}
return bufferedInputStream;
}

@Override
public String asString() {
if (cacheString == null) {
cacheString = ScxHttpBody.super.asString();
}
return cacheString;
public String toString() {
return asString();
}

}
12 changes: 12 additions & 0 deletions scx-http/src/main/java/cool/scx/http/ScxHttpClientRequest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package cool.scx.http;

import com.fasterxml.jackson.databind.JsonNode;
import cool.scx.http.content_type.ContentType;
import cool.scx.http.cookie.Cookie;
import cool.scx.http.media.MediaWriter;
import cool.scx.http.media.byte_array.ByteArrayWriter;
import cool.scx.http.media.empty.EmptyWriter;
import cool.scx.http.media.form_params.FormParams;
import cool.scx.http.media.form_params.FormParamsWriter;
import cool.scx.http.media.input_stream.InputStreamWriter;
import cool.scx.http.media.json_node.JsonNodeWriter;
import cool.scx.http.media.multi_part.MultiPart;
import cool.scx.http.media.multi_part.MultiPartWriter;
import cool.scx.http.media.object.ObjectWriter;
Expand Down Expand Up @@ -72,10 +76,18 @@ default ScxHttpClientResponse send(InputStream inputStream) {
return send(new InputStreamWriter(inputStream));
}

default ScxHttpClientResponse send(FormParams formParams) {
return send(new FormParamsWriter(formParams));
}

default ScxHttpClientResponse send(MultiPart multiPart) {
return send(new MultiPartWriter(multiPart));
}

default ScxHttpClientResponse send(JsonNode jsonNode) {
return send(new JsonNodeWriter(jsonNode));
}

default ScxHttpClientResponse send(Object object) {
return send(new ObjectWriter(object));
}
Expand Down
12 changes: 12 additions & 0 deletions scx-http/src/main/java/cool/scx/http/ScxHttpServerResponse.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package cool.scx.http;

import com.fasterxml.jackson.databind.JsonNode;
import cool.scx.http.content_type.ContentType;
import cool.scx.http.cookie.Cookie;
import cool.scx.http.media.MediaWriter;
import cool.scx.http.media.byte_array.ByteArrayWriter;
import cool.scx.http.media.empty.EmptyWriter;
import cool.scx.http.media.form_params.FormParams;
import cool.scx.http.media.form_params.FormParamsWriter;
import cool.scx.http.media.input_stream.InputStreamWriter;
import cool.scx.http.media.json_node.JsonNodeWriter;
import cool.scx.http.media.multi_part.MultiPart;
import cool.scx.http.media.multi_part.MultiPartWriter;
import cool.scx.http.media.object.ObjectWriter;
Expand Down Expand Up @@ -77,10 +81,18 @@ default void send(InputStream inputStream) {
send(new InputStreamWriter(inputStream));
}

default void send(FormParams formParams) {
send(new FormParamsWriter(formParams));
}

default void send(MultiPart multiPart) {
send(new MultiPartWriter(multiPart));
}

default void send(JsonNode jsonNode) {
send(new JsonNodeWriter(jsonNode));
}

default void send(Object object) {
send(new ObjectWriter(object));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,24 @@

public class FormParams extends ParametersImpl<String, String> {

@Override
public FormParams set(String name, String... value) {
return (FormParams) super.set(name, value);
}

@Override
public FormParams add(String name, String... value) {
return (FormParams) super.add(name, value);
}

@Override
public FormParams remove(String name) {
return (FormParams) super.remove(name);
}

@Override
public FormParams clear() {
return (FormParams) super.clear();
}

}
Loading

0 comments on commit 7fbad36

Please sign in to comment.