Skip to content

Commit

Permalink
Merge branch 'master' into large_payload
Browse files Browse the repository at this point in the history
  • Loading branch information
brianquinlan committed Jul 10, 2023
2 parents f040a30 + c148a3a commit 1b9db2b
Show file tree
Hide file tree
Showing 10 changed files with 552 additions and 2 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/java.yml
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
1 change: 1 addition & 0 deletions pkgs/java_http/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
5 changes: 5 additions & 0 deletions pkgs/java_http/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
include: ../../analysis_options.yaml

analyzer:
exclude:
- lib/src/third_party/**
15 changes: 15 additions & 0 deletions pkgs/java_http/jnigen.yaml
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'
3 changes: 1 addition & 2 deletions pkgs/java_http/lib/java_http.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
// 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.

library;

export 'src/java_client.dart';
export 'src/java_http_base.dart';
43 changes: 43 additions & 0 deletions pkgs/java_http/lib/src/java_client.dart
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://github.com/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://github.com/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');
}
}
Loading

0 comments on commit 1b9db2b

Please sign in to comment.