--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/.name Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,1 @@
+http-client-tutorial
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/compiler.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="CompilerConfiguration">
+ <wildcardResourcePatterns>
+ <entry name="!?*.java" />
+ <entry name="!?*.form" />
+ <entry name="!?*.class" />
+ <entry name="!?*.groovy" />
+ <entry name="!?*.scala" />
+ <entry name="!?*.flex" />
+ <entry name="!?*.kt" />
+ <entry name="!?*.clj" />
+ </wildcardResourcePatterns>
+ <annotationProcessing>
+ <profile name="Maven default annotation processors profile" enabled="true">
+ <sourceOutputDir name="target/generated-sources/annotations" />
+ <sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
+ <outputRelativeToContentRoot value="true" />
+ <module name="http-tutorial" />
+ </profile>
+ </annotationProcessing>
+ <bytecodeTargetLevel>
+ <module name="http-tutorial" target="9" />
+ </bytecodeTargetLevel>
+ </component>
+ <component name="JavacSettings">
+ <option name="ADDITIONAL_OPTIONS_STRING" value="--add-modules=jdk.incubator.httpclient" />
+ </component>
+</project>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-annotations/2.8.0/jackson-annotations-2.8.0-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_9.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.9">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.8.9/jackson-core-2.8.9.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.8.9/jackson-core-2.8.9-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-core/2.8.9/jackson-core-2.8.9-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_9.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.9">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.8.9/jackson-databind-2.8.9.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.8.9/jackson-databind-2.8.9-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/com/fasterxml/jackson/core/jackson-databind/2.8.9/jackson-databind-2.8.9-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/libraries/Maven__junit_junit_4_11.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: junit:junit:4.11">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.11/junit-4.11-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,13 @@
+<component name="libraryTable">
+ <library name="Maven: org.hamcrest:hamcrest-core:1.3">
+ <CLASSES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar!/" />
+ </CLASSES>
+ <JAVADOC>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-javadoc.jar!/" />
+ </JAVADOC>
+ <SOURCES>
+ <root url="jar://$MAVEN_REPOSITORY$/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3-sources.jar!/" />
+ </SOURCES>
+ </library>
+</component>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/misc.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="MavenProjectsManager">
+ <option name="originalFiles">
+ <list>
+ <option value="$PROJECT_DIR$/pom.xml" />
+ </list>
+ </option>
+ </component>
+ <component name="ProjectRootManager" version="2" languageLevel="JDK_1_9" default="false" project-jdk-name="9" project-jdk-type="JavaSDK">
+ <output url="file://$PROJECT_DIR$/out" />
+ </component>
+</project>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/modules.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ProjectModuleManager">
+ <modules>
+ <module fileurl="file://$PROJECT_DIR$/http-tutorial.iml" filepath="$PROJECT_DIR$/http-tutorial.iml" />
+ <module fileurl="file://$PROJECT_DIR$/src/main/main.iml" filepath="$PROJECT_DIR$/src/main/main.iml" />
+ <module fileurl="file://$PROJECT_DIR$/src/test/test.iml" filepath="$PROJECT_DIR$/src/test/test.iml" />
+ </modules>
+ </component>
+</project>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/vcs.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="VcsDirectoryMappings">
+ <mapping directory="$PROJECT_DIR$" vcs="hg4idea" />
+ </component>
+</project>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.idea/workspace.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,664 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project version="4">
+ <component name="ChangeListManager">
+ <list default="true" id="370c2318-db1e-4222-8c67-6545c7e7a90a" name="Default" comment="">
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/.name" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/compiler.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_annotations_2_8_0.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_core_2_8_9.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/libraries/Maven__com_fasterxml_jackson_core_jackson_databind_2_8_9.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/libraries/Maven__junit_junit_4_11.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/libraries/Maven__org_hamcrest_hamcrest_core_1_3.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/misc.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/modules.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/vcs.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/http-tutorial.iml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/pom.xml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/main/java/openjdk/http/tutorial/exercise1/Retrievals.java" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/main/main.iml" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/test/java/openjdk/http/tutorial/Exercise1Test.java" />
+ <change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/src/test/test.iml" />
+ </list>
+ <ignored path="$PROJECT_DIR$/out/" />
+ <ignored path="$PROJECT_DIR$/target/" />
+ <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
+ <option name="TRACKING_ENABLED" value="true" />
+ <option name="SHOW_DIALOG" value="false" />
+ <option name="HIGHLIGHT_CONFLICTS" value="true" />
+ <option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
+ <option name="LAST_RESOLUTION" value="IGNORE" />
+ </component>
+ <component name="FileEditorManager">
+ <leaf>
+ <file leaf-file-name="pom.xml" pinned="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/pom.xml">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="0">
+ <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ </file>
+ <file leaf-file-name="Exercise1Test.java" pinned="false" current-in-tab="false">
+ <entry file="file://$PROJECT_DIR$/src/test/java/openjdk/http/tutorial/Exercise1Test.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="345">
+ <caret line="23" column="0" lean-forward="false" selection-start-line="23" selection-start-column="0" selection-end-line="23" selection-end-column="0" />
+ <folding>
+ <element signature="e#0#11067#0" expanded="true" />
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ </file>
+ <file leaf-file-name="Retrievals.java" pinned="false" current-in-tab="true">
+ <entry file="file://$PROJECT_DIR$/src/main/java/openjdk/http/tutorial/exercise1/Retrievals.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="441">
+ <caret line="40" column="38" lean-forward="false" selection-start-line="40" selection-start-column="38" selection-end-line="40" selection-end-column="38" />
+ <folding>
+ <element signature="e#0#8269#0" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ </file>
+ </leaf>
+ </component>
+ <component name="GradleLocalSettings">
+ <option name="externalProjectsViewState">
+ <projects_view />
+ </option>
+ </component>
+ <component name="IdeDocumentHistory">
+ <option name="CHANGED_PATHS">
+ <list>
+ <option value="$PROJECT_DIR$/src/test/java/openjdk/http/tutorial/Exercise1Test.java" />
+ <option value="$PROJECT_DIR$/src/main/java/openjdk/http/tutorial/exercise1/Retrievals.java" />
+ </list>
+ </option>
+ </component>
+ <component name="MavenProjectNavigator">
+ <treeState>
+ <expand>
+ <path>
+ <item name="" type="16c1761:MavenProjectsStructure$RootNode" />
+ <item name="http-tutorial" type="9519ce18:MavenProjectsStructure$ProjectNode" />
+ </path>
+ <path>
+ <item name="" type="16c1761:MavenProjectsStructure$RootNode" />
+ <item name="http-tutorial" type="9519ce18:MavenProjectsStructure$ProjectNode" />
+ <item name="Lifecycle" type="58874e2:MavenProjectsStructure$LifecycleNode" />
+ </path>
+ </expand>
+ <select />
+ </treeState>
+ </component>
+ <component name="MavenRunner">
+ <option name="jreName" value="9" />
+ <option name="vmOptions" value="--add-modules=jdk.incubator.httpclient" />
+ </component>
+ <component name="ProjectFrameBounds">
+ <option name="x" value="251" />
+ <option name="y" value="24" />
+ <option name="width" value="1588" />
+ <option name="height" value="1021" />
+ </component>
+ <component name="ProjectInspectionProfilesVisibleTreeState">
+ <entry key="Project Default">
+ <profile-state>
+ <expanded-state>
+ <State>
+ <id />
+ </State>
+ <State>
+ <id>Abstraction issuesJava</id>
+ </State>
+ <State>
+ <id>Android > Lint > Correctness</id>
+ </State>
+ <State>
+ <id>Android > Lint > Correctness > Messages</id>
+ </State>
+ <State>
+ <id>Android > Lint > Performance</id>
+ </State>
+ <State>
+ <id>Android > Lint > Security</id>
+ </State>
+ <State>
+ <id>Android > Lint > Usability > Icons</id>
+ </State>
+ <State>
+ <id>Android Lint for Kotlin</id>
+ </State>
+ <State>
+ <id>Assignment issuesGroovy</id>
+ </State>
+ <State>
+ <id>Assignment issuesJava</id>
+ </State>
+ <State>
+ <id>Class structureJava</id>
+ </State>
+ <State>
+ <id>Code style issuesJava</id>
+ </State>
+ <State>
+ <id>Compiler issuesJava</id>
+ </State>
+ <State>
+ <id>Control FlowGroovy</id>
+ </State>
+ <State>
+ <id>Control flow issuesJava</id>
+ </State>
+ <State>
+ <id>Data flow issuesGroovy</id>
+ </State>
+ <State>
+ <id>Data flow issuesJava</id>
+ </State>
+ <State>
+ <id>Declaration redundancyJava</id>
+ </State>
+ <State>
+ <id>Encapsulation issuesJava</id>
+ </State>
+ <State>
+ <id>Error handlingGroovy</id>
+ </State>
+ <State>
+ <id>Error handlingJava</id>
+ </State>
+ <State>
+ <id>Finalization issuesJava</id>
+ </State>
+ <State>
+ <id>General</id>
+ </State>
+ <State>
+ <id>Groovy</id>
+ </State>
+ <State>
+ <id>ImportsJava</id>
+ </State>
+ <State>
+ <id>Inheritance issuesJava</id>
+ </State>
+ <State>
+ <id>Initialization issuesJava</id>
+ </State>
+ <State>
+ <id>Internationalization issuesJava</id>
+ </State>
+ <State>
+ <id>J2ME issuesJava</id>
+ </State>
+ <State>
+ <id>JUnit issuesJava</id>
+ </State>
+ <State>
+ <id>Java</id>
+ </State>
+ <State>
+ <id>Java 5Java language level migration aidsJava</id>
+ </State>
+ <State>
+ <id>Java 7Java language level migration aidsJava</id>
+ </State>
+ <State>
+ <id>Java 9Java language level migration aidsJava</id>
+ </State>
+ <State>
+ <id>Java language level issuesJava</id>
+ </State>
+ <State>
+ <id>Java language level migration aidsJava</id>
+ </State>
+ <State>
+ <id>JavaBeans issuesJava</id>
+ </State>
+ <State>
+ <id>Kotlin</id>
+ </State>
+ <State>
+ <id>Logging issuesJava</id>
+ </State>
+ <State>
+ <id>Manifest</id>
+ </State>
+ <State>
+ <id>Method MetricsGroovy</id>
+ </State>
+ <State>
+ <id>Method metricsJava</id>
+ </State>
+ <State>
+ <id>Naming ConventionsGroovy</id>
+ </State>
+ <State>
+ <id>Naming conventionsJava</id>
+ </State>
+ <State>
+ <id>Numeric issuesJava</id>
+ </State>
+ <State>
+ <id>OtherGroovy</id>
+ </State>
+ <State>
+ <id>Pattern Validation</id>
+ </State>
+ <State>
+ <id>Performance issuesJava</id>
+ </State>
+ <State>
+ <id>Plugin DevKit</id>
+ </State>
+ <State>
+ <id>Portability issuesJava</id>
+ </State>
+ <State>
+ <id>Probable bugsJava</id>
+ </State>
+ <State>
+ <id>Properties Files</id>
+ </State>
+ <State>
+ <id>Properties FilesJava</id>
+ </State>
+ <State>
+ <id>RegExp</id>
+ </State>
+ <State>
+ <id>Security issuesJava</id>
+ </State>
+ <State>
+ <id>Serialization issuesJava</id>
+ </State>
+ <State>
+ <id>Threading issuesGroovy</id>
+ </State>
+ <State>
+ <id>Threading issuesJava</id>
+ </State>
+ <State>
+ <id>Verbose or redundant code constructsJava</id>
+ </State>
+ <State>
+ <id>Visibility issuesJava</id>
+ </State>
+ <State>
+ <id>XSLT</id>
+ </State>
+ </expanded-state>
+ </profile-state>
+ </entry>
+ </component>
+ <component name="ProjectLevelVcsManager" settingsEditedManually="true" />
+ <component name="ProjectView">
+ <navigator currentView="ProjectPane" proportions="" version="1">
+ <flattenPackages />
+ <showMembers />
+ <showModules />
+ <showLibraryContents />
+ <hideEmptyPackages />
+ <abbreviatePackageNames />
+ <autoscrollToSource />
+ <autoscrollFromSource />
+ <sortByType />
+ <manualOrder />
+ <foldersAlwaysOnTop value="true" />
+ </navigator>
+ <panes>
+ <pane id="Scratches" />
+ <pane id="ProjectPane">
+ <subPane>
+ <expand>
+ <path>
+ <item name="http-client-tutorial" type="b2602c69:ProjectViewProjectNode" />
+ <item name="sandbox_tutorial" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="http-client-tutorial" type="b2602c69:ProjectViewProjectNode" />
+ <item name="sandbox_tutorial" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="http-client-tutorial" type="b2602c69:ProjectViewProjectNode" />
+ <item name="sandbox_tutorial" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ <item name="main" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="http-client-tutorial" type="b2602c69:ProjectViewProjectNode" />
+ <item name="sandbox_tutorial" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ <item name="main" type="462c0819:PsiDirectoryNode" />
+ <item name="java" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="http-client-tutorial" type="b2602c69:ProjectViewProjectNode" />
+ <item name="sandbox_tutorial" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ <item name="main" type="462c0819:PsiDirectoryNode" />
+ <item name="java" type="462c0819:PsiDirectoryNode" />
+ <item name="exercise1" type="462c0819:PsiDirectoryNode" />
+ </path>
+ <path>
+ <item name="http-client-tutorial" type="b2602c69:ProjectViewProjectNode" />
+ <item name="sandbox_tutorial" type="462c0819:PsiDirectoryNode" />
+ <item name="src" type="462c0819:PsiDirectoryNode" />
+ <item name="main" type="462c0819:PsiDirectoryNode" />
+ <item name="java" type="462c0819:PsiDirectoryNode" />
+ <item name="exercise1" type="462c0819:PsiDirectoryNode" />
+ <item name="Retrievals" type="1a9f42e2:ClassTreeNode" />
+ </path>
+ <path>
+ <item name="http-client-tutorial" type="b2602c69:ProjectViewProjectNode" />
+ <item name="External Libraries" type="cb654da1:ExternalLibrariesNode" />
+ </path>
+ </expand>
+ <select />
+ </subPane>
+ </pane>
+ <pane id="Scope" />
+ <pane id="PackagesPane" />
+ <pane id="AndroidView" />
+ </panes>
+ </component>
+ <component name="PropertiesComponent">
+ <property name="GoToClass.includeLibraries" value="false" />
+ <property name="GoToClass.toSaveIncludeLibraries" value="false" />
+ <property name="GoToFile.includeJavaFiles" value="false" />
+ <property name="MemberChooser.sorted" value="false" />
+ <property name="MemberChooser.showClasses" value="true" />
+ <property name="MemberChooser.copyJavadoc" value="false" />
+ <property name="options.lastSelected" value="terminal" />
+ <property name="options.splitter.main.proportions" value="0.3" />
+ <property name="options.splitter.details.proportions" value="0.2" />
+ <property name="options.searchVisible" value="true" />
+ <property name="project.structure.last.edited" value="Modules" />
+ <property name="project.structure.proportion" value="0.15" />
+ <property name="project.structure.side.proportion" value="0.2" />
+ <property name="settings.editor.selected.configurable" value="preferences.sourceCode" />
+ </component>
+ <component name="RunDashboard">
+ <option name="ruleStates">
+ <list>
+ <RuleState>
+ <option name="name" value="ConfigurationTypeDashboardGroupingRule" />
+ </RuleState>
+ <RuleState>
+ <option name="name" value="StatusDashboardGroupingRule" />
+ </RuleState>
+ </list>
+ </option>
+ </component>
+ <component name="RunManager">
+ <configuration default="true" type="Applet" factoryName="Applet">
+ <option name="WIDTH" value="400" />
+ <option name="HEIGHT" value="300" />
+ <option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
+ <module />
+ </configuration>
+ <configuration default="true" type="Application" factoryName="Application">
+ <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
+ <option name="MAIN_CLASS_NAME" />
+ <option name="VM_PARAMETERS" />
+ <option name="PROGRAM_PARAMETERS" />
+ <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+ <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+ <option name="ALTERNATIVE_JRE_PATH" />
+ <option name="ENABLE_SWING_INSPECTOR" value="false" />
+ <option name="ENV_VARIABLES" />
+ <option name="PASS_PARENT_ENVS" value="true" />
+ <module name="" />
+ <envs />
+ </configuration>
+ <configuration default="true" type="JUnit" factoryName="JUnit">
+ <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
+ <module name="" />
+ <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+ <option name="ALTERNATIVE_JRE_PATH" />
+ <option name="PACKAGE_NAME" />
+ <option name="MAIN_CLASS_NAME" />
+ <option name="METHOD_NAME" />
+ <option name="TEST_OBJECT" value="class" />
+ <option name="VM_PARAMETERS" value="-ea" />
+ <option name="PARAMETERS" />
+ <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+ <option name="ENV_VARIABLES" />
+ <option name="PASS_PARENT_ENVS" value="true" />
+ <option name="TEST_SEARCH_SCOPE">
+ <value defaultName="moduleWithDependencies" />
+ </option>
+ <envs />
+ <patterns />
+ </configuration>
+ <configuration default="true" type="#org.jetbrains.idea.devkit.run.PluginConfigurationType" factoryName="Plugin">
+ <module name="" />
+ <option name="VM_PARAMETERS" value="-Xmx512m -Xms256m -XX:MaxPermSize=250m -ea" />
+ <option name="PROGRAM_PARAMETERS" />
+ <predefined_log_file id="idea.log" enabled="true" />
+ </configuration>
+ <configuration default="true" type="Remote" factoryName="Remote">
+ <option name="USE_SOCKET_TRANSPORT" value="true" />
+ <option name="SERVER_MODE" value="false" />
+ <option name="SHMEM_ADDRESS" value="javadebug" />
+ <option name="HOST" value="localhost" />
+ <option name="PORT" value="5005" />
+ </configuration>
+ <configuration default="true" type="TestNG" factoryName="TestNG">
+ <extension name="coverage" enabled="false" merge="false" sample_coverage="true" runner="idea" />
+ <module name="" />
+ <option name="ALTERNATIVE_JRE_PATH_ENABLED" value="false" />
+ <option name="ALTERNATIVE_JRE_PATH" />
+ <option name="SUITE_NAME" />
+ <option name="PACKAGE_NAME" />
+ <option name="MAIN_CLASS_NAME" />
+ <option name="METHOD_NAME" />
+ <option name="GROUP_NAME" />
+ <option name="TEST_OBJECT" value="CLASS" />
+ <option name="VM_PARAMETERS" value="-ea" />
+ <option name="PARAMETERS" />
+ <option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
+ <option name="OUTPUT_DIRECTORY" />
+ <option name="ANNOTATION_TYPE" />
+ <option name="ENV_VARIABLES" />
+ <option name="PASS_PARENT_ENVS" value="true" />
+ <option name="TEST_SEARCH_SCOPE">
+ <value defaultName="moduleWithDependencies" />
+ </option>
+ <option name="USE_DEFAULT_REPORTERS" value="false" />
+ <option name="PROPERTIES_FILE" />
+ <envs />
+ <properties />
+ <listeners />
+ </configuration>
+ <configuration name="<template>" type="WebApp" default="true" selected="false">
+ <Host>localhost</Host>
+ <Port>5050</Port>
+ </configuration>
+ </component>
+ <component name="ShelveChangesManager" show_recycled="false">
+ <option name="remove_strategy" value="false" />
+ </component>
+ <component name="SvnConfiguration">
+ <configuration>$USER_HOME$/.subversion</configuration>
+ </component>
+ <component name="TaskManager">
+ <task active="true" id="Default" summary="Default task">
+ <changelist id="370c2318-db1e-4222-8c67-6545c7e7a90a" name="Default" comment="" />
+ <created>1516127026428</created>
+ <option name="number" value="Default" />
+ <option name="presentableId" value="Default" />
+ <updated>1516127026428</updated>
+ </task>
+ <servers />
+ </component>
+ <component name="ToolWindowManager">
+ <frame x="251" y="24" width="1588" height="1021" extended-state="0" />
+ <editor active="true" />
+ <layout>
+ <window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
+ <window_info id="FindBugs-IDEA" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Palette	" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Image Layers" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Capture Analysis" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
+ <window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.23929471" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.32982087" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
+ <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+ <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
+ <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
+ <window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Theme Preview" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
+ <window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
+ <window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
+ <window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
+ <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
+ <window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+ <window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
+ <window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
+ <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
+ </layout>
+ </component>
+ <component name="VcsContentAnnotationSettings">
+ <option name="myLimit" value="2678400000" />
+ </component>
+ <component name="XDebuggerManager">
+ <breakpoint-manager />
+ <watches-manager />
+ </component>
+ <component name="editorHistoryManager">
+ <entry file="file://$PROJECT_DIR$/pom.xml">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="0">
+ <caret line="0" column="0" lean-forward="false" selection-start-line="0" selection-start-column="0" selection-end-line="0" selection-end-column="0" />
+ <folding />
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/test/java/openjdk/http/tutorial/Exercise1Test.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="345">
+ <caret line="23" column="0" lean-forward="false" selection-start-line="23" selection-start-column="0" selection-end-line="23" selection-end-column="0" />
+ <folding>
+ <element signature="e#0#11067#0" expanded="true" />
+ <element signature="imports" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ <entry file="file://$PROJECT_DIR$/src/main/java/openjdk/http/tutorial/exercise1/Retrievals.java">
+ <provider selected="true" editor-type-id="text-editor">
+ <state relative-caret-position="441">
+ <caret line="40" column="38" lean-forward="false" selection-start-line="40" selection-start-column="38" selection-end-line="40" selection-end-column="38" />
+ <folding>
+ <element signature="e#0#8269#0" expanded="true" />
+ </folding>
+ </state>
+ </provider>
+ </entry>
+ </component>
+ <component name="hg4idea.settings">
+ <option name="RECENT_HG_ROOT_PATH" value="$PROJECT_DIR$" />
+ </component>
+ <component name="masterDetails">
+ <states>
+ <state key="ArtifactsStructureConfigurable.UI">
+ <settings>
+ <artifact-editor />
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="FacetStructureConfigurable.UI">
+ <settings>
+ <last-edited>No facets are configured</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="GlobalLibrariesConfigurable.UI">
+ <settings>
+ <last-edited>testng</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="JdkListConfigurable.UI">
+ <settings>
+ <last-edited>1.8</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="ModuleStructureConfigurable.UI">
+ <settings>
+ <last-edited>http-tutorial</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="ProjectJDKs.UI">
+ <settings>
+ <last-edited>9</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ <state key="ProjectLibrariesConfigurable.UI">
+ <settings>
+ <last-edited>Maven: org.hamcrest:hamcrest-core:1.3</last-edited>
+ <splitter-proportions>
+ <option name="proportions">
+ <list>
+ <option value="0.2" />
+ </list>
+ </option>
+ </splitter-proportions>
+ </settings>
+ </state>
+ </states>
+ </component>
+</project>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/http-tutorial.iml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_9">
+ <output url="file://$MODULE_DIR$/target/classes" />
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
+ <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
+ <excludeFolder url="file://$MODULE_DIR$/target" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
+ <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
+ <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.9" level="project" />
+ <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
+ <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.9" level="project" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/pom.xml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.openjdk.http.tutorial</groupId>
+ <artifactId>http-tutorial</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>3.7.0</version>
+ <configuration>
+ <source>9</source>
+ <target>9</target>
+ <compilerArgument>--add-modules=jdk.incubator.httpclient</compilerArgument>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>2.20.1</version>
+ <configuration>
+ <argLine>--add-modules=jdk.incubator.httpclient</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.8.9</version>
+ </dependency>
+ </dependencies>
+
+</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/java/openjdk/http/tutorial/exercise1/Retrievals.java Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,229 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package openjdk.http.tutorial.exercise1;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.nio.file.StandardOpenOption;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import jdk.incubator.http.HttpClient;
+import jdk.incubator.http.HttpRequest;
+import jdk.incubator.http.HttpResponse;
+import jdk.incubator.http.HttpResponse.BodyHandler;
+
+import static java.lang.System.out;
+import static java.util.stream.Collectors.joining;
+import static jdk.incubator.http.HttpClient.Version.*;
+import static jdk.incubator.http.HttpResponse.BodyHandler.*;
+
+/**
+ * @author Chris Hegarty
+ */
+public class Retrievals {
+
+ /**
+ * Exercise 1.
+ *
+ * Retrieve the response status code from a request to the given
+ * URI. The returned response code will be a int.
+ *
+ * Hint: use the discard BodyHandler since the response body is not
+ * interesting.
+ *
+ * Hint: static imports reduce boilerplate when using BodyHandlers
+ * and BodyProcessors, e.g. import static
+ * jdk.incubator.http.HttpResponse.BodyHandler.discard
+ */
+ public static int retrieveTheStatusCode(URI uri)
+ throws IOException, InterruptedException
+ {
+ HttpClient client = HttpClient.newBuilder().version(HTTP_1_1).build();
+ HttpRequest request = HttpRequest.newBuilder(uri).GET().build();
+ HttpResponse<?> response = client.send(request, discard(null));
+
+ return response.statusCode();
+ }
+
+ /**
+ * Exercise 1.
+ *
+ * Retrieve the response body from a given URI. Return the response
+ * body as a String.
+ *
+ * Hint: use the asString BodyHandler to convert the HTTP response
+ * body to a String.
+ *
+ * Hint: static imports reduce boilerplate when using BodyHandlers
+ * and BodyProcessors, e.g. import static
+ * jdk.incubator.http.HttpResponse.BodyHandler.asString
+ */
+ public static String retrieveResourceAsString(URI uri)
+ throws IOException, InterruptedException
+ {
+ HttpClient client = HttpClient.newBuilder().version(HTTP_1_1).build();
+ HttpRequest request = HttpRequest.newBuilder(uri).GET().build();
+ HttpResponse<String> response = client.send(request, asString());
+
+ return response.body();
+ }
+
+ /**
+ * Exercise 2.
+ *
+ * Retrieve the response body from a given URI, streaming teh body
+ * out to a file. Return the file's Path.
+ *
+ * Hint: use {@linkplain BodyHandler#asFile} to stream the HTTP
+ * response body to a file.
+ */
+ public static Path retrieveResourceAsFile(URI uri)
+ throws IOException, InterruptedException
+ {
+ HttpClient client = HttpClient.newBuilder().build();
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(uri)
+ .version(HTTP_1_1)
+ .GET()
+ .build();
+ HttpResponse<Path> response = client.send(request,
+ asFile(Paths.get("retrieveResourceAsFile.txt"), StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE));
+
+ System.out.println("CHEGAR: sc=" + response.statusCode());
+ System.out.println("CHEGAR: by=" + Files.readAllLines(response.body()).stream().collect(joining()));
+
+ return response.body();
+ }
+
+
+ /**
+ * Asserts that the response code is 200 ( OK ).
+ *
+ * Can be used in CompletableFuture pipelines when checking the
+ * response of an {@linkplain HttpClient#sendAsync} call. For
+ * example:
+ * client.sendAsync(request, bodyHandler)
+ * .thenApply(Retrievals::require200StatusCode)
+ * .thenApply(...)
+ *
+ */
+ public static <T> HttpResponse<T> require200StatusCode(HttpResponse<T> response) {
+ int sc = response.statusCode();
+ if (sc != 200) {
+ IOException e = new IOException("Expected 200, got: " + sc);
+ throw new UncheckedIOException(e);
+ }
+ return response;
+ }
+
+ /**
+ * Exercise 3.
+ *
+ * Retrieve the response body from a given URI, using the
+ * asynchronous send API, sendAsync. Return a CompletableFuture that
+ * completes with the response body as a String.
+ *
+ * Hint: The {@linkplain CompletableFuture#thenApply(Function)}
+ * method can be used to map the HttpResponse to a String.
+ */
+ public static CompletableFuture<String> retrieveResourceAsStringUsingAsyncAPI(URI uri) {
+ return HttpClient.newHttpClient()
+ .sendAsync(HttpRequest.newBuilder(uri).version(HTTP_1_1).build(), asString()) // TODO: why version needed?
+ .thenApply(Retrievals::require200StatusCode)
+ .thenApply(HttpResponse::body);
+ }
+
+
+ /**
+ * Wrapper around Jackson's ObjectMapper that provides an unchecked
+ * {@code readValue}, what can be used to help solve the next
+ * exercise, 4.
+ */
+ public static class UncheckedObjectMapper extends ObjectMapper {
+
+ /** Parses the given JSON string into a Map. */
+ Map<String,String> readValue(String content) {
+ try {
+ return this.readValue(content, new TypeReference<>(){});
+ } catch (IOException ioe) {
+ throw new UncheckedIOException(ioe);
+ }
+ }
+ }
+
+ /**
+ * Exercise 4.
+ *
+ * Retrieve the response body from a given URI. The response body
+ * will be in the JSON format. The Jackson based UncheckedObjectMapper
+ * ( above ) can be used to parse the String response body into a
+ * Map.
+ *
+ * Hint: The asynchronous send API will allow construction of a
+ * pipeline of CompletableFutures.
+ *
+ * Hint: The {@linkplain CompletableFuture#thenApply(Function)}
+ * method can be used to map the HttpResponse to a String, and then
+ * again from a Sting to a Map ( via the object mapper ).
+ */
+ public CompletableFuture<Map<String,String>> JSONBodyAsMap(URI uri) {
+ UncheckedObjectMapper objectMapper = new UncheckedObjectMapper();
+ return HttpClient.newHttpClient()
+ .sendAsync(HttpRequest.newBuilder(uri).version(HTTP_1_1).build(), asString())
+ .thenApply(HttpResponse::body)
+ .thenApply(objectMapper::readValue);
+ }
+
+
+
+ /**
+ * Post the given {@code data}, and receive the same data in
+ * response. Return the response body data as a String.
+ */
+ public static String postData(URI uri, String data)
+ throws IOException, InterruptedException
+ {
+ HttpClient client = HttpClient.newBuilder().build();
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(uri)
+ .version(HTTP_1_1)
+ .POST(HttpRequest.BodyProcessor.fromString(data))
+ .build();
+ HttpResponse<String> response = client.send(request, asString());
+
+ return response.body();
+ }
+
+
+ // JSON processor
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/main.iml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="false" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module>
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/java/openjdk/http/tutorial/Exercise1Test.java Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,354 @@
+/*
+ * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package openjdk.http.tutorial;
+
+/**
+ * @author Chris Hegarty
+ */
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.net.URI;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import java.util.function.Function;
+
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import jdk.incubator.http.HttpClient;
+import jdk.incubator.http.HttpRequest;
+import jdk.incubator.http.HttpResponse;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestRule;
+import org.junit.rules.TestWatcher;
+import org.junit.runner.Description;
+import openjdk.http.tutorial.exercise1.Retrievals;
+import openjdk.http.tutorial.exercise1.Retrievals.UncheckedObjectMapper;
+import static java.lang.System.out;
+import static java.nio.file.StandardOpenOption.*;
+import static java.util.stream.Collectors.joining;
+import static jdk.incubator.http.HttpClient.Version.*;
+import static jdk.incubator.http.HttpResponse.BodyHandler.asFile;
+import static jdk.incubator.http.HttpResponse.BodyHandler.asString;
+import static jdk.incubator.http.HttpResponse.BodyHandler.discard;
+import static org.junit.Assert.assertEquals;
+
+public class Exercise1Test {
+
+ @Test
+ public void retrieveTheStatusCode()
+ throws IOException, InterruptedException
+ {
+ URI uri = URI.create("http://httpbin.org/get");
+
+ int expectedStatusCode = statusCode(uri);
+ int actualStatusCode = Retrievals.retrieveTheStatusCode(uri);
+
+ assertEquals("Unexpected status code",
+ expectedStatusCode,
+ actualStatusCode);
+ }
+
+ @Test
+ public void retrieveResourceAsString()
+ throws IOException, InterruptedException
+ {
+ URI uri = URI.create("http://httpbin.org/get");
+
+ String expectedResponseBody = bodyAsString(uri);
+ String actualResponseBody = Retrievals.retrieveResourceAsString(uri);
+
+ assertEquals("Unexpected response body",
+ expectedResponseBody,
+ actualResponseBody);
+ }
+
+ @Test
+ public void retrieveResourceAsFile()
+ throws IOException, InterruptedException
+ {
+ URI uri = URI.create("http://httpbin.org/get");
+
+ Path expectedResponseBodyFile = bodyAsFile(uri);
+ Path actualResponseBodyFile = Retrievals.retrieveResourceAsFile(uri);
+ byte[] b1 = Files.readAllBytes(expectedResponseBodyFile);
+ byte[] b2 = Files.readAllBytes(actualResponseBodyFile);
+
+ System.out.println("CHEGAR b1 = " + new String(b1));
+ System.out.println("CHEGAR b2 = " + new String(b2));
+
+ Assert.assertArrayEquals("Unexpected response body", b1, b2);
+ }
+
+ @Test
+ public void retrieveResourceAsStringUsingAsyncAPI()
+ throws IOException, InterruptedException
+ {
+ URI uri = URI.create("http://httpbin.org/get");
+
+ String expectedResponseBody = bodyAsString(uri);
+ String actualResponseBody =
+ Retrievals.retrieveResourceAsStringUsingAsyncAPI(uri).join();
+
+ assertEquals("Unexpected response body",
+ expectedResponseBody,
+ actualResponseBody);
+ }
+
+// @Test
+// public void JSONBodyAsMap() {
+// throws IOException, InterruptedException
+// URI uri = URI.create("http://httpbin.org/get");
+//
+// UncheckedObjectMapper objectMapper = new UncheckedObjectMapper();
+// String expectedResponseBody = objectMapper(bodyAsString(uri));
+// String actualResponseBody =
+// Retrievals.retrieveResourceAsStringUsingAsyncAPI(uri).join();
+//
+// assertEquals("Unexpected response body",
+// expectedResponseBody,
+// actualResponseBody);
+// }
+
+
+
+
+
+ //@Test
+ public void postData()
+ throws IOException, InterruptedException
+ {
+ URI uri = URI.create("http://httpbin.org/post");
+ String message = "Hello there!";
+
+ String actualResponseBody = Retrievals.postData(uri, message);
+ String expectedResponseBody = message;
+
+ assertEquals("Unexpected response body",
+ expectedResponseBody,
+ actualResponseBody);
+ }
+
+ /** Wrapper around Jackson's ObjectMapper that provides unchecked readValue. */
+ static class UncheckedObjectMapper extends ObjectMapper{
+
+ Map<String,String> readValue(String content) {
+ try {
+ return this.readValue(content, new TypeReference<>(){});
+ } catch (IOException ioe) {
+ throw new UncheckedIOException(ioe);
+ }
+ }
+ }
+
+ private UncheckedObjectMapper objectMapper = new UncheckedObjectMapper();
+
+
+ /**
+ * The Echo JSON service on echo.jsontest.com returns a customized
+ * JSON object that you can define through a REST-style URL. For
+ * example, calling http://echo.jsontest.com/key/value/one/two
+ * will return the following JSON:
+ *
+ * {
+ * “one”: “two”,
+ * “key”: “value”
+ * }
+ */
+ @Test
+ public void bodyAsJSON() {
+ String[] pairs = new String[] {
+ "Name", "chegar",
+ "Country", "Ireland",
+ "Citizenship", "Irish"
+ };
+ String path = Arrays.stream(pairs).collect(joining("/"));
+ URI uri = URI.create("http://echo.jsontest.com/" + path);
+
+ HttpClient client = HttpClient.newBuilder().build();
+ HttpRequest request = HttpRequest.newBuilder(uri).GET().build();
+ client.sendAsync(request, asString())
+ .thenCompose(response -> { // maps HttpResponse to String
+ assertEquals(response.statusCode(), 200);
+ return CompletableFuture.completedFuture(response.body()); })
+ .thenAccept(body -> { // consumes the response body
+ out.println("received: " + body);
+ Map<String, String> map = objectMapper.readValue(body);
+
+ assertEquals(map.get("Name"), "chegar");
+ assertEquals(map.get("Country"), "Ireland");
+ assertEquals(map.get("Citizenship"), "Irish"); })
+ .join();
+ }
+
+
+ // ---- some trivial infrastructure to help output messages
+
+ @Rule
+ public TestRule watcher = new TestWatcher() {
+ @Override
+ protected void starting(Description description) {
+ out.println("\nStarting test: " + description.getMethodName());
+ }
+ @Override
+ protected void finished(Description description) {
+ out.println("Finished test: " + description.getMethodName());
+ }
+ @Override
+ protected void failed(Throwable e, Description description) {
+ e.printStackTrace();
+ }
+ };
+
+
+
+ // ---- demonstration code below
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ interface Peeker<T> extends Function<T,T>
+ {
+ void peek(T t);
+
+ default T apply(T t)
+ {
+ peek(t);
+ return t;
+ }
+ }
+
+ static void assertStatusCode200(HttpResponse<?> response) {
+ assertEquals(200, response.statusCode());
+ }
+
+ private static int statusCode(URI uri) {
+ return HttpClient.newBuilder().version(HTTP_1_1).build()
+ .sendAsync(HttpRequest.newBuilder(uri).build(), discard(null))
+ .thenApply((Peeker<HttpResponse<?>>)Exercise1Test::assertStatusCode200)
+ .thenApply(HttpResponse::statusCode)
+ .join();
+ }
+
+ private static String bodyAsString(URI uri) {
+ return HttpClient.newBuilder().version(HTTP_1_1).build()
+ .sendAsync(HttpRequest.newBuilder(uri).build(), asString())
+ .thenApply((Peeker<HttpResponse<String>>)Exercise1Test::assertStatusCode200)
+ .thenApply(HttpResponse::body)
+ .join();
+ }
+
+// private static String bodyAsString(URI uri)
+// throws IOException, InterruptedException
+// {
+// HttpClient client = HttpClient.newBuilder().build();
+// HttpRequest request = HttpRequest.newBuilder(uri)
+// .version(HttpClient.Version.HTTP_1_1)
+// .GET()
+// .build();
+// HttpResponse<String> response = client.send(request, asString());
+//
+// Assert.assertEquals(200, response.statusCode());
+//
+// return response.body();
+// }
+
+ private static Path bodyAsFile(URI uri)
+ throws IOException, InterruptedException
+ {
+ HttpClient client = HttpClient.newBuilder().build();
+ HttpRequest request = HttpRequest.newBuilder(uri)
+ .version(HttpClient.Version.HTTP_1_1)
+ .GET()
+ .build();
+ Path p = Paths.get("Exercise1Test_bodyAsFile.txt");
+ HttpResponse<Path> response = client.send(request,
+ asFile(p, TRUNCATE_EXISTING, WRITE));
+
+ Assert.assertEquals(200, response.statusCode());
+
+ return response.body();
+ }
+
+ private static String postDataGetResponseBody(URI uri, String data)
+ throws IOException, InterruptedException
+ {
+ HttpClient client = HttpClient.newBuilder().build();
+ HttpRequest request = HttpRequest.newBuilder()
+ .uri(uri)
+ .version(HttpClient.Version.HTTP_1_1)
+ .POST(HttpRequest.BodyProcessor.fromString(data))
+ .build();
+ HttpResponse<String> response = client.send(request, asString());
+
+ ObjectMapper objectMapper = new ObjectMapper();
+ Map<String,Object> map = objectMapper.readValue(response.body(), new TypeReference<>(){});
+
+ System.out.println("CHEGAR map: " + map);
+
+ //JSONObject json = new JSONObject(myResponse);
+
+ Assert.assertEquals(200, response.statusCode());
+
+ return response.body();
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/test/test.iml Tue Jan 16 19:14:34 2018 +0000
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<module type="JAVA_MODULE" version="4">
+ <component name="NewModuleRootManager" inherit-compiler-output="true">
+ <exclude-output />
+ <content url="file://$MODULE_DIR$">
+ <sourceFolder url="file://$MODULE_DIR$/java" isTestSource="true" />
+ </content>
+ <orderEntry type="inheritedJdk" />
+ <orderEntry type="sourceFolder" forTests="false" />
+ </component>
+</module>
\ No newline at end of file