├── .gitignore ├── .java-version ├── LICENSE.txt ├── README.md ├── app-update-ws ├── README.md └── restclient.json ├── build.gradle ├── cli ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── wiztools │ └── restclient │ └── cli │ ├── CliMain.java │ └── NonExistFileGenerator.java ├── dist-build.sh ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── icons-src ├── add-affinity_designer2.afdesign ├── edit-affinity_designer2.afdesign ├── file-open-affinity_designer2.afdesign ├── go-affinity_designer2.afdesign └── pencil-affinity_designer2.afdesign ├── lib ├── build.gradle └── src │ ├── main │ └── java │ │ └── org │ │ └── wiztools │ │ └── restclient │ │ ├── AppBundler.java │ │ ├── Base64Exception.java │ │ ├── FileType.java │ │ ├── GlobalOptions.java │ │ ├── HTTPClientRequestExecuter.java │ │ ├── HTTPClientUtil.java │ │ ├── IGlobalOptions.java │ │ ├── ImplementedBy.java │ │ ├── MessageI18N.java │ │ ├── MultipleRequestInSameRequestExecuterException.java │ │ ├── OptionsLock.java │ │ ├── ProxyConfig.java │ │ ├── RCConstants.java │ │ ├── RESTTestCase.java │ │ ├── ServiceLocator.java │ │ ├── TestUtil.java │ │ ├── Versions.java │ │ ├── View.java │ │ ├── ViewAdapter.java │ │ ├── bean │ │ ├── AbstractReqEntitySimpleBean.java │ │ ├── Auth.java │ │ ├── AuthorizationHeaderAuth.java │ │ ├── AuthorizationHeaderAuthBean.java │ │ ├── BasicAuth.java │ │ ├── BasicAuthBean.java │ │ ├── BasicDigestAuth.java │ │ ├── BasicDigestAuthBaseBean.java │ │ ├── ContentType.java │ │ ├── ContentTypeBean.java │ │ ├── DigestAuth.java │ │ ├── DigestAuthBean.java │ │ ├── HTTPAuthMethod.java │ │ ├── HTTPMethod.java │ │ ├── HTTPVersion.java │ │ ├── HostnameVerifier.java │ │ ├── KeyStore.java │ │ ├── KeyStoreBean.java │ │ ├── KeyStoreType.java │ │ ├── MultipartMode.java │ │ ├── MultipartSubtype.java │ │ ├── OAuth2BearerAuth.java │ │ ├── OAuth2BearerAuthBean.java │ │ ├── ReqEntity.java │ │ ├── ReqEntityBasePart.java │ │ ├── ReqEntityByteArray.java │ │ ├── ReqEntityByteArrayBean.java │ │ ├── ReqEntityFile.java │ │ ├── ReqEntityFileBean.java │ │ ├── ReqEntityFilePart.java │ │ ├── ReqEntityFilePartBean.java │ │ ├── ReqEntityMultipart.java │ │ ├── ReqEntityMultipartBean.java │ │ ├── ReqEntityPart.java │ │ ├── ReqEntitySimple.java │ │ ├── ReqEntityStream.java │ │ ├── ReqEntityString.java │ │ ├── ReqEntityStringBean.java │ │ ├── ReqEntityStringPart.java │ │ ├── ReqEntityStringPartBean.java │ │ ├── ReqEntityUrlStream.java │ │ ├── ReqEntityUrlStreamBean.java │ │ ├── ReqResBean.java │ │ ├── Request.java │ │ ├── RequestBean.java │ │ ├── RequestExecuter.java │ │ ├── Response.java │ │ ├── ResponseBean.java │ │ ├── TLSReq.java │ │ ├── TLSReqBean.java │ │ ├── TestException.java │ │ ├── TestExceptionResult.java │ │ ├── TestExceptionResultBean.java │ │ ├── TestResult.java │ │ ├── TestResultBean.java │ │ ├── UsernamePasswordAuth.java │ │ └── UsernamePasswordAuthBaseBean.java │ │ ├── http │ │ └── RESTClientCookieStore.java │ │ ├── persistence │ │ ├── PersistenceException.java │ │ ├── PersistenceRead.java │ │ ├── PersistenceWrite.java │ │ ├── XMLCollectionUtil.java │ │ ├── XMLException.java │ │ ├── XmlAuthUtil.java │ │ ├── XmlBodyRead.java │ │ ├── XmlBodyWrite.java │ │ ├── XmlPersistenceRead.java │ │ ├── XmlPersistenceWrite.java │ │ └── XmlTLSUtil.java │ │ ├── test │ │ └── RESTTestCase.java │ │ └── util │ │ ├── ConfigUtil.java │ │ ├── ContentTypesCommon.java │ │ ├── HTMLIndentUtil.java │ │ ├── HexDump.java │ │ ├── HttpUtil.java │ │ ├── IDNUtil.java │ │ ├── JSONUtil.java │ │ ├── MultiEntryRes.java │ │ ├── MultiEntryUtil.java │ │ ├── SSLUtil.java │ │ ├── Url.java │ │ ├── Util.java │ │ ├── XMLIndentUtil.java │ │ └── XMLUtil.java │ └── test │ ├── java │ └── org │ │ └── wiztools │ │ └── restclient │ │ ├── AuthElementTest.java │ │ ├── BodyPersistenceTest.java │ │ ├── HTTPClientRequestExecuterTest.java │ │ ├── SslTest.java │ │ ├── UtilTest.java │ │ ├── XMLUtilTest.java │ │ └── util │ │ ├── HttpUtilTest.java │ │ ├── IDNUtilTest.java │ │ ├── JSONUtilTest.java │ │ └── XMLIndentUtilTest.java │ └── resources │ ├── input_ISO.xml │ ├── issue_191 │ └── one-line.json │ ├── org │ └── wiztools │ │ └── restclient │ │ └── xml │ │ ├── charset1.xml │ │ ├── charset2.xml │ │ └── charset3.xml │ ├── output_ISO.xml │ ├── reqBodyByteArray.rcq │ ├── reqBodyFile.rcq │ ├── reqBodyMultipart.rcq │ ├── reqBodyString.rcq │ ├── reqFromXml.rcq │ ├── reqOAuth2Bearer.rcq │ ├── reqSsl.rcq │ ├── resFromXml.rcs │ ├── resTestScriptIntegrity.rcq │ └── subhash_by_aarthi.jpeg ├── mac-run-ui.sh ├── server ├── build.gradle └── src │ └── main │ └── java │ └── org │ └── wiztools │ └── restclient │ └── server │ ├── TraceServer.java │ ├── TraceServlet.java │ └── Util.java ├── settings.gradle └── ui ├── ant-lib ├── ant-xpath-task-1.0-SNAPSHOT.jar └── appbundler-1.0ea.jar ├── build.gradle ├── graphics-src ├── 30_icon_art_text2.artx │ ├── Preview │ │ └── preview.png │ ├── QuickLook │ │ └── Preview.pdf │ └── doc.thread ├── README.md ├── mac-icon_1024.artx │ ├── Preview │ │ └── preview.png │ ├── QuickLook │ │ └── Preview.pdf │ └── doc.thread └── rest-client-splash.artx │ ├── Preview │ └── preview.png │ ├── QuickLook │ └── Preview.pdf │ └── doc.thread └── src ├── main ├── app-resources │ └── rest-client_30.icns ├── java │ └── org │ │ └── wiztools │ │ └── restclient │ │ └── ui │ │ ├── AboutDialog.java │ │ ├── AbstractScriptEditor.java │ │ ├── AuthHelper.java │ │ ├── EncodingUtil.java │ │ ├── EscapableDialog.java │ │ ├── FileChooserType.java │ │ ├── FileOpenUtil.java │ │ ├── FontableEditor.java │ │ ├── ISessionView.java │ │ ├── KeyValMultiEntryDialog.java │ │ ├── Main.java │ │ ├── MessageDialog.java │ │ ├── Mime.java │ │ ├── MultiEntryAdd.java │ │ ├── Native.java │ │ ├── PasswordGenDialog.java │ │ ├── RCFileFilter.java │ │ ├── RCFileView.java │ │ ├── RCUIConstants.java │ │ ├── RESTMain.java │ │ ├── RESTUserInterface.java │ │ ├── RESTView.java │ │ ├── RESTViewImpl.java │ │ ├── RSyntaxScriptEditor.java │ │ ├── RecentFilesHelper.java │ │ ├── SVGLoad.java │ │ ├── ScriptEditor.java │ │ ├── ScriptEditorFactory.java │ │ ├── ScrollableComponent.java │ │ ├── SessionFrame.java │ │ ├── SessionTableModel.java │ │ ├── StatusBarPanel.java │ │ ├── StatusBarPanelImpl.java │ │ ├── TextEditorSyntax.java │ │ ├── TwoColumnTableModel.java │ │ ├── TwoColumnTablePanel.java │ │ ├── UIUtil.java │ │ ├── URLEncodeDecodeDialog.java │ │ ├── ViewPanel.java │ │ ├── component │ │ ├── BackgroundFormatterJob.java │ │ ├── BodyPopupMenu.java │ │ └── BodyPopupMenuListener.java │ │ ├── dnd │ │ ├── DndAction.java │ │ └── FileDropTargetListener.java │ │ ├── history │ │ ├── HistoryManager.java │ │ └── HistoryManagerImpl.java │ │ ├── lifecycle │ │ ├── LifecycleManager.java │ │ ├── LifecycleManagerImpl.java │ │ ├── Shutdown.java │ │ └── Startup.java │ │ ├── option │ │ ├── IOptionsPanel.java │ │ ├── OptionsConnectionPanel.java │ │ ├── OptionsDialog.java │ │ ├── OptionsEtcPanel.java │ │ ├── OptionsFontPanel.java │ │ └── OptionsProxyPanel.java │ │ ├── reqauth │ │ ├── ReqAuthPanel.java │ │ └── ReqAuthPanelImpl.java │ │ ├── reqbody │ │ ├── AddMultipartBaseDialog.java │ │ ├── AddMultipartFileDialog.java │ │ ├── AddMultipartPartListener.java │ │ ├── AddMultipartStringDialog.java │ │ ├── BodyContentTypeDialog.java │ │ ├── ContentTypeCharsetChangeListener.java │ │ ├── ContentTypeCharsetComponent.java │ │ ├── ContentTypeCharsetComponentImpl.java │ │ ├── ContentTypeSelectorOnFile.java │ │ ├── MultipartOptionsDialog.java │ │ ├── ParameterDialog.java │ │ ├── ParameterGenerationListener.java │ │ ├── ReqBodyPanel.java │ │ ├── ReqBodyPanelByteArray.java │ │ ├── ReqBodyPanelFile.java │ │ ├── ReqBodyPanelImpl.java │ │ ├── ReqBodyPanelMultipart.java │ │ ├── ReqBodyPanelNone.java │ │ ├── ReqBodyPanelString.java │ │ └── ReqBodyPanelUrlStream.java │ │ ├── reqetc │ │ ├── ReqEtcPanel.java │ │ └── ReqEtcPanelImpl.java │ │ ├── reqgo │ │ ├── ReqUrlGoPanel.java │ │ ├── ReqUrlGoPanelImpl.java │ │ ├── UrlComboBox.java │ │ └── UrlListPersistUtil.java │ │ ├── reqmethod │ │ ├── ReqMethodPanel.java │ │ └── ReqMethodPanelImpl.java │ │ ├── reqtest │ │ ├── ReqTestPanel.java │ │ ├── ReqTestPanelImpl.java │ │ └── RunTestDialog.java │ │ ├── reqtls │ │ ├── KeyStoreDialog.java │ │ ├── KeyStoreListener.java │ │ ├── KeyStorePanel.java │ │ ├── ReqTLSPanel.java │ │ ├── ReqTLSPanelImpl.java │ │ └── StoreTypePanel.java │ │ ├── resbody │ │ ├── AbstractResBody.java │ │ ├── ResBodyBinaryPanel.java │ │ ├── ResBodyImagePanel.java │ │ ├── ResBodyNonePanel.java │ │ ├── ResBodyPanel.java │ │ ├── ResBodyPanelImpl.java │ │ └── ResBodyTextPanel.java │ │ ├── resheader │ │ ├── ResHeaderPanel.java │ │ ├── ResHeaderPanelImpl.java │ │ └── ResponseHeaderTableModel.java │ │ ├── resstats │ │ ├── ResStatsPanel.java │ │ └── ResStatsPanelImpl.java │ │ ├── resstatus │ │ ├── ResStatusPanel.java │ │ └── ResStatusPanelImpl.java │ │ ├── restest │ │ ├── FailureTableModel.java │ │ ├── ResTestPanel.java │ │ └── ResTestPanelImpl.java │ │ └── update │ │ └── AppUpdateRunner.java └── resources │ └── org │ └── wiztools │ └── restclient │ ├── PasswordHelp.txt │ ├── Splash.png │ ├── add.svg │ ├── edit.svg │ ├── go.svg │ ├── icon.svg │ ├── load_from_file.svg │ ├── logo_30.png │ ├── messages.properties │ ├── mime.types │ ├── pencil-add.svg │ ├── s_archive.svg │ ├── s_cancel.svg │ ├── s_cog.svg │ ├── s_delete.svg │ ├── s_file.svg │ ├── s_folder.svg │ ├── s_help.svg │ ├── s_insert_parameters.svg │ ├── s_lightning.svg │ ├── s_request.svg │ ├── s_response.svg │ ├── s_stop.svg │ ├── s_tag.svg │ ├── s_wand.svg │ ├── test-script.template │ ├── test │ ├── s_accept.svg │ ├── s_contrast_low.svg │ └── s_cross.svg │ ├── tls.md │ └── uioptionsdialog.properties └── test └── java └── org └── wiztools └── restclient └── ui ├── RecentFilesHelperTest.java ├── history └── HistoryManagerImplTest.java └── update └── AppUpdateRunnerTest.java /.gitignore: -------------------------------------------------------------------------------- 1 | /restclient-server/target/ 2 | /restclient-lib/target/ 3 | /restclient-ui/target/ 4 | /restclient-cli/target/ 5 | /restclient-jfx/target/ 6 | /target/ 7 | /build/ 8 | **/build/ 9 | .idea 10 | *.iml 11 | .gradle 12 | /.nb-gradle/ 13 | .classpath 14 | .project 15 | .settings/ 16 | .vscode/ 17 | bin/ -------------------------------------------------------------------------------- /.java-version: -------------------------------------------------------------------------------- 1 | 17 2 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WizTools.org RESTClient 2 | 3 | ## About 4 | 5 | RESTClient is a Java application to test RESTful webservices. It can be used to test variety of HTTP communications. There are two executables: 6 | 7 | * GUI version (restclient-ui-X-fat.jar download) 8 | * Cli version for batch execution of .rcq files (restclient-cli-X-fat.jar download) 9 | 10 | ### Since 2007 11 | 12 | The first version of RESTClient was released late 2007. Since then the tool has been in continuous development. Visit [project news page](https://github.com/wiztools/rest-client/wiki/News) for history of releases. 13 | 14 | ### Download / Install 15 | 16 | Release binaries are available from [GitHub releases](https://github.com/wiztools/rest-client/releases). 17 | 18 | Archives of pre-GitHub era release-builds are available at [WizTools.org Download](http://download.wiztools.org/rest-client/archive/index.html). 19 | 20 | ### Support 21 | 22 | Post your queries in [Google Group mailing list](https://groups.google.com/forum/#!forum/rest-client). 23 | 24 | ### Book 25 | 26 | [![](http://books.wiztools.org/restclient-book/restclient-book-small.jpg)](http://www.amazon.com/dp/B00KEADQF2?tag=wiztooorg-20) 27 | 28 | ### Screenshot 29 | 30 | 4.0 release: 31 | 32 | [![](https://live.staticflickr.com/65535/54274308984_5307e9a09c_o_d.png)](https://www.flickr.com/photos/subwiz/54274308984/) 33 | 34 | More screenshots here: http://flickr.com/photos/subwiz/tags/restclient/ 35 | 36 | ### Subscribing to New Releases 37 | 38 | Releases and product information is published in the following channels: 39 | 40 | * [Blog](https://medium.com/wiztools) 41 | -------------------------------------------------------------------------------- /app-update-ws/README.md: -------------------------------------------------------------------------------- 1 | To be uploaded to: 2 | 3 | http://static.wiztools.org/v/restclient.json 4 | 5 | -------------------------------------------------------------------------------- /app-update-ws/restclient.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "4.0.3", 3 | "dl_url": "https://github.com/wiztools/rest-client/releases/tag/v4.0.3", 4 | "release_notes_url": "https://github.com/wiztools/rest-client/releases/tag/v4.0.3" 5 | } 6 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | allprojects { 2 | repositories { 3 | mavenLocal() 4 | mavenCentral() 5 | maven { 6 | url = "https://jitpack.io" 7 | } 8 | } 9 | tasks.withType(JavaCompile) { 10 | sourceCompatibility = '17' 11 | targetCompatibility = '17' 12 | } 13 | gradle.projectsEvaluated { 14 | tasks.withType(JavaCompile) { 15 | // options.compilerArgs << "-Xlint:all" 16 | options.compilerArgs << "-Xlint:deprecation" << "-Xlint:unchecked" 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /cli/build.gradle: -------------------------------------------------------------------------------- 1 | plugins{ 2 | id 'java' 3 | id 'application' 4 | id 'com.gradleup.shadow' version '9.0.0-beta11' 5 | } 6 | 7 | // Application plugin config: 8 | application{ 9 | mainClass = 'org.wiztools.restclient.cli.CliMain' 10 | applicationName = 'restclient-cli' 11 | applicationDefaultJvmArgs = ['-Xms128m', '-Xmx512m'] 12 | } 13 | 14 | tasks.withType(Tar) { 15 | compression = Compression.GZIP 16 | archiveExtension = 'tgz' // set the extension to .tgz instead of .tar.gz 17 | } 18 | 19 | repositories { 20 | mavenLocal() 21 | mavenCentral() 22 | } 23 | 24 | tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { 25 | archiveBaseName = 'restclient-cli' 26 | archiveClassifier = 'fat' 27 | } 28 | 29 | dependencies { 30 | implementation project(':lib'), 31 | 'com.google.code.cli-parser:cli:7', 32 | 'org.slf4j:slf4j-simple:2.0.17' // for jetty logs 33 | testImplementation 'junit:junit:4.+' 34 | } 35 | -------------------------------------------------------------------------------- /cli/src/main/java/org/wiztools/restclient/cli/NonExistFileGenerator.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.cli; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | class NonExistFileGenerator { 10 | 11 | private final File outDir; 12 | private final String fileName; 13 | private final String extension; 14 | 15 | NonExistFileGenerator(File outDir, String fileName, String extension) { 16 | this.outDir = outDir; 17 | this.fileName = fileName; 18 | this.extension = extension; 19 | } 20 | 21 | File getFile() { 22 | final File outFile = new File(outDir, fileName + extension); 23 | if(outFile.exists()){ 24 | System.err.println("File exists: " + outFile.getAbsolutePath()); 25 | for(int i = 0; i< Integer.MAX_VALUE; i++){ 26 | final File newOutFile = new File(outDir, fileName + "_" + i + extension); 27 | if(!newOutFile.exists()){ 28 | System.err.println("Using alternative: " + newOutFile.getAbsolutePath()); 29 | return newOutFile; 30 | } 31 | } 32 | } 33 | return outFile; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /dist-build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | ./gradlew clean build 4 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | version=4.0.4-SNAPSHOT 2 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-all.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /icons-src/add-affinity_designer2.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/icons-src/add-affinity_designer2.afdesign -------------------------------------------------------------------------------- /icons-src/edit-affinity_designer2.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/icons-src/edit-affinity_designer2.afdesign -------------------------------------------------------------------------------- /icons-src/file-open-affinity_designer2.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/icons-src/file-open-affinity_designer2.afdesign -------------------------------------------------------------------------------- /icons-src/go-affinity_designer2.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/icons-src/go-affinity_designer2.afdesign -------------------------------------------------------------------------------- /icons-src/pencil-affinity_designer2.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/icons-src/pencil-affinity_designer2.afdesign -------------------------------------------------------------------------------- /lib/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | dependencies { 6 | api project(':server'), 7 | 'javax.inject:javax.inject:1', 8 | 'junit:junit:4.+', 9 | 'commons-codec:commons-codec:1.17.2', 10 | 'javax.xml.bind:jaxb-api:2.3.1', 11 | 'javax.annotation:javax.annotation-api:1.3.2', 12 | 'com.fasterxml.jackson.core:jackson-databind:2.18.2', 13 | 'org.apache.httpcomponents.client5:httpclient5:5.4.4', 14 | 'org.codehaus.groovy:groovy-all:3.0.23', 15 | 'net.htmlparser.jericho:jericho-html:3.4', 16 | 'com.github.wiztools:app-update-framework:app-update-0.2.1' 17 | api('xom:xom:1.3.9') { 18 | exclude group: 'xerces', module: 'xmlParserAPIs' 19 | exclude group: 'xerces', module: 'xercesImpl' 20 | exclude group: 'xalan', module: 'xalan' 21 | exclude group: 'jaxen', module: 'jaxen' 22 | } 23 | testImplementation 'junit:junit:4.+', 24 | 'com.google.code.gson:gson:2.11.0' 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/AppBundler.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | /** 4 | * Properties defined by AppBundler: 5 | * https://bitbucket.org/infinitekind/appbundler 6 | * @author subwiz 7 | */ 8 | final class AppBundler { 9 | static final String LibraryDirectory = System.getProperty("LibraryDirectory"); 10 | static final String DocumentsDirectory = System.getProperty("DocumentsDirectory"); 11 | static final String CachesDirectory = System.getProperty("CachesDirectory"); 12 | static final String ApplicationSupportDirectory = System.getProperty("ApplicationSupportDirectory"); 13 | static final String SandboxEnabled = System.getProperty("SandboxEnabled"); 14 | } 15 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/Base64Exception.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class Base64Exception extends RuntimeException { 8 | 9 | public Base64Exception(String string) { 10 | super(string); 11 | } 12 | 13 | public Base64Exception(Throwable thrwbl) { 14 | super(thrwbl); 15 | } 16 | 17 | public Base64Exception(String string, Throwable thrwbl) { 18 | super(string, thrwbl); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/IGlobalOptions.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | import java.io.File; 4 | import org.wiztools.commons.SystemProperty; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | @ImplementedBy(GlobalOptions.class) 11 | public interface IGlobalOptions { 12 | 13 | File CONF_DIR = new File( 14 | SystemProperty.userHome + SystemProperty.fileSeparator 15 | + ".rest-client"); 16 | 17 | OptionsLock acquire(); 18 | 19 | String getProperty(String key); 20 | 21 | boolean isPropertyTrue(String key); 22 | 23 | void removeProperty(String key); 24 | 25 | void setProperty(String key, String value); 26 | 27 | void writeProperties(); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/ImplementedBy.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Retention(RetentionPolicy.RUNTIME) 9 | @Target(ElementType.TYPE) 10 | public @interface ImplementedBy { 11 | Class value(); 12 | } -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/MessageI18N.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | import java.text.MessageFormat; 4 | import java.util.Arrays; 5 | import java.util.ResourceBundle; 6 | 7 | /** 8 | * 9 | * @author Subhash 10 | */ 11 | public class MessageI18N { 12 | private static ResourceBundle rb = ResourceBundle.getBundle("org.wiztools.restclient.messages"); 13 | 14 | public static String getMessage(final String key){ 15 | return rb.getString(key); 16 | } 17 | 18 | public static String getMessage(final String key, final String[] parameters){ 19 | return MessageFormat.format(rb.getString(key), Arrays.stream(parameters).toArray(Object[]::new)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/MultipleRequestInSameRequestExecuterException.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class MultipleRequestInSameRequestExecuterException extends RuntimeException { 8 | public MultipleRequestInSameRequestExecuterException(String msg){ 9 | super(msg); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/OptionsLock.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | import java.io.Closeable; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface OptionsLock extends Closeable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/RCConstants.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | /** 4 | * 5 | * @author Subhash 6 | */ 7 | public interface RCConstants { 8 | public final String TITLE = "WizTools.org RESTClient "; 9 | public final String SHORT_TITLE = "RESTClient "; 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/RESTTestCase.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | import org.wiztools.restclient.bean.Response; 4 | import org.wiztools.restclient.bean.Request; 5 | import groovy.test.GroovyTestCase; 6 | 7 | /** 8 | * 9 | * @author schandran 10 | */ 11 | public class RESTTestCase extends GroovyTestCase { 12 | 13 | protected Request request; 14 | protected Response response; 15 | 16 | public void setRequest(final Request request){ 17 | this.request = request; 18 | } 19 | 20 | public void setResponse(final Response response){ 21 | this.response = response; 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/Versions.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | import org.wiztools.appupdate.Version; 4 | import org.wiztools.appupdate.VersionImpl; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public final class Versions { 11 | public static final String CURRENT = "4.0.4"; 12 | 13 | private static final Version MIN = new VersionImpl("3.0"); 14 | private static final Version MAX = new VersionImpl(CURRENT); 15 | 16 | public static void versionValidCheck(final String restVersion) 17 | throws VersionValidationException { 18 | if (restVersion == null) { 19 | throw new VersionValidationException("Attribute `version' not available for root element"); 20 | } 21 | Version stored = new VersionImpl(restVersion); 22 | if(!stored.isWithin(MIN, MAX)) { 23 | throw new VersionValidationException("Version not supported"); 24 | } 25 | } 26 | 27 | public static class VersionValidationException extends Exception { 28 | public VersionValidationException(String message) { 29 | super(message); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/View.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | import org.wiztools.restclient.bean.Response; 4 | import org.wiztools.restclient.bean.Request; 5 | 6 | /** 7 | * This is the callback interface for RequestExecuter. An implementation 8 | * of this interface needs to be passed to RequestExecuter (actually, a number 9 | * of View implementation could be passed to RequestExecuter--it is an vararg 10 | * parameter). The callback methods will be called during various stages in 11 | * request processing. 12 | * @author subwiz 13 | */ 14 | public interface View { 15 | /** 16 | * This is called just before starting the request processing. 17 | * @param request The same request object passed to RequestExecuter. 18 | */ 19 | public void doStart(Request request); 20 | 21 | /** 22 | * When the request processing is completed, the response object is 23 | * received by this method. 24 | * @param response The response object from the successful request execution. 25 | */ 26 | public void doResponse(Response response); 27 | 28 | /** 29 | * This callback is called when the request is aborted during its progress 30 | * by the call of RequestExecuter.abortExecution(). 31 | */ 32 | public void doCancelled(); 33 | 34 | /** 35 | * When the request has completed, this method is called. 36 | */ 37 | public void doEnd(); 38 | 39 | /** 40 | * Whenever an error is encountered, this is called. This usually is the 41 | * error trace. 42 | * @param error The error as string. 43 | */ 44 | public void doError(String error); 45 | } 46 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/ViewAdapter.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient; 2 | 3 | import org.wiztools.restclient.bean.Response; 4 | import org.wiztools.restclient.bean.Request; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public class ViewAdapter implements View { 11 | 12 | public void doStart(Request request) { 13 | 14 | } 15 | 16 | public void doResponse(Response response) { 17 | 18 | } 19 | 20 | public void doCancelled() { 21 | 22 | } 23 | 24 | public void doEnd() { 25 | 26 | } 27 | 28 | public void doError(String error) { 29 | 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/AbstractReqEntitySimpleBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import org.wiztools.restclient.util.HttpUtil; 4 | 5 | /** 6 | * This class is declared abstract because we do not want anyone to instantiate 7 | * this class. The only purpose of this class is extension. 8 | * @author subwiz 9 | */ 10 | public abstract class AbstractReqEntitySimpleBean implements ReqEntitySimple { 11 | 12 | protected final ContentType contentType; 13 | 14 | public AbstractReqEntitySimpleBean(ContentType contentType) { 15 | this.contentType = contentType; 16 | } 17 | 18 | @Override 19 | public ContentType getContentType() { 20 | return contentType; 21 | } 22 | 23 | @Override 24 | public String getContentTypeCharsetFormatted() { 25 | return HttpUtil.getFormattedContentType(contentType); 26 | } 27 | 28 | @Override 29 | public Object clone() { 30 | return null; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/Auth.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * Marker interface to hold all Auth types. 7 | * @author subwiz 8 | */ 9 | public interface Auth extends Serializable { 10 | 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/AuthorizationHeaderAuth.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface AuthorizationHeaderAuth extends Auth { 8 | String getAuthorizationHeaderValue(); 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/AuthorizationHeaderAuthBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class AuthorizationHeaderAuthBean implements AuthorizationHeaderAuth { 8 | 9 | protected String authorizationHeaderValue; 10 | 11 | public void setAuthorizationHeaderValue(String value) { 12 | authorizationHeaderValue = value; 13 | } 14 | 15 | @Override 16 | public String getAuthorizationHeaderValue() { 17 | return authorizationHeaderValue; 18 | } 19 | 20 | @Override 21 | public boolean equals(Object obj) { 22 | if (obj == null) { 23 | return false; 24 | } 25 | if (getClass() != obj.getClass()) { 26 | return false; 27 | } 28 | final AuthorizationHeaderAuthBean other = (AuthorizationHeaderAuthBean) obj; 29 | if ((this.authorizationHeaderValue == null) ? (other.authorizationHeaderValue != null) : !this.authorizationHeaderValue.equals(other.authorizationHeaderValue)) { 30 | return false; 31 | } 32 | return true; 33 | } 34 | 35 | @Override 36 | public int hashCode() { 37 | int hash = 5; 38 | hash = 97 * hash + (this.authorizationHeaderValue != null ? this.authorizationHeaderValue.hashCode() : 0); 39 | return hash; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "@AuthorizationHeaderAuth[authorizationHeaderValue=" 45 | + authorizationHeaderValue + "]"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/BasicAuth.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface BasicAuth extends BasicDigestAuth { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/BasicAuthBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class BasicAuthBean extends BasicDigestAuthBaseBean implements BasicAuth { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/BasicDigestAuth.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface BasicDigestAuth extends UsernamePasswordAuth { 8 | String getHost(); 9 | String getRealm(); 10 | boolean isPreemptive(); 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/BasicDigestAuthBaseBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class BasicDigestAuthBaseBean extends UsernamePasswordAuthBaseBean implements BasicDigestAuth { 8 | 9 | private String host; 10 | private String realm; 11 | private boolean preemptive; 12 | 13 | public void setHost(String host) { 14 | this.host = host; 15 | } 16 | 17 | public void setPreemptive(boolean preemptive) { 18 | this.preemptive = preemptive; 19 | } 20 | 21 | public void setRealm(String realm) { 22 | this.realm = realm; 23 | } 24 | 25 | @Override 26 | public String getHost() { 27 | return host; 28 | } 29 | 30 | @Override 31 | public String getRealm() { 32 | return realm; 33 | } 34 | 35 | @Override 36 | public boolean isPreemptive() { 37 | return preemptive; 38 | } 39 | 40 | @Override 41 | public boolean equals(Object obj) { 42 | if (obj == null) { 43 | return false; 44 | } 45 | if (getClass() != obj.getClass()) { 46 | return false; 47 | } 48 | if(!super.equals(obj)) { 49 | return false; 50 | } 51 | final BasicDigestAuthBaseBean other = (BasicDigestAuthBaseBean) obj; 52 | if ((this.host == null) ? (other.host != null) : !this.host.equals(other.host)) { 53 | return false; 54 | } 55 | if ((this.realm == null) ? (other.realm != null) : !this.realm.equals(other.realm)) { 56 | return false; 57 | } 58 | if (this.preemptive != other.preemptive) { 59 | return false; 60 | } 61 | return true; 62 | } 63 | 64 | @Override 65 | public int hashCode() { 66 | int hash = super.hashCode(); 67 | hash = 13 * hash + (this.host != null ? this.host.hashCode() : 0); 68 | hash = 13 * hash + (this.realm != null ? this.realm.hashCode() : 0); 69 | hash = 13 * hash + (this.preemptive ? 1 : 0); 70 | return hash; 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | StringBuilder sb = new StringBuilder(); 76 | sb.append("@BasicDigestAuth["); 77 | sb.append("username=").append(username).append(", "); 78 | sb.append("password-length=").append(password.length).append(", "); 79 | sb.append("host=").append(host).append(", "); 80 | sb.append("realm=").append(realm).append(", "); 81 | sb.append("preemptive=").append(preemptive); 82 | sb.append("]"); 83 | return sb.toString(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ContentType.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.nio.charset.Charset; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface ContentType { 10 | String getContentType(); 11 | Charset getCharset(); 12 | } 13 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ContentTypeBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.nio.charset.Charset; 4 | import org.wiztools.commons.StringUtil; 5 | import org.wiztools.restclient.util.HttpUtil; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | public class ContentTypeBean implements ContentType { 12 | 13 | private String contentType; 14 | private Charset charset; 15 | 16 | public ContentTypeBean(String contentType, Charset charset) { 17 | if(StringUtil.isEmpty(contentType)) { 18 | throw new IllegalArgumentException("content-type MUST NOT be empty!"); 19 | } 20 | this.contentType = contentType; 21 | this.charset = charset; 22 | } 23 | 24 | @Override 25 | public String getContentType() { 26 | return contentType; 27 | } 28 | 29 | @Override 30 | public Charset getCharset() { 31 | return charset; 32 | } 33 | 34 | @Override 35 | public boolean equals(Object obj) { 36 | if (obj == null) { 37 | return false; 38 | } 39 | if (getClass() != obj.getClass()) { 40 | return false; 41 | } 42 | final ContentTypeBean other = (ContentTypeBean) obj; 43 | if ((this.contentType == null) ? (other.contentType != null) : !this.contentType.equals(other.contentType)) { 44 | return false; 45 | } 46 | if (this.charset != other.charset && (this.charset == null || !this.charset.equals(other.charset))) { 47 | return false; 48 | } 49 | return true; 50 | } 51 | 52 | @Override 53 | public int hashCode() { 54 | int hash = 7; 55 | hash = 37 * hash + (this.contentType != null ? this.contentType.hashCode() : 0); 56 | hash = 37 * hash + (this.charset != null ? this.charset.hashCode() : 0); 57 | return hash; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return HttpUtil.getFormattedContentType(contentType, charset); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/DigestAuth.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface DigestAuth extends BasicDigestAuth { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/DigestAuthBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class DigestAuthBean extends BasicDigestAuthBaseBean implements DigestAuth { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/HTTPAuthMethod.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.util.logging.Level; 4 | import java.util.logging.Logger; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public enum HTTPAuthMethod { 11 | BASIC, 12 | DIGEST, 13 | OAUTH_20_BEARER; 14 | 15 | private static final Logger LOG = Logger.getLogger( 16 | HTTPAuthMethod.class.getName() 17 | ); 18 | 19 | public static HTTPAuthMethod get(final String name) { 20 | if ("BASIC".equals(name)) { 21 | return BASIC; 22 | } else if ("DIGEST".equals(name)) { 23 | return DIGEST; 24 | } else if ("OAUTH_20_BEARER".equals(name)) { 25 | return OAUTH_20_BEARER; 26 | } else { 27 | LOG.log( 28 | Level.WARNING, 29 | "HTTPAuthMethod string unrecognized: {0}", 30 | name 31 | ); 32 | LOG.log(Level.WARNING, "Sending default method: {0}", BASIC); 33 | return BASIC; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/HTTPMethod.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.util.Objects; 4 | import java.util.logging.Logger; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public class HTTPMethod { 11 | public static final HTTPMethod GET = new HTTPMethod("GET"); 12 | public static final HTTPMethod POST = new HTTPMethod("POST"); 13 | public static final HTTPMethod PUT = new HTTPMethod("PUT"); 14 | public static final HTTPMethod PATCH = new HTTPMethod("PATCH"); 15 | public static final HTTPMethod DELETE = new HTTPMethod("DELETE"); 16 | public static final HTTPMethod HEAD = new HTTPMethod("HEAD"); 17 | public static final HTTPMethod OPTIONS = new HTTPMethod("OPTIONS"); 18 | public static final HTTPMethod TRACE = new HTTPMethod("TRACE"); 19 | 20 | private final String method; 21 | 22 | public HTTPMethod(String method) { 23 | this.method = method; 24 | } 25 | 26 | public static HTTPMethod get(final String method){ 27 | if("GET".equals(method)){ 28 | return GET; 29 | } 30 | else if("POST".equals(method)){ 31 | return POST; 32 | } 33 | else if("PUT".equals(method)){ 34 | return PUT; 35 | } 36 | else if("PATCH".equals(method)) { 37 | return PATCH; 38 | } 39 | else if("DELETE".equals(method)){ 40 | return DELETE; 41 | } 42 | else if("HEAD".equals(method)){ 43 | return HEAD; 44 | } 45 | else if("OPTIONS".equals(method)){ 46 | return OPTIONS; 47 | } 48 | else if("TRACE".equals(method)){ 49 | return TRACE; 50 | } 51 | else{ 52 | return new HTTPMethod(method); 53 | } 54 | } 55 | 56 | public String name() { 57 | return method; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return name(); 63 | } 64 | 65 | @Override 66 | public int hashCode() { 67 | int hash = 5; 68 | hash = 53 * hash + Objects.hashCode(this.method); 69 | return hash; 70 | } 71 | 72 | @Override 73 | public boolean equals(Object obj) { 74 | if (this == obj) { 75 | return true; 76 | } 77 | if (obj == null) { 78 | return false; 79 | } 80 | if (getClass() != obj.getClass()) { 81 | return false; 82 | } 83 | final HTTPMethod other = (HTTPMethod) obj; 84 | if (!Objects.equals(this.method, other.method)) { 85 | return false; 86 | } 87 | return true; 88 | } 89 | 90 | } 91 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/HTTPVersion.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public enum HTTPVersion { 8 | HTTP_1_1("HTTP 1.1", "1.1"), 9 | HTTP_1_0("HTTP 1.0", "1.0"); 10 | 11 | private String msg; 12 | private String versionNumber; 13 | 14 | HTTPVersion(String desc, String versionNumber){ 15 | this.msg = desc; 16 | this.versionNumber = versionNumber; 17 | } 18 | 19 | public String versionNumber(){ 20 | return versionNumber; 21 | } 22 | 23 | @Override 24 | public String toString(){ 25 | return msg; 26 | } 27 | 28 | public static HTTPVersion getDefault(){ 29 | return HTTP_1_1; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/HostnameVerifier.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public enum HostnameVerifier { 8 | 9 | STRICT("Strict"), 10 | ALLOW_ALL("Allow All"); 11 | 12 | private final String displayName; 13 | HostnameVerifier(String displayName){ 14 | this.displayName = displayName; 15 | } 16 | 17 | @Override 18 | public String toString(){ 19 | return displayName; 20 | } 21 | 22 | public static HostnameVerifier[] getAll(){ 23 | return new HostnameVerifier[]{STRICT, ALLOW_ALL}; 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/KeyStore.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.security.KeyStoreException; 6 | import java.security.NoSuchAlgorithmException; 7 | import java.security.cert.CertificateException; 8 | import java.security.spec.InvalidKeySpecException; 9 | 10 | /** 11 | * 12 | * @author subwiz 13 | */ 14 | public interface KeyStore { 15 | File getFile(); 16 | KeyStoreType getType(); 17 | char[] getPassword(); 18 | 19 | java.security.KeyStore getKeyStore() throws KeyStoreException, 20 | IOException, 21 | InvalidKeySpecException, 22 | NoSuchAlgorithmException, 23 | CertificateException; 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/KeyStoreBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.security.KeyStoreException; 6 | import java.security.NoSuchAlgorithmException; 7 | import java.security.cert.CertificateException; 8 | import java.security.spec.InvalidKeySpecException; 9 | import org.wiztools.restclient.util.SSLUtil; 10 | 11 | /** 12 | * 13 | * @author subwiz 14 | */ 15 | public class KeyStoreBean implements KeyStore { 16 | 17 | private File file; 18 | private KeyStoreType type = KeyStoreType.JKS; 19 | private char[] password; 20 | 21 | public void setFile(File file) { 22 | this.file = file; 23 | } 24 | 25 | public void setType(KeyStoreType type) { 26 | this.type = type; 27 | } 28 | 29 | public void setPassword(char[] password) { 30 | this.password = password; 31 | } 32 | 33 | @Override 34 | public File getFile() { 35 | return file; 36 | } 37 | 38 | @Override 39 | public KeyStoreType getType() { 40 | return type; 41 | } 42 | 43 | @Override 44 | public char[] getPassword() { 45 | if(type == KeyStoreType.PEM) { 46 | return SSLUtil.PEM_PWD.toCharArray(); 47 | } 48 | return password; 49 | } 50 | 51 | @Override 52 | public java.security.KeyStore getKeyStore() 53 | throws KeyStoreException, IOException, InvalidKeySpecException, 54 | NoSuchAlgorithmException, CertificateException { 55 | return SSLUtil.getKeyStore(file, type, password); 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | StringBuilder sb = new StringBuilder(); 61 | sb.append("@SSLKeyStore["); 62 | sb.append("type=").append(type).append(", "); 63 | sb.append("file=").append(file.getPath()).append(", "); 64 | sb.append("password=").append( 65 | (password!=null? password.length: 0)).append(", "); 66 | sb.append("]"); 67 | return sb.toString(); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/KeyStoreType.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public enum KeyStoreType { 8 | JKS, PKCS12, PEM; 9 | 10 | public String[] getFileExtns() { 11 | switch(this) { 12 | case JKS: 13 | return new String[]{".jks"}; 14 | case PKCS12: 15 | return new String[]{".p12", ".pfx", ".pkcs12"}; 16 | case PEM: 17 | return new String[]{".pem", ".cert", ".cer", ".crt"}; 18 | } 19 | return new String[]{}; 20 | } 21 | 22 | public static KeyStoreType detectByExtn(String fileName) { 23 | fileName = fileName.toLowerCase(); 24 | 25 | if(isOfType(fileName, JKS)) return JKS; 26 | if(isOfType(fileName, PKCS12)) return PKCS12; 27 | if(isOfType(fileName, PEM)) return PEM; 28 | 29 | return null; 30 | } 31 | 32 | private static boolean isOfType(String fileName, KeyStoreType type) { 33 | for(String extn: type.getFileExtns()) { 34 | if(fileName.endsWith(extn)) { 35 | return true; 36 | } 37 | } 38 | return false; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/MultipartMode.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public enum MultipartMode { 8 | // BROWSER_COMPATIBLE, RFC_6532, STRICT; 9 | LEGACY, STRICT, EXTENDED; 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/MultipartSubtype.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public enum MultipartSubtype { 8 | FORM_DATA, MIXED, DIGEST, MESSAGE, ALTERNATIVE, RELATED, REPORT, SIGNED, 9 | ENCRYPTED, X_MIXED_REPLACE, BYTERANGE; 10 | 11 | @Override 12 | public String toString() { 13 | return this.name().toLowerCase().replaceAll("_", "-"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/OAuth2BearerAuth.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface OAuth2BearerAuth extends AuthorizationHeaderAuth { 8 | 9 | String getOAuth2BearerToken(); 10 | 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/OAuth2BearerAuthBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.util.regex.Matcher; 4 | import java.util.regex.Pattern; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public class OAuth2BearerAuthBean extends AuthorizationHeaderAuthBean implements OAuth2BearerAuth { 11 | private final static Pattern p = Pattern.compile("Bearer\\s(.*)"); 12 | 13 | public void setOAuth2BearerToken(String token) { 14 | setAuthorizationHeaderValue("Bearer " + token); 15 | } 16 | 17 | @Override 18 | public String getOAuth2BearerToken() { 19 | String fullHeader = getAuthorizationHeaderValue(); 20 | Matcher m = p.matcher(fullHeader); 21 | if(m.matches()) { 22 | return m.group(1); 23 | } 24 | throw new IllegalStateException("OAuth2 Header does not match pattern: " + p); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntity.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface ReqEntity extends Cloneable, Serializable { 10 | Object clone(); 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityBasePart.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.util.Objects; 4 | import org.wiztools.commons.CollectionsUtil; 5 | import org.wiztools.commons.MultiValueMap; 6 | import org.wiztools.commons.MultiValueMapArrayList; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | public abstract class ReqEntityBasePart implements ReqEntityPart { 13 | 14 | protected final String name; 15 | protected final ContentType contentType; 16 | protected final MultiValueMap fields = new MultiValueMapArrayList<>(); 17 | 18 | public ReqEntityBasePart(String name, ContentType contentType) { 19 | this.name = name; 20 | this.contentType = contentType; 21 | } 22 | 23 | @Override 24 | public String getName() { 25 | return name; 26 | } 27 | 28 | @Override 29 | public ContentType getContentType() { 30 | return contentType; 31 | } 32 | 33 | public void addField(String key, String value) { 34 | fields.put(key, value); 35 | } 36 | 37 | @Override 38 | public MultiValueMap getFields() { 39 | return CollectionsUtil.unmodifiableMultiValueMap(fields); 40 | } 41 | 42 | @Override 43 | public int hashCode() { 44 | int hash = 7; 45 | hash = 79 * hash + Objects.hashCode(this.name); 46 | hash = 79 * hash + Objects.hashCode(this.contentType); 47 | hash = 79 * hash + Objects.hashCode(this.fields); 48 | return hash; 49 | } 50 | 51 | @Override 52 | public boolean equals(Object obj) { 53 | if (obj == null) { 54 | return false; 55 | } 56 | if (getClass() != obj.getClass()) { 57 | return false; 58 | } 59 | final ReqEntityBasePart other = (ReqEntityBasePart) obj; 60 | if (!Objects.equals(this.name, other.name)) { 61 | return false; 62 | } 63 | if (!Objects.equals(this.contentType, other.contentType)) { 64 | return false; 65 | } 66 | if (!Objects.equals(this.fields, other.fields)) { 67 | return false; 68 | } 69 | return true; 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityByteArray.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface ReqEntityByteArray extends ReqEntitySimple { 8 | byte[] getBody(); 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityByteArrayBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public class ReqEntityByteArrayBean extends AbstractReqEntitySimpleBean implements ReqEntityByteArray { 10 | 11 | private byte[] body; 12 | 13 | public ReqEntityByteArrayBean(byte[] body, ContentType contentType) { 14 | super(contentType); 15 | this.body = body; 16 | } 17 | 18 | @Override 19 | public byte[] getBody() { 20 | return Arrays.copyOf(body, body.length); 21 | } 22 | 23 | @Override 24 | public Object clone() { 25 | ReqEntityByteArrayBean out = new ReqEntityByteArrayBean( 26 | Arrays.copyOf(body, body.length), contentType); 27 | return out; 28 | } 29 | 30 | @Override 31 | public boolean equals(Object obj) { 32 | if (obj == null) { 33 | return false; 34 | } 35 | if (getClass() != obj.getClass()) { 36 | return false; 37 | } 38 | final ReqEntityByteArrayBean other = (ReqEntityByteArrayBean) obj; 39 | if (!Arrays.equals(this.body, other.body)) { 40 | return false; 41 | } 42 | if ((this.contentType == null) ? (other.contentType != null) : !this.contentType.equals(other.contentType)) { 43 | return false; 44 | } 45 | return true; 46 | } 47 | 48 | @Override 49 | public int hashCode() { 50 | int hash = 3; 51 | hash = 37 * hash + Arrays.hashCode(this.body); 52 | hash = 37 * hash + (this.contentType != null ? this.contentType.hashCode() : 0); 53 | return hash; 54 | } 55 | 56 | @Override 57 | public String toString() { 58 | StringBuilder sb = new StringBuilder(); 59 | sb.append("@ReqBodyByteArray["); 60 | sb.append(contentType).append(", "); 61 | sb.append("byte-arr-length=").append(body.length); 62 | sb.append("]"); 63 | return sb.toString(); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityFile.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface ReqEntityFile extends ReqEntitySimple { 10 | File getBody(); 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityFileBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public class ReqEntityFileBean extends AbstractReqEntitySimpleBean implements ReqEntityFile { 10 | 11 | private final File body; 12 | 13 | public ReqEntityFileBean(File body, ContentType contentType) { 14 | super(contentType); 15 | this.body = body; 16 | } 17 | 18 | @Override 19 | public File getBody() { 20 | return body; 21 | } 22 | 23 | @Override 24 | public Object clone() { 25 | return null; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object obj) { 30 | if (obj == null) { 31 | return false; 32 | } 33 | if (getClass() != obj.getClass()) { 34 | return false; 35 | } 36 | final ReqEntityFileBean other = (ReqEntityFileBean) obj; 37 | if (this.body != other.body && (this.body == null || !this.body.equals(other.body))) { 38 | return false; 39 | } 40 | if ((this.contentType == null) ? (other.contentType != null) : !this.contentType.equals(other.contentType)) { 41 | return false; 42 | } 43 | return true; 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | int hash = 7; 49 | hash = 79 * hash + (this.body != null ? this.body.hashCode() : 0); 50 | hash = 79 * hash + (this.contentType != null ? this.contentType.hashCode() : 0); 51 | return hash; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | StringBuilder sb = new StringBuilder(); 57 | sb.append("@ReqBodyFile["); 58 | sb.append(contentType).append(", "); 59 | sb.append(body); 60 | sb.append("]"); 61 | return sb.toString(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityFilePart.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface ReqEntityFilePart extends ReqEntityPart { 10 | File getPart(); 11 | String getFilename(); 12 | } 13 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityFilePartBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.File; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public class ReqEntityFilePartBean extends ReqEntityBasePart implements ReqEntityFilePart { 10 | 11 | private final File file; 12 | private final String filename; 13 | 14 | public ReqEntityFilePartBean(String name, String fileName, ContentType type, File file) { 15 | super(name, type); 16 | this.file = file; 17 | this.filename = fileName; 18 | } 19 | 20 | public ReqEntityFilePartBean(String name, File file) { 21 | super(name, null); 22 | this.file = file; 23 | this.filename = file.getName(); 24 | } 25 | 26 | @Override 27 | public File getPart() { 28 | return file; 29 | } 30 | 31 | @Override 32 | public String getFilename() { 33 | return filename; 34 | } 35 | 36 | @Override 37 | public boolean equals(Object obj) { 38 | if (obj == null) { 39 | return false; 40 | } 41 | if (getClass() != obj.getClass()) { 42 | return false; 43 | } 44 | final ReqEntityFilePartBean other = (ReqEntityFilePartBean) obj; 45 | if (!super.equals(obj)) { 46 | return false; 47 | } 48 | if (this.file != other.file && (this.file == null || !this.file.equals(other.file))) { 49 | return false; 50 | } 51 | if (this.filename != other.filename && (this.filename == null || !this.filename.equals(other.filename))) { 52 | return false; 53 | } 54 | return true; 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | int hash = 5; 60 | hash = 19 * hash + (super.hashCode()); 61 | hash = 19 * hash + (this.file != null ? this.file.hashCode() : 0); 62 | hash = 19 * hash + (this.filename != null ? this.filename.hashCode() : 0); 63 | return hash; 64 | } 65 | 66 | @Override 67 | public String toString() { 68 | StringBuilder sb = new StringBuilder(); 69 | sb.append("@ReqEntityFilePart[") 70 | .append("name=").append(name).append(", ") 71 | .append("fileName=").append(filename).append(", ") 72 | .append("contentType=").append(contentType).append(", ") 73 | .append("file=").append(file) 74 | .append("]"); 75 | return sb.toString(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityMultipart.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface ReqEntityMultipart extends ReqEntity { 10 | MultipartSubtype getSubtype(); 11 | MultipartMode getMode(); 12 | List getBody(); 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityMultipartBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.util.Collections; 4 | import java.util.List; 5 | import java.util.Objects; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | public class ReqEntityMultipartBean implements ReqEntityMultipart { 12 | 13 | private final MultipartSubtype subType; 14 | private final MultipartMode mode; 15 | private final List parts; 16 | 17 | public ReqEntityMultipartBean(List parts) { 18 | this(parts, null); 19 | } 20 | 21 | public ReqEntityMultipartBean(List parts, 22 | MultipartMode mode) { 23 | this(parts, null, null); 24 | } 25 | 26 | public ReqEntityMultipartBean(List parts, 27 | MultipartMode mode, 28 | MultipartSubtype subType) { 29 | this.parts = Collections.unmodifiableList(parts); 30 | this.mode = mode != null? mode: MultipartMode.STRICT; 31 | this.subType = subType; 32 | } 33 | 34 | @Override 35 | public MultipartSubtype getSubtype() { 36 | return subType; 37 | } 38 | 39 | @Override 40 | public MultipartMode getMode() { 41 | return mode; 42 | } 43 | 44 | @Override 45 | public List getBody() { 46 | return parts; 47 | } 48 | 49 | @Override 50 | public Object clone() { 51 | return null; 52 | } 53 | 54 | @Override 55 | public int hashCode() { 56 | int hash = 5; 57 | hash = 29 * hash + Objects.hashCode(this.subType); 58 | hash = 29 * hash + Objects.hashCode(this.mode); 59 | hash = 29 * hash + Objects.hashCode(this.parts); 60 | return hash; 61 | } 62 | 63 | @Override 64 | public boolean equals(Object obj) { 65 | if (obj == null) { 66 | return false; 67 | } 68 | if (getClass() != obj.getClass()) { 69 | return false; 70 | } 71 | final ReqEntityMultipartBean other = (ReqEntityMultipartBean) obj; 72 | if (this.subType != other.subType) { 73 | return false; 74 | } 75 | if (this.mode != other.mode) { 76 | return false; 77 | } 78 | if (!Objects.equals(this.parts, other.parts)) { 79 | return false; 80 | } 81 | return true; 82 | } 83 | 84 | @Override 85 | public String toString() { 86 | StringBuilder sb = new StringBuilder(); 87 | sb.append("@ReqEntityMultipart"); 88 | sb.append("{").append(subType).append(", ").append(mode).append("}"); 89 | sb.append("[").append(parts).append("]"); 90 | return sb.toString(); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityPart.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.Serializable; 4 | import org.wiztools.commons.MultiValueMap; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public interface ReqEntityPart extends Serializable { 11 | String getName(); 12 | ContentType getContentType(); 13 | MultiValueMap getFields(); 14 | } 15 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntitySimple.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface ReqEntitySimple extends ReqEntity { 8 | ContentType getContentType(); 9 | String getContentTypeCharsetFormatted(); 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityStream.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public interface ReqEntityStream extends ReqEntitySimple { 11 | InputStream getBody() throws IOException; 12 | long getLength() throws IOException; 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityString.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface ReqEntityString extends ReqEntitySimple { 8 | String getBody(); 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityStringBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author schandran 6 | */ 7 | public final class ReqEntityStringBean extends AbstractReqEntitySimpleBean implements ReqEntityString { 8 | 9 | private String body; 10 | 11 | public ReqEntityStringBean(String body, ContentType contentType){ 12 | super(contentType); 13 | this.body = body; 14 | } 15 | 16 | @Override 17 | public String getBody() { 18 | return body; 19 | } 20 | 21 | public void setBody(String body) { 22 | this.body = body; 23 | } 24 | 25 | @Override 26 | public Object clone(){ 27 | ReqEntityStringBean cloned = new ReqEntityStringBean(body, contentType); 28 | return cloned; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object o){ 33 | if(this == o){ 34 | return true; 35 | } 36 | if(o instanceof ReqEntityStringBean){ 37 | ReqEntityStringBean bean = (ReqEntityStringBean)o; 38 | boolean isEqual = true; 39 | isEqual = isEqual && (this.body == null? bean.body == null: this.body.equals(bean.body)); 40 | isEqual = isEqual && (this.contentType == null? bean.contentType == null: this.contentType.equals(bean.contentType)); 41 | return isEqual; 42 | } 43 | return false; 44 | } 45 | 46 | @Override 47 | public int hashCode() { 48 | int hash = 3; 49 | hash = 29 * hash + (this.contentType != null ? this.contentType.hashCode() : 0); 50 | hash = 29 * hash + (this.body != null ? this.body.hashCode() : 0); 51 | return hash; 52 | } 53 | 54 | @Override 55 | public String toString(){ 56 | StringBuilder sb = new StringBuilder(); 57 | sb.append("@ReqBodyString["); 58 | sb.append(contentType).append(", "); 59 | sb.append(body); 60 | sb.append("]"); 61 | return sb.toString(); 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityStringPart.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface ReqEntityStringPart extends ReqEntityPart { 8 | String getPart(); 9 | } 10 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityStringPartBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class ReqEntityStringPartBean extends ReqEntityBasePart implements ReqEntityStringPart { 8 | 9 | final String part; 10 | 11 | public ReqEntityStringPartBean(String name, ContentType contentType, String part) { 12 | super(name, contentType); 13 | this.part = part; 14 | } 15 | 16 | @Override 17 | public String getPart() { 18 | return part; 19 | } 20 | 21 | @Override 22 | public ContentType getContentType() { 23 | return contentType; 24 | } 25 | 26 | @Override 27 | public String getName() { 28 | return name; 29 | } 30 | 31 | @Override 32 | public boolean equals(Object obj) { 33 | if (obj == null) { 34 | return false; 35 | } 36 | if (getClass() != obj.getClass()) { 37 | return false; 38 | } 39 | final ReqEntityStringPartBean other = (ReqEntityStringPartBean) obj; 40 | if (!super.equals(obj)) { 41 | return false; 42 | } 43 | if ((this.part == null) ? (other.part != null) : !this.part.equals(other.part)) { 44 | return false; 45 | } 46 | 47 | return true; 48 | } 49 | 50 | @Override 51 | public int hashCode() { 52 | int hash = 3; 53 | hash = 53 * hash + (super.hashCode()); 54 | hash = 53 * hash + (this.part != null ? this.part.hashCode() : 0); 55 | return hash; 56 | } 57 | 58 | @Override 59 | public String toString() { 60 | StringBuilder sb = new StringBuilder(); 61 | sb.append("@ReqEntityStringPart[") 62 | .append("name=").append(name).append(", ") 63 | .append("contentType=").append(contentType).append(", ") 64 | .append("part=").append(part) 65 | .append("]"); 66 | return sb.toString(); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityUrlStream.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.net.URL; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface ReqEntityUrlStream extends ReqEntityStream { 10 | URL getUrl(); 11 | } 12 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqEntityUrlStreamBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.net.URL; 6 | import java.net.URLConnection; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | public class ReqEntityUrlStreamBean extends AbstractReqEntitySimpleBean implements ReqEntityUrlStream { 13 | 14 | private final URL url; 15 | private InputStream is; 16 | private long length; 17 | 18 | public ReqEntityUrlStreamBean(ContentType contentType, URL url) { 19 | super(contentType); 20 | this.url = url; 21 | } 22 | 23 | private void init() throws IOException { 24 | if(is == null && length == 0) { 25 | URLConnection con = url.openConnection(); 26 | is = con.getInputStream(); 27 | length = con.getContentLength(); 28 | } 29 | } 30 | 31 | @Override 32 | public URL getUrl() { 33 | return url; 34 | } 35 | 36 | @Override 37 | public InputStream getBody() throws IOException { 38 | init(); 39 | return is; 40 | } 41 | 42 | @Override 43 | public long getLength() throws IOException { 44 | init(); 45 | return length; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/ReqResBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author rsubramanian 6 | */ 7 | public final class ReqResBean implements Cloneable{ 8 | 9 | private Request requestBean; 10 | private Response responseBean; 11 | 12 | public Request getRequestBean() { 13 | return requestBean; 14 | } 15 | 16 | public void setRequestBean(Request requestBean) { 17 | this.requestBean = requestBean; 18 | } 19 | 20 | public Response getResponseBean() { 21 | return responseBean; 22 | } 23 | 24 | public void setResponseBean(Response responseBean) { 25 | this.responseBean = responseBean; 26 | } 27 | 28 | @Override 29 | public Object clone(){ 30 | ReqResBean cloned = new ReqResBean(); 31 | if(requestBean != null){ 32 | Request clonedRequestBean = (Request)requestBean.clone(); 33 | cloned.requestBean = clonedRequestBean; 34 | } 35 | if(responseBean != null){ 36 | //Response clonedResponseBean = (Response)responseBean.clone(); 37 | //cloned.responseBean = clonedResponseBean; 38 | } 39 | return cloned; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/Request.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.Serializable; 4 | import java.net.HttpCookie; 5 | import java.net.URL; 6 | import java.util.List; 7 | import org.wiztools.commons.MultiValueMap; 8 | 9 | /** 10 | * 11 | * @author subwiz 12 | */ 13 | public interface Request extends Cloneable, Serializable { 14 | 15 | Auth getAuth(); 16 | 17 | ReqEntity getBody(); 18 | 19 | MultiValueMap getHeaders(); 20 | 21 | List getCookies(); 22 | 23 | HTTPVersion getHttpVersion(); 24 | 25 | HTTPMethod getMethod(); 26 | 27 | TLSReq getTLSReq(); 28 | 29 | String getTestScript(); 30 | 31 | URL getUrl(); 32 | 33 | boolean isFollowRedirect(); 34 | 35 | boolean isIgnoreResponseBody(); 36 | 37 | Object clone(); 38 | } 39 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/RequestExecuter.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.HTTPClientRequestExecuter; 5 | import org.wiztools.restclient.View; 6 | 7 | /** 8 | * This is the interface used to execute the HTTP request. For getting the 9 | * default implementation for this interface, use the Implementation class: 10 | * 11 | *
12 |  * import org.wiztools.restclient.RequestExecuter;
13 |  * import org.wiztools.restclient.Implementation;
14 |  * 
15 | * @author subwiz 16 | */ 17 | @ImplementedBy(HTTPClientRequestExecuter.class) 18 | public interface RequestExecuter { 19 | 20 | /** 21 | * Use this method to execute the HTTP request. 22 | * @param request The request object. 23 | * @param views This is a vararg parameter. You may pass any number of View 24 | * implementation. 25 | */ 26 | void execute(Request request, View ... views); 27 | 28 | /** 29 | * Use this method to abort a request in progress. The recommended way to 30 | * use this: 31 | * 32 | *
33 |      *
34 |      * import org.wiztools.restclient.Request;
35 |      * import org.wiztools.restclient.View;
36 |      * import org.wiztools.restclient.RequestExecuter;
37 |      * import org.wiztools.restclient.ServiceLocator;
38 |      *
39 |      * ...
40 |      *
41 |      * final Request request = ...;
42 |      * final View view = ...;
43 |      * final RequestExecuter executer = ServiceLocator.getInstance(RequestExecuter.class);
44 |      * Thread t = new Thread(){
45 |      *      {@literal @}Override
46 |      *      public void run(){
47 |      *          executer.execute(request, view);
48 |      *      }
49 |      *      {@literal @}Override
50 |      *      public void interrupt(){
51 |      *          executer.abortExecution();
52 |      *          super.interrupt();
53 |      *      }
54 |      * }
55 |      * t.start();
56 |      *
57 |      * // to interrupt in later stage:
58 |      * t.interrupt();
59 |      *
60 |      * 
61 | */ 62 | void abortExecution(); 63 | } 64 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/Response.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.Serializable; 4 | import org.wiztools.commons.MultiValueMap; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public interface Response extends Cloneable, Serializable { 11 | 12 | long getExecutionTime(); 13 | 14 | MultiValueMap getHeaders(); 15 | 16 | ContentType getContentType(); 17 | 18 | byte[] getResponseBody(); 19 | 20 | int getStatusCode(); 21 | 22 | String getStatusLine(); 23 | 24 | TestResult getTestResult(); 25 | 26 | Object clone(); 27 | } 28 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/TLSReq.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface TLSReq extends Serializable { 10 | 11 | HostnameVerifier getHostNameVerifier(); 12 | boolean isTrustAllCerts(); 13 | 14 | KeyStore getKeyStore(); 15 | 16 | KeyStore getTrustStore(); 17 | } 18 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/TestException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | 6 | package org.wiztools.restclient.bean; 7 | 8 | /** 9 | * 10 | * @author Subhash 11 | */ 12 | public class TestException extends Exception { 13 | public TestException(final String msg, final Throwable err){ 14 | super(msg, err); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/TestExceptionResult.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface TestExceptionResult { 8 | 9 | String getExceptionMessage(); 10 | 11 | int getLineNumber(); 12 | 13 | } 14 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/TestExceptionResultBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class TestExceptionResultBean implements TestExceptionResult { 8 | private int lineNumber; 9 | private String exceptionMessage; 10 | 11 | @Override 12 | public String getExceptionMessage() { 13 | return exceptionMessage; 14 | } 15 | 16 | public void setExceptionMessage(String exceptionMessage) { 17 | this.exceptionMessage = exceptionMessage; 18 | } 19 | 20 | @Override 21 | public int getLineNumber() { 22 | return lineNumber; 23 | } 24 | 25 | public void setLineNumber(int lineNumber) { 26 | this.lineNumber = lineNumber; 27 | } 28 | 29 | @Override 30 | public boolean equals(Object obj) { 31 | if (obj == null) { 32 | return false; 33 | } 34 | if (getClass() != obj.getClass()) { 35 | return false; 36 | } 37 | final TestExceptionResult other = (TestExceptionResult) obj; 38 | if (this.lineNumber != other.getLineNumber()) { 39 | return false; 40 | } 41 | if ((this.exceptionMessage == null) ? (other.getExceptionMessage() != null) : !this.exceptionMessage.equals(other.getExceptionMessage())) { 42 | return false; 43 | } 44 | return true; 45 | } 46 | 47 | @Override 48 | public int hashCode() { 49 | int hash = 7; 50 | hash = 97 * hash + this.lineNumber; 51 | hash = 97 * hash + (this.exceptionMessage != null ? this.exceptionMessage.hashCode() : 0); 52 | return hash; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/TestResult.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.io.Serializable; 4 | import java.util.List; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public interface TestResult extends Serializable { 11 | 12 | int getErrorCount(); 13 | 14 | List getErrors(); 15 | 16 | int getFailureCount(); 17 | 18 | List getFailures(); 19 | 20 | String getMessage(); 21 | 22 | int getRunCount(); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/UsernamePasswordAuth.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface UsernamePasswordAuth extends Auth { 8 | String getUsername(); 9 | char[] getPassword(); 10 | } 11 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/bean/UsernamePasswordAuthBaseBean.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.bean; 2 | 3 | import java.util.Arrays; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public class UsernamePasswordAuthBaseBean implements UsernamePasswordAuth { 10 | 11 | protected String username; 12 | protected char[] password; 13 | 14 | public void setPassword(char[] password) { 15 | this.password = password; 16 | } 17 | 18 | public void setUsername(String username) { 19 | this.username = username; 20 | } 21 | 22 | @Override 23 | public final String getUsername() { 24 | return username; 25 | } 26 | 27 | @Override 28 | public final char[] getPassword() { 29 | if(password == null) { 30 | return new char[]{}; 31 | } 32 | return Arrays.copyOf(password, password.length); 33 | } 34 | 35 | @Override 36 | public boolean equals(Object obj) { 37 | if (obj == null) { 38 | return false; 39 | } 40 | if (getClass() != obj.getClass()) { 41 | return false; 42 | } 43 | final UsernamePasswordAuthBaseBean other = (UsernamePasswordAuthBaseBean) obj; 44 | if ((this.username == null) ? (other.username != null) : !this.username.equals(other.username)) { 45 | return false; 46 | } 47 | if (!Arrays.equals(this.password, other.password)) { 48 | return false; 49 | } 50 | return true; 51 | } 52 | 53 | @Override 54 | public int hashCode() { 55 | int hash = 3; 56 | hash = 67 * hash + (this.username != null ? this.username.hashCode() : 0); 57 | hash = 67 * hash + Arrays.hashCode(this.password); 58 | return hash; 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/http/RESTClientCookieStore.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.http; 2 | 3 | import java.time.Instant; 4 | import java.util.ArrayList; 5 | import java.util.Collections; 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | import org.apache.hc.client5.http.cookie.Cookie; 10 | import org.apache.hc.client5.http.cookie.CookieStore; 11 | 12 | /** 13 | * 14 | * @author subwiz 15 | */ 16 | public class RESTClientCookieStore implements CookieStore { 17 | 18 | private List cookies = new ArrayList(); 19 | 20 | @Override 21 | public void addCookie(Cookie cookie) { 22 | cookies.add(cookie); 23 | } 24 | 25 | @Override 26 | public List getCookies() { 27 | return Collections.unmodifiableList(cookies); 28 | } 29 | 30 | @SuppressWarnings("deprecation") 31 | public boolean clearExpired(Date date) { 32 | // Do nothing 33 | return true; 34 | } 35 | 36 | @Override 37 | public boolean clearExpired(Instant date) { 38 | // Do nothing 39 | return true; 40 | } 41 | 42 | @Override 43 | public void clear() { 44 | cookies.clear(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/persistence/PersistenceException.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.persistence; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class PersistenceException extends RuntimeException { 8 | 9 | // public PersistenceException() { 10 | // } 11 | 12 | public PersistenceException(String message) { 13 | super(message); 14 | } 15 | 16 | public PersistenceException(Throwable cause) { 17 | super(cause); 18 | } 19 | 20 | public PersistenceException(String message, Throwable cause) { 21 | super(message, cause); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/persistence/PersistenceRead.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.persistence; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import org.wiztools.restclient.bean.Request; 6 | import org.wiztools.restclient.bean.Response; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | public interface PersistenceRead { 13 | Request getRequestFromFile(File f) throws IOException, PersistenceException; 14 | Response getResponseFromFile(File f) throws IOException, PersistenceException; 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/persistence/PersistenceWrite.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.persistence; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import org.wiztools.restclient.bean.Request; 6 | import org.wiztools.restclient.bean.Response; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | public interface PersistenceWrite { 13 | void writeRequest(Request req, File f) throws IOException, PersistenceException; 14 | void writeResponse(Response res, File f) throws IOException, PersistenceException; 15 | } 16 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/persistence/XMLCollectionUtil.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.persistence; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | import nu.xom.Attribute; 8 | import nu.xom.Document; 9 | import nu.xom.Element; 10 | import nu.xom.Elements; 11 | import org.wiztools.restclient.Versions; 12 | import org.wiztools.restclient.bean.Request; 13 | 14 | /** 15 | * 16 | * @author subwiz 17 | */ 18 | public final class XMLCollectionUtil { 19 | 20 | private XMLCollectionUtil() {} 21 | 22 | public static void writeRequestCollectionXML(final List requests, final File f) 23 | throws IOException, XMLException { 24 | XmlPersistenceWrite xUtl = new XmlPersistenceWrite(); 25 | 26 | Element eRoot = new Element("request-collection"); 27 | eRoot.addAttribute(new Attribute("version", Versions.CURRENT)); 28 | for(Request req: requests) { 29 | Element e = xUtl.getRequestElement(req); 30 | eRoot.appendChild(e); 31 | } 32 | Document doc = new Document(eRoot); 33 | xUtl.writeXML(doc, f); 34 | } 35 | 36 | public static List getRequestCollectionFromXMLFile(final File f) 37 | throws IOException, XMLException { 38 | XmlPersistenceRead xUtlRead = new XmlPersistenceRead(); 39 | 40 | List out = new ArrayList<>(); 41 | Document doc = xUtlRead.getDocumentFromFile(f); 42 | Element eRoot = doc.getRootElement(); 43 | if(!"request-collection".equals(eRoot.getLocalName())) { 44 | throw new XMLException("Expecting root element , but found: " 45 | + eRoot.getLocalName()); 46 | } 47 | final String version = eRoot.getAttributeValue("version"); 48 | try { 49 | Versions.versionValidCheck(version); 50 | } 51 | catch(Versions.VersionValidationException ex) { 52 | throw new XMLException(ex); 53 | } 54 | xUtlRead.setReadVersion(version); 55 | 56 | Elements eRequests = doc.getRootElement().getChildElements(); 57 | for(int i=0; i contentTypes = new ArrayList<>(); 13 | 14 | static { 15 | contentTypes.add("Accept"); 16 | contentTypes.add("Accept-Charset"); 17 | contentTypes.add("Accept-Encoding"); 18 | contentTypes.add("Accept-Language"); 19 | contentTypes.add("Content-MD5"); 20 | contentTypes.add("Content-Type"); 21 | contentTypes.add("Date"); 22 | contentTypes.add("Expect"); 23 | contentTypes.add("From"); 24 | contentTypes.add("If-Match"); 25 | contentTypes.add("If-Modified-Since"); 26 | contentTypes.add("If-None-Match"); 27 | contentTypes.add("If-Range"); 28 | contentTypes.add("If-Unmodified-Since"); 29 | contentTypes.add("Max-Forwards"); 30 | contentTypes.add("Origin"); 31 | contentTypes.add("Pragma"); 32 | contentTypes.add("Range"); 33 | contentTypes.add("Referer"); 34 | contentTypes.add("TE"); 35 | contentTypes.add("User-Agent"); 36 | contentTypes.add("Upgrade"); 37 | contentTypes.add("Via"); 38 | contentTypes.add("Warning"); 39 | } 40 | 41 | public static List getCommon() { 42 | return Collections.unmodifiableList(contentTypes); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/util/HTMLIndentUtil.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import java.io.IOException; 4 | import net.htmlparser.jericho.Source; 5 | import net.htmlparser.jericho.SourceFormatter; 6 | import java.io.StringWriter; 7 | import java.util.logging.Level; 8 | import java.util.logging.Logger; 9 | 10 | /** 11 | * @author yeradis 12 | */ 13 | public final class HTMLIndentUtil { 14 | 15 | private static final Logger LOG = Logger.getLogger(HTMLIndentUtil.class.getName()); 16 | 17 | private HTMLIndentUtil() { 18 | } 19 | 20 | public static String getIndented(String inHTML) { 21 | String formated_html = null; 22 | try { 23 | StringWriter writer = new StringWriter(); 24 | new SourceFormatter(new Source(inHTML)).setIndentString(" ").setTidyTags(true).setCollapseWhiteSpace(true).writeTo(writer); 25 | formated_html = writer.toString(); 26 | } 27 | catch (IOException e) { 28 | LOG.log(Level.SEVERE, null, e); 29 | } 30 | return formated_html; 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/util/IDNUtil.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import java.net.IDN; 4 | import java.net.MalformedURLException; 5 | import java.net.URI; 6 | import java.net.URISyntaxException; 7 | import java.net.URL; 8 | 9 | /** 10 | * Utility to convert to IDN name. 11 | * @author subwiz 12 | */ 13 | public final class IDNUtil { 14 | public static URL getIDNizedURL(URL inUrl) throws IllegalArgumentException { 15 | try { 16 | return new URI( 17 | inUrl.getProtocol(), 18 | null, 19 | IDN.toASCII(inUrl.getHost()), 20 | inUrl.getPort(), 21 | inUrl.getPath(), 22 | inUrl.getQuery(), 23 | inUrl.getRef() 24 | ).toURL(); 25 | } catch(MalformedURLException | URISyntaxException ex) { 26 | throw new IllegalArgumentException(ex); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/util/JSONUtil.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import java.io.IOException; 4 | import java.io.StringReader; 5 | import java.io.StringWriter; 6 | import java.util.logging.Level; 7 | import java.util.logging.Logger; 8 | 9 | import com.fasterxml.jackson.core.JsonFactory; 10 | import com.fasterxml.jackson.core.JsonGenerator; 11 | import com.fasterxml.jackson.core.JsonParseException; 12 | import com.fasterxml.jackson.core.JsonParser; 13 | import com.fasterxml.jackson.core.util.DefaultPrettyPrinter; 14 | import com.fasterxml.jackson.databind.DeserializationFeature; 15 | import com.fasterxml.jackson.databind.JsonNode; 16 | import com.fasterxml.jackson.databind.ObjectMapper; 17 | 18 | /** 19 | * 20 | * @author subwiz 21 | */ 22 | public final class JSONUtil { 23 | 24 | private static final Logger LOG = Logger.getLogger(JSONUtil.class.getName()); 25 | 26 | private JSONUtil(){} 27 | 28 | public static class JSONParseException extends Exception{ 29 | public JSONParseException(String message){ 30 | super(message); 31 | } 32 | } 33 | 34 | // Jackson Object Mapper used in indent operation: 35 | private static final ObjectMapper jsonObjMapper = new ObjectMapper(); 36 | static { 37 | jsonObjMapper.enable( 38 | DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, 39 | DeserializationFeature.USE_BIG_INTEGER_FOR_INTS 40 | ); 41 | } 42 | 43 | public static String indentJSON(final String jsonIn) throws JSONParseException{ 44 | JsonFactory fac = new JsonFactory(); 45 | try{ 46 | JsonParser parser = fac.createParser(new StringReader(jsonIn)); 47 | JsonNode node = null; 48 | try{ 49 | node = jsonObjMapper.readTree(parser); 50 | } 51 | catch(JsonParseException ex){ 52 | throw new JSONParseException(ex.getMessage()); 53 | } 54 | StringWriter out = new StringWriter(); 55 | 56 | // Create pretty printer: 57 | JsonGenerator gen = fac.createGenerator(out); 58 | DefaultPrettyPrinter pp = new DefaultPrettyPrinter(); 59 | pp.indentArraysWith(new DefaultPrettyPrinter.FixedSpaceIndenter()); 60 | gen.setPrettyPrinter(pp); 61 | 62 | // Now write: 63 | jsonObjMapper.writeTree(gen, node); 64 | 65 | gen.flush(); 66 | gen.close(); 67 | return out.toString(); 68 | } 69 | catch(IOException ex){ 70 | LOG.log(Level.SEVERE, null, ex); 71 | } 72 | return jsonIn; 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/util/MultiEntryRes.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import java.util.ArrayList; 4 | import java.util.LinkedHashMap; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public class MultiEntryRes { 9 | private List linesNotMatching = new ArrayList<>(); 10 | private Map keyValMap = new LinkedHashMap<>(); 11 | 12 | public void addInvalidLine(String line) { 13 | linesNotMatching.add(line); 14 | } 15 | 16 | public void addEntry(String key, String value) { 17 | keyValMap.put(key, value); 18 | } 19 | 20 | public List getInvalidLines() { 21 | return linesNotMatching; 22 | } 23 | 24 | public Map getEntries() { 25 | return keyValMap; 26 | } 27 | } -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/util/MultiEntryUtil.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import org.wiztools.commons.MultiValueMap; 4 | 5 | public class MultiEntryUtil { 6 | public static MultiEntryRes parse(String str) { 7 | MultiEntryRes res = new MultiEntryRes(); 8 | 9 | String[] line_arr = str.split("\\n"); 10 | for (String line: line_arr) { 11 | int index = line.indexOf(':'); 12 | if ((index > -1) && (index != 0) && (index != (line.length() - 1))) { 13 | String key = line.substring(0, index); 14 | String value = line.substring(index + 1); 15 | key = key.trim(); 16 | value = value.trim(); 17 | if ("".equals(key) || "".equals(value)) { 18 | res.addInvalidLine(line); 19 | } else { 20 | res.addEntry(key, value); 21 | } 22 | } else { 23 | if (!"".equals(line.trim())) { // Add only non-blank line 24 | res.addInvalidLine(line); 25 | } 26 | } 27 | } 28 | 29 | return res; 30 | } 31 | 32 | public static String join(MultiValueMap map) { 33 | StringBuilder out = new StringBuilder(); 34 | for(String key: map.keySet()) { 35 | for(String v: map.get(key)) { 36 | out.append(key) 37 | .append(": ").append(v); 38 | } 39 | } 40 | return out.toString(); 41 | } 42 | } -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/util/Url.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URISyntaxException; 5 | 6 | public class Url { 7 | public static java.net.URL get(String spec) throws MalformedURLException { 8 | if(spec == null || spec.trim().isEmpty()) { 9 | throw new MalformedURLException("URL is empty"); 10 | } 11 | try { 12 | return new java.net.URI(spec).toURL(); 13 | } catch(URISyntaxException ex) { 14 | throw new MalformedURLException(ex.toString()); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /lib/src/main/java/org/wiztools/restclient/util/XMLIndentUtil.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import java.io.IOException; 4 | import java.io.StringReader; 5 | import java.io.StringWriter; 6 | import java.io.Writer; 7 | import javax.xml.parsers.DocumentBuilderFactory; 8 | import javax.xml.parsers.ParserConfigurationException; 9 | import org.w3c.dom.Document; 10 | import org.w3c.dom.Node; 11 | import org.w3c.dom.bootstrap.DOMImplementationRegistry; 12 | import org.w3c.dom.ls.DOMImplementationLS; 13 | import org.w3c.dom.ls.LSOutput; 14 | import org.w3c.dom.ls.LSSerializer; 15 | import org.wiztools.restclient.persistence.XMLException; 16 | import org.xml.sax.InputSource; 17 | import org.xml.sax.SAXException; 18 | 19 | /** 20 | * 21 | * @author subwiz 22 | */ 23 | public final class XMLIndentUtil { 24 | private XMLIndentUtil() { 25 | } 26 | 27 | public static String getIndented(String inXml) throws IOException { 28 | try { 29 | final InputSource src = new InputSource(new StringReader(inXml)); 30 | final Document domDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(src); 31 | String encoding = domDoc.getXmlEncoding(); 32 | if (encoding == null) { 33 | // defaults to UTF-8 34 | encoding = "UTF-8"; 35 | } 36 | final Node document = domDoc.getDocumentElement(); 37 | final boolean keepDeclaration = inXml.startsWith(" params = new MultiValueMapLinkedHashSet(); 42 | params.put("q", "r1"); 43 | params.put("q", "r2"); 44 | String expResult = "q=r1&q=r2"; 45 | String result = Util.parameterEncode(params); 46 | assertEquals(expResult, result); 47 | } 48 | 49 | /** 50 | * Test of getCharsetFromContentType method, of class Util. 51 | */ 52 | @Test 53 | public void testGetCharsetFromContentType() { 54 | System.out.println("getCharsetFromContentType"); 55 | String contentType = "Content-type: text/html; charset=UTF-8"; 56 | String expResult = "UTF-8"; 57 | String result = HttpUtil.getCharsetFromContentType(contentType); 58 | assertEquals(expResult, result); 59 | 60 | // when charset is not available, return null: 61 | contentType = "Content-type: text/html"; 62 | expResult = null; 63 | result = HttpUtil.getCharsetFromContentType(contentType); 64 | assertEquals(expResult, result); 65 | } 66 | 67 | @Test 68 | public void testGetMimeFromContentType() { 69 | System.out.println("getMimeFromContentType"); 70 | String contentType = "application/xml;charset=UTF-8"; 71 | String expResult = "application/xml"; 72 | String result = HttpUtil.getMimeFromContentType(contentType); 73 | assertEquals(expResult, result); 74 | } 75 | } -------------------------------------------------------------------------------- /lib/src/test/java/org/wiztools/restclient/util/HttpUtilTest.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | import org.junit.After; 3 | import org.junit.AfterClass; 4 | import org.junit.Before; 5 | import org.junit.BeforeClass; 6 | import org.junit.Test; 7 | import static org.junit.Assert.*; 8 | import org.wiztools.commons.Charsets; 9 | import org.wiztools.restclient.bean.ContentType; 10 | import org.wiztools.restclient.bean.ContentTypeBean; 11 | 12 | /** 13 | * 14 | * @author subwiz 15 | */ 16 | public class HttpUtilTest { 17 | 18 | public HttpUtilTest() { 19 | } 20 | 21 | @BeforeClass 22 | public static void setUpClass() { 23 | } 24 | 25 | @AfterClass 26 | public static void tearDownClass() { 27 | } 28 | 29 | @Before 30 | public void setUp() { 31 | } 32 | 33 | @After 34 | public void tearDown() { 35 | } 36 | 37 | /** 38 | * Test of getContentType method, of class HttpUtil. 39 | */ 40 | @Test 41 | public void testGetContentType_String() { 42 | System.out.println("getContentType"); 43 | String header = "application/vnd.mnet.staticwebspaces+xml;version=1;charset=UTF-8"; 44 | ContentType expResult = new ContentTypeBean("application/vnd.mnet.staticwebspaces+xml", Charsets.UTF_8); 45 | ContentType result = HttpUtil.getContentType(header); 46 | assertEquals(expResult, result); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /lib/src/test/java/org/wiztools/restclient/util/IDNUtilTest.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.net.MalformedURLException; 6 | import java.net.URI; 7 | import java.net.URISyntaxException; 8 | import java.net.URL; 9 | 10 | import org.junit.Test; 11 | 12 | public class IDNUtilTest { 13 | @Test 14 | public void TestIDNURL() { 15 | try { 16 | URL url = new URI("http://wiztools.org/path?qry=subhash").toURL(); 17 | assertEquals(url.getPath(), "/path"); 18 | URL idnUrl = IDNUtil.getIDNizedURL(url); 19 | assertEquals(idnUrl.getPath(), "/path"); 20 | } catch(MalformedURLException | URISyntaxException ex) { 21 | ex.printStackTrace(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /lib/src/test/java/org/wiztools/restclient/util/JSONUtilTest.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import java.io.File; 6 | import org.junit.After; 7 | import org.junit.AfterClass; 8 | import org.junit.Before; 9 | import org.junit.BeforeClass; 10 | import org.junit.Test; 11 | import static org.junit.Assert.*; 12 | import org.wiztools.commons.Charsets; 13 | import org.wiztools.commons.FileUtil; 14 | 15 | /** 16 | * 17 | * @author subwiz 18 | */ 19 | public class JSONUtilTest { 20 | 21 | public JSONUtilTest() { 22 | } 23 | 24 | @BeforeClass 25 | public static void setUpClass() { 26 | } 27 | 28 | @AfterClass 29 | public static void tearDownClass() { 30 | } 31 | 32 | @Before 33 | public void setUp() { 34 | } 35 | 36 | @After 37 | public void tearDown() { 38 | } 39 | 40 | public static class Issue191Bean { 41 | private String date; 42 | private String performance; 43 | private String totalValue; 44 | 45 | public String getDate() { 46 | return date; 47 | } 48 | 49 | public void setDate(String date) { 50 | this.date = date; 51 | } 52 | 53 | public String getPerformance() { 54 | return performance; 55 | } 56 | 57 | public void setPerformance(String performance) { 58 | this.performance = performance; 59 | } 60 | 61 | public String getTotalValue() { 62 | return totalValue; 63 | } 64 | 65 | public void setTotalValue(String totalValue) { 66 | this.totalValue = totalValue; 67 | } 68 | 69 | } 70 | 71 | /** 72 | * Test of indentJSON method, of class JSONUtil. 73 | */ 74 | @Test 75 | public void testIndentJSON() throws Exception { 76 | System.out.println("indentJSON"); 77 | String jsonIn = FileUtil.getContentAsString( 78 | new File("src/test/resources/issue_191/one-line.json"), Charsets.UTF_8); 79 | 80 | String expResult = "1.015786164055542498"; 81 | 82 | String resultJson = JSONUtil.indentJSON(jsonIn); 83 | Gson gson = new GsonBuilder().create(); 84 | Issue191Bean indentedObj = gson.fromJson(resultJson, Issue191Bean.class); 85 | String result = indentedObj.performance; 86 | 87 | // Test loss of double precision in indented json: 88 | assertEquals(expResult, result); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /lib/src/test/java/org/wiztools/restclient/util/XMLIndentUtilTest.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.util; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | 5 | import java.io.File; 6 | import org.junit.Test; 7 | import org.wiztools.commons.Charsets; 8 | import org.wiztools.commons.FileUtil; 9 | 10 | /** 11 | * Test of {@link XMLIndentUtil}. 12 | */ 13 | public class XMLIndentUtilTest { 14 | /** 15 | * Test of XMLIndentUtil.getIndented(String inXml) with ISO-8859-1 Encoding. 16 | */ 17 | // @Test 18 | public void testGetIndentedISO() throws Exception { 19 | String inXml = FileUtil.getContentAsString( 20 | new File("src/test/resources/input_ISO.xml"), Charsets.ISO_8859_1); 21 | String expectedResult = FileUtil.getContentAsString( 22 | new File("src/test/resources/output_ISO.xml"), Charsets.ISO_8859_1); 23 | String result = XMLIndentUtil.getIndented(inXml); 24 | System.out.println("Expected:\n" + expectedResult); 25 | System.out.println("Is:\n" + result); 26 | assertEquals(expectedResult, result); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /lib/src/test/resources/input_ISO.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 10 4 | 71714 5 | someuser 6 | somepassword 7 | 2012-04-19T11:15:43 8 | someurl.com 9 | 12892 10 | 11 | -------------------------------------------------------------------------------- /lib/src/test/resources/issue_191/one-line.json: -------------------------------------------------------------------------------- 1 | {"date":"2013-11-18","performance":1.015786164055542498,"totalValue":43903.53} 2 | -------------------------------------------------------------------------------- /lib/src/test/resources/org/wiztools/restclient/xml/charset1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /lib/src/test/resources/org/wiztools/restclient/xml/charset2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /lib/src/test/resources/org/wiztools/restclient/xml/charset3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /lib/src/test/resources/output_ISO.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 10 5 | 6 | 7 | 71714 8 | 9 | 10 | someuser 11 | 12 | 13 | somepassword 14 | 15 | 16 | 2012-04-19T11:15:43 17 | 18 | 19 | someurl.com 20 | 21 | 22 | 12892 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /lib/src/test/resources/reqBodyFile.rcq: -------------------------------------------------------------------------------- 1 | 2 | 1.1http://localhost:10101/POST/etc/hosts 3 | -------------------------------------------------------------------------------- /lib/src/test/resources/reqBodyMultipart.rcq: -------------------------------------------------------------------------------- 1 | 2 | 1.1http://localhost:10101/POST/etc/hostsHello Babes! 3 | -------------------------------------------------------------------------------- /lib/src/test/resources/reqBodyString.rcq: -------------------------------------------------------------------------------- 1 | 2 | 1.1http://localhost:10101/POSTSubhash loves Aarthi 3 | -------------------------------------------------------------------------------- /lib/src/test/resources/reqFromXml.rcq: -------------------------------------------------------------------------------- 1 | 2 | 1.1http://localhost:10101/POSTrealmusernamecGFzc3dvcmQ=
Body Text 3 | -------------------------------------------------------------------------------- /lib/src/test/resources/reqOAuth2Bearer.rcq: -------------------------------------------------------------------------------- 1 | 2 | 1.1http://localhost:10101/GETsubhash 3 | -------------------------------------------------------------------------------- /lib/src/test/resources/reqSsl.rcq: -------------------------------------------------------------------------------- 1 | 2 | 1.1https://www.webshop.co.uk/GETALLOW_ALL 3 | -------------------------------------------------------------------------------- /lib/src/test/resources/resFromXml.rcs: -------------------------------------------------------------------------------- 1 | 2 | 11HTTP/1.1 200 OK
KipSRVNUQ2xpZW50IFRyYWNlU2VydmxldCoqCgoqTWV0aG9kKgoJR0VUCgoqUGF0aCBJbmZvKgoJLwoKKkhlYWRlcnMqCglIb3N0OiBsb2NhbGhvc3Q6MTAxMDEKCUNvbm5lY3Rpb246IEtlZXAtQWxpdmUKCVVzZXItQWdlbnQ6IEFwYWNoZS1IdHRwQ2xpZW50LzQuMi4xIChqYXZhIDEuNSkKCipRdWVyeSBTdHJpbmcqCgludWxsCgoqUGFyYW1ldGVycyoKCipCb2R5IChGaXJzdCAxMDAgY2hhcmFjdGVycyBvbmx5KSoKCQoK 3 | -------------------------------------------------------------------------------- /lib/src/test/resources/resTestScriptIntegrity.rcq: -------------------------------------------------------------------------------- 1 | 2 | 1.1http://localhost:10101/GET/* 3 | * This is a template provided by RESTClient. Modify as per need. 4 | */ 5 | 6 | // The test class name should end with `Test'--this is a convention: 7 | public class TemplateClassTest 8 | extends org.wiztools.restclient.RESTTestCase{ 9 | 10 | // Test method names should start with `test': 11 | public void testStatus(){ 12 | if(response.getStatusCode() != 200){ 13 | fail("This will fail the test!"); 14 | } 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /lib/src/test/resources/subhash_by_aarthi.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/lib/src/test/resources/subhash_by_aarthi.jpeg -------------------------------------------------------------------------------- /mac-run-ui.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -e 4 | 5 | # read version: 6 | source ./gradle.properties 7 | 8 | jcmd=java 9 | if [ -n "$JAVA_HOME" ]; then 10 | jcmd=$JAVA_HOME/bin/java 11 | fi 12 | 13 | ./gradlew build 14 | 15 | $jcmd -Dorg.apache.commons.logging.Log=org.apache.commons.logging.impl.SimpleLog \ 16 | -Dorg.apache.commons.logging.simplelog.log.org.apache.http.wire=DEBUG \ 17 | -Dapple.laf.useScreenMenuBar=true \ 18 | -Dapple.awt.application.name=RESTClient \ 19 | -jar ui/build/libs/restclient-ui-$version-fat.jar 20 | -------------------------------------------------------------------------------- /server/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java-library' 3 | } 4 | 5 | dependencies { 6 | api 'com.github.wiztools:commons-lib:0.4.3', 7 | 'org.eclipse.jetty:jetty-server:11.0.22', 8 | 'org.eclipse.jetty:jetty-servlet:11.0.22', 9 | 'jakarta.servlet:jakarta.servlet-api:6.1.0' 10 | testImplementation 'junit:junit:4.+' 11 | } 12 | -------------------------------------------------------------------------------- /server/src/main/java/org/wiztools/restclient/server/TraceServer.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.server; 2 | 3 | import java.util.logging.Logger; 4 | import org.eclipse.jetty.server.Server; 5 | import org.eclipse.jetty.servlet.ServletContextHandler; 6 | import org.eclipse.jetty.servlet.ServletHolder; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | public class TraceServer { 13 | 14 | private static final Logger LOG = Logger.getLogger(TraceServer.class.getName()); 15 | 16 | public static final String SYS_PROPERTY_PORT = "rc:trace-server-port"; 17 | public static final int DEFAULT_PORT = 10101; 18 | 19 | public static final int PORT; 20 | private static final Server server; 21 | 22 | static{ 23 | // Set the port 24 | int port = 0; 25 | try{ 26 | String t = System.getProperty(SYS_PROPERTY_PORT); 27 | if(t != null){ 28 | int t_port = Integer.parseInt(t); 29 | if(t_port > 65535 || t_port < 0){ 30 | LOG.warning(SYS_PROPERTY_PORT 31 | + " is not in valid port range. Reverting to default:" 32 | + DEFAULT_PORT); 33 | port = DEFAULT_PORT; 34 | } 35 | else{ 36 | port = t_port; 37 | } 38 | } 39 | else{ // System property not supplied, use default port 40 | port = DEFAULT_PORT; 41 | } 42 | } 43 | catch(NumberFormatException ex){ 44 | LOG.warning(SYS_PROPERTY_PORT 45 | + " is not a number. Reverting to default: " 46 | + DEFAULT_PORT); 47 | port = DEFAULT_PORT; 48 | } 49 | PORT = port; 50 | 51 | // Create the server object 52 | server = new Server(PORT); 53 | 54 | // Attach the trace servlet 55 | ServletContextHandler ctx = new ServletContextHandler(); 56 | ctx.setContextPath("/"); 57 | server.setHandler(ctx); 58 | 59 | ctx.addServlet(new ServletHolder(new TraceServlet()), "/*"); 60 | 61 | server.setStopAtShutdown(true); 62 | } 63 | 64 | public static synchronized void start() throws Exception{ 65 | if(!(server.isStarted() || server.isRunning())){ 66 | server.start(); 67 | } 68 | } 69 | 70 | public static boolean isRunning(){ 71 | return server.isRunning() || server.isStarted(); 72 | } 73 | 74 | public static synchronized void stop() throws Exception{ 75 | server.stop(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /server/src/main/java/org/wiztools/restclient/server/Util.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.server; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.nio.ByteBuffer; 6 | import java.nio.CharBuffer; 7 | import java.nio.charset.CharsetDecoder; 8 | import java.nio.charset.CodingErrorAction; 9 | import org.wiztools.commons.Charsets; 10 | import org.wiztools.commons.StreamUtil; 11 | 12 | /** 13 | * 14 | * @author subwiz 15 | */ 16 | class Util { 17 | private Util() {} 18 | 19 | private static final int MAX_BODY_CHARS = 100; 20 | 21 | static String inputStreamToString(InputStream is) throws IOException { 22 | CharsetDecoder decoder = Charsets.US_ASCII.newDecoder(); 23 | decoder.onMalformedInput(CodingErrorAction.IGNORE); 24 | decoder.onUnmappableCharacter(CodingErrorAction.REPLACE); 25 | decoder.replaceWith("?"); 26 | CharBuffer buffer = decoder.decode( 27 | ByteBuffer.wrap(StreamUtil.inputStream2Bytes(is))); 28 | String t = buffer.toString(); 29 | t = (t.length()<(MAX_BODY_CHARS+1))? t: t.substring(MAX_BODY_CHARS); 30 | if(t.isEmpty()) { 31 | return ""; 32 | } 33 | return t.replaceAll("\\p{C}", "?") + "..."; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | include 'server' 2 | include 'lib' 3 | include 'ui' 4 | include 'cli' 5 | // include 'restclient-jfx' 6 | -------------------------------------------------------------------------------- /ui/ant-lib/ant-xpath-task-1.0-SNAPSHOT.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/ant-lib/ant-xpath-task-1.0-SNAPSHOT.jar -------------------------------------------------------------------------------- /ui/ant-lib/appbundler-1.0ea.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/ant-lib/appbundler-1.0ea.jar -------------------------------------------------------------------------------- /ui/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'java' 3 | id 'application' 4 | id 'com.gradleup.shadow' version '9.0.0-beta11' 5 | id 'project-report' 6 | } 7 | 8 | // Application plugin config: 9 | application{ 10 | mainClass = 'org.wiztools.restclient.ui.Main' 11 | applicationName = 'restclient-ui' 12 | applicationDefaultJvmArgs = ['-Xms128m', '-Xmx512m'] 13 | } 14 | 15 | tasks.withType(Tar) { 16 | compression = Compression.GZIP 17 | archiveExtension = 'tgz' // set the extension to .tgz instead of .tar.gz 18 | } 19 | 20 | tasks.named('shadowJar', com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar) { 21 | archiveBaseName = 'restclient-ui' 22 | archiveClassifier = 'fat' 23 | } 24 | 25 | dependencies { 26 | implementation project(':lib'), 27 | 'org.apache.xmlgraphics:batik-transcoder:1.18', 28 | 'org.apache.xmlgraphics:batik-codec:1.18', 29 | 'org.wiztools:filechooser-abstraction:0.1.0', 30 | 'com.jidesoft:jide-oss:3.6.18', 31 | 'org.swinglabs.swingx:swingx-autocomplete:1.6.5-1', 32 | 'com.fifesoft:rsyntaxtextarea:3.5.3', 33 | 'com.formdev:flatlaf:3.5.4', 34 | 'com.github.pcj:google-options:1.0.0', 35 | 'com.github.rjeschke:txtmark:0.13', 36 | 'org.slf4j:slf4j-simple:2.0.17' // for jetty logs 37 | testImplementation 'junit:junit:4.+' 38 | } 39 | -------------------------------------------------------------------------------- /ui/graphics-src/30_icon_art_text2.artx/Preview/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/30_icon_art_text2.artx/Preview/preview.png -------------------------------------------------------------------------------- /ui/graphics-src/30_icon_art_text2.artx/QuickLook/Preview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/30_icon_art_text2.artx/QuickLook/Preview.pdf -------------------------------------------------------------------------------- /ui/graphics-src/30_icon_art_text2.artx/doc.thread: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/30_icon_art_text2.artx/doc.thread -------------------------------------------------------------------------------- /ui/graphics-src/README.md: -------------------------------------------------------------------------------- 1 | Created using Art Text 2 in Mac. 2 | -------------------------------------------------------------------------------- /ui/graphics-src/mac-icon_1024.artx/Preview/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/mac-icon_1024.artx/Preview/preview.png -------------------------------------------------------------------------------- /ui/graphics-src/mac-icon_1024.artx/QuickLook/Preview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/mac-icon_1024.artx/QuickLook/Preview.pdf -------------------------------------------------------------------------------- /ui/graphics-src/mac-icon_1024.artx/doc.thread: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/mac-icon_1024.artx/doc.thread -------------------------------------------------------------------------------- /ui/graphics-src/rest-client-splash.artx/Preview/preview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/rest-client-splash.artx/Preview/preview.png -------------------------------------------------------------------------------- /ui/graphics-src/rest-client-splash.artx/QuickLook/Preview.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/rest-client-splash.artx/QuickLook/Preview.pdf -------------------------------------------------------------------------------- /ui/graphics-src/rest-client-splash.artx/doc.thread: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/graphics-src/rest-client-splash.artx/doc.thread -------------------------------------------------------------------------------- /ui/src/main/app-resources/rest-client_30.icns: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/src/main/app-resources/rest-client_30.icns -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/AboutDialog.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.awt.AWTEvent; 4 | import java.awt.BorderLayout; 5 | import java.awt.FlowLayout; 6 | import java.awt.GridLayout; 7 | import java.awt.event.ActionEvent; 8 | import java.awt.event.ActionListener; 9 | 10 | import javax.annotation.PostConstruct; 11 | import javax.inject.Inject; 12 | import javax.swing.*; 13 | import org.wiztools.restclient.MessageI18N; 14 | import org.wiztools.restclient.RCConstants; 15 | import org.wiztools.restclient.Versions; 16 | 17 | /** 18 | * 19 | * @author schandran 20 | */ 21 | class AboutDialog extends EscapableDialog { 22 | 23 | private AboutDialog me = this; 24 | 25 | @Inject 26 | public AboutDialog(RESTUserInterface ui){ 27 | super(ui.getFrame(), true); 28 | } 29 | 30 | @PostConstruct 31 | protected void init(){ 32 | // Title 33 | setTitle("About"); 34 | 35 | JPanel jp = new JPanel(); 36 | jp.setBorder(BorderFactory.createEmptyBorder( 37 | RESTViewImpl.BORDER_WIDTH, 38 | RESTViewImpl.BORDER_WIDTH, 39 | RESTViewImpl.BORDER_WIDTH, 40 | RESTViewImpl.BORDER_WIDTH)); 41 | jp.setLayout(new BorderLayout()); 42 | 43 | JPanel jp_north = new JPanel(); 44 | jp_north.setLayout(new FlowLayout(FlowLayout.CENTER)); 45 | JLabel jl_title = new JLabel( 46 | "

" + 47 | RCConstants.TITLE + Versions.CURRENT + 48 | "

"); 49 | jp_north.add(jl_title); 50 | jp.add(jp_north, BorderLayout.NORTH); 51 | 52 | JPanel jp_center = new JPanel(); 53 | jp_center.setLayout(new GridLayout(1, 1)); 54 | JTextPane jtp = new JTextPane(); 55 | jtp.setEditable(false); 56 | jtp.setContentType("text/html"); 57 | jtp.setText(MessageI18N.getMessage("menu.help.about")); 58 | jp_center.add(new JScrollPane(jtp)); 59 | jp.add(jp_center, BorderLayout.CENTER); 60 | 61 | JPanel jp_south = new JPanel(); 62 | jp_south.setLayout(new FlowLayout(FlowLayout.CENTER)); 63 | JButton jb_ok = new JButton("Ok"); 64 | jb_ok.setMnemonic('o'); 65 | jb_ok.addActionListener(new ActionListener() { 66 | @Override 67 | public void actionPerformed(ActionEvent arg0) { 68 | hideMe(); 69 | } 70 | }); 71 | getRootPane().setDefaultButton(jb_ok); 72 | jp_south.add(jb_ok); 73 | jp.add(jp_south, BorderLayout.SOUTH); 74 | 75 | setContentPane(jp); 76 | 77 | pack(); 78 | 79 | jb_ok.requestFocus(); 80 | } 81 | 82 | @Override 83 | public void doEscape(AWTEvent event) { 84 | hideMe(); 85 | } 86 | 87 | public void hideMe(){ 88 | me.setVisible(false); 89 | } 90 | 91 | } 92 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/AbstractScriptEditor.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public abstract class AbstractScriptEditor implements ScriptEditor { 8 | private String source; 9 | 10 | @Override 11 | public final void setText(String text) { 12 | source = text; 13 | setViewText(text); 14 | } 15 | 16 | @Override 17 | public final void setSourceText(String text) { 18 | source = text; 19 | } 20 | 21 | @Override 22 | public final String getSourceText() { 23 | return source; 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/AuthHelper.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.util.List; 4 | import org.wiztools.restclient.bean.HTTPAuthMethod; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public class AuthHelper { 11 | 12 | public static final String NONE = "None"; 13 | public static final String BASIC = "BASIC"; 14 | public static final String DIGEST = "DIGEST"; 15 | public static final String OAUTH2_BEARER = "OAuth2 Bearer"; 16 | 17 | private static final String[] ALL = new String[] { 18 | NONE, 19 | BASIC, 20 | DIGEST, 21 | OAUTH2_BEARER, 22 | }; 23 | 24 | public static String[] getAll() { 25 | return ALL; 26 | } 27 | 28 | public static boolean isBasicOrDigest(List authMethods) { 29 | return ( 30 | authMethods.contains(HTTPAuthMethod.BASIC) || 31 | authMethods.contains(HTTPAuthMethod.DIGEST) 32 | ); 33 | } 34 | 35 | public static boolean isBearer(List authMethods) { 36 | return authMethods.contains(HTTPAuthMethod.OAUTH_20_BEARER); 37 | } 38 | 39 | // String methods: 40 | public static boolean isNone(String input) { 41 | return NONE.equals(input); 42 | } 43 | 44 | public static boolean isBasicOrDigest(String input) { 45 | return isBasic(input) || isDigest(input); 46 | } 47 | 48 | public static boolean isBasic(String input) { 49 | return BASIC.equals(input); 50 | } 51 | 52 | public static boolean isDigest(String input) { 53 | return DIGEST.equals(input); 54 | } 55 | 56 | public static boolean isBearer(String input) { 57 | return OAUTH2_BEARER.equals(input); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/EncodingUtil.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.net.URLDecoder; 5 | import java.net.URLEncoder; 6 | 7 | /** 8 | * Utility class for JavaScript compatible UTF-8 encoding and decoding. 9 | * 10 | * @see http://stackoverflow.com/questions/607176/java-equivalent-to-javascripts-encodeuricomponent-that-produces-identical-output 11 | * @author John Topley 12 | */ 13 | class EncodingUtil { 14 | /** 15 | * Decodes the passed UTF-8 String using an algorithm that's compatible with 16 | * JavaScript's decodeURIComponent function. Returns 17 | * null if the String is null. 18 | * 19 | * @param s The UTF-8 encoded String to be decoded 20 | * @return the decoded String 21 | */ 22 | public static String decodeURIComponent(String s) { 23 | if (s == null) { 24 | return null; 25 | } 26 | 27 | String result = null; 28 | 29 | try { 30 | result = URLDecoder.decode(s, "UTF-8"); 31 | } 32 | 33 | // This exception should never occur. 34 | catch (UnsupportedEncodingException e) { 35 | result = s; 36 | } 37 | 38 | return result; 39 | } 40 | 41 | /** 42 | * Encodes the passed String as UTF-8 using an algorithm that's compatible 43 | * with JavaScript's encodeURIComponent function. Returns 44 | * null if the String is null. 45 | * 46 | * @param s The String to be encoded 47 | * @return the encoded String 48 | */ 49 | public static String encodeURIComponent(String s) { 50 | String result = null; 51 | 52 | try { 53 | result = URLEncoder.encode(s, "UTF-8") 54 | .replaceAll("\\+", "%20") 55 | .replaceAll("\\%21", "!") 56 | .replaceAll("\\%27", "'") 57 | .replaceAll("\\%28", "(") 58 | .replaceAll("\\%29", ")") 59 | .replaceAll("\\%7E", "~"); 60 | } 61 | 62 | // This exception should never occur. 63 | catch (UnsupportedEncodingException e) { 64 | result = s; 65 | } 66 | 67 | return result; 68 | } 69 | 70 | /** 71 | * Private constructor to prevent this class from being instantiated. 72 | */ 73 | private EncodingUtil() {} 74 | } 75 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/EscapableDialog.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.awt.AWTEvent; 4 | import java.awt.Component; 5 | import java.awt.Container; 6 | import java.awt.Frame; 7 | import java.awt.event.ContainerEvent; 8 | import java.awt.event.ContainerListener; 9 | import java.awt.event.KeyEvent; 10 | import java.awt.event.KeyListener; 11 | import java.awt.event.WindowAdapter; 12 | import java.awt.event.WindowEvent; 13 | import javax.swing.JDialog; 14 | 15 | /** 16 | * 17 | * @author subwiz 18 | */ 19 | public abstract class EscapableDialog extends JDialog implements KeyListener, ContainerListener { 20 | 21 | private final Frame _frame; 22 | 23 | public EscapableDialog(Frame f, boolean modal) { 24 | super(f, modal); 25 | _frame = f; 26 | registerKeyAction(this); 27 | this.addWindowListener(new WindowAdapter() { 28 | @Override 29 | public void windowClosing(WindowEvent event){ 30 | doEscape(event); 31 | } 32 | }); 33 | } 34 | 35 | public abstract void doEscape(AWTEvent event); 36 | 37 | //KeyListener interface 38 | @Override 39 | public void keyPressed(KeyEvent e) { 40 | if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { 41 | doEscape(e); 42 | } 43 | } 44 | 45 | @Override 46 | public void keyReleased(KeyEvent e) { 47 | } 48 | 49 | @Override 50 | public void keyTyped(KeyEvent e) { 51 | } 52 | 53 | //ContainerListener interface 54 | @Override 55 | public void componentAdded(ContainerEvent e) { 56 | registerKeyAction(e.getChild()); 57 | } 58 | 59 | @Override 60 | public void componentRemoved(ContainerEvent e) { 61 | registerKeyAction(e.getChild()); 62 | } 63 | 64 | private void registerKeyAction(Component c) { 65 | if (c instanceof EscapableDialog == false) { 66 | c.removeKeyListener(this); 67 | c.addKeyListener(this); 68 | } 69 | 70 | if (c instanceof Container) { 71 | Container cnt = (Container) c; 72 | cnt.removeContainerListener(this); 73 | cnt.addContainerListener(this); 74 | Component[] ch = cnt.getComponents(); 75 | for (int i = 0; i < ch.length; i++) { 76 | registerKeyAction(ch[i]); 77 | } 78 | } 79 | } 80 | 81 | /** 82 | * Center the dialog relative to parent before displaying. 83 | */ 84 | @Override 85 | public void setVisible(boolean boo){ 86 | if(boo){ 87 | this.setLocationRelativeTo(_frame); 88 | } 89 | super.setVisible(boo); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/FileChooserType.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | /** 4 | * 5 | * @author Subhash 6 | */ 7 | public enum FileChooserType { 8 | OPEN_REQUEST, 9 | OPEN_RESPONSE, 10 | OPEN_ARCHIVE, 11 | OPEN_REQUEST_BODY, 12 | OPEN_HISTORY, 13 | OPEN_TEST_SCRIPT, 14 | OPEN_GENERIC, 15 | 16 | SAVE_REQUEST, 17 | SAVE_RESPONSE, 18 | SAVE_ARCHIVE, 19 | SAVE_RESPONSE_BODY, 20 | SAVE_HISTORY; 21 | } 22 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/FontableEditor.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.awt.Font; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface FontableEditor { 10 | public String FONT_NAME_PROPERTY = "font.options.font"; 11 | public String FONT_SIZE_PROPERTY = "font.options.fontSize"; 12 | 13 | public void setEditorFont(Font font); 14 | public Font getEditorFont(); 15 | } 16 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/ISessionView.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import org.wiztools.restclient.bean.Request; 4 | import org.wiztools.restclient.bean.Response; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | interface ISessionView { 11 | public void add(Request request, Response response); 12 | public void clear(); 13 | } 14 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/MessageDialog.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.awt.AWTEvent; 4 | import java.awt.BorderLayout; 5 | import java.awt.FlowLayout; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | import javax.inject.Inject; 9 | import javax.swing.JButton; 10 | import javax.swing.JPanel; 11 | import javax.swing.JScrollPane; 12 | import javax.swing.JTextArea; 13 | 14 | /** 15 | * 16 | * @author schandran 17 | */ 18 | public class MessageDialog extends EscapableDialog { 19 | 20 | private final MessageDialog messageDialog; 21 | private RESTUserInterface ui; 22 | 23 | /** Creates new form ErrorDialog */ 24 | @Inject 25 | public MessageDialog(RESTUserInterface ui) { 26 | super(ui.getFrame(), true); 27 | this.ui = ui; 28 | this.setTitle("Error!"); 29 | initComponents(); 30 | this.messageDialog = this; 31 | } 32 | 33 | private void initComponents() { 34 | 35 | JPanel jp = new JPanel(); 36 | jp.setLayout(new BorderLayout()); 37 | jta_error = new JTextArea(10, 40); 38 | jta_error.setEditable(false); 39 | JScrollPane jsp = new JScrollPane(jta_error); 40 | jp.add(jsp, BorderLayout.CENTER); 41 | 42 | JPanel jp_south = new JPanel(); 43 | jp_south.setLayout(new FlowLayout(FlowLayout.CENTER)); 44 | 45 | jb_ok = new JButton("Ok"); 46 | jb_ok.setMnemonic('o'); 47 | getRootPane().setDefaultButton(jb_ok); 48 | jb_ok.addActionListener(new ActionListener() { 49 | public void actionPerformed(ActionEvent event) { 50 | jb_okActionPerformed(event); 51 | } 52 | }); 53 | jp_south.add(jb_ok); 54 | 55 | jp.add(jp_south, BorderLayout.SOUTH); 56 | 57 | this.setContentPane(jp); 58 | 59 | pack(); 60 | } 61 | 62 | @Override 63 | public void doEscape(AWTEvent event){ 64 | hideDialog(); 65 | } 66 | 67 | private void jb_okActionPerformed(java.awt.event.ActionEvent evt) { 68 | hideDialog(); 69 | } 70 | 71 | private void hideDialog(){ 72 | messageDialog.setVisible(false); 73 | } 74 | 75 | void showError(final String error){ 76 | showMessage("Error", error); 77 | } 78 | 79 | void showMessage(final String title, final String message){ 80 | messageDialog.setTitle(title); 81 | jta_error.setText(message); 82 | jta_error.setCaretPosition(0); 83 | messageDialog.setLocationRelativeTo(ui.getFrame()); 84 | jb_ok.requestFocus(); 85 | messageDialog.setVisible(true); 86 | } 87 | 88 | private javax.swing.JTextArea jta_error; 89 | private JButton jb_ok; 90 | } 91 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/Mime.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.net.URLConnection; 6 | import java.nio.file.Files; 7 | 8 | public final class Mime { 9 | /** 10 | * This is the most accurate way to determine the content-type. 11 | * @param file 12 | * @return 13 | */ 14 | public static String forFile(File file) { 15 | try { 16 | return Files.probeContentType(file.toPath()); 17 | } catch(IOException ex) { 18 | return "application/octet-stream"; 19 | } 20 | } 21 | 22 | /** 23 | * This is a less accurate implementation of determining the content-type. 24 | * @param name 25 | * @return 26 | */ 27 | public static String forFileName(String name) { 28 | return URLConnection.guessContentTypeFromName(name); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/MultiEntryAdd.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import org.wiztools.restclient.util.MultiEntryRes; 4 | 5 | /** 6 | * 7 | * @author Subhash 8 | */ 9 | interface MultiEntryAdd { 10 | public void add(MultiEntryRes res); 11 | } 12 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/Native.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | public final class Native { 4 | public static final boolean isMac; 5 | 6 | static { 7 | String osName = System.getProperty("os.name").toLowerCase(); 8 | isMac = osName.startsWith("mac"); 9 | } 10 | 11 | static { 12 | if(isMac) { 13 | System.setProperty("apple.laf.useScreenMenuBar", "true"); 14 | System.setProperty("apple.awt.application.name", "RESTClient"); 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/RCFileFilter.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.io.File; 4 | import org.wiztools.filechooser.FileFilter; 5 | import org.wiztools.restclient.FileType; 6 | 7 | /** 8 | * 9 | * @author Subhash 10 | */ 11 | public class RCFileFilter implements FileFilter { 12 | 13 | private final String type; 14 | public RCFileFilter(String type){ 15 | this.type = type; 16 | } 17 | 18 | @Override 19 | public final boolean accept(File f) { 20 | if(f.isDirectory()){ 21 | return true; 22 | } 23 | final String path = f.getAbsolutePath().toLowerCase(); 24 | if(FileType.REQUEST_EXT.equals(type) && path.endsWith(FileType.REQUEST_EXT)) { 25 | return true; 26 | } 27 | else if(FileType.RESPONSE_EXT.equals(type) && path.endsWith(FileType.RESPONSE_EXT)) { 28 | return true; 29 | } 30 | else if(FileType.ARCHIVE_EXT.equals(type) && path.endsWith(FileType.ARCHIVE_EXT)) { 31 | return true; 32 | } 33 | return false; 34 | } 35 | 36 | @Override 37 | public final String getDescription() { 38 | return FileType.getNameFromExt(type); 39 | } 40 | 41 | public String getFileTypeExt(){ 42 | return this.type; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/RCFileView.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.io.File; 4 | import javax.swing.Icon; 5 | import javax.swing.filechooser.FileView; 6 | import org.wiztools.restclient.FileType; 7 | 8 | /** 9 | * 10 | * @author Subhash 11 | */ 12 | public class RCFileView extends FileView { 13 | @Override 14 | public String getTypeDescription(final File f) { 15 | return FileType.getNameFromExt(FileType.getType(f)); 16 | } 17 | 18 | public static final String iconBasePath = "org/wiztools/restclient/"; 19 | public static final Icon FOLDER_ICON = SVGLoad.scaledIcon(iconBasePath + "s_folder.svg"); 20 | public static final Icon FILE_ICON = SVGLoad.scaledIcon(iconBasePath + "s_file.svg"); 21 | public static final Icon REQUEST_ICON = SVGLoad.scaledIcon(iconBasePath + "s_request.svg"); 22 | public static final Icon RESPONSE_ICON = SVGLoad.scaledIcon(iconBasePath + "s_response.svg"); 23 | public static final Icon ARCHIVE_ICON = SVGLoad.scaledIcon(iconBasePath + "s_archive.svg"); 24 | 25 | @Override 26 | public Icon getIcon(final File f){ 27 | Icon icon; 28 | 29 | String type = FileType.getType(f); 30 | if(f.isDirectory()){ 31 | icon = FOLDER_ICON; 32 | } 33 | else if(FileType.REQUEST_EXT.equals(type)){ 34 | icon = REQUEST_ICON; 35 | } 36 | else if(FileType.RESPONSE_EXT.equals(type)){ 37 | icon = RESPONSE_ICON; 38 | } 39 | else if(FileType.ARCHIVE_EXT.equals(type)){ 40 | icon = ARCHIVE_ICON; 41 | } 42 | else{ 43 | icon = FILE_ICON; 44 | } 45 | return icon; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/RCUIConstants.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.util.logging.Level; 4 | import java.util.logging.Logger; 5 | import org.wiztools.commons.StringUtil; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | public final class RCUIConstants { 12 | 13 | private static final Logger LOG = Logger.getLogger(RCUIConstants.class.getName()); 14 | 15 | private RCUIConstants() {} 16 | 17 | public static final String SYS_PROPERTY_FONT_SIZE = "rc:ui-font-size"; 18 | public static final int DEFAULT_UI_FONT_SIZE = 12; 19 | 20 | public static int getUIFontSize() { 21 | final String t = System.getProperty(RCUIConstants.SYS_PROPERTY_FONT_SIZE); 22 | if(StringUtil.isNotEmpty(t)) { 23 | try { 24 | final int fontSize = Integer.parseInt(t); 25 | if(fontSize < RCUIConstants.DEFAULT_UI_FONT_SIZE) { 26 | throw new NumberFormatException("Font size value cannot be less than " 27 | + RCUIConstants.DEFAULT_UI_FONT_SIZE + "."); 28 | } 29 | return fontSize; 30 | } 31 | catch(NumberFormatException ex) { 32 | LOG.log(Level.WARNING, "Illegal font size specified: {0}", t); 33 | } 34 | } 35 | return -1; 36 | } 37 | 38 | public static int getUIFontSizeDefault() { 39 | final int size = getUIFontSize(); 40 | return size==-1? DEFAULT_UI_FONT_SIZE: size; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/RESTUserInterface.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import java.awt.Component; 5 | import java.io.File; 6 | import javax.swing.JFrame; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | @ImplementedBy(RESTMain.class) 13 | public interface RESTUserInterface { 14 | 15 | public JFrame getFrame(); 16 | 17 | public File getOpenFile(final FileChooserType type); 18 | 19 | public File getOpenFile(final FileChooserType type, final Component parent); 20 | 21 | public File getSaveFile(final FileChooserType type); 22 | 23 | public RESTView getView(); 24 | 25 | } 26 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/RESTView.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import java.awt.Container; 5 | import java.awt.Font; 6 | import org.wiztools.restclient.View; 7 | import org.wiztools.restclient.bean.Request; 8 | import org.wiztools.restclient.bean.Response; 9 | 10 | /** 11 | * 12 | * @author subwiz 13 | */ 14 | @ImplementedBy(RESTViewImpl.class) 15 | public interface RESTView extends View { 16 | int BORDER_WIDTH = 5; 17 | 18 | void disableBody(); 19 | 20 | void enableBody(); 21 | 22 | Request getLastRequest(); 23 | 24 | Response getLastResponse(); 25 | 26 | Request getRequestFromUI(); 27 | Response getResponseFromUI(); 28 | 29 | Font getTextAreaFont(); 30 | 31 | String getUrl(); 32 | 33 | void runClonedRequestTest(Request request, Response response); 34 | 35 | void setStatusMessage(final String msg); 36 | 37 | void setTextAreaFont(final Font f); 38 | 39 | void setTextAreaScrollSpeed(final int scrollSpeed); 40 | 41 | void setUrl(String url); 42 | 43 | void showError(final String error); 44 | void showError(final Throwable ex); 45 | 46 | void showMessage(final String title, final String message); 47 | 48 | void setUIFromRequest(Request request); 49 | void setUIFromResponse(Response response); 50 | 51 | void clearUIResponse(); 52 | 53 | void clearUIRequest(); 54 | 55 | void setUIToLastRequestResponse(); 56 | 57 | Container getContainer(); 58 | } 59 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/RSyntaxScriptEditor.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; 4 | import org.fife.ui.rsyntaxtextarea.SyntaxConstants; 5 | 6 | import javax.swing.*; 7 | import javax.swing.text.JTextComponent; 8 | 9 | /** 10 | * 11 | * @author subwiz 12 | */ 13 | public class RSyntaxScriptEditor extends AbstractScriptEditor { 14 | 15 | private final RSyntaxTextArea textArea = new RSyntaxTextArea(); 16 | 17 | public RSyntaxScriptEditor() { 18 | // remove the default popup: 19 | textArea.setPopupMenu(null); 20 | 21 | // Anti-aliased: 22 | textArea.setAntiAliasingEnabled(true); 23 | } 24 | 25 | public RSyntaxScriptEditor(TextEditorSyntax syntax) { 26 | this(); 27 | setSyntax(syntax); 28 | } 29 | 30 | @Override 31 | public final void setSyntax(TextEditorSyntax syntax) { 32 | switch(syntax) { 33 | case GROOVY: 34 | textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_GROOVY); 35 | break; 36 | case XML: 37 | textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_XML); 38 | break; 39 | case JSON: 40 | case JS: 41 | textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT); 42 | break; 43 | case HTML: 44 | textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML); 45 | break; 46 | case CSS: 47 | textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CSS); 48 | break; 49 | default: 50 | textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE); 51 | } 52 | } 53 | 54 | @Override 55 | public JComponent getEditorView() { 56 | return textArea; 57 | } 58 | 59 | @Override 60 | public JTextComponent getEditorComponent() { 61 | return textArea; 62 | } 63 | 64 | @Override 65 | public String getText() { 66 | return textArea.getText(); 67 | } 68 | 69 | @Override 70 | public void setViewText(String text) { 71 | textArea.setText(text); 72 | } 73 | 74 | @Override 75 | public String getViewText() { 76 | return textArea.getText(); 77 | } 78 | 79 | @Override 80 | public void setCaretPosition(int offset) { 81 | textArea.setCaretPosition(offset); 82 | } 83 | 84 | @Override 85 | public void setEditable(boolean editable) { 86 | textArea.setEditable(editable); 87 | } 88 | 89 | @Override 90 | public void setEnabled(boolean enabled) { 91 | textArea.setEnabled(enabled); 92 | } 93 | 94 | @Override 95 | public void setPopupMenu(final JPopupMenu menu) { 96 | textArea.setPopupMenu(menu); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/SVGLoad.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.io.ByteArrayOutputStream; 4 | import java.io.IOException; 5 | import java.net.URL; 6 | import java.awt.GraphicsConfiguration; 7 | import java.awt.GraphicsDevice; 8 | import java.awt.GraphicsEnvironment; 9 | import javax.swing.ImageIcon; 10 | 11 | import org.apache.batik.transcoder.TranscoderException; 12 | import org.apache.batik.transcoder.TranscoderInput; 13 | import org.apache.batik.transcoder.TranscoderOutput; 14 | import org.apache.batik.transcoder.image.PNGTranscoder; 15 | 16 | public final class SVGLoad { 17 | private static final double SCALE_FACTOR = getScreenScaleFactor(); 18 | 19 | private static double getScreenScaleFactor() { 20 | GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); 21 | GraphicsDevice gd = ge.getDefaultScreenDevice(); 22 | GraphicsConfiguration gc = gd.getDefaultConfiguration(); 23 | return gc.getDefaultTransform().getScaleX(); 24 | } 25 | 26 | /** 27 | * 28 | * @param path is the resource path in the classpath. 29 | * @param baseWidth 30 | * @param baseHeight 31 | * @return 32 | */ 33 | public static ImageIcon scaledIcon(String path, int baseWidth, int baseHeight) { 34 | try { 35 | // Calculate scaled dimensions 36 | int scaledWidth = (int) (baseWidth * SCALE_FACTOR); 37 | int scaledHeight = (int) (baseHeight * SCALE_FACTOR); 38 | 39 | // Set up SVG transcoder 40 | URL url = SVGLoad.class.getClassLoader().getResource(path); 41 | TranscoderInput input = new TranscoderInput(url.openStream()); 42 | ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 43 | TranscoderOutput output = new TranscoderOutput(outputStream); 44 | 45 | PNGTranscoder transcoder = new PNGTranscoder(); 46 | transcoder.addTranscodingHint(PNGTranscoder.KEY_WIDTH, (float) scaledWidth); 47 | transcoder.addTranscodingHint(PNGTranscoder.KEY_HEIGHT, (float) scaledHeight); 48 | 49 | // Perform transcoding 50 | transcoder.transcode(input, output); 51 | 52 | // Convert to ImageIcon 53 | byte[] imageData = outputStream.toByteArray(); 54 | return new ImageIcon(imageData); 55 | 56 | } catch (TranscoderException | IOException ex) { 57 | throw new RuntimeException("[loadSVG]", ex); 58 | } 59 | } 60 | 61 | private static final int ICON_DEF_WIDTH = 8, ICON_DEF_HEIGHT = 8; 62 | 63 | public static ImageIcon scaledIcon(String path) { 64 | return scaledIcon(path, ICON_DEF_WIDTH, ICON_DEF_HEIGHT); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/ScriptEditor.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import javax.swing.JComponent; 4 | import javax.swing.JPopupMenu; 5 | import javax.swing.text.JTextComponent; 6 | 7 | /** 8 | * 9 | */ 10 | public interface ScriptEditor { 11 | 12 | public void setSyntax(TextEditorSyntax syntax); 13 | 14 | /** 15 | * view component for test script editor 16 | * 17 | * @return JComponent object 18 | */ 19 | public JComponent getEditorView(); 20 | 21 | /** 22 | * The editor component is returned. 23 | */ 24 | public JTextComponent getEditorComponent(); 25 | 26 | /** 27 | * get test script code 28 | * 29 | * @return script 30 | */ 31 | public String getText(); 32 | 33 | /** 34 | * set text script code 35 | * 36 | * @param text script code 37 | */ 38 | public void setText(String text); 39 | 40 | public String getSourceText(); 41 | 42 | public void setSourceText(String text); 43 | 44 | public String getViewText(); 45 | 46 | public void setViewText(String text); 47 | 48 | /** 49 | * set caret position 50 | * 51 | * @param offset offset 52 | */ 53 | public void setCaretPosition(int offset); 54 | 55 | /** 56 | * set editable mark 57 | * 58 | * @param editable editable mark 59 | */ 60 | public void setEditable(boolean editable); 61 | 62 | public void setEnabled(boolean enabled); 63 | 64 | public void setPopupMenu(JPopupMenu menu); 65 | } -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/ScriptEditorFactory.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public final class ScriptEditorFactory { 8 | 9 | public static ScriptEditor getGroovyScriptEditor(){ 10 | return new RSyntaxScriptEditor(TextEditorSyntax.GROOVY); 11 | } 12 | 13 | public static ScriptEditor getXMLScriptEditor(){ 14 | return new RSyntaxScriptEditor(TextEditorSyntax.XML); 15 | } 16 | 17 | public static ScriptEditor getTextAreaScriptEditor(){ 18 | return new RSyntaxScriptEditor(TextEditorSyntax.NONE); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/ScrollableComponent.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | /** 4 | * @author FS 5 | */ 6 | public interface ScrollableComponent { 7 | public void setScrollSpeed(int scrollSpeed); 8 | } 9 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/SessionFrame.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Container; 5 | import java.awt.Dimension; 6 | import java.awt.event.WindowAdapter; 7 | import java.awt.event.WindowEvent; 8 | import javax.swing.JFrame; 9 | import javax.swing.JOptionPane; 10 | import javax.swing.JScrollPane; 11 | import javax.swing.JTable; 12 | import javax.swing.WindowConstants; 13 | 14 | /** 15 | * 16 | * @author subwiz 17 | */ 18 | class SessionFrame extends JFrame { 19 | 20 | private final SessionFrame me; 21 | 22 | private final SessionTableModel stm = new SessionTableModel(new String[]{"Request", "Response"}); 23 | private final JTable jt = new JTable(stm); 24 | 25 | public SessionFrame(String title){ 26 | super(title); 27 | me = this; 28 | 29 | Container c = this.getContentPane(); 30 | c.setLayout(new BorderLayout()); 31 | 32 | jt.setPreferredSize(new Dimension(200, 300)); 33 | c.add(new JScrollPane(jt), BorderLayout.CENTER); 34 | 35 | this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); 36 | this.addWindowListener(new WindowAdapter() { 37 | @Override 38 | public void windowClosing(WindowEvent we){ 39 | int confirmValue = JOptionPane.showConfirmDialog(me, "You will loose any unsaved session data if you\n" + 40 | " close the Session Window. Do you want to close?", "Close Session Window?", JOptionPane.YES_NO_OPTION); 41 | if(confirmValue == JOptionPane.YES_OPTION){ 42 | stm.clear(); 43 | me.setVisible(false); 44 | } 45 | } 46 | }); 47 | 48 | pack(); 49 | } 50 | 51 | public ISessionView getSessionView(){ 52 | return stm; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/StatusBarPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | @ImplementedBy(StatusBarPanelImpl.class) 10 | public interface StatusBarPanel extends ViewPanel { 11 | void setStatus(String status); 12 | 13 | void showProgressBar(); 14 | void hideProgressBar(); 15 | } 16 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/StatusBarPanelImpl.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Component; 5 | import java.awt.Dimension; 6 | import java.awt.event.ActionEvent; 7 | import java.awt.event.ActionListener; 8 | import java.util.Calendar; 9 | 10 | import javax.annotation.PostConstruct; 11 | import javax.swing.*; 12 | 13 | import org.wiztools.restclient.RCConstants; 14 | 15 | /** 16 | * 17 | * @author subwiz 18 | */ 19 | public class StatusBarPanelImpl extends JPanel implements StatusBarPanel { 20 | 21 | private final JLabel jl_status = new JLabel(" " + RCConstants.TITLE); 22 | private final JProgressBar jpb_status = new JProgressBar(); 23 | 24 | private Calendar statusLastUpdated; 25 | 26 | @PostConstruct 27 | protected void init() { 28 | // Status clear timer: 29 | // Start status clear timer: 30 | statusLastUpdated = Calendar.getInstance(); 31 | new Timer(5*1000, new ActionListener() { 32 | @Override 33 | public void actionPerformed(ActionEvent e) { 34 | Calendar c = (Calendar)statusLastUpdated.clone(); 35 | c.add(Calendar.SECOND, 20); 36 | if(Calendar.getInstance().after(c)){ 37 | setStatus(RCConstants.TITLE); 38 | } 39 | } 40 | }).start(); 41 | 42 | // Label 43 | setBorder(BorderFactory.createBevelBorder(1)); 44 | setLayout(new BorderLayout()); 45 | jl_status.setFont(UIUtil.FONT_DIALOG_PLAIN); 46 | add(jl_status, BorderLayout.CENTER); 47 | 48 | // Progress bar 49 | Dimension d = jpb_status.getPreferredSize(); 50 | d.height = d.height - 4; 51 | jpb_status.setPreferredSize(d); 52 | jpb_status.setIndeterminate(true); 53 | jpb_status.setVisible(false); 54 | add(jpb_status, BorderLayout.EAST); 55 | } 56 | 57 | @Override 58 | public void setStatus(String status) { 59 | jl_status.setText(" " + status); 60 | jl_status.setToolTipText(status); 61 | statusLastUpdated = Calendar.getInstance(); 62 | } 63 | 64 | @Override 65 | public void showProgressBar() { 66 | jpb_status.setVisible(true); 67 | } 68 | 69 | @Override 70 | public void hideProgressBar() { 71 | jpb_status.setVisible(false); 72 | } 73 | 74 | @Override 75 | public Component getComponent() { 76 | return this; 77 | } 78 | 79 | @Override 80 | public void clear() { 81 | setStatus("Cleared!"); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/TextEditorSyntax.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public enum TextEditorSyntax { 8 | NONE, GROOVY, XML, JSON, JS, HTML, CSS; 9 | } 10 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/ViewPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.awt.Component; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface ViewPanel { 10 | Component getComponent(); 11 | 12 | void clear(); 13 | } 14 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/component/BackgroundFormatterJob.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.component; 2 | 3 | import java.util.concurrent.ExecutorService; 4 | import java.util.concurrent.Executors; 5 | import java.util.concurrent.Future; 6 | import java.util.concurrent.TimeUnit; 7 | import javax.swing.SwingUtilities; 8 | 9 | /** 10 | * 11 | * @author subhash 12 | */ 13 | public class BackgroundFormatterJob { 14 | private final ExecutorService formatterThreadPool = Executors.newSingleThreadExecutor(); 15 | private Future formatterFuture; 16 | 17 | public void run(Runnable r, 18 | final BodyPopupMenuListener listener, 19 | boolean isSeparateThread) { 20 | if(isSeparateThread) { 21 | if(formatterFuture != null && !formatterFuture.isDone()) { 22 | listener.onMessage("Last formatter job running!"); 23 | return; 24 | } 25 | listener.onMessage("Starting formatter job..."); 26 | new Thread() { 27 | 28 | @Override 29 | public void run() { 30 | while(true) { 31 | // Sleep: 32 | try { 33 | TimeUnit.SECONDS.sleep(30); 34 | } 35 | catch(InterruptedException ex) { 36 | ex.printStackTrace(); 37 | } 38 | 39 | // Feedback to user: 40 | if(formatterFuture != null && !formatterFuture.isDone()) { 41 | SwingUtilities.invokeLater(new Runnable() { 42 | @Override 43 | public void run() { 44 | listener.onMessage("Still running formatter job..."); 45 | } 46 | }); 47 | } 48 | else { 49 | break; 50 | } 51 | } 52 | } 53 | 54 | }.start(); 55 | 56 | formatterFuture = formatterThreadPool.submit(r); 57 | } 58 | else { 59 | r.run(); 60 | } 61 | } 62 | 63 | public void cancelRunningJob() { 64 | if(formatterFuture != null && !formatterFuture.isDone()) { 65 | formatterFuture.cancel(true); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/component/BodyPopupMenuListener.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.component; 2 | 3 | /** 4 | * 5 | * @author subhash 6 | */ 7 | public interface BodyPopupMenuListener { 8 | void onSuccess(String msg); 9 | void onFailure(String msg); 10 | void onMessage(String msg); 11 | } 12 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/dnd/DndAction.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.dnd; 2 | 3 | import java.io.File; 4 | import java.util.List; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | public interface DndAction { 11 | void onDrop(List files); 12 | } 13 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/history/HistoryManager.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.history; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import org.wiztools.restclient.bean.Request; 7 | import org.wiztools.restclient.util.ConfigUtil; 8 | 9 | /** 10 | * 11 | * @author subwiz 12 | */ 13 | @ImplementedBy(HistoryManagerImpl.class) 14 | public interface HistoryManager { 15 | 16 | String HISTORY_SIZE_CONFIG_KEY = "ui.history.size"; 17 | 18 | int DEFAULT_HISTORY_SIZE = 15; 19 | File DEFAULT_FILE = ConfigUtil.getConfigFile("history.xml"); 20 | 21 | void setHistorySize(int size); 22 | int getHistorySize(); 23 | 24 | void add(Request request); 25 | 26 | Request back(); 27 | Request forward(); 28 | Request current(); 29 | Request lastRequest(); 30 | 31 | boolean isMostRecent(); 32 | boolean isOldest(); 33 | 34 | boolean isEmpty(); 35 | 36 | void clear(); 37 | 38 | void save(File file) throws IOException; 39 | void load(File file) throws IOException; 40 | } 41 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/lifecycle/LifecycleManager.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.lifecycle; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | @ImplementedBy(LifecycleManagerImpl.class) 10 | public interface LifecycleManager { 11 | void registerStartupListener(Startup startupListener); 12 | void registerShutdownListener(Shutdown shutdownListener); 13 | void runStartupListeners(); 14 | } 15 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/lifecycle/LifecycleManagerImpl.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.lifecycle; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | import javax.annotation.PostConstruct; 6 | import javax.inject.Singleton; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | @Singleton 13 | public class LifecycleManagerImpl implements LifecycleManager { 14 | 15 | private final List startupListeners = new ArrayList(); 16 | private final List shutdownListeners = new ArrayList(); 17 | 18 | @PostConstruct 19 | protected void init() { 20 | Runtime.getRuntime().addShutdownHook(new Thread() { 21 | 22 | @Override 23 | public void run() { 24 | for(Shutdown s: shutdownListeners) { 25 | s.onShutdown(); 26 | } 27 | } 28 | 29 | }); 30 | } 31 | 32 | @Override 33 | public void registerStartupListener(Startup startupListener) { 34 | startupListeners.add(startupListener); 35 | } 36 | 37 | @Override 38 | public void registerShutdownListener(Shutdown shutdownListener) { 39 | shutdownListeners.add(shutdownListener); 40 | } 41 | 42 | @Override 43 | public void runStartupListeners() { 44 | for(Startup s: startupListeners) { 45 | s.onStartup(); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/lifecycle/Shutdown.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.lifecycle; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface Shutdown { 8 | void onShutdown(); 9 | } 10 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/lifecycle/Startup.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.lifecycle; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public interface Startup { 8 | void onStartup(); 9 | } 10 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/option/IOptionsPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.option; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * 7 | * @author Subhash 8 | */ 9 | public interface IOptionsPanel { 10 | /** 11 | * Method for loading last saved option values from persistent storage. 12 | */ 13 | public void initOptions(); 14 | 15 | /** 16 | * Method for writing options to persistent storage. 17 | */ 18 | public void shutdownOptions(); 19 | 20 | /** 21 | * When Ok is pressed in the Options dialog, this method is called first. 22 | * @return List of errors, or an empty List, or null 23 | */ 24 | public List validateInput(); 25 | 26 | /** 27 | * After validation step, this method is called. 28 | * @return true on success, false on failure to set the options 29 | */ 30 | public boolean saveOptions(); 31 | 32 | /** 33 | * When Cancel button is pressed, this method is called--basically 34 | * used to revert the Option UI values to the last selected value. 35 | * @return 36 | */ 37 | public boolean revertOptions(); // When cancel is pressed 38 | } 39 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqauth/ReqAuthPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqauth; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import java.util.List; 5 | import org.wiztools.restclient.bean.Auth; 6 | import org.wiztools.restclient.ui.ViewPanel; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | @ImplementedBy(ReqAuthPanelImpl.class) 13 | public interface ReqAuthPanel extends ViewPanel { 14 | 15 | void setAuth(Auth auth); 16 | Auth getAuth(); 17 | List validateIfFilled(); 18 | } 19 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqbody/AddMultipartBaseDialog.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqbody; 2 | 3 | import java.awt.AWTEvent; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import org.wiztools.restclient.ui.EscapableDialog; 7 | import org.wiztools.restclient.ui.RESTUserInterface; 8 | 9 | /** 10 | * 11 | * @author subwiz 12 | */ 13 | public abstract class AddMultipartBaseDialog extends EscapableDialog { 14 | 15 | protected final List listeners = new ArrayList(); 16 | protected RESTUserInterface rest_ui; 17 | 18 | public AddMultipartBaseDialog(RESTUserInterface rest_ui) { 19 | super(rest_ui.getFrame(), true); 20 | 21 | this.rest_ui = rest_ui; 22 | } 23 | 24 | @Override 25 | public void doEscape(AWTEvent event) { 26 | clear(); 27 | setVisible(false); 28 | } 29 | 30 | public void addMultipartPartListener(AddMultipartPartListener listener) { 31 | listeners.add(listener); 32 | } 33 | 34 | public abstract void clear(); 35 | } 36 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqbody/AddMultipartPartListener.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqbody; 2 | 3 | import org.wiztools.restclient.bean.ReqEntityPart; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface AddMultipartPartListener { 10 | void addPart(ReqEntityPart part); 11 | } 12 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqbody/ContentTypeCharsetChangeListener.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqbody; 2 | 3 | /** 4 | * 5 | * @author Subhash 6 | */ 7 | public interface ContentTypeCharsetChangeListener { 8 | public void changed(String contentType, String charSet); 9 | } 10 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqbody/ContentTypeCharsetComponent.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqbody; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import java.nio.charset.Charset; 5 | import org.wiztools.restclient.bean.ContentType; 6 | import org.wiztools.restclient.ui.ViewPanel; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | @ImplementedBy(ContentTypeCharsetComponentImpl.class) 13 | public interface ContentTypeCharsetComponent extends ViewPanel { 14 | 15 | int TEXT_FIELD_LENGTH = 26; 16 | 17 | void disableComponent(); 18 | 19 | void enableComponent(); 20 | 21 | Charset getCharset(); 22 | 23 | String getCharsetString(); 24 | 25 | ContentType getContentType(); 26 | 27 | String getContentTypeCharsetString(); 28 | 29 | String getContentTypeString(); 30 | 31 | void requestFocus(); 32 | 33 | void setCharset(Charset charset); 34 | 35 | void setContentType(String contentType); 36 | 37 | void setContentTypeCharset(ContentType contentType); 38 | 39 | void setContentTypeCharset(String contentType, Charset charset); 40 | 41 | } 42 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqbody/ContentTypeSelectorOnFile.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqbody; 2 | 3 | import java.awt.Component; 4 | import java.io.File; 5 | import java.io.IOException; 6 | import java.nio.charset.Charset; 7 | import javax.swing.JOptionPane; 8 | import org.wiztools.restclient.persistence.PersistenceException; 9 | import org.wiztools.restclient.ui.Mime; 10 | import org.wiztools.restclient.util.XMLUtil; 11 | 12 | /** 13 | * 14 | * @author subwiz 15 | */ 16 | final class ContentTypeSelectorOnFile { 17 | 18 | private ContentTypeSelectorOnFile() {} 19 | 20 | static void select(ContentTypeCharsetComponent jp_content_type_charset, 21 | File file, Component parent) { 22 | final String mime = Mime.forFile(file); 23 | if(!mime.equals("content/unknown")) { 24 | final String origContentType = jp_content_type_charset.getContentType().getContentType(); 25 | if(!mime.equals(origContentType)) { 26 | final int result = JOptionPane.showConfirmDialog(parent, 27 | "The content-type selected (" + origContentType + ") does NOT match\n" 28 | + "the computed file mime type (" + mime + ")\n" 29 | + "Do you want to update the content-type to `" + mime + "'?", 30 | "Mime-type mismatch correction", 31 | JOptionPane.YES_NO_OPTION); 32 | if(result == JOptionPane.YES_OPTION) { 33 | // Set content type 34 | jp_content_type_charset.setContentType(mime); 35 | 36 | // Check if XML content type: 37 | if(XMLUtil.XML_MIME.equals(mime)){ 38 | try { 39 | String charset = XMLUtil.getDocumentCharset(file); 40 | if(charset != null && !(charset.equals(jp_content_type_charset.getCharsetString()))) { 41 | final int charsetYesNo = JOptionPane.showConfirmDialog(parent, 42 | "Change charset to `" + charset + "'?", 43 | "Change charset?", 44 | JOptionPane.YES_NO_OPTION); 45 | if(charsetYesNo == JOptionPane.YES_OPTION) { 46 | jp_content_type_charset.setCharset(Charset.forName(charset)); 47 | } 48 | } 49 | } 50 | catch(IOException | PersistenceException ex) { 51 | // do nothing! 52 | } 53 | } 54 | } 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqbody/ParameterGenerationListener.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqbody; 2 | 3 | /** 4 | * 5 | * @author schandran 6 | */ 7 | public interface ParameterGenerationListener { 8 | public void onParameterGeneration(String params); 9 | } 10 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqbody/ReqBodyPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqbody; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.bean.ReqEntity; 5 | import org.wiztools.restclient.ui.ViewPanel; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | @ImplementedBy(ReqBodyPanelImpl.class) 12 | public interface ReqBodyPanel extends ViewPanel { 13 | void enableBody(); 14 | void disableBody(); 15 | 16 | void setEntity(ReqEntity entity); 17 | ReqEntity getEntity(); 18 | } 19 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqbody/ReqBodyPanelNone.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqbody; 2 | 3 | import java.awt.Component; 4 | import javax.swing.JPanel; 5 | import org.wiztools.restclient.bean.ReqEntity; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | public class ReqBodyPanelNone extends JPanel implements ReqBodyPanel { 12 | 13 | @Override 14 | public void enableBody() { 15 | // do nothing! 16 | } 17 | 18 | @Override 19 | public void disableBody() { 20 | // do nothing! 21 | } 22 | 23 | @Override 24 | public void clear() { 25 | // do nothing! 26 | } 27 | 28 | @Override 29 | public void setEntity(ReqEntity entity) { 30 | // do nothing! 31 | } 32 | 33 | @Override 34 | public ReqEntity getEntity() { 35 | return null; 36 | } 37 | 38 | @Override 39 | public Component getComponent() { 40 | return this; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqetc/ReqEtcPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqetc; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.bean.HTTPVersion; 5 | import org.wiztools.restclient.ui.ViewPanel; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | @ImplementedBy(ReqEtcPanelImpl.class) 12 | public interface ReqEtcPanel extends ViewPanel { 13 | HTTPVersion getHttpVersion(); 14 | void setHttpVersion(HTTPVersion version); 15 | 16 | boolean isFollowRedirects(); 17 | void setFollowRedirects(boolean b); 18 | 19 | boolean isIgnoreResponseBody(); 20 | void setIgnoreResponseBody(boolean b); 21 | } 22 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqgo/ReqUrlGoPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqgo; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import java.awt.event.ActionListener; 5 | import org.wiztools.restclient.ui.ViewPanel; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | @ImplementedBy(ReqUrlGoPanelImpl.class) 12 | public interface ReqUrlGoPanel extends ViewPanel { 13 | enum ACTION_TYPE{GO, CANCEL}; 14 | 15 | void setAsRunning(); 16 | void setAsIdle(); 17 | 18 | void clearHistory(); 19 | 20 | boolean isIdle(); 21 | boolean isRunning(); 22 | 23 | String getUrlString(); 24 | void setUrlString(String url); 25 | 26 | boolean isSslUrl(); 27 | 28 | void addActionListener(ActionListener listener); 29 | } 30 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqgo/UrlListPersistUtil.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqgo; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.File; 5 | import java.io.FileInputStream; 6 | import java.io.IOException; 7 | import java.io.InputStreamReader; 8 | import java.util.ArrayList; 9 | import java.util.Collections; 10 | import java.util.List; 11 | import org.wiztools.commons.Charsets; 12 | import org.wiztools.commons.FileUtil; 13 | import org.wiztools.restclient.util.ConfigUtil; 14 | 15 | /** 16 | * 17 | * @author subwiz 18 | */ 19 | public final class UrlListPersistUtil { 20 | 21 | private static final File LIST_FILE = ConfigUtil.getConfigFile("urls.list"); 22 | 23 | private UrlListPersistUtil() {} 24 | 25 | 26 | public static void persist(List urlList) throws IOException { 27 | StringBuilder sb = new StringBuilder(); 28 | for(String url: urlList) { 29 | sb.append(url).append("\n"); 30 | } 31 | FileUtil.writeString(LIST_FILE, sb.toString(), Charsets.UTF_8); 32 | } 33 | 34 | public static List load() throws IOException { 35 | if(!LIST_FILE.exists()) { 36 | return Collections.emptyList(); 37 | } 38 | else { 39 | List out = new ArrayList(); 40 | 41 | BufferedReader br = new BufferedReader( 42 | new InputStreamReader( 43 | new FileInputStream(LIST_FILE), Charsets.UTF_8)); 44 | String line; 45 | while((line = br.readLine()) != null) { 46 | if(!line.trim().equals("")) { // ignore empty line 47 | out.add(line); 48 | } 49 | } 50 | 51 | return out; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqmethod/ReqMethodPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqmethod; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.bean.HTTPMethod; 5 | import org.wiztools.restclient.ui.ViewPanel; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | @ImplementedBy(ReqMethodPanelImpl.class) 12 | public interface ReqMethodPanel extends ViewPanel { 13 | 14 | boolean doesSelectedMethodSupportEntityBody(); 15 | 16 | HTTPMethod getSelectedMethod(); 17 | 18 | void setSelectedMethod(HTTPMethod method); 19 | 20 | } 21 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqtest/ReqTestPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqtest; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.bean.Request; 5 | import org.wiztools.restclient.bean.Response; 6 | import org.wiztools.restclient.ui.ViewPanel; 7 | 8 | /** 9 | * 10 | * @author subwiz 11 | */ 12 | @ImplementedBy(ReqTestPanelImpl.class) 13 | public interface ReqTestPanel extends ViewPanel { 14 | String getTestScript(); 15 | void setTestScript(String script); 16 | void runClonedRequestTest(Request request, Response response); 17 | } 18 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqtls/KeyStoreListener.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqtls; 2 | 3 | import org.wiztools.restclient.bean.KeyStore; 4 | 5 | /** 6 | * 7 | * @author subwiz 8 | */ 9 | public interface KeyStoreListener { 10 | /** 11 | * Triggered when Ok button is pressed. 12 | * @param store Will always be NOT null. 13 | */ 14 | void onOk(KeyStore store); 15 | 16 | /** 17 | * Triggered when Cancel button is clicked. 18 | */ 19 | void onCancel(); 20 | } 21 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqtls/ReqTLSPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqtls; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.bean.TLSReq; 5 | import org.wiztools.restclient.ui.ViewPanel; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | @ImplementedBy(ReqTLSPanelImpl.class) 12 | public interface ReqTLSPanel extends ViewPanel { 13 | 14 | TLSReq getSslReq(); 15 | void setSslReq(TLSReq sslReq); 16 | 17 | } 18 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/reqtls/StoreTypePanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.reqtls; 2 | 3 | import java.awt.FlowLayout; 4 | import java.awt.event.ItemListener; 5 | import javax.swing.ButtonGroup; 6 | import javax.swing.JPanel; 7 | import javax.swing.JRadioButton; 8 | import org.wiztools.restclient.bean.KeyStoreType; 9 | 10 | /** 11 | * 12 | * @author subwiz 13 | */ 14 | public class StoreTypePanel extends JPanel { 15 | 16 | private final JRadioButton jrb_jks = new JRadioButton(KeyStoreType.JKS.name()); 17 | private final JRadioButton jrb_pkcs12 = new JRadioButton(KeyStoreType.PKCS12.name()); 18 | private final JRadioButton jrb_pem = new JRadioButton(KeyStoreType.PEM.name()); 19 | 20 | public StoreTypePanel() { 21 | this.setLayout(new FlowLayout(FlowLayout.LEFT)); 22 | 23 | ButtonGroup grp = new ButtonGroup(); 24 | grp.add(jrb_jks); 25 | grp.add(jrb_pkcs12); 26 | grp.add(jrb_pem); 27 | 28 | // JKS to be selected by default: 29 | jrb_jks.setSelected(true); 30 | 31 | add(jrb_jks); 32 | add(jrb_pkcs12); 33 | add(jrb_pem); 34 | } 35 | 36 | public KeyStoreType getSelectedKeyStoreType() { 37 | if(jrb_jks.isSelected()) { 38 | return KeyStoreType.JKS; 39 | } 40 | else if(jrb_pkcs12.isSelected()) { 41 | return KeyStoreType.PKCS12; 42 | } 43 | else if(jrb_pem.isSelected()) { 44 | return KeyStoreType.PEM; 45 | } 46 | return KeyStoreType.PEM; 47 | } 48 | 49 | public void setSelectedKeyStoreType(KeyStoreType type) { 50 | switch(type) { 51 | case JKS: 52 | jrb_jks.setSelected(true); 53 | break; 54 | case PKCS12: 55 | jrb_pkcs12.setSelected(true); 56 | break; 57 | case PEM: 58 | jrb_pem.setSelected(true); 59 | break; 60 | default: 61 | throw new IllegalArgumentException("Unknown keystore-type: " + type); 62 | } 63 | } 64 | 65 | public void addItemListener(ItemListener listener, KeyStoreType ... types) { 66 | for(KeyStoreType type: types) { 67 | switch(type) { 68 | case JKS: 69 | jrb_jks.addItemListener(listener); 70 | break; 71 | case PKCS12: 72 | jrb_pkcs12.addItemListener(listener); 73 | break; 74 | case PEM: 75 | jrb_pem.addItemListener(listener); 76 | break; 77 | default: 78 | throw new IllegalArgumentException("Unknown keystore-type: " + type); 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resbody/AbstractResBody.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resbody; 2 | 3 | import java.awt.Component; 4 | import javax.swing.JPanel; 5 | import org.wiztools.restclient.bean.ContentType; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | public abstract class AbstractResBody extends JPanel implements ResBodyPanel { 12 | protected byte[] body; 13 | protected ContentType type; 14 | 15 | @Override 16 | public void setBody(byte[] body, ContentType type) { 17 | this.body = body; 18 | this.type = type; 19 | } 20 | 21 | @Override 22 | public byte[] getBody() { 23 | return body; 24 | } 25 | 26 | @Override 27 | public Component getComponent() { 28 | return this; 29 | } 30 | 31 | @Override 32 | public final void clear() { 33 | body = null; 34 | 35 | clearUI(); 36 | } 37 | 38 | public abstract void clearUI(); 39 | } 40 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resbody/ResBodyBinaryPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resbody; 2 | 3 | import java.awt.GridLayout; 4 | import javax.annotation.PostConstruct; 5 | import javax.swing.JTextArea; 6 | import org.wiztools.restclient.bean.ContentType; 7 | import org.wiztools.restclient.ui.UIUtil; 8 | import org.wiztools.restclient.util.HexDump; 9 | 10 | /** 11 | * 12 | * @author subwiz 13 | */ 14 | public class ResBodyBinaryPanel extends AbstractResBody { 15 | 16 | private JTextArea jta = new JTextArea(); 17 | 18 | @PostConstruct 19 | protected void init() { 20 | jta.setEditable(false); 21 | jta.setFont(UIUtil.FONT_MONO_PLAIN); 22 | setLayout(new GridLayout()); 23 | add(jta); 24 | } 25 | 26 | @Override 27 | public void setBody(byte[] body, ContentType type) { 28 | // Call the super method 29 | super.setBody(body, type); 30 | 31 | // Set the hex display value 32 | jta.setText(HexDump.getHexDataDumpAsString(body)); 33 | jta.setCaretPosition(0); 34 | } 35 | 36 | @Override 37 | public void clearUI() { 38 | jta.setText(""); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resbody/ResBodyImagePanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resbody; 2 | 3 | import java.awt.GridLayout; 4 | import java.awt.image.BufferedImage; 5 | import java.io.ByteArrayInputStream; 6 | import java.io.IOException; 7 | import javax.annotation.PostConstruct; 8 | import javax.imageio.ImageIO; 9 | import javax.swing.ImageIcon; 10 | import javax.swing.JLabel; 11 | import org.wiztools.restclient.bean.ContentType; 12 | 13 | /** 14 | * 15 | * @author subwiz 16 | */ 17 | public class ResBodyImagePanel extends AbstractResBody { 18 | 19 | private JLabel jl = new JLabel(); 20 | 21 | @PostConstruct 22 | protected void init() { 23 | setLayout(new GridLayout()); 24 | 25 | add(jl); 26 | } 27 | 28 | @Override 29 | public void setBody(byte[] body, ContentType type) { 30 | // Call parent: 31 | super.setBody(body, type); 32 | 33 | // Generate UI: 34 | try { 35 | BufferedImage img = ImageIO.read(new ByteArrayInputStream(body)); 36 | jl.setIcon(new ImageIcon(img)); 37 | } 38 | catch(IOException ex) { 39 | throw new RuntimeException(ex); 40 | } 41 | } 42 | 43 | @Override 44 | public void clearUI() { 45 | jl.setIcon(null); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resbody/ResBodyNonePanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resbody; 2 | 3 | /** 4 | * 5 | * @author subwiz 6 | */ 7 | public class ResBodyNonePanel extends AbstractResBody { 8 | 9 | @Override 10 | public void clearUI() { 11 | // do nothing! 12 | } 13 | 14 | } 15 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resbody/ResBodyPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resbody; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.bean.ContentType; 5 | import org.wiztools.restclient.ui.ViewPanel; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | @ImplementedBy(ResBodyPanelImpl.class) 12 | public interface ResBodyPanel extends ViewPanel { 13 | void setBody(byte[] data, ContentType type); 14 | byte[] getBody(); 15 | } 16 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resbody/ResBodyPanelImpl.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resbody; 2 | 3 | import java.awt.Font; 4 | import java.awt.GridLayout; 5 | import javax.annotation.PostConstruct; 6 | import javax.inject.Inject; 7 | import javax.swing.JScrollPane; 8 | import org.wiztools.commons.StringUtil; 9 | import org.wiztools.restclient.bean.ContentType; 10 | import org.wiztools.restclient.ui.FontableEditor; 11 | import org.wiztools.restclient.ui.ScrollableComponent; 12 | import org.wiztools.restclient.util.HttpUtil; 13 | 14 | /** 15 | * 16 | * @author subwiz 17 | */ 18 | public class ResBodyPanelImpl extends AbstractResBody implements FontableEditor, ScrollableComponent { 19 | 20 | @Inject private ResBodyTextPanel jp_text; 21 | @Inject private ResBodyImagePanel jp_image; 22 | @Inject private ResBodyBinaryPanel jp_binary; 23 | @Inject private ResBodyNonePanel jp_none; 24 | 25 | private JScrollPane jsp = new JScrollPane(); 26 | 27 | @PostConstruct 28 | protected void init() { 29 | jsp.setViewportView(jp_none); 30 | 31 | setLayout(new GridLayout()); 32 | add(jsp); 33 | } 34 | 35 | @Override 36 | public void setBody(byte[] body, ContentType type) { 37 | // Call super: 38 | super.setBody(body, type); 39 | 40 | // Display the new body: 41 | if(type != null && StringUtil.isNotEmpty(type.getContentType())) { 42 | if(HttpUtil.isTextContentType(type.getContentType())) { 43 | jp_text.setBody(body, type); 44 | jsp.setViewportView(jp_text); 45 | } 46 | else if(HttpUtil.isWebImageContentType(type.getContentType())) { 47 | jp_image.setBody(body, type); 48 | jsp.setViewportView(jp_image); 49 | } 50 | else { 51 | setBinaryBody(); 52 | } 53 | } 54 | else { 55 | setBinaryBody(); 56 | } 57 | } 58 | 59 | private void setBinaryBody() { 60 | jp_binary.setBody(body, type); 61 | jsp.setViewportView(jp_binary); 62 | } 63 | 64 | @Override 65 | public void setEditorFont(Font font) { 66 | jp_text.setEditorFont(font); 67 | } 68 | 69 | @Override 70 | public Font getEditorFont() { 71 | return jp_text.getEditorFont(); 72 | } 73 | 74 | @Override 75 | public void setScrollSpeed(int scrollSpeed) { 76 | jsp.getVerticalScrollBar().setUnitIncrement(scrollSpeed); 77 | } 78 | 79 | @Override 80 | public void clearUI() { 81 | jp_text.clear(); 82 | jp_image.clear(); 83 | jp_binary.clear(); 84 | jsp.setViewportView(jp_none); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resheader/ResHeaderPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resheader; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.commons.MultiValueMap; 5 | import org.wiztools.restclient.ui.ViewPanel; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | @ImplementedBy(ResHeaderPanelImpl.class) 12 | public interface ResHeaderPanel extends ViewPanel { 13 | MultiValueMap getHeaders(); 14 | void setHeaders(MultiValueMap headers); 15 | } 16 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resheader/ResponseHeaderTableModel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resheader; 2 | 3 | import javax.swing.table.AbstractTableModel; 4 | import org.wiztools.commons.MultiValueMap; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | class ResponseHeaderTableModel extends AbstractTableModel { 11 | 12 | private final String[] title = new String[]{"HTTP Header", "Value"}; 13 | private String[][] headers; 14 | 15 | public void setHeaders(MultiValueMap mapHeaders){ 16 | if(mapHeaders == null){ 17 | headers = new String[0][0]; 18 | } 19 | else{ 20 | headers = new String[mapHeaders.values().size()][2]; 21 | int i = 0; 22 | for(String key: mapHeaders.keySet()){ 23 | for(String value: mapHeaders.get(key)) { 24 | headers[i][0] = key; 25 | headers[i][1] = value; 26 | i++; 27 | } 28 | } 29 | } 30 | fireTableDataChanged(); 31 | } 32 | 33 | public String[][] getHeaders(){ 34 | return headers; 35 | } 36 | 37 | @Override 38 | public String getColumnName(int col) { 39 | return title[col]; 40 | } 41 | 42 | @Override 43 | public int getRowCount() { 44 | if(headers == null){ 45 | return 0; 46 | } 47 | return headers.length; 48 | } 49 | 50 | @Override 51 | public int getColumnCount() { 52 | // Key and Value 53 | return 2; 54 | } 55 | 56 | @Override 57 | public Object getValueAt(int row, int column) { 58 | // 0 means key 59 | if(column == 0){ 60 | return headers[row][0]; 61 | } 62 | else{ 63 | return headers[row][1]; 64 | } 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resstats/ResStatsPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resstats; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.ui.ViewPanel; 5 | 6 | /** 7 | * 8 | * @author subhash 9 | */ 10 | @ImplementedBy(ResStatsPanelImpl.class) 11 | public interface ResStatsPanel extends ViewPanel { 12 | long getExecutionTime(); 13 | long getBodySize(); 14 | 15 | void setExecutionTime(long time); 16 | void setBodySize(long size); 17 | } 18 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resstats/ResStatsPanelImpl.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resstats; 2 | 3 | import java.awt.Component; 4 | import java.awt.FlowLayout; 5 | import java.awt.GridLayout; 6 | import javax.annotation.PostConstruct; 7 | import javax.swing.JLabel; 8 | import javax.swing.JPanel; 9 | import javax.swing.JTextField; 10 | import org.wiztools.restclient.ui.UIUtil; 11 | 12 | /** 13 | * 14 | * @author subhash 15 | */ 16 | public class ResStatsPanelImpl extends JPanel implements ResStatsPanel { 17 | 18 | private long executionTime; 19 | private long bodySize; 20 | 21 | private static final String UNKNOWN_NUM = "[x]"; 22 | 23 | private final JTextField jtf_execTime = new JTextField(UNKNOWN_NUM); 24 | private final JTextField jtf_bodySize = new JTextField(UNKNOWN_NUM); 25 | 26 | @PostConstruct 27 | protected void init() { 28 | setLayout(new FlowLayout(FlowLayout.LEFT)); 29 | 30 | // Set big fonts: 31 | jtf_execTime.setFont(UIUtil.FONT_BIG); 32 | jtf_bodySize.setFont(UIUtil.FONT_BIG); 33 | jtf_execTime.setEditable(false); 34 | jtf_bodySize.setEditable(false); 35 | 36 | JPanel jp = new JPanel(new GridLayout(2, 3)); 37 | // Response time: 38 | { 39 | JLabel jl = new JLabel("Response time: "); 40 | jl.setFont(UIUtil.FONT_BIG); 41 | jp.add(jl); 42 | } 43 | jp.add(jtf_execTime); 44 | jp.add(new JLabel(" ms")); 45 | 46 | // Body size: 47 | { 48 | JLabel jl = new JLabel("Body size: "); 49 | jl.setFont(UIUtil.FONT_BIG); 50 | jp.add(jl); 51 | } 52 | jp.add(jtf_bodySize); 53 | jp.add(new JLabel(" bytes")); 54 | 55 | this.add(jp); 56 | } 57 | 58 | @Override 59 | public long getExecutionTime() { 60 | return executionTime; 61 | } 62 | 63 | @Override 64 | public long getBodySize() { 65 | return bodySize; 66 | } 67 | 68 | @Override 69 | public void setExecutionTime(long time) { 70 | executionTime = time; 71 | String val = time == 0l? UNKNOWN_NUM: String.valueOf(time); 72 | jtf_execTime.setText(val); 73 | } 74 | 75 | @Override 76 | public void setBodySize(long size) { 77 | bodySize = size; 78 | String val = size == 0l? UNKNOWN_NUM: String.valueOf(size); 79 | jtf_bodySize.setText(val); 80 | } 81 | 82 | @Override 83 | public Component getComponent() { 84 | return this; 85 | } 86 | 87 | @Override 88 | public void clear() { 89 | setExecutionTime(0l); 90 | setBodySize(0l); 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resstatus/ResStatusPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resstatus; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.ui.ViewPanel; 5 | 6 | /** 7 | * 8 | * @author subwiz 9 | */ 10 | @ImplementedBy(ResStatusPanelImpl.class) 11 | public interface ResStatusPanel extends ViewPanel { 12 | String getStatus(); 13 | void setStatus(String status); 14 | } 15 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/resstatus/ResStatusPanelImpl.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.resstatus; 2 | 3 | import java.awt.BorderLayout; 4 | import java.awt.Component; 5 | import javax.annotation.PostConstruct; 6 | import javax.swing.JLabel; 7 | import javax.swing.JPanel; 8 | import javax.swing.JTextField; 9 | import org.wiztools.restclient.ui.RESTView; 10 | 11 | /** 12 | * 13 | * @author subwiz 14 | */ 15 | public class ResStatusPanelImpl extends JPanel implements ResStatusPanel { 16 | 17 | private JTextField jtf = new JTextField(); 18 | 19 | @PostConstruct 20 | protected void init() { 21 | setLayout(new BorderLayout(RESTView.BORDER_WIDTH, RESTView.BORDER_WIDTH)); 22 | JLabel jl_res_statusLine = new JLabel("Status: "); 23 | add(jl_res_statusLine, BorderLayout.WEST); 24 | jtf.setColumns(35); 25 | jtf.setEditable(false); 26 | add(jtf, BorderLayout.CENTER); 27 | } 28 | 29 | @Override 30 | public Component getComponent() { 31 | return this; 32 | } 33 | 34 | @Override 35 | public String getStatus() { 36 | return jtf.getText(); 37 | } 38 | 39 | @Override 40 | public void setStatus(String status) { 41 | jtf.setText(status); 42 | } 43 | 44 | @Override 45 | public void clear() { 46 | jtf.setText(""); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/restest/FailureTableModel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.restest; 2 | 3 | import java.util.List; 4 | import javax.swing.table.AbstractTableModel; 5 | import org.wiztools.restclient.bean.TestExceptionResult; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | class FailureTableModel extends AbstractTableModel { 12 | 13 | private Object[] failures; 14 | 15 | public void setData(List failures) { 16 | if (failures != null) { 17 | this.failures = failures.toArray(); 18 | } 19 | fireTableDataChanged(); 20 | } 21 | 22 | @Override 23 | public String getColumnName(int col) { 24 | if (col == 0) { 25 | return "Message"; 26 | } else { 27 | return "Line"; 28 | } 29 | } 30 | 31 | @Override 32 | public int getRowCount() { 33 | if (failures == null) { 34 | return 0; 35 | } 36 | return failures.length; 37 | } 38 | 39 | @Override 40 | public int getColumnCount() { 41 | return 2; 42 | } 43 | 44 | @Override 45 | public Object getValueAt(int rowIndex, int columnIndex) { 46 | TestExceptionResult bean = (TestExceptionResult) failures[rowIndex]; 47 | if (columnIndex == 0) { 48 | return bean.getExceptionMessage(); 49 | } else { 50 | return bean.getLineNumber(); 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ui/src/main/java/org/wiztools/restclient/ui/restest/ResTestPanel.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.restest; 2 | 3 | import org.wiztools.restclient.ImplementedBy; 4 | import org.wiztools.restclient.bean.TestResult; 5 | import org.wiztools.restclient.ui.ViewPanel; 6 | 7 | /** 8 | * 9 | * @author subwiz 10 | */ 11 | @ImplementedBy(ResTestPanelImpl.class) 12 | public interface ResTestPanel extends ViewPanel { 13 | TestResult getTestResult(); 14 | void setTestResult(TestResult result); 15 | } 16 | -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/PasswordHelp.txt: -------------------------------------------------------------------------------- 1 | RESTClient uses Base64 encoding for storing passwords. This is a basic measure to ensure that the passwords are not visible to the naked eye (although this is easily computable). When writing/editing RESTClient files by hand, it might be needed to convert passwords to the format RESTClient understands. For purposes like these, this plugin might be used. -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/Splash.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/src/main/resources/org/wiztools/restclient/Splash.png -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/add.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | RC 14 | 15 | 16 | -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/logo_30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wiztools/rest-client/e4e25f05f3b9d7468f8dc08620d535ededbda178/ui/src/main/resources/org/wiztools/restclient/logo_30.png -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/messages.properties: -------------------------------------------------------------------------------- 1 | 2 | 3 | menu.help.about = RESTClient is a Java application (both cli and gui)
\ 4 | / framework to test RESTful webservices. It can
\ 5 | be used to test variety of HTTP communications.

\ 6 | https://github.com/wiztools/rest-client

\ 7 | RESTClient is covered by Apache 2 License:

\ 8 | http://www.apache.org/licenses/LICENSE-2.0.html

\ 9 | RESTClient includes Silk Icons:

\ 10 | http://www.famfamfam.com/lab/icons/silk/

\ 11 | These icons are covered by Creative Commons
Attribution 2.5 License.

\ 12 | RESTClient is dedicated to Aarthi Rajan, @subwiz's
sweetheart .

\ 13 | Special thanks to people from REST-discuss:

\ 14 | http://tech.groups.yahoo.com/group/rest-discuss/

\ 15 | For providing insightful feedbacks, feature requests
and bugs. 16 | 17 | yes-no.cant.save.request = The Request details in the UI has changed from the last Request.
\ 18 | RESTClient saves only the last completed Request. If you want to save the
last completed Request, press Ok.

\ 19 | Else, if you want to save the request with changed parameters, press
Cancel and complete the request before attempting to save. 20 | 21 | yes-no.cant.save.req-res = The {0} details in the UI has changed from the last Request.
\ 22 | RESTClient saves only the last {1}.

If you want to save the last {1}, press Ok.

\ 23 | Else, if you want to save the {0} with changed parameters, press
Cancel and complete the request before attempting to save. 24 | 25 | help.keyval.multi = Enter each key-value pair in separate line.\nThe key and value should be separated by `:'. 26 | -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/s_tag.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | image/svg+xml 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/test-script.template: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a template provided by RESTClient. Modify as per need. 3 | */ 4 | 5 | // The test class name should end with `Test'--this is a convention: 6 | public class TemplateClassTest 7 | extends org.wiztools.restclient.RESTTestCase { 8 | 9 | // Test method names must start with `test': 10 | public void testStatus() { 11 | if(response.getStatusCode() != 200) { 12 | fail("This will fail the test!"); 13 | } 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /ui/src/main/resources/org/wiztools/restclient/uioptionsdialog.properties: -------------------------------------------------------------------------------- 1 | # This lists the org.wiztools.restclient.ui.OptionsDialog panels and their tab name 2 | 3 | panel=Connection:org.wiztools.restclient.ui.option.OptionsConnectionPanel,\ 4 | Proxy:org.wiztools.restclient.ui.option.OptionsProxyPanel,\ 5 | Font:org.wiztools.restclient.ui.option.OptionsFontPanel,\ 6 | Etc.:org.wiztools.restclient.ui.option.OptionsEtcPanel 7 | -------------------------------------------------------------------------------- /ui/src/test/java/org/wiztools/restclient/ui/RecentFilesHelperTest.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui; 2 | 3 | import java.io.File; 4 | import java.io.UnsupportedEncodingException; 5 | import java.net.URLEncoder; 6 | import java.util.LinkedList; 7 | import java.util.List; 8 | import static org.junit.Assert.assertEquals; 9 | import org.junit.*; 10 | 11 | /** 12 | * 13 | * @author subwiz 14 | */ 15 | public class RecentFilesHelperTest { 16 | 17 | public RecentFilesHelperTest() { 18 | } 19 | 20 | @BeforeClass 21 | public static void setUpClass() throws Exception { 22 | } 23 | 24 | @AfterClass 25 | public static void tearDownClass() throws Exception { 26 | } 27 | 28 | @Before 29 | public void setUp() { 30 | } 31 | 32 | @After 33 | public void tearDown() { 34 | } 35 | 36 | private String encode(String str) { 37 | try{ 38 | return URLEncoder.encode(str, "UTF-8"); 39 | } 40 | catch(UnsupportedEncodingException ex) { 41 | throw new RuntimeException(ex); 42 | } 43 | } 44 | 45 | /** 46 | * Test of getStringRepresentation method, of class UIPreferenceRepo. 47 | */ 48 | @Test 49 | public void testGetStringRepresentation() throws Exception{ 50 | System.out.println("getStringRepresentation"); 51 | LinkedList recentFiles = new LinkedList(); 52 | File file1 = new File("subhash.txt"); 53 | recentFiles.add(file1); 54 | File file2 = new File("aarthi.txt"); 55 | recentFiles.add(file2); 56 | RecentFilesHelper instance = new RecentFilesHelper(); 57 | String expResult = encode(file1.getAbsolutePath()) + ";" + encode(file2.getAbsolutePath()); 58 | String result = instance.getStringRepresentation(recentFiles); 59 | assertEquals(expResult, result); 60 | } 61 | 62 | /** 63 | * Test of getListRepresentation method, of class UIPreferenceRepo. 64 | */ 65 | @Test 66 | public void testGetListRepresentation() { 67 | System.out.println("getListRepresentation"); 68 | RecentFilesHelper instance = new RecentFilesHelper(); 69 | 70 | File file1 = new File(new File(System.getProperty("user.dir")), "subhash.txt"); 71 | File file2 = new File(new File(System.getProperty("user.dir")), "aarthi.txt"); 72 | 73 | LinkedList expResult = new LinkedList(); 74 | expResult.add(file1); 75 | expResult.add(file2); 76 | 77 | String recentFilesStr = instance.getStringRepresentation(expResult); 78 | List result = instance.getListRepresentation(recentFilesStr); 79 | assertEquals(expResult, result); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /ui/src/test/java/org/wiztools/restclient/ui/update/AppUpdateRunnerTest.java: -------------------------------------------------------------------------------- 1 | package org.wiztools.restclient.ui.update; 2 | 3 | import org.junit.After; 4 | import org.junit.AfterClass; 5 | import org.junit.Before; 6 | import org.junit.BeforeClass; 7 | import org.junit.Test; 8 | import static org.junit.Assert.*; 9 | import org.wiztools.appupdate.VersionImpl; 10 | 11 | /** 12 | * 13 | * @author subhash 14 | */ 15 | public class AppUpdateRunnerTest { 16 | 17 | public AppUpdateRunnerTest() { 18 | } 19 | 20 | @BeforeClass 21 | public static void setUpClass() { 22 | } 23 | 24 | @AfterClass 25 | public static void tearDownClass() { 26 | } 27 | 28 | @Before 29 | public void setUp() { 30 | } 31 | 32 | @After 33 | public void tearDown() { 34 | } 35 | 36 | /** 37 | * Test of doUpdateCheck method, of class AppUpdateRunner. 38 | */ 39 | @Test 40 | public void testDoUpdateCheck() { 41 | System.out.println("doUpdateCheck"); 42 | long lastUpdateCheck = 0L; 43 | AppUpdateRunner instance = new AppUpdateRunner(); 44 | boolean expResult = true; 45 | boolean result = instance.doUpdateCheck(lastUpdateCheck); 46 | assertEquals(expResult, result); 47 | } 48 | 49 | @Test 50 | public void testRequiresUpdate() throws Exception { 51 | AppUpdateRunner instance = new AppUpdateRunner(); 52 | boolean result = instance.requiresUpdate(new VersionImpl("10.0")); 53 | assertTrue(result); 54 | } 55 | } 56 | --------------------------------------------------------------------------------