-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Java http BaseClient implementation (#980)
- Loading branch information
1 parent
474999f
commit c148a3a
Showing
10 changed files
with
552 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
name: package:java_http CI | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- master | ||
paths: | ||
- 'pkgs/java_http/**' | ||
- 'pkgs/http_client_conformance_tests/**' | ||
- '.github/workflows/java.yml' | ||
pull_request: | ||
paths: | ||
- 'pkgs/java_http/**' | ||
- 'pkgs/http_client_conformance_tests/**' | ||
- '.github/workflows/java.yml' | ||
schedule: | ||
# Runs every Sunday at midnight (00:00 UTC). | ||
- cron: "0 0 * * 0" | ||
|
||
env: | ||
PUB_ENVIRONMENT: bot.github | ||
|
||
jobs: | ||
analyze: | ||
name: Lint and static analysis | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: pkgs/java_http | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: subosito/flutter-action@v2 | ||
with: | ||
channel: 'stable' | ||
|
||
- id: install | ||
name: Install dependencies | ||
run: dart pub get | ||
|
||
- name: Check formatting | ||
run: dart format --output=none --set-exit-if-changed . | ||
if: always() && steps.install.outcome == 'success' | ||
|
||
- name: Analyze code | ||
run: dart analyze --fatal-infos | ||
if: always() && steps.install.outcome == 'success' | ||
|
||
test: | ||
needs: analyze | ||
name: Build and test | ||
runs-on: ubuntu-latest | ||
defaults: | ||
run: | ||
working-directory: pkgs/java_http | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: subosito/flutter-action@v2 | ||
with: | ||
channel: 'stable' | ||
|
||
- name: Build jni dynamic libraries | ||
run: dart run jni:setup | ||
|
||
- name: Run tests | ||
run: dart test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
include: ../../analysis_options.yaml | ||
|
||
analyzer: | ||
exclude: | ||
- lib/src/third_party/** |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Regenerate bindings with `dart run jnigen --config jnigen.yaml`. | ||
|
||
summarizer: | ||
backend: asm | ||
|
||
output: | ||
bindings_type: dart_only | ||
dart: | ||
path: 'lib/src/third_party/' | ||
|
||
class_path: | ||
- 'classes.jar' | ||
|
||
classes: | ||
- 'java.net.URL' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:convert'; | ||
import 'dart:io'; | ||
|
||
import 'package:http/http.dart'; | ||
import 'package:jni/jni.dart'; | ||
import 'package:path/path.dart'; | ||
|
||
import 'third_party/java/net/URL.dart'; | ||
|
||
// TODO: Add a description of the implementation. | ||
// Look at the description of cronet_client.dart and cupertino_client.dart for | ||
// examples. | ||
// See https:/dart-lang/http/pull/980#discussion_r1253697461. | ||
class JavaClient extends BaseClient { | ||
void _initJVM() { | ||
if (!Platform.isAndroid) { | ||
Jni.spawnIfNotExists(dylibDir: join('build', 'jni_libs')); | ||
} | ||
} | ||
|
||
@override | ||
Future<StreamedResponse> send(BaseRequest request) async { | ||
// TODO: Move the call to _initJVM() to the JavaClient constructor. | ||
// See https:/dart-lang/http/pull/980#discussion_r1253700470. | ||
_initJVM(); | ||
|
||
final javaUrl = URL.ctor3(request.url.toString().toJString()); | ||
final dartUrl = Uri.parse(javaUrl.toString1().toDartString()); | ||
|
||
const result = 'Hello World!'; | ||
final stream = Stream.value(latin1.encode(result)); | ||
|
||
return StreamedResponse(stream, 200, | ||
contentLength: 12, | ||
request: Request(request.method, dartUrl), | ||
headers: {'content-type': 'text/plain'}, | ||
reasonPhrase: 'OK'); | ||
} | ||
} |
Oops, something went wrong.