Skip to content

Commit

Permalink
Update README.md.
Browse files Browse the repository at this point in the history
  • Loading branch information
gk-brown committed Oct 15, 2024
1 parent 635eb76 commit 2160829
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 25 deletions.
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ The following multi-value types are also supported:
* `java.util.Set`
* array/varargs

Additionally, `java.util.Map`, bean, and record types are supported for [body content](#body-content). Arguments of type `jakarta.servlet.http.Part` may be used with `POST` requests submitted using the multi-part form data encoding.
Additionally, `java.util.Map`, bean, and record types are supported for [body content](#body-content). Arguments of type `jakarta.servlet.http.Part` may be used with `POST` requests submitted as [multi-part form data](https://jakarta.ee/specifications/servlet/5.0/jakarta-servlet-spec-5.0#_MultipartConfig).

Unspecified values are automatically converted to `0`, `false`, or the null character for primitive types. `Date` values are decoded from a long value representing epoch time in milliseconds. Other values are parsed from their string representations.

Expand Down Expand Up @@ -360,7 +360,7 @@ public interface RequestHandler {
}
```

For example, the `WebServiceProxy.FormDataRequestHandler` class submits requests as form data. When using the multi-part encoding (the default), instances of `java.nio.file.Path` represent file uploads and behave similarly to `<input type="file">` tags in HTML.
For example, the `WebServiceProxy.FormDataRequestHandler` class submits requests as [form data](https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4). When using the multi-part encoding (the default), instances of `java.nio.file.Path` represent file uploads and behave similarly to `<input type="file">` tags in HTML.

Service operations are invoked via the following method:

Expand Down Expand Up @@ -423,7 +423,7 @@ public static <T> T of(Class<T> type, URI baseURI, Map<String, Object> headers)

Both versions return an implementation of a given interface that submits requests to the provided URI. An optional map accepted by the second version can be used to provide common request headers.

The `RequestMethod` and `ResourcePath` annotations are used as described [earlier](#webservice) for `WebService`. The optional `ServicePath` annotation can be used to associate a base path with a proxy type. Proxy methods must include a throws clause that declares `IOException`, so that callers can handle unexpected failures. For example:
The optional `ServicePath` annotation can be used to associate a base path with a proxy type. The `RequestMethod` and `ResourcePath` annotations are used as described [earlier](#webservice) for `WebService`. Proxy methods must include a throws clause that declares `IOException`, so that callers can handle unexpected failures. For example:

```java
@ServicePath("math")
Expand Down Expand Up @@ -605,6 +605,8 @@ course.setRoomNumber(210);
var courseAdapter = new BeanAdapter(course);

System.out.println(courseAdapter.get("name")); // CS 101
System.out.println(courseAdapter.get("building")); // Technology Lab
System.out.println(courseAdapter.get("roomNumber")); // 210
```

`BeanAdapter` can also be used to facilitate type-safe access to loosely typed data structures:
Expand All @@ -619,6 +621,8 @@ var map = mapOf(
var course = BeanAdapter.coerce(map, Course.class);

System.out.println(course.getName()); // CS 101
System.out.println(course.getBuilding()); // Technology Lab
System.out.println(course.getRoomNumber()); // 210
```

An interface can be used instead of a class to provide a strongly typed "view" of the underlying data. For example:
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

subprojects {
group = 'org.httprpc'
version = '4.6'
version = '4.6.1'

apply plugin: 'java-library'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@

@WebServlet(urlPatterns = {"/bulk-upload/*"}, loadOnStartup = 1)
public class BulkUploadService extends AbstractDatabaseService {
public interface Row {
String getText1();
String getText2();
Double getNumber1();
Double getNumber2();
Double getNumber3();
}

private static final int BATCH_SIZE = 25000;

@RequestMethod("POST")
Expand Down
18 changes: 18 additions & 0 deletions kilo-test/src/main/java/org/httprpc/kilo/test/Row.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Licensed 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.httprpc.kilo.test;

public record Row(String text1, String text2, Integer number1, Double number2, Double number3) {
}
17 changes: 4 additions & 13 deletions kilo-test/src/test/java/org/httprpc/kilo/test/BulkUploadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
import java.io.IOException;
import java.net.URI;
import java.util.Iterator;
import java.util.Map;

import static org.httprpc.kilo.util.Collections.*;

public class BulkUploadTest {
public static class Rows implements Iterable<Map<String, Object>> {
public static class Rows implements Iterable<Row> {
private int count;

private int i = 0;
Expand All @@ -33,24 +30,18 @@ public Rows(int count) {
this.count = count;
}

private Map<String, Object> row = mapOf(
entry("text1", "abcdefghijklmnopqrstuvwxyz"),
entry("text2", "ABCDEFG"),
entry("number1", 123456),
entry("number2", 101.05),
entry("number3", 2002.0125)
);
private Row row = new Row("abcdefghijklmnopqrstuvwxyz", "ABCDEFG", 123456, 101.05, 2002.0125);

@Override
public Iterator<Map<String, Object>> iterator() {
public Iterator<Row> iterator() {
return new Iterator<>() {
@Override
public boolean hasNext() {
return i < count;
}

@Override
public Map<String, Object> next() {
public Row next() {
i++;

return row;
Expand Down
4 changes: 4 additions & 0 deletions kilo-test/src/test/java/org/httprpc/kilo/test/Examples.java
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ public static void adaptBean() {
var courseAdapter = new BeanAdapter(course);

System.out.println(courseAdapter.get("name")); // CS 101
System.out.println(courseAdapter.get("building")); // Technology Lab
System.out.println(courseAdapter.get("roomNumber")); // 210
}

public static void coerceBean() {
Expand All @@ -217,6 +219,8 @@ public static void coerceBean() {
var course = BeanAdapter.coerce(map, Course.class);

System.out.println(course.getName()); // CS 101
System.out.println(course.getBuilding()); // Technology Lab
System.out.println(course.getRoomNumber()); // 210
}

public static void interfaceProxy() {
Expand Down

0 comments on commit 2160829

Please sign in to comment.