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 |
--------------------------------------------------------------------------------
/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.HostnameVerifier;
12 | import org.wiztools.restclient.bean.TLSReqBean;
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(org.wiztools.restclient.util.Url.get("https://www.webshop.co.uk/"));
47 | expResult.setMethod(HTTPMethod.GET);
48 | expResult.setHttpVersion(HTTPVersion.HTTP_1_1);
49 | expResult.setFollowRedirect(true);
50 | TLSReqBean ssl = new TLSReqBean();
51 | ssl.setTrustAllCerts(true);
52 | ssl.setHostNameVerifier(HostnameVerifier.ALLOW_ALL);
53 | expResult.setTLSReq(ssl);
54 |
55 | Request actual = p.getRequestFromFile(new File("src/test/resources/reqSsl.rcq"));
56 |
57 | assertEquals(expResult, actual);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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/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/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/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/test/java/org/wiztools/restclient/UtilTest.java:
--------------------------------------------------------------------------------
1 | package org.wiztools.restclient;
2 |
3 | import static org.junit.Assert.assertEquals;
4 | import org.junit.*;
5 | import org.wiztools.commons.MultiValueMap;
6 | import org.wiztools.commons.MultiValueMapLinkedHashSet;
7 | import org.wiztools.restclient.util.HttpUtil;
8 | import org.wiztools.restclient.util.Util;
9 |
10 | /**
11 | *
12 | * @author subWiz
13 | */
14 | public class UtilTest {
15 |
16 | public UtilTest() {
17 | }
18 |
19 | @BeforeClass
20 | public static void setUpClass() throws Exception {
21 | }
22 |
23 | @AfterClass
24 | public static void tearDownClass() throws Exception {
25 | }
26 |
27 | @Before
28 | public void setUp() {
29 | }
30 |
31 | @After
32 | public void tearDown() {
33 | }
34 |
35 | /**
36 | * Test of parameterEncode method, of class Util.
37 | */
38 | @Test
39 | public void testParameterEncode() {
40 | System.out.println("parameterEncode");
41 | MultiValueMap 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/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; idecodeURIComponent 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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(" 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/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/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/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/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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/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 |
--------------------------------------------------------------------------------