Fixed some warnings and started on the NetLog project

This commit is contained in:
Ziver Koc 2013-05-03 19:31:45 +00:00
parent db9b2bf307
commit 27b12e1b9b
29 changed files with 722 additions and 322 deletions

View file

@ -5,12 +5,11 @@
<classpathentry kind="lib" path="libs/dom4j-1.6.1.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/dom4j-1.6.1/src"/>
<classpathentry kind="lib" path="libs/wsdl4j-1.6.2.jar"/>
<classpathentry kind="lib" path="libs/javassist.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/javassist-3.12.GA"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v6.0"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="lib" path="libs/commons-fileupload-1.2.1.jar" sourcepath="C:/Users/Ziver/Documents/Programmering/Java/libs/commons/commons-fileupload-1.2.1-sources.jar"/>
<classpathentry kind="lib" path="libs/commons-io-1.4.jar"/>
<classpathentry kind="lib" path="libs/mysql-connector-java-5.1.14-bin.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="C:/Program Files/Java/jre7/lib/jfxrt.jar"/>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v7.0"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View file

@ -1,6 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-modules id="moduleCoreId" project-version="1.5.0">
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="ZUtil">
<wb-resource deploy-path="/" source-path="/src"/>
</wb-module>
</project-modules>

View file

@ -0,0 +1,85 @@
/*******************************************************************************
* Copyright (c) 2011 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package zutil.log.net;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import zutil.log.LogUtil;
public class NetLogClient extends Thread{
private static final Logger logger = LogUtil.getLogger();
private ConcurrentLinkedQueue<NetLogListener> listeners;
private Socket s;
public NetLogClient(String host, int port) throws UnknownHostException, IOException{
s = new Socket(host, port);
listeners = new ConcurrentLinkedQueue<NetLogListener>();
this.start();
}
public void addListener(NetLogListener listener){
logger.info("Registring new NetLogListener: "+listener.getClass().getName());
listeners.add( listener );
}
public void run(){
try{
ObjectInputStream in = new ObjectInputStream( s.getInputStream() );
while( true ){
Object o = in.readObject();
for( NetLogListener listener : listeners ){
if( o instanceof NetLogMessage )
listener.handleLogMessage((NetLogMessage)o);
else if( o instanceof NetLogExceptionMessage )
listener.handleExceptionMessage((NetLogExceptionMessage)o);
else if( o instanceof NetLogStatusMessage )
listener.handleStatusMessage((NetLogStatusMessage)o);
else
logger.warning("Received unknown message: "+o.getClass().getName());
}
}
} catch( Exception e ){
logger.log(Level.SEVERE, null, e);
close();
}
}
public void close(){
try{
this.interrupt();
s.close();
} catch (Exception e){
logger.log(Level.SEVERE, "Unable to close Client Socket.", e);
}
}
}

View file

@ -0,0 +1,87 @@
/*******************************************************************************
* Copyright (c) 2011 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package zutil.log.net;
import java.util.logging.LogRecord;
import zutil.net.nio.message.Message;
public class NetLogExceptionMessage extends Message {
private static final long serialVersionUID = 1L;
private int count;
private String name;
private String message;
private String stackTrace;
NetLogExceptionMessage(String name, String message, String stackTrace){
this.count = 1;
this.name = name;
this.message = message;
this.stackTrace = stackTrace;
}
public NetLogExceptionMessage(LogRecord record) {
Throwable exception = record.getThrown();
this.count = 1;
this.name = exception.getClass().getName();
this.message = exception.getMessage();
this.stackTrace = "";
for(int i=0; i<exception.getStackTrace().length; i++){
this.stackTrace += exception.getStackTrace()[i].toString();
}
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getStackTrace() {
return stackTrace;
}
public void setStackTrace(String stackTrace) {
this.stackTrace = stackTrace;
}
}

View file

@ -1,4 +1,25 @@
package zutil.log.netlog;
/*******************************************************************************
* Copyright (c) 2011 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package zutil.log.net;
import java.io.IOException;
@ -13,7 +34,7 @@ import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import javafx.scene.layout.AnchorPane;
public class NetLoggerClient extends Application{
public class NetLogGuiClient extends Application{
public static final String VERSION = "0.1";
// UI elements
@ -22,7 +43,7 @@ public class NetLoggerClient extends Application{
public static void main(String[] args) {
Application.launch(NetLoggerClient.class, args);
Application.launch(NetLogGuiClient.class, args);
}
@Override

View file

@ -0,0 +1,167 @@
/*******************************************************************************
* Copyright (c) 2011 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package zutil.log.net;
import java.net.URL;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import zutil.log.LogUtil;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TableColumn;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.TableView;
import javafx.scene.control.Label;
import javafx.scene.control.cell.PropertyValueFactory;
public class NetLogGuiClientInstance implements Initializable, NetLogListener {
private static final Logger logger = LogUtil.getLogger();
private static enum Status{RUNNING, PAUSED, DISCONNECTED}
// Logic variables
private NetLogClient net;
private Status status;
private final ObservableList<NetLogExceptionMessage> exceptionData =
FXCollections.observableArrayList(
new NetLogExceptionMessage("java.lang.NullPointerException", "", " at com.example.myproject.Book.getTitle(Book.java:16) \n at com.example.myproject.Author.getBookTitles(Author.java:25) \n at com.example.myproject.Bootstrap.main(Bootstrap.java:14)"),
new NetLogExceptionMessage("java.lang.NullPointerException", "", " at com.example.myproject.Book.getTitle(Book.java:16) \n at com.example.myproject.Author.getBookTitles(Author.java:25) \n at com.example.myproject.Bootstrap.main(Bootstrap.java:14)"),
new NetLogExceptionMessage("java.io.FileNotFoundException", "fred.txt", " at java.io.FileInputStream.<init>(FileInputStream.java) \n at java.io.FileInputStream.<init>(FileInputStream.java) \n at ExTest.readMyFile(ExTest.java:19) \n at ExTest.main(ExTest.java:7)")
);
// UI elements
@FXML private ToggleButton pauseButton;
@FXML private Label logCountLabel;
@FXML private ProgressBar progressBar;
@FXML private TableView<NetLogMessage> logTable;
@FXML private TableColumn<NetLogMessage, Long> logTimestampColumn;
@FXML private TableColumn<NetLogMessage, String> logLevelColumn;
@FXML private TableColumn<NetLogMessage, String> logColumn;
@FXML private TableView<NetLogExceptionMessage> exceptionTable;
@FXML private TableColumn<NetLogExceptionMessage, Long> exCountColumn;
@FXML private TableColumn<NetLogExceptionMessage, String> exNameColumn;
@FXML private TableColumn<NetLogExceptionMessage, String> exMessageColumn;
@FXML private TableColumn<NetLogExceptionMessage, String> exStackTraceColumn;
public void initialize(URL arg0, ResourceBundle arg1) {
// Connect to Server
try{
net = new NetLogClient("localhost", 5050);
net.addListener( this );
status = Status.RUNNING;
}catch(Exception e){
logger.log(Level.SEVERE, null, e);
status = Status.DISCONNECTED;
}
updateStatus();
// Setup Gui
logTimestampColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, Long>("timestamp"));
logLevelColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, String>("level"));
logColumn.setCellValueFactory(new PropertyValueFactory<NetLogMessage, String>("log"));
exCountColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, Long>("count"));
exNameColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("name"));
exMessageColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("message"));
exStackTraceColumn.setCellValueFactory(new PropertyValueFactory<NetLogExceptionMessage, String>("stackTrace"));
//logTable.setItems(logData);
exceptionTable.setItems(exceptionData);
}
/************* NETWORK *****************/
public void handleLogMessage(NetLogMessage log) {
logTable.getItems().add( log );
}
public void handleExceptionMessage(NetLogExceptionMessage exception) {
exceptionTable.getItems().add( exception );
}
public void handleStatusMessage(NetLogStatusMessage status) {
// TODO Auto-generated method stub
}
/*************** GUI *******************/
@FXML
protected void handlePauseAction(ActionEvent event) {
if(status == Status.RUNNING){
status = Status.PAUSED;
logger.info("Logging paused");
}
else if(status == Status.PAUSED){
status = Status.RUNNING;
logger.info("Logging Unpaused");
}
updateStatus();
}
@FXML
protected void handleDisconnectAction(Event event) {
logger.info("Disconnecting from Log Server");
net.close();
status = Status.DISCONNECTED;
updateStatus();
}
@FXML
protected void handleLevelChanged(ActionEvent event) {
logger.info("Updating Log Level");
}
@FXML
protected void handleIntervalChanged(ActionEvent event) {
logger.info("Updating Log Interval");
}
private void updateStatus(){
if(progressBar == null || pauseButton == null){
return;
}
if(status == Status.RUNNING){
progressBar.setProgress(-1.0);
pauseButton.setText("Pause");
}
else if(status == Status.PAUSED){
progressBar.setProgress(1.0);
pauseButton.setText("Unpause");
}
else if(status == Status.DISCONNECTED){
progressBar.setProgress(0);
pauseButton.disableProperty();
}
}
}

