simple multithreaded proxy server

master
Vyacheslav N. Boyko 2018-10-23 07:49:51 +03:00
parent 2cf720d5b4
commit 0119a00d35
9 changed files with 1134 additions and 0 deletions

1
.gitignore vendored 100644
View File

@ -0,0 +1 @@
target/**

186
jProxy.ipr 100644
View File

@ -0,0 +1,186 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<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="jproxy" />
</profile>
</annotationProcessing>
<bytecodeTargetLevel>
<module name="jproxy" target="8" />
</bytecodeTargetLevel>
</component>
<component name="Encoding">
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
</component>
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
</profile>
<version value="1.0" />
</component>
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="Palette2">
<group name="Swing">
<item class="com.intellij.uiDesigner.HSpacer" tooltip-text="Horizontal Spacer" icon="/com/intellij/uiDesigner/icons/hspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="1" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="com.intellij.uiDesigner.VSpacer" tooltip-text="Vertical Spacer" icon="/com/intellij/uiDesigner/icons/vspacer.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="1" anchor="0" fill="2" />
</item>
<item class="javax.swing.JPanel" icon="/com/intellij/uiDesigner/icons/panel.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3" />
</item>
<item class="javax.swing.JScrollPane" icon="/com/intellij/uiDesigner/icons/scrollPane.png" removable="false" auto-create-binding="false" can-attach-label="true">
<default-constraints vsize-policy="7" hsize-policy="7" anchor="0" fill="3" />
</item>
<item class="javax.swing.JButton" icon="/com/intellij/uiDesigner/icons/button.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="0" fill="1" />
<initial-values>
<property name="text" value="Button" />
</initial-values>
</item>
<item class="javax.swing.JRadioButton" icon="/com/intellij/uiDesigner/icons/radioButton.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="RadioButton" />
</initial-values>
</item>
<item class="javax.swing.JCheckBox" icon="/com/intellij/uiDesigner/icons/checkBox.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="3" anchor="8" fill="0" />
<initial-values>
<property name="text" value="CheckBox" />
</initial-values>
</item>
<item class="javax.swing.JLabel" icon="/com/intellij/uiDesigner/icons/label.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="8" fill="0" />
<initial-values>
<property name="text" value="Label" />
</initial-values>
</item>
<item class="javax.swing.JTextField" icon="/com/intellij/uiDesigner/icons/textField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JPasswordField" icon="/com/intellij/uiDesigner/icons/passwordField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JFormattedTextField" icon="/com/intellij/uiDesigner/icons/formattedTextField.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1">
<preferred-size width="150" height="-1" />
</default-constraints>
</item>
<item class="javax.swing.JTextArea" icon="/com/intellij/uiDesigner/icons/textArea.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTextPane" icon="/com/intellij/uiDesigner/icons/textPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JEditorPane" icon="/com/intellij/uiDesigner/icons/editorPane.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JComboBox" icon="/com/intellij/uiDesigner/icons/comboBox.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="2" anchor="8" fill="1" />
</item>
<item class="javax.swing.JTable" icon="/com/intellij/uiDesigner/icons/table.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JList" icon="/com/intellij/uiDesigner/icons/list.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="2" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTree" icon="/com/intellij/uiDesigner/icons/tree.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3">
<preferred-size width="150" height="50" />
</default-constraints>
</item>
<item class="javax.swing.JTabbedPane" icon="/com/intellij/uiDesigner/icons/tabbedPane.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSplitPane" icon="/com/intellij/uiDesigner/icons/splitPane.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="3" hsize-policy="3" anchor="0" fill="3">
<preferred-size width="200" height="200" />
</default-constraints>
</item>
<item class="javax.swing.JSpinner" icon="/com/intellij/uiDesigner/icons/spinner.png" removable="false" auto-create-binding="true" can-attach-label="true">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSlider" icon="/com/intellij/uiDesigner/icons/slider.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="8" fill="1" />
</item>
<item class="javax.swing.JSeparator" icon="/com/intellij/uiDesigner/icons/separator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="6" anchor="0" fill="3" />
</item>
<item class="javax.swing.JProgressBar" icon="/com/intellij/uiDesigner/icons/progressbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1" />
</item>
<item class="javax.swing.JToolBar" icon="/com/intellij/uiDesigner/icons/toolbar.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="6" anchor="0" fill="1">
<preferred-size width="-1" height="20" />
</default-constraints>
</item>
<item class="javax.swing.JToolBar$Separator" icon="/com/intellij/uiDesigner/icons/toolbarSeparator.png" removable="false" auto-create-binding="false" can-attach-label="false">
<default-constraints vsize-policy="0" hsize-policy="0" anchor="0" fill="1" />
</item>
<item class="javax.swing.JScrollBar" icon="/com/intellij/uiDesigner/icons/scrollbar.png" removable="false" auto-create-binding="true" can-attach-label="false">
<default-constraints vsize-policy="6" hsize-policy="0" anchor="0" fill="2" />
</item>
</group>
</component>
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/jproxy.iml" filepath="$PROJECT_DIR$/jproxy.iml" />
</modules>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
<component name="libraryTable">
<library name="Maven: junit:junit:4.12">
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/junit/junit/4.12/junit-4.12-sources.jar!/" />
</SOURCES>
</library>
<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>
</project>

614
jProxy.iws 100644
View File

@ -0,0 +1,614 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ChangeListManager">
<list default="true" id="27bd0fac-9043-4d05-8780-09e69fc6f7ca" name="Default Changelist" comment="" />
<ignored path="$PROJECT_DIR$/out/" />
<ignored path="$PROJECT_DIR$/target/" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" 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="FUSProjectUsageTrigger">
<session id="2059998503">
<usages-collector id="statistics.lifecycle.project">
<counts>
<entry key="project.open.time.11" value="1" />
<entry key="project.opened" value="1" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.edit">
<counts>
<entry key="dummy" value="7" />
<entry key="java" value="3180" />
<entry key="xml" value="10" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.edit">
<counts>
<entry key="JAVA" value="3180" />
<entry key="PLAIN_TEXT" value="7" />
<entry key="XML" value="10" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.extensions.open">
<counts>
<entry key="java" value="9" />
</counts>
</usages-collector>
<usages-collector id="statistics.file.types.open">
<counts>
<entry key="JAVA" value="9" />
</counts>
</usages-collector>
</session>
</component>
<component name="FileEditorManager">
<leaf>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/JProxy.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="6" column="74" selection-start-line="6" selection-start-column="74" selection-end-line="6" selection-end-column="74" />
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/ClientListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="155">
<caret line="29" column="30" selection-start-line="29" selection-start-column="30" selection-end-line="29" selection-end-column="30" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/test/java/ru/bvn13/JProxyTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="197">
<caret line="39" column="21" lean-forward="true" selection-start-line="39" selection-start-column="21" selection-end-line="39" selection-end-column="21" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/ProxyServer.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="319">
<caret line="34" lean-forward="true" selection-start-line="34" selection-end-line="34" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
</leaf>
</component>
<component name="FileTemplateManagerImpl">
<option name="RECENT_TEMPLATES">
<list>
<option value="Class" />
</list>
</option>
</component>
<component name="IdeDocumentHistory">
<option name="CHANGED_PATHS">
<list>
<option value="$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/App.java" />
<option value="$PROJECT_DIR$/pom.xml" />
<option value="$PROJECT_DIR$/src/test/java/ru/bvn13/JProxyTest.java" />
<option value="$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/ProxyServer.java" />
<option value="$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/JProxy.java" />
<option value="$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/ClientListener.java" />
</list>
</option>
</component>
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
<component name="JsGulpfileManager">
<detection-done>true</detection-done>
<sorting>DEFINITION_ORDER</sorting>
</component>
<component name="MavenImportPreferences">
<option name="importingSettings">
<MavenImportingSettings>
<option name="importAutomatically" value="true" />
</MavenImportingSettings>
</option>
</component>
<component name="MavenProjectNavigator">
<treeState>
<expand>
<path>
<item name="" type="16c1761:MavenProjectsStructure$RootNode" />
<item name="jproxy" type="9519ce18:MavenProjectsStructure$ProjectNode" />
</path>
<path>
<item name="" type="16c1761:MavenProjectsStructure$RootNode" />
<item name="jproxy" type="9519ce18:MavenProjectsStructure$ProjectNode" />
<item name="Dependencies" type="f4be9f2a:MavenProjectsStructure$DependenciesNode" />
</path>
<path>
<item name="" type="16c1761:MavenProjectsStructure$RootNode" />
<item name="jproxy" type="9519ce18:MavenProjectsStructure$ProjectNode" />
<item name="Dependencies" type="f4be9f2a:MavenProjectsStructure$DependenciesNode" />
<item name="junit:junit:4.12" type="c0821a7e:MavenProjectsStructure$DependencyNode" />
</path>
</expand>
<select />
</treeState>
</component>
<component name="MavenRunner">
<option name="jreName" value="#JAVA_INTERNAL" />
<option name="vmOptions" value="-Xmx2048m" />
</component>
<component name="ProjectFrameBounds" extendedState="6">
<option name="x" value="-4" />
<option name="width" value="1932" />
<option name="height" value="1047" />
</component>
<component name="ProjectView">
<navigator proportions="" version="1">
<foldersAlwaysOnTop value="true" />
</navigator>
<panes>
<pane id="Scope" />
<pane id="PackagesPane" />
<pane id="ProjectPane">
<subPane>
<expand>
<path>
<item name="jProxy" type="b2602c69:ProjectViewProjectNode" />
<item name="jproxy" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="jProxy" type="b2602c69:ProjectViewProjectNode" />
<item name="jproxy" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="jProxy" type="b2602c69:ProjectViewProjectNode" />
<item name="jproxy" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="jProxy" type="b2602c69:ProjectViewProjectNode" />
<item name="jproxy" 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="jProxy" type="b2602c69:ProjectViewProjectNode" />
<item name="jproxy" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="main" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
<item name="jproxy" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="jProxy" type="b2602c69:ProjectViewProjectNode" />
<item name="jproxy" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="test" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="jProxy" type="b2602c69:ProjectViewProjectNode" />
<item name="jproxy" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="test" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
</path>
<path>
<item name="jProxy" type="b2602c69:ProjectViewProjectNode" />
<item name="jproxy" type="462c0819:PsiDirectoryNode" />
<item name="src" type="462c0819:PsiDirectoryNode" />
<item name="test" type="462c0819:PsiDirectoryNode" />
<item name="java" type="462c0819:PsiDirectoryNode" />
<item name="bvn13" type="462c0819:PsiDirectoryNode" />
</path>
</expand>
<select />
</subPane>
</pane>
</panes>
</component>
<component name="PropertiesComponent">
<property name="WebServerToolWindowFactoryState" value="false" />
<property name="aspect.path.notification.shown" value="true" />
<property name="com.android.tools.idea.instantapp.provision.ProvisionBeforeRunTaskProvider.myTimeStamp" value="1540269948386" />
<property name="last_opened_file_path" value="$PROJECT_DIR$/../ESB-Manager-2.0/ESBManager2-React" />
<property name="nodejs_interpreter_path.stuck_in_default_project" value="C:/nodejs/node" />
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
<property name="project.structure.last.edited" value="Project" />
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.23210071" />
<property name="settings.editor.selected.configurable" value="reference.projectsettings.compiler.javacompiler" />
</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" selected="Application.JProxy">
<configuration default="true" type="Applet" factoryName="Applet">
<option name="POLICY_FILE" value="$APPLICATION_HOME_DIR$/bin/appletviewer.policy" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="JProxy" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="ru.bvn13.jproxy.JProxy" />
<module name="jproxy" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ru.bvn13.jproxy.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration default="true" type="Application" factoryName="Application">
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="JProxyTest" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="jproxy" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ru.bvn13.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="ru.bvn13" />
<option name="MAIN_CLASS_NAME" value="ru.bvn13.JProxyTest" />
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="JProxyTest.testYandex" type="JUnit" factoryName="JUnit" temporary="true" nameIsGenerated="true">
<module name="jproxy" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="ru.bvn13.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<option name="PACKAGE_NAME" value="ru.bvn13" />
<option name="MAIN_CLASS_NAME" value="ru.bvn13.JProxyTest" />
<option name="METHOD_NAME" value="testYandex" />
<option name="TEST_OBJECT" value="method" />
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration default="true" type="JUnit" factoryName="JUnit">
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration default="true" type="TestNG" factoryName="TestNG">
<option name="WORKING_DIRECTORY" value="$MODULE_DIR$" />
<properties />
<listeners />
<method v="2">
<option name="Make" enabled="true" />
</method>
</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" />
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<list>
<item itemvalue="JUnit.JProxyTest" />
<item itemvalue="JUnit.JProxyTest.testYandex" />
<item itemvalue="Application.JProxy" />
</list>
<recent_temporary>
<list>
<item itemvalue="Application.JProxy" />
<item itemvalue="JUnit.JProxyTest.testYandex" />
<item itemvalue="JUnit.JProxyTest" />
</list>
</recent_temporary>
</component>
<component name="SvnConfiguration">
<configuration />
</component>
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="27bd0fac-9043-4d05-8780-09e69fc6f7ca" name="Default Changelist" comment="" />
<created>1540038559516</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1540038559516</updated>
<workItem from="1540038565897" duration="7977000" />
</task>
<servers />
</component>
<component name="TestHistory">
<history-entry file="JProxyTest - 2018.10.21 at 23h 31m 54s.xml">
<configuration name="JProxyTest" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest - 2018.10.21 at 23h 36m 00s.xml">
<configuration name="JProxyTest" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest - 2018.10.21 at 23h 37m 49s.xml">
<configuration name="JProxyTest" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest - 2018.10.22 at 22h 46m 44s.xml">
<configuration name="JProxyTest" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest - 2018.10.22 at 22h 49m 23s.xml">
<configuration name="JProxyTest" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest - 2018.10.22 at 22h 49m 48s.xml">
<configuration name="JProxyTest" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest - 2018.10.22 at 22h 50m 28s.xml">
<configuration name="JProxyTest" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest - 2018.10.22 at 22h 51m 36s.xml">
<configuration name="JProxyTest" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest_testYandex - 2018.10.22 at 22h 56m 00s.xml">
<configuration name="JProxyTest.testYandex" configurationId="JUnit" />
</history-entry>
<history-entry file="JProxyTest_testYandex - 2018.10.22 at 22h 57m 02s.xml">
<configuration name="JProxyTest.testYandex" configurationId="JUnit" />
</history-entry>
</component>
<component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="7977000" />
</component>
<component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
<editor active="true" />
<layout>
<window_info id="Image Layers" />
<window_info id="Designer" />
<window_info id="UI Designer" />
<window_info id="Capture Tool" />
<window_info id="Favorites" side_tool="true" />
<window_info content_ui="combo" id="Project" order="0" visible="true" weight="0.25" />
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
<window_info anchor="bottom" id="Messages" />
<window_info anchor="bottom" id="Database Changes" show_stripe_button="false" />
<window_info anchor="bottom" id="Version Control" show_stripe_button="false" />
<window_info anchor="bottom" id="Terminal" />
<window_info anchor="bottom" id="Event Log" side_tool="true" />
<window_info anchor="bottom" id="Message" order="0" />
<window_info anchor="bottom" id="Find" order="1" />
<window_info anchor="bottom" id="Run" order="2" weight="0.24222222" />
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
<window_info anchor="bottom" id="TODO" order="6" />
<window_info anchor="right" id="Palette" />
<window_info anchor="right" id="Theme Preview" />
<window_info anchor="right" id="Capture Analysis" />
<window_info anchor="right" id="Palette&#9;" />
<window_info anchor="right" id="Database" />
<window_info anchor="right" id="Maven Projects" weight="0.19669509" />
<window_info anchor="right" id="Commander" order="0" weight="0.4" />
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
</layout>
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="1" />
</component>
<component name="VcsContentAnnotationSettings">
<option name="myLimit" value="2678400000" />
</component>
<component name="XDebuggerManager">
<breakpoint-manager>
<breakpoints>
<line-breakpoint enabled="true" type="java-line">
<url>file://$PROJECT_DIR$/src/test/java/ru/bvn13/JProxyTest.java</url>
<line>41</line>
<properties />
<option name="timeStamp" value="1" />
</line-breakpoint>
</breakpoints>
</breakpoint-manager>
<watches-manager>
<configuration name="Application">
<watch expression="new String(buffer)" language="JAVA" />
</configuration>
</watches-manager>
</component>
<component name="debuggerHistoryManager">
<expressions id="watch">
<expression>
<expression-string>new String(buffer)</expression-string>
<language-id>JAVA</language-id>
<evaluation-mode>EXPRESSION</evaluation-mode>
</expression>
<expression>
<expression-string>buffer.toString()</expression-string>
<language-id>JAVA</language-id>
<evaluation-mode>EXPRESSION</evaluation-mode>
</expression>
</expressions>
</component>
<component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/pom.xml">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="288">
<caret line="17" column="30" selection-start-line="17" selection-start-column="30" selection-end-line="17" selection-end-column="30" />
</state>
</provider>
</entry>
<entry file="jar://C:/Program Files/Java/jdk1.8.0_162/src.zip!/java/io/DataInputStream.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="142" column="21" lean-forward="true" selection-start-line="142" selection-start-column="21" selection-end-line="142" selection-end-column="21" />
</state>
</provider>
</entry>
<entry file="jar://C:/Program Files/Java/jdk1.8.0_162/src.zip!/java/lang/Thread.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-2129">
<caret line="1896" column="23" selection-start-line="1896" selection-start-column="23" selection-end-line="1896" selection-end-column="23" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/ProxyServer.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="319">
<caret line="34" lean-forward="true" selection-start-line="34" selection-end-line="34" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/test/java/ru/bvn13/JProxyTest.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="197">
<caret line="39" column="21" lean-forward="true" selection-start-line="39" selection-start-column="21" selection-end-line="39" selection-end-column="21" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/JProxy.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102">
<caret line="6" column="74" selection-start-line="6" selection-start-column="74" selection-end-line="6" selection-end-column="74" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/src/main/java/ru/bvn13/jproxy/ClientListener.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="155">
<caret line="29" column="30" selection-start-line="29" selection-start-column="30" selection-end-line="29" selection-end-column="30" />
<folding>
<element signature="imports" expanded="true" />
</folding>
</state>
</provider>
</entry>
</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>jdk1.8</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>jproxy</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.23210071" />
<option value="0.6" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ProjectJDKs.UI">
<settings>
<last-edited>1.8</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.20316301" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
<state key="ProjectLibrariesConfigurable.UI">
<settings>
<last-edited>Maven: junit:junit:4.12</last-edited>
<splitter-proportions>
<option name="proportions">
<list>
<option value="0.2" />
</list>
</option>
</splitter-proportions>
</settings>
</state>
</states>
</component>
</project>

16
jproxy.iml 100644
View File

@ -0,0 +1,16 @@
<?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_8">
<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/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.12" level="project" />
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
</component>
</module>

65
pom.xml 100644
View File

@ -0,0 +1,65 @@
<?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>ru.bvn13.jproxy</groupId>
<artifactId>jproxy</artifactId>
<version>1.0</version>
<name>jproxy</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

View File

@ -0,0 +1,127 @@
package ru.bvn13.jproxy;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Created by bvn13 on 20.10.2018.
*/
public class ClientListener implements Runnable {
private ExecutorService executor;
private Socket internalSocket;
private Socket externalSocket;
private String extHost;
private int extPort;
private DataInputStream internalInStream;
private DataInputStream externalInStream;
private DataOutputStream internalOutStream;
private DataOutputStream externalOutStream;
AtomicBoolean isTerminated = new AtomicBoolean(false);
private static class SenderThread implements Runnable {
private Socket senderSocket;
private Socket receiverSocket;
private DataInputStream sender;
private DataOutputStream receiver;
private int bufferLength;
private String name;
private ClientListener owner;
public SenderThread(ClientListener owner, String name, Socket senderSocket, Socket receiverSocket, DataInputStream sender, DataOutputStream receiver, int bufferLength) {
this.owner = owner;
this.name = name;
this.senderSocket = senderSocket;
this.receiverSocket = receiverSocket;
this.sender = sender;
this.receiver = receiver;
this.bufferLength = bufferLength;
}
@Override
public void run() {
byte[] buffer = new byte[bufferLength];
try {
for (Thread.yield(); !senderSocket.isClosed() && !receiverSocket.isClosed(); Thread.yield()) {
System.out.println(String.format("%s waits for data...", name));
int bytesRead = sender.read(buffer, 0, bufferLength);
if (bytesRead < 0) {
System.out.println(String.format("%s - transmission terminated", name));
owner.isTerminated.set(true);
return;
}
System.out.println(String.format("%s read %d bytes", name, bytesRead));
receiver.write(buffer, 0, bytesRead);
receiver.flush();
System.out.println(String.format("%s sent %d bytes", name, bytesRead));
}
} catch (IOException e) {
e.printStackTrace();
owner.isTerminated.set(true);
} catch (Throwable t) {
t.printStackTrace();
owner.isTerminated.set(true);
}
}
}
public ClientListener(Socket socket, String extHost, int extPort) {
Objects.requireNonNull(socket, "socket required");
Objects.requireNonNull(extHost, "host required");
this.internalSocket = socket;
this.extHost = extHost;
this.extPort = extPort;
this.executor = Executors.newFixedThreadPool(2);
}
@Override
public void run() {
System.out.println("STARTING");
try {
this.externalSocket = new Socket(extHost, extPort);
this.internalInStream = new DataInputStream(this.internalSocket.getInputStream());
this.internalOutStream = new DataOutputStream(this.internalSocket.getOutputStream());
this.externalInStream = new DataInputStream(this.externalSocket.getInputStream());
this.externalOutStream = new DataOutputStream(this.externalSocket.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
return;
}
startInternalToExternalSender();
startExternalToInternalSender();
for (Thread.yield(); !internalSocket.isClosed() && !externalSocket.isClosed() && !isTerminated.get(); Thread.yield()) {
Thread.yield();
}
System.out.println("STOPPING");
executor.shutdown();
System.out.println("STOPPED");
}
private void startInternalToExternalSender() {
executor.execute(new SenderThread(this,"SENDER", internalSocket, externalSocket, internalInStream, externalOutStream, 4096));
}
private void startExternalToInternalSender() {
executor.execute(new SenderThread(this,"RECEIVER", externalSocket, internalSocket, externalInStream, internalOutStream, 4096));
}
}

View File

@ -0,0 +1,10 @@
package ru.bvn13.jproxy;
public class JProxy
{
public static void main( String[] args )
{
ProxyServer server = new ProxyServer(8099, "192.168.199.200", 1122);
}
}

View File

@ -0,0 +1,38 @@
package ru.bvn13.jproxy;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Created by bvn13 on 20.10.2018.
*/
public class ProxyServer {
private final ExecutorService executor = Executors.newCachedThreadPool();
public ProxyServer(int portListen, String extHost, int extPort) {
executor.execute(() -> {
try (ServerSocket server = new ServerSocket(portListen)) {
while (!server.isClosed()) {
Socket client = server.accept();
executor.execute(new ClientListener(client, extHost, extPort));
}
} catch (IOException e) {
e.printStackTrace();
} finally {
executor.shutdown();
}
});
}
}

View File

@ -0,0 +1,77 @@
package ru.bvn13;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
import ru.bvn13.jproxy.JProxy;
import ru.bvn13.jproxy.ProxyServer;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/**
* Unit test for simple JProxy.
*/
public class JProxyTest
{
private ProxyServer proxy;
private ExecutorService executor = Executors.newSingleThreadExecutor();
private String request = "GET / HTTP/1.1\n" +
"User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)\n" +
"Host: yandex.ru\n" +
"Accept-Language: en-us\n" +
"Accept-Encoding: gzip, deflate\n" +
"Connection: Keep-Alive";
@Before
public void before() {
//proxy = new ProxyServer(8099, "yandex.ru", 80);
}
@Test
public void testYandex() {
Socket socket = null;
DataInputStream in = null;
DataOutputStream out = null;
byte[] buffer = new byte[4096];
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
socket = new Socket("localhost", 8099);
in = new DataInputStream(socket.getInputStream());
out = new DataOutputStream(socket.getOutputStream());
out.write(request.getBytes());
out.flush();
int bytesRead = 0;
do {
bytesRead = in.read(buffer, 0, 4096);
for (int i = 0; i < bytesRead; i++) {
System.out.print(buffer[i]);
}
System.out.println();
} while (bytesRead > 0);
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("", e);
}
}
}