Skip to content

Commit 73cb12d

Browse files
committed
2 parents df647d0 + 3cd289a commit 73cb12d

File tree

6 files changed

+289
-86
lines changed

6 files changed

+289
-86
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
<img src="https://raw.githubusercontent.com/tinystruct/tinystruct2.0/master/favicon.png" title="tinystruct2.0" />
12
tinystruct2.0
23
=========
34
[![Build Status](https://travis-ci.org/m0ver/tinystruct2.0.svg?branch=master)](https://travis-ci.org/m0ver/tinystruct2.0)
45

56
This is an example project based on tinystruct2.0, it supports both C/S application and B/S web application development.
67

8+
9+
710
To execute it in CLI mode
811
---
912
```tcsh
@@ -35,7 +38,6 @@ You can access the below URLs after deployed the project in Tomcat 6.0+ :
3538
3639
* <a href="http://localhost:8080/?q=say/Praise%20to%20the%20Lord!">http://localhost:8080/?q=say/Praise%20to%20the%20Lord! </a><br />
3740
* <a href="http://localhost:8080/?q=praise">http://localhost:8080/?q=praise </a><br />
38-
* <a href="http://localhost:8080/?q=say/Hello%20World">http://localhost:8080/?q=say/Hello%20World </a><br />
3941
* <a href="http://localhost:8080/?q=youhappy">http://localhost:8080/?q=youhappy</a><br />
4042
* <a href="http://localhost:8080/?q=say/%E4%BD%A0%E7%9F%A5%E9%81%93%E5%85%A8%E4%B8%96%E7%95%8C%E6%9C%80%E7%95%85%E9%94%80%E7%9A%84%E4%B9%A6%E6%98%AF%E5%93%AA%E4%B8%80%E6%9C%AC%E4%B9%A6%E5%90%97%EF%BC%9F">http://localhost:8080/?q=say/%E4%BD%A0%E7%9F%A5%E9%81%93%E5%85%A8%E4%B8%96%E7%95%8C%E6%9C%80%E7%95%85%E9%94%80%E7%9A%84%E4%B9%A6%E6%98%AF%E5%93%AA%E4%B8%80%E6%9C%AC%E4%B9%A6%E5%90%97%EF%BC%9F</a>
4143
@@ -50,7 +52,6 @@ Results in your browser should be:
5052
<blockquote>
5153
<h1>Praise to the Lord!</h1>
5254
Praise to the Lord!
53-
<h1>Hello World</h1>
5455
<i>true</i>
5556
<h1>你知道全世界最畅销的书是哪一本书吗?</h1>
5657
</blockquote>

favicon.png

5.56 KB
Loading

src/themes/smalltalk.view

Lines changed: 61 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,18 @@
347347
$('#messages').append($li);
348348
$('#list').animate({scrollTop: $('#messages').height()}, 'fast');
349349
break;
350+
case 'session-timeout':
351+
$li = $("<li />");
352+
$li.html("System Notification:\t" + $data.user + " left from this conversation.");
353+
$('#messages').append($li);
354+
$('#list').animate({scrollTop: $('#messages').height()}, 'fast');
355+
break;
356+
case 'expired':
357+
$li = $("<li />");
358+
$li.html("System Notification:\tIt's an expired conversation, you have to refresh the current page or request a new meeting code.");
359+
$('#messages').append($li);
360+
$('#list').animate({scrollTop: $('#messages').height()}, 'fast');
361+
break;
350362
default:
351363
timer.setAction(function(){
352364
document.title = $_user + " is typing" + dotted;
@@ -369,26 +381,40 @@
369381
data: { cmd: cmd }
370382
}).done(function( msg ) {
371383
if(msg.error == "missing user") {
372-
if (user) {
373-
$.ajax({
374-
type: "POST",
375-
url: "[%LINK:talk/start%]/"+ user
376-
}).done(function( msg ) {});
377-
}
378-
else {
379-
$("#modal").modal();
380-
}
381-
}
382-
383-
if(msg.error == "expired") {
384-
if(confirm("The conversation is expired, Do you want to reload the conversation?")) {
385-
$.ajax({
386-
type: "POST",
387-
url: $('#link').text()
388-
}).done(function( msg ) {});
389-
}
390-
}
384+
if (user) {
385+
$.ajax({
386+
type: "POST",
387+
url: "[%LINK:talk/start%]/"+ user
388+
}).done(function( msg ) {});
389+
}
390+
else {
391+
$("#modal").modal();
392+
}
393+
}
391394
}).fail(function( msg ) {
395+
switch(msg.responseJSON.error) {
396+
case 'session-timeout':
397+
$li = $("<li />");
398+
$li.html("System Notification:\t" + $data.user + " left from this conversation.");
399+
$('#messages').append($li);
400+
$('#list').animate({scrollTop: $('#messages').height()}, 'fast');
401+
402+
if(confirm("Your session is timed out, Do you want to reload the conversation?")) {
403+
$.ajax({
404+
type: "POST",
405+
url: $('#link').text()
406+
}).done(function( msg ) {});
407+
}
408+
break;
409+
case 'expired':
410+
$li = $("<li />");
411+
$li.html("System Notification:\tIt's an expired conversation, you have to refresh the current page or request a new meeting code.");
412+
$('#messages').append($li);
413+
$('#list').animate({scrollTop: $('#messages').height()}, 'fast');
414+
break;
415+
default:break;
416+
}
417+
392418
console.log('Fail.');
393419
console.log(msg);
394420
});
@@ -413,12 +439,22 @@
413439
$.getJSON( "[%LINK:talk/update%]/{%meeting_code%}/{%session_id%}", function(data) {
414440
update(data);
415441
is_running = false;
416-
}).done(function() {
442+
}).done(function( msg ) {
417443
autoupdate();
418444
is_running = false;
419445
}).fail(function( msg ) {
420-
connection_timer.start();
421-
is_running = false;
446+
$msg = msg.responseJSON;
447+
if($msg.error == "expired") {
448+
command("expired");
449+
}
450+
else if($msg.error == "session-timeout") {
451+
command("session-timeout");
452+
}
453+
else {
454+
connection_timer.start();
455+
is_running = false;
456+
console.log($msg);
457+
}
422458
});
423459
}
424460
}
@@ -456,7 +492,7 @@
456492

457493
var post_timer = new Timer(.2, function(){
458494
if(i++<200){
459-
$("#text").text(user+' post '+i);
495+
$("#text").text(user+' posts '+i);
460496
$("#sender").submit();
461497
}
462498
else this.complete();
@@ -629,7 +665,7 @@
629665
<input id="attachment" name="attachment" type="file" class="file-loading btn-default" multiple="true" />
630666
<br />
631667
<input type="button" id="button" value="Send" class="btn btn-primary" />
632-
<!--<input type="button" id="test" value="Test" class="btn btn-secondary" />-->
668+
<input type="button" id="test" value="Test" class="btn btn-secondary" />
633669
</form>
634670
</div>
635671

@@ -672,7 +708,7 @@
672708

673709
<footer class="footer">
674710
<div class="container">
675-
<p class="text-muted"> © 2016 </p>
711+
<p class="text-muted"> © 2017 </p>
676712
</div>
677713
</footer>
678714

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
package tinystruct.examples;
2+
3+
import java.io.BufferedReader;
4+
import java.io.FileInputStream;
5+
import java.io.IOException;
6+
import java.io.InputStreamReader;
7+
import java.net.HttpURLConnection;
8+
import java.net.MalformedURLException;
9+
import java.net.URL;
10+
import java.util.Iterator;
11+
import java.util.List;
12+
import java.util.Map;
13+
import java.util.Map.Entry;
14+
import java.util.Set;
15+
16+
import org.tinystruct.AbstractApplication;
17+
import org.tinystruct.ApplicationException;
18+
19+
public class redirectChecker extends AbstractApplication {
20+
21+
@Override
22+
public void init() {
23+
// TODO Auto-generated method stub
24+
this.setAction("check", "start");
25+
}
26+
27+
/**
28+
HTTP/1.1 301 Moved Permanently
29+
Server:[nginx]
30+
X-Request-ID:[v-34c8ab26-3140-11e6-8d1f-22000aab1671]
31+
X-Content-Type-Options:[nosniff]
32+
X-Age:[158593]
33+
Connection:[keep-alive]
34+
Date:[Wed, 15 Jun 2016 04:27:24 GMT]
35+
X-Varnish:[2128902194 2128190039]
36+
Cache-Control:[max-age=1209600]
37+
Content-Encoding:[gzip]
38+
Vary:[Accept-Encoding]
39+
Expires:[Mon, 27 Jun 2016 08:24:11 GMT]
40+
Content-Length:[217]
41+
X-Cache-Hits:[168]
42+
Location:[http://domain.com/path]
43+
Content-Type:[text/html; charset=iso-8859-1]
44+
* @throws ApplicationException
45+
*/
46+
public void start() throws ApplicationException{
47+
try
48+
{
49+
FileInputStream fileInput = new FileInputStream("url-rules.txt");
50+
InputStreamReader reader = new InputStreamReader(fileInput);
51+
BufferedReader bufferReader = new BufferedReader(reader);
52+
53+
String line, destinationURL, currentURL;
54+
String[] parts;
55+
URL from;
56+
while((line = bufferReader.readLine()) != null)
57+
{
58+
parts = line.split("\\t|\\s");
59+
destinationURL = parts[1];
60+
from = new URL(parts[0]);
61+
62+
boolean follow = false, redirected = false;
63+
do {
64+
HttpURLConnection connection = (HttpURLConnection) from.openConnection();
65+
connection.setInstanceFollowRedirects(follow);
66+
connection.connect();
67+
currentURL = connection.getHeaderField("Location").trim();
68+
69+
int responseCode = connection.getResponseCode();
70+
71+
redirected = (responseCode == 302);
72+
73+
if(!destinationURL.trim().equalsIgnoreCase(currentURL)) {
74+
Map<String, List<String>> list = connection.getHeaderFields();
75+
Set<Entry<String, List<String>>> set = list.entrySet();
76+
Iterator<Entry<String, List<String>>> iterator = set.iterator();
77+
Entry<String, List<String>> entity;
78+
while(iterator.hasNext()) {
79+
entity = iterator.next();
80+
System.out.println(entity.getKey()+":"+entity.getValue());
81+
}
82+
}
83+
if(redirected) from = new URL(currentURL);
84+
System.out.println("Status:\t"+ connection.getHeaderField(0) +"\t"+ (destinationURL.trim().equalsIgnoreCase(currentURL)?"OK":"Failure"));
85+
System.out.println("From:\t"+from+"\r\nTo:\t"+currentURL+"\r\n");
86+
} while (redirected);
87+
88+
System.out.println();
89+
}
90+
bufferReader.close();
91+
reader.close();
92+
fileInput.close();
93+
} catch (MalformedURLException e) {
94+
throw new ApplicationException(e.getMessage(), e.getCause());
95+
} catch (IOException e) {
96+
throw new ApplicationException(e.getMessage(), e.getCause());
97+
}
98+
}
99+
100+
@Override
101+
public String version() {
102+
// TODO Auto-generated method stub
103+
return null;
104+
}
105+
106+
}

0 commit comments

Comments
 (0)