View file

@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2011 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package zutil.log.net;
public interface NetLogListener {
/**
* Handle incoming log messages
*/
public void handleLogMessage( NetLogMessage log );
/**
* Handle incoming exception messages
*/
public void handleExceptionMessage( NetLogExceptionMessage exception );
/**
* Handle incoming status messages
*/
public void handleStatusMessage( NetLogStatusMessage status );
}

View file

@ -0,0 +1,104 @@
/*******************************************************************************
* Copyright (c) 2011 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package zutil.log.net;
import java.util.logging.LogRecord;
import zutil.net.nio.message.Message;
public class NetLogMessage extends Message {
private static final long serialVersionUID = 1L;
private long timestamp;
private String level;
private int threadID;
private String className;
private String methodName;
private String log;
public NetLogMessage(String level, long timestamp, String log){
this.level = level;
this.timestamp = timestamp;
this.log = log;
}
public NetLogMessage( LogRecord record ){
timestamp = record.getMillis();
level = record.getLevel().getName();
threadID = record.getThreadID();
className = record.getSourceClassName();
methodName = record.getSourceMethodName();
log = record.getMessage();
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public int getThreadID() {
return threadID;
}
public void setThreadID(int threadID) {
this.threadID = threadID;
}
public String getClassName() {
return className;
}
public void setClassName(String className) {
this.className = className;
}
public String getMethodName() {
return methodName;
}
public void setMethodName(String methodName) {
this.methodName = methodName;
}
public String getLog() {
return log;
}
public void setLog(String log) {
this.log = log;
}
}

View file

@ -0,0 +1,153 @@
/*******************************************************************************
* Copyright (c) 2011 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package zutil.log.net;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.logging.Handler;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;
import zutil.log.LogUtil;
import zutil.net.nio.message.Message;
import zutil.net.threaded.ThreadedTCPNetworkServer;
import zutil.net.threaded.ThreadedTCPNetworkServerThread;
public class NetLogServer extends Handler {
private static final Logger logger = LogUtil.getLogger();
private NetLogNetwork net;
/**
* @param port the port the server will listen on
*/
public NetLogServer(int port) {
super();
net = new NetLogNetwork(port);
}
public void publish(LogRecord record) {
// ensure that this log record should be logged by this Handler
if (!isLoggable(record))
return;
// Output the formatted data to the file
if(record.getThrown() != null){
NetLogExceptionMessage exception = new NetLogExceptionMessage(record);
net.sendMessage( exception );
}
else{
NetLogMessage log = new NetLogMessage(record);
net.sendMessage( log );
}
}
public void flush() {}
public void close() {
net.close();
}
class NetLogNetwork extends ThreadedTCPNetworkServer{
private ConcurrentLinkedQueue<NetLogServerThread> threads;
public NetLogNetwork(int port) {
super(port);
threads = new ConcurrentLinkedQueue<NetLogServerThread>();
}
public void sendMessage(Message log){
for( NetLogServerThread thread : threads ){
thread.queueMessage( log );
}
}
@Override
protected ThreadedTCPNetworkServerThread getThreadInstance(Socket s) {
try {
NetLogServerThread thread = new NetLogServerThread(s);
logger.info("Client connection from: "+s.getInetAddress());
threads.add( thread );
return thread;
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to start Client thread", e);
}
return null;
}
class NetLogServerThread implements ThreadedTCPNetworkServerThread{
private Queue<Message> queue;
private ObjectOutputStream out;
private Socket s;
public NetLogServerThread(Socket s) throws IOException{
queue = new LinkedList<Message>();
this.s = s;
out = new ObjectOutputStream( s.getOutputStream() );
}
public void queueMessage(Message log){
queue.add( log );
queue.notify();
}
public void run() {
try {
while( true ){
while( !queue.isEmpty() ){
Message msg = queue.poll();
out.writeObject( msg );
}
queue.wait();
}
} catch (Exception e) {
logger.log(Level.SEVERE, null, e);
} finally {
this.close();
}
}
public void close(){
try {
out.close();
s.close();
queue = null;
threads.remove(this);
} catch (IOException e) {
logger.log(Level.SEVERE, "Unable to close Client Socket", e);
}
}
}
}
}

