KeyGrab – grab key combinations using TextField in Swing/Java.
Posted by ski | Filed under Developement, English
Description.
This small component was cut out form the bigger project. It’s extension of JTextLabel which easily can be added to you java swing project, to provide text box which can easily grab and display key combinations.
Features.
- Open source, free to use.
- Free access to current key combination associated with TextBox.
- Callbacks while new conbinations is being set.
- Possibility of overwiting names of the keys.
- Easy integartion with IDEs ( can be added as component to i.e. Netbens )
- anyway, it’s in-4-hours-made component – feature list ends here :)
Usage.
Key[] defaultKeys = new Key[]{ new Key(KeyEvent.VK_SHIFT), new Key('A') };
KeyGrab keyGrabTextBox = new KeyGrab(defaultKeys);
Download.
- All-in-one – keygrab-1.0-src.zip (71kb, zip)- source files, demo and jar ready to include to your project.
- Demo and component – keygrab-1.0-demo.jar (7kb, jar)- see demo or include it to the project.
- Component only – keygrab-1.0.jar (6k, jar)- add to your project and use.
Tags: Java, JTextField, key listener, Swing
Simple way to speed up JBOSS build (deploy to RAM)
Posted by ski | Filed under Developement
Usually, while working with web applications, I need to redeploy it several times a day. As we all know, waiting for build (clean-compile-build-deploy) to finish is big pain in the ass ( aka bottleneck ;)) This note is valid for temporary build ( those going by default to JBOSS_HOME/server/default/temp directory and for computers with big amount of RAM. Idea is very simple – use RAM as virtual drive, and put jboss deploy directory on it (only temp, not all jboss!)
0. Is your computer able to handle this?
We need a lot of free ram to put there jboss build directory.
During your working day, check amount of your used / free memmory. Do not count allocated memmory (calculated together with page file), but only phisical RAM. When we create ram disk, and it (or something else) mus bu catched on HDD this solution does not make sense!
Than, check how much memmory is taken by your deployed applications.
In my case ( 4GB ram in total, used max 2.5 Gb for Windows, Eclipse, some tools, running jboss, foobar2000, browsers, etc. ). Jboss build takes maximum 500-600Mb (without precompilation of jsps). In this case, I decided to allocate 1GB of RAM disk, which should be enough ( almost 100% of reserve for jboss, 500Mb left for system).
1. Create RAM disk.
1. Go and grab RAMdisk here.
2. Install the programm, I used 1Gb, media type “Fixed media” (“RAM Drive” causes reboot btw.) and R for drive letter (who will guess why?).
2. Change JBOSS configuration to write /tmp into ram drive.
Edit run.bat ( JBOSS_HOME/bin/run.bat ). Do not use run.config because it’s platform dependent. Find place to add JAVA_OPTS ( after all are defined, but before they are read ). Add following line:
rem RAMDISK set JAVA_OPTS=%JAVA_OPTS% -Djboss.server.temp.dir=R:/temp/jboss
This simply adds JBOSS property jboss.server.temp.dir which points to your RAM disk. According to this programm’s specification, do not use the root of this disk ( always write inside /temp ). Btw, description of other JBOSS properties can be found here.
Now restart your server, when it’s up some files should appear in the RAM disk.
In my case time decreased from 5:30 to 4:02. Improvements depends on some things ( speed of your HDD, number of files to deploy, etc. ). You must check by yourself, consider how many deploys you’re doing during the day, and decide if it’s worth grabbing your RAM or not. And remember once again, that files will disapear on power failure or BSOD. ( for those who likes modifing files with “hot deploy” )
Good luck!
debian/ubuntu various config notes
Posted by ski | Filed under Uncategorized
Various notes about configuration in Debian/Ubuntu systems.
1.Decrease default size of the font in CLI (console).
in the /boot/grub/menus.lst add “vga=791″ for your boot option
kernel /boot/vmlinu(...) vga=791 ro quiet nosplash
other available options are
640x480 | 800x600 1024x768 1280x1024 1600x1200 256 (8 bit) | 769 771 773 775 796 32,768 (15 bit)| 784 787 790 793 797 65,536 (16 bit)| 785 788 791 794 798 16.8M (24 bit) | 786 789 792 795 799
2. Install bcm43xx drivers without Internet connection.
0. Download firmawe from
http://downloads.openwrt.org/sources/wl_apsta-3.130.20.0.o
http://mirror2.openwrt
1. From CD of ubuntu.
sudo apt-cdrom add
sudo aptitude update
sudo aptitude install b43-fwcutter
2. Install firmware using GUI.
found on http://ubuntuforums.org/showpost.php?p=6028741&postcount=4
Connecting webservice using server’s certificate with Axis 1.4.
Posted by ski | Filed under Developement
This informations were gathered while dealing with following problem -
access remote webservice from java application, using server’s certificate/ private key. Target service was Yandex, as it’s available only for registered user I’ll skip credentials and user details. Client’s machine was some distribution of Fedora, so I’ll explain this case, but solutions should work on most of Linux machines.
prerequirements
1. wsdl file of the target webservice ( for yandex it’s http://soap-new.direct.yandex.ru/api.wsdl )
2. login and password for the service.
If you use Yandex you need to create your private key and “certificate request” and than send them using special form .As the result you’ll have
private.key – our private key
cacert.pem, cert.crt – certificates of the server
3. java, of course, security provider ( I used Bouncy Castle, instalation notes are described on their page ), Axis 1.4.
PHP approach
I’ll mention approach in PHP, as I found code snippet for it. Here, the case is really really simple ( example requires NuSoap, nice SOAP tool for PHP – download it and put into “lib/” to make first import correct ).
<?php
require_once('lib/nusoap.php');
$proxyhost = '';
$proxyport = '';
$proxyusername = '';
$proxypassword = '';
$wsdlurl = "http://soap-new.direct.yandex.ru/api.wsdl";
$client = new nusoap_client($wsdlurl, 'wsdl', $proxyhost, $proxyport,
$proxyusername, $proxypassword);
$client->authtype = 'certificate';
$client->decode_utf8 = 0;
$client->soap_defencoding = 'UTF-8';
$client->certRequest['sslcertfile'] = 'cert.crt';
$client->certRequest['sslkeyfile'] = 'private.key';
$client->certRequest['cainfofile'] = 'cacert.pem'; $client->username=__WS_USERNAME__; $client->password=__WS_PASSWORD__;
$params[] = __WS_USERNAME__;
$result = $client->call('PingAPI', array()); // PingAPI is the method of the service which returns '1' if correctly called
print_r($result); print_r($client->faultdetail); print_r($client->error_str); print_r($client->faultstring); print_r($client->responseData); print_r($client->requestHeaders);
if($client->fault)
{
echo "FAULT : " . $client->fault;
}
?>
Java keystore.
Truststore is the place where we will hold all informations about service providers we trust. In our case we need to create java’s keystore (.jks file). Please create java kaystore named keystore.jks and import to it mentioned certificate, using your own password ( __JKS_PASSWORD__ ) which, should be different than server’s one.
Stub and working code.
Let’s create stub from WSDL file. Than, we import generated files ( or better, pack them into jar befor – you’ll find it more handy in the future). We must create configuration file ( app-client-config.wsdd ) which we can put in the src/ directory.
Content of app-clinet-config.wsdd would be :
<?xml version="1.0" encoding="UTF-8"?> <deployment xmlns="http://xml.apache.org/axis/wsdd/" xmlns:java="http://xml.apache.org/axis/wsdd/providers/java"> <globalConfiguration> <parameter name="disablePrettyXML" value="true" /> <requestFlow> <handler type="java:org.apache.ws.axis.security.WSDoAllSender"> <parameter name="action" value="Signature" /> <parameter name="user" value="__WS_USERNAME__" /> <parameter name="passwordCallbackClass" value="pl.mgorski.client.PWCallback" /> <parameter name="signaturePropFile" value="crypto.properties" /> <parameter name="signatureKeyIdentifier" value="DirectReference" /> </handler> </requestFlow> <responseFlow> <handler type="java:org.apache.ws.axis.security.WSDoAllReceiver"> <parameter name="action" value="Signature Encrypt" /> <parameter name="encryptionUser" value="__WS_USER__" /> <parameter name="passwordCallbackClass" value="pl.mgorski.client.PWCallback" /> <parameter name="signaturePropFile" value="crypto.properties" /> <parameter name="encryptionPropFile" value="crypto.properties" /> <parameter name="encryptionKeyIdentifier" value="X509KeyIdentifier" /> </handler> </responseFlow> </globalConfiguration> <transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender" /> <transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender" /> <transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender" /> </deployment>
PWCallback
In this file we apply password for out/in-going requests.
package pl.mgorski.client;
import org.apache.ws.security.WSPasswordCallback;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.UnsupportedCallbackException;
import java.io.IOException;
public class PWCallBack implements CallbackHandler {
/**
* Method handle
*
* @param callbacks
* @throws IOException
* @throws UnsupportedCallbackException
*/
public void handle(Callback[] callbacks)
throws IOException, UnsupportedCallbackException {
for (int i = 0; i < callbacks.length; i++) {
if (callbacks[i] instanceof WSPasswordCallback) {
WSPasswordCallback pc = (WSPasswordCallback) callbacks[i];
/*
* here call a function/method to lookup the password for
* the given identifier (e.g. a user name or keystore alias)
* e.g.: pc.setPassword(passStore.getPassword(pc.getIdentfifier))
* for testing we supply a fixed name here.
*/
pc.setPassword( __WS_PASSWORD__);
} else {
throw new UnsupportedCallbackException(callbacks[i],
"Unrecognized Callback");
}
}
}
}
crypto.properties
[sourcecode language='properties']
In this file, let’s configure keystores. It’s important to protect keystore from unwanted access.
org.apache.ws.security.crypto.merlin.file=/home/__PATH_TO_KEYSTORE__/keystore.jks
org.apache.ws.security.crypto.merlin.keystore.password=__JKS_PASSWORD__
org.apache.ws.security.crypto.merlin.keystore.alias=__JKS_ALIAS__
org.apache.ws.security.crypto.merlin.alias.password=__JKS_PASSWORD__
[/sourcecode]
Working stub.
YandexAPIServiceLocator l = new YandexAPIServiceLocator(new FileProvider("app-client-config.wsdd"));
APIPort port = l.getAPIPort();
((GeocodingSoapBindingStub) port)._setProperty(WSHandlerConstants.ACTION, WSHandlerConstants.SIGNATURE);
((GeocodingSoapBindingStub) port)._setProperty(WSHandlerConstants.USER, __WS_USERNAME__);
((GeocodingSoapBindingStub) port)._setProperty(WSHandlerConstants.MUST_UNDERSTAND, "false");
((GeocodingSoapBindingStub) port).setUsername(__WS_USERNAME__);
((GeocodingSoapBindingStub) port).setPassword(__WS_PASSWORD__);
int ping = port.pingAPI();
assertEquals( 1, ping ); // Junit, feel free to use your own check here.
If everything is well configured, this should work. I did it some time ago, so it’s possible that I forgot to past something. If it doesn’t work, let me know!
Enjoy!
Tags: Axis, Bouncy Castle, Certificate, CRT, Fedora, Java, keystore, Merlin, PHP, truststore, Webservice, Yandex
SCJP 6.0 code snippets – Part 1
Posted by ski | Filed under Developement
Since I started to study to SCJP, I’ll put here some notes. I learn reading SCJP Sun Certified Programmer for Java 6, and making some small code snippets, I’ll paste them + notes here, maybe you’ll find it usefull. I think everyone who learns to SCJP should do his/her own, but if you don’t have time, or want to come back to topic, or something else, you can tak a look on those.
Moreover, please note that
- all uncommented code is COMPILABLE
- parts commented usually do not compile, reason is explained in a comment.
- “dupa” means “ass” in polish ( and it’s used a lot like “foo” and “bar” :) )
- Each section is separate java file
- Names are a bit strange, but it’s like this to keep orderd inside package
Ready – set – go
basics, identifiers
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
public class S001Identifiers {
/**
* @param args
*/
public static void main(String[] args) {
int _a;
int $c;
int ______2_w;
int _$;
int €;
int £;
/** NOT LEGAL */
// int :b;
// int -d;
// int e#;
// int .f;
// int 7g
/**
* most weird keywords:
* strictfp assert (1.4) enum (1.5) native goto default
*/
}
class JavaBeanClass {
// public void setMyValue(int v);
// public int getMyValue();
// public boolean isMyStatus();
// public void addMyListener(MyListener m);
// public void removeMyListener(MyListener m);
//
// /** NOT VALID!!!*/
// void setCustomerName(String s) // must be public
// public void modifyMyValue(int v) // can't use 'modify'
// public void addXListener(MyListener m) // listener type mismatch
}
//
//
// ,
}
package must be over import
import between package and class
default class access == “package” access
class access
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
public class S002ClassAccess {
}
// default access
class Ass {
}
class A {
};
final class B {
}
// private class C {} // wrong ( outside of the public class)
// protected class D {} // wrogn!!
strictfp final class E {
}; // IEEE 754 rules of floating point
// abstract final class E {}; // wrong!
class NotAbstract {
// abstract method dupa(); // wrong!
}
abstract class CarAbstract {
final void eatThis() {
};
private final void eatThis4() {
}; // only warning!
public final void eatThis2() {
};
}
bounce
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
import java.io.Serializable;
public interface S003Bounceable {
public static int MAX = 100;
// public static volatile int MAX2 = 100; // wrong! wrong!
public static final int MAX3 = 100;
void bounce();
// private void bouncePrivate(); // wrong
// protected void bouncePrivateProt(); // wrong
public void bouncePrivatePub();
abstract void dupa();
// static void eatCock(); // wrong and bad name
}
interface Two extends S003Bounceable, Serializable {
}
class Dupa implements S003Bounceable {
@Override
public void bounce() {
// MAX3 = 3; // WRONG
// MAX = 100;
}
@Override
public void bouncePrivatePub() {
// TODO Auto-generated method stub
}
@Override
public void dupa() {
// TODO Auto-generated method stub
}
}
member modifiers
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
public class S004MemberModifiers {
private int a = 0;
public int b = 1;
protected void dupa() {
System.out.println("DUPA = " + a + "," + b);
a++;
}
public static void main(String[] args) {
Ext e = new Ext();
e.doSth();
}
}
class Ext extends S004MemberModifiers {
public void doSth() {
dupa();
}
}
default member access
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
public class S005DefaultMemberAccess {
public void testPublic() {
};
protected void testProtect() {
};
private void testPriv() {
};
void testDefault() {
};
}
class Extension extends S005DefaultMemberAccess {
@Override
void testDefault() {
// TODO Auto-generated method stub
super.testDefault();
}
@Override
protected void testProtect() {
// TODO Auto-generated method stub
super.testProtect();
}
protected int testPriv() {
return 0;
} // OK!
}
# def member access – same pkg
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
public class S005DefaultMemberAccessSamePkg {
public static void main(String[] args) {
S005DefaultMemberAccess dm = new S005DefaultMemberAccess();
dm.testDefault();
dm.testProtect();
dm.testPublic();
System.out.println("ALL ok");
}
}
other modifiers
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
public strictfp class S006OOtherModifiers {
native void methodInC(); // like abstract
// synchronized abstract void syncMe(); // not allowed with abstract!
synchronized void syncMe(){ } ;;;; // mark no implementation
strictfp long method(){ return 1L;};
public void dupa( int dupa, String...strings ){
}
}
local variable init
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
public class S007LocalVariables {
int a;
// final int af; // do not allow default value for final
final int af2 = 0;
public void doMe() {
int b; // not initialized (only warning) !!!!
// af2 = 3; // cannot reassign WRONG!!
System.out.println("read a = " + a);
// System.out.println( "read a = " + b); // wrong !
}
public static void main(String[] args) {
S007LocalVariables s = new S007LocalVariables();
s.doMe();
}
}
enum with a variable assigned
/**
* mgorski.pl, This code is published under Creative Commons licence.
* @author Marcin Górski , 2009.
**/
package scjp;
public enum S009Enum {
BIG(10), SMALL(5) {
@Override
public String getCode() { // this overrides code for SMALL
return "B";
}
};
S009Enum(int size) {
this.size = size;
}
private int size;
public int getSize() {
return size;
}
public String getCode() {
return "A";
}
}
Tags: 6, code snippets, Java5, Java6, mock exam, SCJP, study notes
GWT1.7-PHP5.2-JSON
Posted by ski | Filed under Developement, English
Here I’ll present a “quickstart” application of the GWT + PHP. There are a lot of different approaches to do GWT-PHP communication, I’ll use JSON. In my approach, I’ll use two bean-like (Java) classes PHPRequest and PHPResponse, which encapsulate sending and receiving data. Of course, in so simple example it’s piece of additional job, but while application is growing, this small job effects in clarity and easy maintainance of the code. This application has been build as re-make of “JSON” application from samples of GWT 1.7.
For impatients – live demo and source code.
Here you can see live demo, and here you can download sources.
Requirements.
- GWT 1.7 ( here ) ( I use 1.7 which is currently the newest one, but it should work on the 1.6 also. Older versions have incompatible compiler, so you’ll need do some tweaks)
- PHP 5.2 ( since this version json_decode and json_encode methods are build-in, in older you’ll need to use JSON libraries ). On Windows, I use EasyPHP.
- Java 1.5 or higher, Ant, some IDE ( I use Eclipse Galileo PDT ).
Idea.
I’ll create application based on two projects – app-php and app-gwt. First one will contain files we want to put on the PHP server – after build this folder can be copied to the public server. Basically, there is JSON.html file ( which we open in order to see application ) and all goodies compiled from GWT ( json folder ). In the server dir, we have json-dispatcher.php which is target of JSON call. The second project, is the GWT source and the ant buildfile.
6-steps flow.
- View part contains TextBox where you can put your name (or any swearword you want).
- When you click “Search” button, data are being encapsulated inside of the PHPRequest class.
- PHPRequest object is being pushed using JSON to the server’s json-dispatcher.php.
- Server parse request, and create response of the type PHPResponse (php) and send back to GWT.
- GWT receives response as the callback, and transforms it into PHPResponse (java) object.
- PHPResponse object is being send to the method, which displays its content inside the labels.
How to run it – configuration.
- Download and extract sources. Put app-gwt to your workspace, and app-php inside www of you PHP server. You can use import->project in Eclipse.
- Open build.xml file from app-gwt . And take a look on:
<property name=”gwt.sdk” location=”D:/dev/gwt-1.7.0/” />
<property name=”php.app.dir” location=”c:/EasyPHP-3.0/www/app-php/” />
gwt.sdk is obviously directory of your GWT
php.app.dir is directory, where compiled GWT files are being copied. - If your server is running, you should be able to see application under http://localhost/app-php/JSON.html
- Look through the projects, do changes, play.
ant gwtc – will compile the project
ant php - will compile AND copy the result inside of the preconfigured directory ( point 2 )
ant hosted - will not work ( we don’t use Tomcat ) - Mark that on the server side ( app-php/server/json-dispatcher.php ) code responsible for creating response is put between “** logic**” comments. If you create more request, you will need to add condition, which response is valid for which request.
Hope this was helpful as good quickstar point !
Tags: Eclipse, GWT 1.7, Java, JSON, live demo, PHP5, Quickstart, source code
Parco Nazionale Dolomiti Bellunesi – Monte Pavione 2335
Posted by ski | Filed under English, Expeditions, Italy
I’d like to describe one of the excursions, which took place in the western part of Parco Nazionale Dolomiti Bellunesi on 04/07/2009.
Arrival.
We came with the car to Passo Croce d’Aune, here you can leave your car [here]. Passo Croce d’Aune (1,011 m) is a mountain pass in the Dolomites in the province of Belluno, easy to reach from Feltre or Belluno.
From there, path goes through the forest along the trail #802. In the begining there is nothing special, but after 30 minutes of march panorama becomes wider. After passing the forest level, around 1400 m way becomes to eb very tortuous, but most of the bents can be short cut with small passes.
At height of 1993 we approach Rifugio (shelter) dal Piaz. From this place we can see most of the trail we have made, and also some of the upcoming one.
We decided to go to Monte Pavione, so further way goes along trail #817. It still around 400 meters up to climb, but since you come to the level of the shelter, way is very easy and breathtaking. Most part of the trail goes with the ridge, so all the road you can watch the landscapes in every direction.
Monte Pavione, is the highest peak in the Vette Feltrine, the southernmost group of the Dolomite. On the top of this hill there is border between Trentino and Veneto. M Pavione has a striking pyramid shape.
Way back goes with old southern hillside trail (I marked it on the map with the blue curve, but there is no trail there now, only a path). Path is all covered with the small rocks, pieces of the eroding mountains. It looks very steep, but going down with it is very easy, you can even run without hesitation (yes, we tried:)).
After joining #810 path goes slowly down, to the shelter, and than with the same way to Croce d’Aune.
FYI, we started to climb around 9 in the morning, and reached the peak around 3 PM. The hardest part is in the begging, but it’s just sheer, not dangerous at all unless you won’t touch the electric cow herder.
Here are some photos of the route, more you can see in my picassa gallery ( link is on the right toolbar )
Thanks for reading, and cu on the trail!
Tags: Alpi, Alps, excursion, expedition, Monte Pavione, Parco Nazionale Dolomiti Bellunesi, wycieczka, wyprawa








