Dienstag, 26. Oktober 2010

TakeOwnership Explorer menu entry for german Windows 7

Create a file like: TakeOwnershipGer.reg.
Fill it with this:

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\shell\runas]
@="Take Ownership"
"NoWorkingDirectory"=""

[HKEY_CLASSES_ROOT\Directory\shell\runas\command]
@="cmd.exe /c takeown /f \"%1\" /r /d j && icacls \"%1\" /grant administratoren:F /t"
"IsolatedCommand"="cmd.exe /c takeown /f \"%1\" /r /d j && icacls \"%1\" /grant administratoren:F /t"


---

Found this for english windows here:
http://www.blogsdna.com/2173/add-take-ownership-option-in-right-click-context-menu-of-windows-7.htm

Also this is untested but seems to support more options:
http://beatmasters-winlite-blog.de/?p=1609

Freitag, 18. Juni 2010

JBoss Tools and JBoss AS 5

Well, for some reason the JBoss Tools Team refuses to add easy Seam support for JBoss 5.

If you create a new Seam war project with JBoss 5, you get many weird errors.

Some suggest to add all entities to persistence.xml....

http://seamframework.org/Documentation/RunningSeamExamplesWithJBossApplicationServer5
and
https://jira.jboss.org/browse/JBSEAM-3821

But the real soultion is this:

add the following line to persistence.xml:
<property name="jboss.entity.manager.factory.jndi.name" value="java:/myEntityManagerFactory">

remove the following lines in components.xml:

<persistence:entity-manager-factory name="entityManagerFactory"
persistence-unit-name="MYPU"/>

<persistence:managed-persistence-context name="entityManager" auto-create="true"
entity-manager-factory="#{entityManagerFactory}"/>

add the following line:

<persistence:managed-persistence-context name="entityManager" auto-create="true"
entity-manager-factory="#{entityManagerFactory}"
persistence-unit-jndi-name="java:/myEntityManagerFactory"/>

Also hot depoly doesn't work anymore with JBoss 5 AS if you start it normally.
Try to start JBoss AS 5 in debug mode, then hot deploy should work again.
Don't know why though...

Happy Coding all !
Ray.

Freitag, 28. Mai 2010

OpenVPN client error: Sorry, 'Auth' password cannot be read from a file.

If you don't like to be patronized by OpenVPN client here is a version
with the compile flag ENABLE_PASSWORD_SAVE set:

http://rapidshare.com/files/388904833/openvpn-2.1.1-passwordsave-install.exe

Found in:

forum.perfect-privacy.com

Confirmed to work.
Great job who ever compiled it, thanks !

Samstag, 9. Januar 2010

Add custom entries to NetBeans palette including events

Inspired by:
http://www.ryerson.ca/~dgrimsha/courses/cps841/JB_events.html

I could finally make my dream EventPanel.
Extending JPanel it allows Listeners to register for the paint event.

So you don't need to subclass JPanel anymore.
Just add EventPanel to NetBeans and add an event handler
for the now selectable paint event.

The Graphics2D object is placed into the the event Source object.

Get the source here:
http://kenai.com/projects/rayssharedcode/sources

Freitag, 27. November 2009

Turn JBoss AS into a HSQLDB server

Developing with Seam its nice to have easy access to a test DB.
Hypersonic SQL fits the need nicely.
Best of all - its distributed with JBoss AS already.

Before now, I used the supplied hsqldb-ds.xml and modified it to my needs,
inlcuding enabling the hsqldb over tcp mbean.

But it was painful to create a new dummy Seam project with the JBoss Tools
just to switch the datasource file later.

Then it occured to me:

Why not just copy the mbean part into a new service.xml file ?

Then I can use a persisting hsqldb server in tcp mode and create new
Seam projects with the real datasource from the start.

So without further ado here is the contents of my new hsqldb-service.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.jdbc.HypersonicDatabase" name="jboss:service=HypersonicDB">
<attribute name="Port">9001</attribute>
<attribute name="BindAddress">${jboss.bind.address} </attribute>
<attribute name="Silent">true</attribute>
<attribute name="Database">default</attribute>
<attribute name="Trace">false</attribute>
<attribute name="No_system_exit">true</attribute>
</mbean>
</server>



Update:
Use 127.0.0.1 instead of ${jboss.bind.address}.
Makes it easier to create ds.xml files for and makes it more secure.