View file

@ -0,0 +1,31 @@
/*******************************************************************************
* Copyright (c) 2011 Ziver Koc
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
******************************************************************************/
package zutil.log.net;
import zutil.net.nio.message.Message;
public class NetLogStatusMessage extends Message{
private static final long serialVersionUID = 1L;
public long totalMemory;
public long freememory;
}

View file

@ -8,7 +8,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="zutil.log.netlog.NetLoggerClient">
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="zutil.log.net.NetLogGuiClient">
<children>
<MenuBar prefWidth="598.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<menus>

View file

@ -9,7 +9,7 @@
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="zutil.log.netlog.NetLoggerClientInstance">
<BorderPane xmlns:fx="http://javafx.com/fxml" fx:controller="zutil.log.net.NetLogGuiClientInstance">
<bottom>
<ToolBar maxHeight="22.0" minHeight="19.0" prefHeight="22.0" prefWidth="839.0">
<items>

View file

@ -1,50 +0,0 @@
package zutil.log.netlog;
public class NLExceptionData {
private int count;
private String name;
private String message;
private String stackTrace;
NLExceptionData(String name, String message, String stackTrace){
this.count = 0;
this.name = name;
this.message = message;
this.stackTrace = stackTrace;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getStackTrace() {
return stackTrace;
}
public void setStackTrace(String stackTrace) {
this.stackTrace = stackTrace;
}
}

View file

@ -1,39 +0,0 @@
package zutil.log.netlog;
public class NLLogData {
private String level;
private long timestamp;
private String log;
NLLogData(String level, long timestamp, String log){
this.level = level;
this.timestamp = timestamp;
this.log = log;
}
public String getLevel() {
return level;
}
public void setLevel(String level) {
this.level = level;
}
public long getTimestamp() {
return timestamp;
}
public void setTimestamp(long timestamp) {
this.timestamp = timestamp;
}
public String getLog() {
return log;
}
public void setLog(String log) {
this.log = log;
}
}

View file

@ -1,119 +0,0 @@
package zutil.log.netlog;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.event.Event;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.TableColumn;
import javafx.scene.control.ToggleButton;
import javafx.scene.control.TableView;
import javafx.scene.control.Label;
import javafx.scene.control.cell.PropertyValueFactory;
public class NetLoggerClientInstance implements Initializable {
private enum Status{RUNNING, PAUSED, DISCONNECTED}
// Logic variables
private Status status;
private final ObservableList<NLExceptionData> exceptionData =
FXCollections.observableArrayList(
new NLExceptionData("java.lang.NullPointerException", "", " at com.example.myproject.Book.getTitle(Book.java:16) \n at com.example.myproject.Author.getBookTitles(Author.java:25) \n at com.example.myproject.Bootstrap.main(Bootstrap.java:14)"),
new NLExceptionData("java.lang.NullPointerException", "", " at com.example.myproject.Book.getTitle(Book.java:16) \n at com.example.myproject.Author.getBookTitles(Author.java:25) \n at com.example.myproject.Bootstrap.main(Bootstrap.java:14)"),
new NLExceptionData("java.io.FileNotFoundException", "fred.txt", " at java.io.FileInputStream.<init>(FileInputStream.java) \n at java.io.FileInputStream.<init>(FileInputStream.java) \n at ExTest.readMyFile(ExTest.java:19) \n at ExTest.main(ExTest.java:7)")
);
// UI elements
@FXML private ToggleButton pauseButton;
@FXML private TableView<NLLogData> logTable;
@FXML private TableColumn<NLLogData, Long> logTimestampColumn;
@FXML private TableColumn<NLLogData, String> logLevelColumn;
@FXML private TableColumn<NLLogData, String> logColumn;
@FXML private TableView<NLExceptionData> exceptionTable;
@FXML private TableColumn<NLExceptionData, Long> exCountColumn;
@FXML private TableColumn<NLExceptionData, String> exNameColumn;
@FXML private TableColumn<NLExceptionData, String> exMessageColumn;
@FXML private TableColumn<NLExceptionData, String> exStackTraceColumn;
@FXML private Label logCountLabel;
@FXML private ProgressBar progressBar;
public void initialize(URL arg0, ResourceBundle arg1) {
status = Status.RUNNING;
updateStatus();
logTimestampColumn.setCellValueFactory(new PropertyValueFactory<NLLogData, Long>("timestamp"));
logLevelColumn.setCellValueFactory(new PropertyValueFactory<NLLogData, String>("level"));
logColumn.setCellValueFactory(new PropertyValueFactory<NLLogData, String>("log"));
exCountColumn.setCellValueFactory(new PropertyValueFactory<NLExceptionData, Long>("count"));
exNameColumn.setCellValueFactory(new PropertyValueFactory<NLExceptionData, String>("name"));
exMessageColumn.setCellValueFactory(new PropertyValueFactory<NLExceptionData, String>("message"));
exStackTraceColumn.setCellValueFactory(new PropertyValueFactory<NLExceptionData, String>("stackTrace"));
//logTable.setItems(logData);
exceptionTable.setItems(exceptionData);
}
@FXML
protected void handlePauseAction(ActionEvent event) {
if(status == Status.RUNNING){
status = Status.PAUSED;
System.out.println("Logging Paused");
}
else if(status == Status.PAUSED){
status = Status.RUNNING;
System.out.println("Logging Unpaused");
}
updateStatus();
}
@FXML
protected void handleDisconnectAction(Event event) {
System.out.println("Disconnected changed");
status = Status.DISCONNECTED;
updateStatus();
}
@FXML
protected void handleLevelChanged(ActionEvent event) {
System.out.println("Level changed");
}
@FXML
protected void handleIntervalChanged(ActionEvent event) {
System.out.println("Interval changed");
}
private void updateStatus(){
if(progressBar == null || pauseButton == null){
System.out.println("progressBar="+progressBar+" pauseButton="+pauseButton);
return;
}
System.out.println("Status: "+status);
if(status == Status.RUNNING){
progressBar.setProgress(-1.0);
pauseButton.setText("Pause");
}
else if(status == Status.PAUSED){
progressBar.setProgress(1.0);
pauseButton.setText("Unpause");
}
else if(status == Status.DISCONNECTED){
progressBar.setProgress(0);
pauseButton.disableProperty();
}
}
}

View file

@ -107,7 +107,7 @@ public class HttpClient {
}
else
request.println("");
request.flush();
request.close();
// Response
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));

