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 |
--------------------------------------------------------------------------------
/restclient-lib/src/test/java/org/wiztools/restclient/SslTest.java:
--------------------------------------------------------------------------------
1 | package org.wiztools.restclient;
2 |
3 | import java.io.File;
4 | import java.net.URL;
5 | import org.junit.*;
6 | import static org.junit.Assert.*;
7 | import org.wiztools.restclient.bean.HTTPMethod;
8 | import org.wiztools.restclient.bean.HTTPVersion;
9 | import org.wiztools.restclient.bean.Request;
10 | import org.wiztools.restclient.bean.RequestBean;
11 | import org.wiztools.restclient.bean.SSLHostnameVerifier;
12 | import org.wiztools.restclient.bean.SSLReqBean;
13 | import org.wiztools.restclient.persistence.PersistenceRead;
14 | import org.wiztools.restclient.persistence.XmlPersistenceRead;
15 |
16 | /**
17 | *
18 | * @author subwiz
19 | */
20 | public class SslTest {
21 |
22 | private PersistenceRead p = new XmlPersistenceRead();
23 |
24 | public SslTest() {
25 | }
26 |
27 | @BeforeClass
28 | public static void setUpClass() throws Exception {
29 | }
30 |
31 | @AfterClass
32 | public static void tearDownClass() throws Exception {
33 | }
34 |
35 | @Before
36 | public void setUp() {
37 | }
38 |
39 | @After
40 | public void tearDown() {
41 | }
42 |
43 | @Test
44 | public void testSsl() throws Exception {
45 | RequestBean expResult = new RequestBean();
46 | expResult.setUrl(new URL("https://www.webshop.co.uk/"));
47 | expResult.setMethod(HTTPMethod.GET);
48 | expResult.setHttpVersion(HTTPVersion.HTTP_1_1);
49 | expResult.setFollowRedirect(true);
50 | SSLReqBean ssl = new SSLReqBean();
51 | ssl.setTrustAllCerts(true);
52 | ssl.setHostNameVerifier(SSLHostnameVerifier.ALLOW_ALL);
53 | expResult.setSslReq(ssl);
54 |
55 | Request actual = p.getRequestFromFile(new File("src/test/resources/reqSsl.rcq"));
56 |
57 | assertEquals(expResult, actual);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-ui/build.gradle:
--------------------------------------------------------------------------------
1 | // plugins {
2 | // id "com.github.cr0.macappbundle" version "3.0.1"
3 | // }
4 | plugins {
5 | id "edu.sc.seis.macAppBundle" version "2.3.0"
6 | }
7 |
8 | apply plugin: 'java'
9 | apply plugin: 'application'
10 |
11 | // Application plugin config:
12 | mainClassName = 'org.wiztools.restclient.ui.Main'
13 | applicationName = 'restclient-ui'
14 | applicationDefaultJvmArgs = ['-Xms128m', '-Xmx512m']
15 |
16 | macAppBundle {
17 | mainClassName = 'org.wiztools.restclient.ui.Main'
18 | icon = 'src/main/app-resources/rest-client_30.icns'
19 | bundleJRE = false
20 | javaProperties.put('apple.laf.useScreenMenuBar', 'true')
21 | bundleIdentifier = 'org.wiztools.restclient.ui'
22 | appName = 'RESTClient'
23 | // appCategory = 'public.app-category.developer-tools'
24 | version = "$version"
25 | // shortVersion = "$version"
26 | bundleIdentifier = 'org.wiztools.restclient.ui'
27 | // bundleCopyright = 'Copyright 2016 WizTools.org'
28 | bundleExtras.put("NSHighResolutionCapable", "true")
29 | javaProperties.put("file.encoding", "utf-8")
30 | // javaXProperties.add("mx1024M")
31 | // backgroundImage = "doc/macbackground.png"
32 | }
33 |
34 | repositories {
35 | mavenLocal()
36 | mavenCentral()
37 | }
38 |
39 | task fatJar(type: Jar) {
40 | baseName = project.name + '-fat'
41 |
42 | manifest {
43 | attributes(
44 | "Main-Class": "$mainClassName",
45 | "SplashScreen-Image": 'org/wiztools/restclient/Splash.png'
46 | )
47 | }
48 |
49 | from {
50 | configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
51 | }
52 | with jar
53 | }
54 |
55 | dependencies {
56 | compile project(':restclient-lib'),
57 | 'org.wiztools:filechooser-abstraction:0.1.0',
58 | 'com.jidesoft:jide-oss:3.6.14',
59 | 'org.swinglabs.swingx:swingx-autocomplete:1.6.5-1',
60 | 'com.fifesoft:rsyntaxtextarea:2.5.8',
61 | 'ch.qos.logback:logback-classic:1.2.3',
62 | 'org.simplericity.macify:macify:1.6'
63 | testCompile 'junit:junit:4.+'
64 | }
65 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-lib/src/test/java/org/wiztools/restclient/AuthElementTest.java:
--------------------------------------------------------------------------------
1 | package org.wiztools.restclient;
2 |
3 | import java.io.File;
4 | import org.junit.*;
5 | import static org.junit.Assert.*;
6 | import org.wiztools.restclient.bean.*;
7 | import org.wiztools.restclient.persistence.PersistenceRead;
8 | import org.wiztools.restclient.persistence.XmlPersistenceRead;
9 | import org.wiztools.restclient.persistence.XmlPersistenceWrite;
10 |
11 | /**
12 | *
13 | * @author subwiz
14 | */
15 | public class AuthElementTest {
16 |
17 | public AuthElementTest() {
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 | @Test
37 | public void testOAuth2Bearer() throws Exception {
38 | System.out.println("testOAuth2Bearer");
39 | PersistenceRead p = new XmlPersistenceRead();
40 | Request req = p.getRequestFromFile(new File("src/test/resources/reqOAuth2Bearer.rcq"));
41 | Auth a = req.getAuth();
42 | OAuth2BearerAuth auth = (OAuth2BearerAuth) a;
43 | assertEquals("subhash", auth.getOAuth2BearerToken());
44 | }
45 |
46 | @Test
47 | public void testNtlm() throws Exception {
48 | System.out.println("testNtlm");
49 | PersistenceRead p = new XmlPersistenceRead();
50 | Request req = p.getRequestFromFile(new File("src/test/resources/reqNtlm.rcq"));
51 | Auth a = req.getAuth();
52 | NtlmAuth auth = (NtlmAuth) a;
53 |
54 | NtlmAuthBean expResult = new NtlmAuthBean();
55 | expResult.setDomain("testdomain");
56 | expResult.setWorkstation("testworkstation");
57 | expResult.setUsername("subwiz");
58 | expResult.setPassword("password".toCharArray());
59 |
60 | assertEquals(expResult, auth);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-lib/src/main/java/org/wiztools/restclient/bean/RequestExecuter.java:
--------------------------------------------------------------------------------
1 | package org.wiztools.restclient.bean;
2 |
3 | import com.google.inject.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 |
--------------------------------------------------------------------------------
/restclient-lib/src/main/java/org/wiztools/restclient/bean/SSLKeyStoreBean.java:
--------------------------------------------------------------------------------
1 | package org.wiztools.restclient.bean;
2 |
3 | import java.io.File;
4 | import java.io.IOException;
5 | import java.security.KeyStore;
6 | import java.security.KeyStoreException;
7 | import java.security.NoSuchAlgorithmException;
8 | import java.security.cert.CertificateException;
9 | import java.security.spec.InvalidKeySpecException;
10 | import org.wiztools.restclient.util.SSLUtil;
11 |
12 | /**
13 | *
14 | * @author subwiz
15 | */
16 | public class SSLKeyStoreBean implements SSLKeyStore {
17 |
18 | private File file;
19 | private KeyStoreType type = KeyStoreType.JKS;
20 | private char[] password;
21 |
22 | public void setFile(File file) {
23 | this.file = file;
24 | }
25 |
26 | public void setType(KeyStoreType type) {
27 | this.type = type;
28 | }
29 |
30 | public void setPassword(char[] password) {
31 | this.password = password;
32 | }
33 |
34 | @Override
35 | public File getFile() {
36 | return file;
37 | }
38 |
39 | @Override
40 | public KeyStoreType getType() {
41 | return type;
42 | }
43 |
44 | @Override
45 | public char[] getPassword() {
46 | if(type == KeyStoreType.PEM) {
47 | return SSLUtil.PEM_PWD.toCharArray();
48 | }
49 | return password;
50 | }
51 |
52 | @Override
53 | public KeyStore getKeyStore()
54 | throws KeyStoreException, IOException, InvalidKeySpecException,
55 | NoSuchAlgorithmException, CertificateException {
56 | return SSLUtil.getKeyStore(file, type, password);
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | StringBuilder sb = new StringBuilder();
62 | sb.append("@SSLKeyStore[");
63 | sb.append("type=").append(type).append(", ");
64 | sb.append("file=").append(file.getPath()).append(", ");
65 | sb.append("password=").append(
66 | (password!=null? password.length: 0)).append(", ");
67 | sb.append("]");
68 | return sb.toString();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/restclient-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 | public static final String NONE = "None";
12 | public static final String BASIC = "BASIC";
13 | public static final String DIGEST = "DIGEST";
14 | public static final String NTLM = "NTLM";
15 | public static final String OAUTH2_BEARER = "OAuth2 Bearer";
16 | public static final String MAUTH = "MAuth";
17 |
18 | private static final String[] ALL = new String[]{NONE, BASIC, DIGEST, NTLM, OAUTH2_BEARER, MAUTH};
19 |
20 | public static String[] getAll() {
21 | return ALL;
22 | }
23 |
24 | public static boolean isBasicOrDigest(List authMethods) {
25 | return authMethods.contains(HTTPAuthMethod.BASIC)
26 | || authMethods.contains(HTTPAuthMethod.DIGEST);
27 | }
28 |
29 | public static boolean isNtlm(List authMethods) {
30 | return authMethods.contains(HTTPAuthMethod.NTLM);
31 | }
32 |
33 | public static boolean isBearer(List authMethods) {
34 | return authMethods.contains(HTTPAuthMethod.OAUTH_20_BEARER);
35 | }
36 |
37 | // String methods:
38 | public static boolean isNone(String input) {
39 | return NONE.equals(input);
40 | }
41 |
42 | public static boolean isBasicOrDigest(String input) {
43 | return isBasic(input) || isDigest(input);
44 | }
45 |
46 | public static boolean isBasic(String input) {
47 | return BASIC.equals(input);
48 | }
49 |
50 | public static boolean isDigest(String input) {
51 | return DIGEST.equals(input);
52 | }
53 |
54 | public static boolean isNtlm(String input) {
55 | return NTLM.equals(input);
56 | }
57 |
58 | public static boolean isBearer(String input) {
59 | return OAUTH2_BEARER.equals(input);
60 | }
61 |
62 | public static boolean isMAuth(String input){ return MAUTH.equals(input);}
63 | }
64 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-lib/src/main/java/org/wiztools/restclient/bean/NtlmAuthBean.java:
--------------------------------------------------------------------------------
1 | package org.wiztools.restclient.bean;
2 |
3 | /**
4 | *
5 | * @author subwiz
6 | */
7 | public class NtlmAuthBean extends UsernamePasswordAuthBaseBean implements NtlmAuth {
8 |
9 | private String domain;
10 | private String workstation;
11 |
12 | @Override
13 | public String getDomain() {
14 | return domain;
15 | }
16 |
17 | public void setDomain(String domain) {
18 | this.domain = domain;
19 | }
20 |
21 | @Override
22 | public String getWorkstation() {
23 | return workstation;
24 | }
25 |
26 | public void setWorkstation(String workstation) {
27 | this.workstation = workstation;
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 | if(!super.equals(obj)) {
39 | return false;
40 | }
41 | final NtlmAuthBean other = (NtlmAuthBean) obj;
42 | if ((this.domain == null) ? (other.domain != null) : !this.domain.equals(other.domain)) {
43 | return false;
44 | }
45 | if ((this.workstation == null) ? (other.workstation != null) : !this.workstation.equals(other.workstation)) {
46 | return false;
47 | }
48 | return true;
49 | }
50 |
51 | @Override
52 | public int hashCode() {
53 | int hash = super.hashCode();
54 | hash = 83 * hash + (this.domain != null ? this.domain.hashCode() : 0);
55 | hash = 83 * hash + (this.workstation != null ? this.workstation.hashCode() : 0);
56 | return hash;
57 | }
58 |
59 | @Override
60 | public String toString() {
61 | StringBuilder sb = new StringBuilder();
62 | sb.append("@NtlmAuth[");
63 | sb.append("username=").append(username).append(", ");
64 | sb.append("password-length=").append(password.length).append(", ");
65 | sb.append("domain=").append(domain).append(", ");
66 | sb.append("workstation=").append(workstation);
67 | sb.append("]");
68 | return sb.toString();
69 | }
70 | }
71 |
--------------------------------------------------------------------------------
/restclient-lib/src/main/java/org/wiztools/restclient/bean/MAuthBean.java:
--------------------------------------------------------------------------------
1 | package org.wiztools.restclient.bean;
2 |
3 | import java.io.File;
4 | import java.io.FileNotFoundException;
5 | import java.util.Objects;
6 | import java.util.Scanner;
7 |
8 | public class MAuthBean implements MAuth {
9 |
10 | private String appUUID;
11 | private String privateKeyFile;
12 | private boolean v2OnlySignRequests;
13 |
14 | @Override
15 | public String getAppUUID() {
16 | return appUUID;
17 | }
18 |
19 | public void setAppUUID(String appUUID) {
20 | this.appUUID = appUUID;
21 | }
22 |
23 | @Override
24 | public String getPrivateKeyFile() {
25 | return privateKeyFile;
26 | }
27 |
28 | @Override
29 | public String getPrivateKeyFromFile() throws FileNotFoundException {
30 | return readFile(privateKeyFile);
31 | }
32 | @Override
33 | public boolean isV2OnlySignRequests() {
34 | return v2OnlySignRequests;
35 | }
36 |
37 | public void setV2OnlySignRequests(boolean v2OnlySignRequests) {
38 | this.v2OnlySignRequests = v2OnlySignRequests;
39 | }
40 |
41 | public void setPrivateKeyFile(String privateKeyFile) {
42 | this.privateKeyFile = privateKeyFile;
43 | }
44 |
45 | private String readFile(String path) throws FileNotFoundException {
46 | Scanner scanner = new Scanner(new File(path));
47 | String privateKeyText = scanner.useDelimiter("\\A").next();
48 | scanner.close();
49 | return privateKeyText;
50 | }
51 |
52 | @Override
53 | public boolean equals(Object o) {
54 | if (this == o) return true;
55 | if (o == null || getClass() != o.getClass()) return false;
56 | MAuthBean mAuthBean = (MAuthBean) o;
57 | return Objects.equals(appUUID, mAuthBean.appUUID) &&
58 | Objects.equals(privateKeyFile, mAuthBean.privateKeyFile) &&
59 | Objects.equals(v2OnlySignRequests, mAuthBean.v2OnlySignRequests);
60 | }
61 |
62 | @Override
63 | public int hashCode() {
64 | return Objects.hash(appUUID, privateKeyFile);
65 | }
66 |
67 | @Override
68 | public String toString() {
69 | return "MAuthBean{" +
70 | "appUUID='" + appUUID + '\'' +
71 | ", privateKeyFile='" + privateKeyFile + '\'' +
72 | ", v2OnlySignRequests='" + v2OnlySignRequests + '\'' +
73 | '}';
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/restclient-ui/src/main/java/org/wiztools/restclient/ui/Main.java:
--------------------------------------------------------------------------------
1 | package org.wiztools.restclient.ui;
2 |
3 | import java.awt.Font;
4 | import java.util.ArrayList;
5 | import java.util.Enumeration;
6 | import java.util.logging.Logger;
7 | import javax.swing.SwingUtilities;
8 | import javax.swing.UIManager;
9 | import org.wiztools.restclient.ServiceLocator;
10 |
11 | /**
12 | *
13 | * @author Subhash
14 | */
15 | public class Main {
16 |
17 | private static final Logger LOG = Logger.getLogger(Main.class.getName());
18 |
19 | private static void setGlobalUIFontSize(final int fontSize){
20 | Font f = new Font(Font.DIALOG, Font.PLAIN, fontSize);
21 | //UIManager.put("Label.font", f);
22 | //UIManager.put("Button.font", f);
23 | //UIManager.put("RadioButton.font", f);
24 | ArrayList excludes = new ArrayList<>();
25 | //excludes.add("TitledBorder.font");
26 | //excludes.add("MenuBar.font");
27 | //excludes.add("MenuItem.font");
28 | //excludes.add("MenuItem.acceleratorFont");
29 | //excludes.add("Menu.font");
30 | //excludes.add("TabbedPane.font");
31 | excludes.add("");
32 |
33 | Enumeration itr = UIManager.getDefaults().keys();
34 | while(itr.hasMoreElements()){
35 | Object o = itr.nextElement();
36 | if(o instanceof String) {
37 | String key = (String) o;
38 | Object value = UIManager.get (key);
39 | if ((value instanceof javax.swing.plaf.FontUIResource)
40 | && (!excludes.contains(key))){
41 | LOG.fine(key);
42 | UIManager.put (key, f);
43 | }
44 | }
45 | }
46 | }
47 |
48 | /**
49 | * @param args the command line arguments
50 | */
51 | public static void main(final String[] args) {
52 | // Set the font:
53 | final int fontSize = RCUIConstants.getUIFontSize();
54 | if(fontSize != -1) {
55 | setGlobalUIFontSize(fontSize);
56 | }
57 |
58 | // Work on the UI:
59 | SwingUtilities.invokeLater(new Runnable() {
60 | @Override
61 | public void run() {
62 | RESTUserInterface ui = ServiceLocator.getInstance(
63 | RESTUserInterface.class);
64 | }
65 | });
66 |
67 | }
68 |
69 | }
70 |
--------------------------------------------------------------------------------
/restclient-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; iNUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/restclient-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(" 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 |
--------------------------------------------------------------------------------
/restclient-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 | import org.codehaus.jackson.JsonFactory;
9 | import org.codehaus.jackson.JsonGenerator;
10 | import org.codehaus.jackson.JsonNode;
11 | import org.codehaus.jackson.JsonParseException;
12 | import org.codehaus.jackson.JsonParser;
13 | import org.codehaus.jackson.map.DeserializationConfig;
14 | import org.codehaus.jackson.map.ObjectMapper;
15 | import org.codehaus.jackson.util.DefaultPrettyPrinter;
16 |
17 | /**
18 | *
19 | * @author subwiz
20 | */
21 | public final class JSONUtil {
22 |
23 | private static final Logger LOG = Logger.getLogger(JSONUtil.class.getName());
24 |
25 | private JSONUtil(){}
26 |
27 | public static class JSONParseException extends Exception{
28 | public JSONParseException(String message){
29 | super(message);
30 | }
31 | }
32 |
33 | // Jackson Object Mapper used in indent operation:
34 | private static final ObjectMapper jsonObjMapper = new ObjectMapper();
35 | static {
36 | jsonObjMapper.enable(DeserializationConfig.Feature.USE_BIG_DECIMAL_FOR_FLOATS);
37 | jsonObjMapper.enable(DeserializationConfig.Feature.USE_BIG_INTEGER_FOR_INTS);
38 | }
39 |
40 | public static String indentJSON(final String jsonIn) throws JSONParseException{
41 | JsonFactory fac = new JsonFactory();
42 | try{
43 | JsonParser parser = fac.createJsonParser(new StringReader(jsonIn));
44 | JsonNode node = null;
45 | try{
46 | node = jsonObjMapper.readTree(parser);
47 | }
48 | catch(JsonParseException ex){
49 | throw new JSONParseException(ex.getMessage());
50 | }
51 | StringWriter out = new StringWriter();
52 |
53 | // Create pretty printer:
54 | JsonGenerator gen = fac.createJsonGenerator(out);
55 | DefaultPrettyPrinter pp = new DefaultPrettyPrinter();
56 | pp.indentArraysWith(new DefaultPrettyPrinter.Lf2SpacesIndenter());
57 | gen.setPrettyPrinter(pp);
58 |
59 | // Now write:
60 | jsonObjMapper.writeTree(gen, node);
61 |
62 | gen.flush();
63 | gen.close();
64 | return out.toString();
65 | }
66 | catch(IOException ex){
67 | LOG.log(Level.SEVERE, null, ex);
68 | }
69 | return jsonIn;
70 | }
71 |
72 | }
73 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------
/restclient-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 |
41 |
42 | if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
43 |
44 | doEscape(e);
45 | }
46 | }
47 |
48 | @Override
49 | public void keyReleased(KeyEvent e) {
50 | }
51 |
52 | @Override
53 | public void keyTyped(KeyEvent e) {
54 | }
55 |
56 | //ContainerListener interface
57 | @Override
58 | public void componentAdded(ContainerEvent e) {
59 | registerKeyAction(e.getChild());
60 | }
61 |
62 | @Override
63 | public void componentRemoved(ContainerEvent e) {
64 | registerKeyAction(e.getChild());
65 | }
66 |
67 | private void registerKeyAction(Component c) {
68 | if (c instanceof EscapableDialog == false) {
69 | c.removeKeyListener(this);
70 | c.addKeyListener(this);
71 | }
72 |
73 | if (c instanceof Container) {
74 | Container cnt = (Container) c;
75 | cnt.removeContainerListener(this);
76 | cnt.addContainerListener(this);
77 | Component[] ch = cnt.getComponents();
78 | for (int i = 0; i < ch.length; i++) {
79 | registerKeyAction(ch[i]);
80 | }
81 | }
82 | }
83 |
84 | /**
85 | * Center the dialog relative to parent before displaying.
86 | */
87 | @Override
88 | public void setVisible(boolean boo){
89 | if(boo){
90 | this.setLocationRelativeTo(_frame);
91 | }
92 | super.setVisible(boo);
93 | }
94 |
95 | }
96 |
--------------------------------------------------------------------------------
/restclient-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 |
--------------------------------------------------------------------------------