<?xml version="1.0" encoding="UTF-8"?>
<server>
<mbean code="org.jboss.jdbc.HypersonicDatabase" name="jboss:service=HypersonicDB">
<attribute name="Port">9001</attribute>
<attribute name="BindAddress">127.0.0.1</attribute>
<attribute name="Silent">true</attribute>
<attribute name="Database">default</attribute>
<attribute name="Trace">false</attribute>
<attribute name="No_system_exit">true</attribute>
</mbean>
</server>

Donnerstag, 19. November 2009

Good source code is the best documentation

There, I said it... but before you hunt me out of the village, let me elaborate.

The way picture editing software sharpens images, is by generating a blurred
or smoothed version of the picture and then calculating all the differences
to the original picture pixels. It then multiplies the differences by a constant
factor based on your settings. The product is then added to the blurred picture
pixels, resulting in a sharper image than the original.

Now, if you take a normal piece of source code and run it through an obfuscator
you kinda get a blurred version of the source code.

My thesis is, that if you look at the differences of the original and the obfuscated code
and enhance the differences, you get self explanatory code.

What does an obfuscator do with f.book(p) ?
=> a.b(c)

So the sharper version of the code would be:
flight.book(passenger);

My rules of thumb are:

1. Make short functions ( one task per function )
2. give function and parameter names explanatory names
3. don't be afraid to refactor if you find a limitation in your code
4. Read Java Concurrency in Practice

Sonntag, 8. November 2009

Hack Java 6 to let SOAP headers for web services be set

Java 6 (and NetBeans) make it extremely hard to let people set SOAP headers.

( UPDATE AT END )

How to normally do it is outlined in the metro guide:
https://metro.dev.java.net/guide/SOAP_headers.html

and looks like this:
WSBindingProvider bp = (WSBindingProvider)port;
bp.setOutboundHeader( Headers.create(new QName("simpleHeader"),"stringValue") );

( Hm, in Java 6 there is only bp.setOutboundHeaders with an "s" at the end... )
Problem is the WSBindingProvider is in an internal package in Java 6.
So javac or NetBeans won't let you compile the code.
( Eclipse lets you btw. if you allow internal class usage in the preferences. )

So what can we do ?

1. Maybe this: http://devplace.wordpress.com/2007/09/24/adding-soap-header-in-java/
in combination with:

BindingProvider bp = (BindingProvider) port;
bp.getBinding():
...

2. Fight the authority and use reflection once again:

public static void setHeader(MyPortType port, String session) throws Exception {
Method[] methods = port.getClass().getMethods();
for (Method method : methods) {
if (method.getName().equals("setOutboundHeaders")) {
Class<?>[] parameterTypes = method.getParameterTypes();
for (Class<?> class1 : parameterTypes) {
if (class1.getName().endsWith(".List")) {
Object h = getHeader(session);
List l = new ArrayList();
l.add(h);
method.invoke(port, l);
return;
}
}
}
}
}


public static Object getHeader(String session) throws Exception {
Class<?> header = Class.forName("com.sun.xml.internal.ws.api.message.Headers");
Method[] methods = header.getDeclaredMethods();
for (Method method : methods) {
Class<?>[] parameterTypes = method.getParameterTypes();
if (parameterTypes.length == 2 && parameterTypes[0].getName().endsWith("QName")) {
return method.invoke(null, new QName("http://schemas.domain.com/2005/01/Product/types", "session"),
session);
}
}
return null;
}
The method getHeader acquires an instance of forbidden Headers class and invokes
the static method "create" to return a new Header object.
(In my code it is only called from the other method "setHeader".)

The method setHeader searches for a method called "setOutboundHeaders"
in the port object which accepts a List object as its parameter.
Then it acquires a new Header object, stuffes it in an ArrayList
and invokes the setOutboundHeaders method.
Voilà.

( Yeah I know I could make better use of the parameter method search, but hey... )

UPDATE:
Here are the refined, clean, loopless methods:


public static Object getHeader(String session) throws Exception {
Class header = Class.forName("com.sun.xml.internal.ws.api.message.Headers");
Method method = header.getDeclaredMethod( "create", QName.class, String.class);
return method.invoke(null, new QName("http://schemas.domain.com/2005/01/product/types", "session"), session);
}

public static void setHeader(MyPortType port, String session) throws Exception {
port.getClass().getMethod("setOutboundHeaders", List.class).invoke(port, Arrays.asList(getHeader(session)));
}


public static void setURL(MyPortType port, String url) {
BindingProvider bp = (BindingProvider) port;
Map rc = bp.getRequestContext();
rc.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, url);
}