View file

@ -85,6 +85,7 @@ public class HttpHeaderParser {
parseLine( tmp );
}
}
sc.close();
parseCookies();
}

View file

@ -21,11 +21,6 @@
******************************************************************************/
package zutil.net.http.multipart;
import java.io.BufferedReader;
import java.io.File;
import zutil.ProgressListener;
/**
* A class for handling multipart field

View file

@ -21,11 +21,8 @@
******************************************************************************/
package zutil.net.http.multipart;
import java.io.BufferedReader;
import java.io.File;
import zutil.ProgressListener;
/**
* A class for handling multipart files

View file

@ -21,12 +21,8 @@
******************************************************************************/
package zutil.net.http.multipart;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@ -101,83 +97,15 @@ public class MultipartParser {
*/
public List<MultipartField> parse() throws IOException{
ArrayList<MultipartField> list = new ArrayList<MultipartField>();
// TODO: parse(list, delimiter);
parse(list, delimiter);
return list;
}
// TODO:
/*
private void parse(List<MultipartField> list, String delimiter) throws IOException{
String line = "";
MultipartField field = null;
delimiter = "--"+delimiter;
String endDelimiter = delimiter+"--";
BufferedWriter out = null;
// Parsing the stream
while(line != null){
line = in.readLine();
// Skip empty lines
if(line == null || line.trim().isEmpty())
continue;
// End of field
else if(line.equals( endDelimiter )){
list.add(field);
if(out != null) out.close();
field.length = field.file.length();
out = null;
field = null;
continue;
}
// New field
else if(line.equals( delimiter )){
if(field != null){
list.add(field);
if(out != null) out.close();
field.length = field.file.length();
out = null;
field = null;
}
// Read the content-disposition
line = in.readLine();
if(line.toLowerCase().startsWith("content-disposition")){
line = line.split(":", 2)[1];
String[] fieldData = line.split(" *; *");
//String type = fieldData[0].toLowerCase();
field = new MultipartField();
field.type = MultipartField.FieldType.Field;
// Parse content-disposition parameters
for(String param : fieldData){
String[] temp = param.split(" *= *");
if(temp[0].equalsIgnoreCase("name"))
field.fieldname = temp[1];
else if(temp[0].equalsIgnoreCase("filename")){
field.filename = temp[1];
field.file = createTempFile();
out = new BufferedWriter(new FileWriter(field.file));
field.type = MultipartField.FieldType.File;
}
}
}
else
throw new IOException("MultipartForm parse error unrecognized line: "+line);
}
// Read field data
else if(field != null){
if(field.type == MultipartField.FieldType.File){
out.append(line);
}
else{
field.value += line;
}
field.received += line.length();
}
}
if(field != null)
throw new IOException("MultipartForm parse error stream ended prematurely");
// TODO:
}
*/
/**
* Creates a temporary file in either the system

View file

@ -46,7 +46,7 @@ import zutil.net.ws.WSParameterDef;
import zutil.net.ws.WSReturnObject;
import zutil.net.ws.WSReturnObject.WSValueName;
import zutil.net.ws.WebServiceDef;
import zutil.parser.wsdl.WSDLWriter;
import zutil.parser.wsdl.WSDLWriterOld;
/**
* This is an HTTPPage for the HTTPServer that
@ -87,7 +87,7 @@ public class SOAPHttpPage implements HttpPage{
/** This instance of the web service class is used if session is disabled **/
private WSInterface ws;
/** The WSDL document **/
private WSDLWriter wsdl;
private WSDLWriterOld wsdl;
/** Session enabled **/
private boolean session_enabled;
@ -95,7 +95,7 @@ public class SOAPHttpPage implements HttpPage{
this.wsDef = wsDef;
this.session_enabled = false;
wsdl = new WSDLWriter( wsDef );
wsdl = new WSDLWriterOld( wsDef );
}
/**

View file

@ -43,7 +43,7 @@ import zutil.log.LogUtil;
* @author Ziver
*/
public abstract class ThreadedTCPNetworkServer extends Thread{
public static final Logger logger = LogUtil.getLogger();
private static final Logger logger = LogUtil.getLogger();
public final int port;
private File keyStore;

View file

@ -34,7 +34,7 @@ public class Base64Decoder {
public static String decode( String data ){
Base64Decoder base64 = new Base64Decoder();
base64.write( data );
return base64.getString();
return base64.toString();
}
public void write( String data ){
@ -76,7 +76,7 @@ public class Base64Decoder {
output.append( buffer, 0, buffi );
}
public String getString(){
public String toString(){
return output.getString();
}
@ -84,8 +84,8 @@ public class Base64Decoder {
return output.getByte();
}
public void reset(){
output.reset();
public void clear(){
output.clear();
rest = 0;
rest_data = 0;
}

View file

@ -88,6 +88,8 @@ public class DataNode implements Iterable<DataNode>{
map = new HashMap<String,DataNode>(); break;
case List:
list = new LinkedList<DataNode>(); break;
default:
break;
}
}

View file

@ -34,15 +34,15 @@ public class Base64Test {
Base64Decoder decoder = new Base64Decoder();
//decoder.decode("TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlzIHNpbmd1bGFyIHBhc3Npb24gZnJvbSBvdGhlciBhbmltYWxzLCB3aGljaCBpcyBhIGx1c3Qgb2YgdGhlIG1pbmQsIHRoYXQgYnkgYSBwZXJzZXZlcmFuY2Ugb2YgZGVsaWdodCBpbiB0aGUgY29udGludWVkIGFuZCBpbmRlZmF0aWdhYmxlIGdlbmVyYXRpb24gb2Yga25vd2xlZGdlLCBleGNlZWRzIHRoZSBzaG9ydCB2ZWhlbWVuY2Ugb2YgYW55IGNhcm5hbCBwbGVhc3VyZS4=");
//assertEquals( "Man is distinguished, not only by his reason, but by this singular passion from other animals, which is a lust of the mind, that by a perseverance of delight in the continued and indefatigable generation of knowledge, exceeds the short vehemence of any carnal pleasure.", decoder.toString() );
decoder.reset();
decoder.decode("YW55IGNhcm5hbCBwbGVhc3VyZQ==");
decoder.clear();
decoder.write("YW55IGNhcm5hbCBwbGVhc3VyZQ==");
assertEquals( "any carnal pleasure", decoder.toString() );
decoder.reset();
decoder.decode("bGVhc3VyZS4=");
decoder.clear();
decoder.write("bGVhc3VyZS4=");
assertEquals( "leasure.", decoder.toString() );
decoder.reset();
decoder.decode("YW55IGNhcm5hbCBwbGVhc3Vy");
decoder.clear();
decoder.write("YW55IGNhcm5hbCBwbGVhc3Vy");
assertEquals( "any carnal pleasur", decoder.toString() );
decoder.reset();
decoder.clear();
}
}

View file

@ -30,6 +30,7 @@ import org.junit.Test;
import zutil.io.BoundaryBufferedInputStream;
import zutil.io.StringInputStream;
@SuppressWarnings("resource")
public class BoundaryBufferedInputStreamTest {
@Test

View file

@ -54,7 +54,6 @@ import zutil.ui.wizard.listener.BlockingWizardListener;
*/
public class Wizard implements ActionListener{
public static final boolean DEBUG = false;
private static final long serialVersionUID = 1L;
/** Some defoult backgrounds for the sidebar */
public static final String BACKGROUND_1 = "zutil/data/wizard1.jpg";

View file

@ -83,7 +83,7 @@ public class WizardActionHandler implements ActionListener, FocusListener, ListS
* JList
*/
else if(c instanceof JList){
JList o = (JList) c;
JList<?> o = (JList<?>) c;
o.addListSelectionListener( this );
}
}
@ -115,7 +115,7 @@ public class WizardActionHandler implements ActionListener, FocusListener, ListS
* JList
*/
else if(c instanceof JList){
JList o = (JList) c;
JList<?> o = (JList<?>) c;
values.put( o.getName() , o.getSelectedValue() );
}
}