Websphere errors regarding Oracle transaction recovery

No Comments »

When restarting Websphere there are occasions when you get errors related to Oracle transaction recovery.

This happens because Websphere is set to recover the transactions that were not handled when the server went down and it cannot do so because Oracle requires special permissions to attempt to perform the recovery.

This problem can occur with all versions of Oracle: 8i, 9i, 10g, 11g.

To resolve the problem, the following commands are needed to be executed as SYS:
grant select on pending_trans$ to <<user>>;
grant select on dba_2pc_pending to <<user>>;
grant select on dba_pending_transactions to <<user>>;
grant execute on dbms_system to <<user>>;
where <<user>> is the username configured in the Websphere datasource, for that specific database.

If you don’t care to recover those transactions and you just hate seeing that exception in the logs over and over again (it does not go away if you attempt yet another restart), you can go ahead and delete the transactions manually.

The transaction logs are stored in the following folder:
<WebSphere Application Server_install_root>\profiles\<PROFILE_NAME>\tranlog\<CELL_NAME>\<NODE_NAME>\<SERVER_NAME>\transaction
You’d have to stop the Websphere server, delete the content of  ‘\transaction’ folder and all subdirectories and restart the Websphere server.

Structuring your code with JQuery

No Comments »

Once you get passed your need to just link certain DOM elements to some hefty Javascript, which as far as I’m concerned JQuery does best, you ultimately get to a point where you have scripts that are just too big to easily maintain. What then? There’s not really that much written on this subject. No where near the best practices that you find on other languages.

The quickest and no bull presentation I could find out is embedded below. It’s not new, but it’s a very useful one on how to structure your code with JQuery.

I chose to disregard the “common belief” that JQuery is not suppose to be used to write large Javascript apps. One should be using Dojo or YUI for that. Agai, I think there’s nothing better than JQuery at the moment. That’s the library that made me [finally] accept that the best way to build web apps is to have [any] Javascript framework at the core and use the server side only to … serve your scripts (and that after coding in Java for more than 10 years and most of those for the web, in one form or another).

How To Manage Large jQuery Apps
View more presentations from Alex Sexton.

And then I found another one…

Meebo, historically

No Comments »

Reading this news here – Meebo started back in 2005, probably even earlier. Still, gotta wonder, 6 years and 25 60 venture capital millions (or better yet, two of the best VC companies behind you)… it took them quite a while for a chat app, didn’t it?

It’s even funnier how “back then” 2005 seems :)

Wicket Component – Simple Breadcrumbs

1 Comment »

A very simple simple wicket component to display links in an hierarchical order. You can see it live here

Full sources are available here.

This is how you add it to the page:

Java

		add(new Breadcrumbs("breadcrumbs",
			Arrays.asList(new WCLink[]{
					new WCLink("Web application section 1", "http://www.1.com"),
					new WCLink("Web application section 11" , "http://www.11.com"),
					new WCLink("Web application section 111", "http://www.111.com")
			}),this));

HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns:wicket>
<body>
    <div wicket:id="breadcrumbs"/>
</body>
</html>

Wicket component code:
Breadcrumbs.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns:wicket>
<head>
</head>
<body>
<wicket:panel>
    <!--
    Wicket component:   JQuery Accordion Menu
    Author:             Nova Creator Software
    Website:            www.novacreator.com
    Software provided as is, without any guarantees.
    Free for any type of usage. We just kindly ask to keep this message.
    -->
    <ul id="breadcrumbs">
        <li wicket:id="repeater"><a wicket:id="link"><span wicket:id="linkName"></span></a></li>
    </ul>
</wicket:panel>
</body>
</html>

Breadcrumbs.java

package com.novacreator.wicketcomponents.breadcrumbs;

import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.html.resources.CompressedResourceReference;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.Model;

import com.novacreator.wicketcomponents.common.WCLink;

/*
Wicket component:   Breadcrumbs
Author:             Nova Creator Software
Website:            www.novacreator.com
Software provided as is, without any guarantees.
Free for any type of usage. We just kindly ask to keep this message.
*/
@SuppressWarnings("serial")
public class Breadcrumbs extends Panel {
	private static final ResourceReference CSS =
		new CompressedResourceReference(Breadcrumbs.class, "res/breadcrumbs.css");

	public Breadcrumbs(String id, List<WCLink> links, final BreadcrumbsListener listener) {
		super(id);

		add(HeaderContributor.forCss(CSS));

		RepeatingView rv = new RepeatingView("repeater");
		add(rv);
		AjaxFallbackLink afl = null;
		for(final WCLink link : links) {
			WebMarkupContainer wmc = new WebMarkupContainer(rv.newChildId());
			rv.add(wmc);
			afl = new AjaxFallbackLink("link"){
				@Override
				public void onClick(AjaxRequestTarget target) {
					if(link.getLink() != null &amp;&amp; !link.getLink().isEmpty()) {
						listener.onBreadcrumbsClick(link.getLink(), target);
					}
				}
			};
			wmc.add(afl);
			afl.add(new Label("linkName", link.getDisplayName()));
		}
		afl.add(new AttributeModifier("style", true, new Model("background:none;")));
	}
}

BreadcrumbsListener.java

package com.novacreator.wicketcomponents.breadcrumbs;

import org.apache.wicket.ajax.AjaxRequestTarget;

/*
Wicket component:   Breadcrumbs
Author:             Nova Creator Software
Website:            www.novacreator.com
Software provided as is, without any guarantees.
Free for any type of usage. We just kindly ask to keep this message.
*/
public interface BreadcrumbsListener {
	public void onBreadcrumbsClick(String link, AjaxRequestTarget target);
}

Wicket Component – JQuery Accordion Menu

No Comments »

Presenting a very simple wicket component for everybody to use – a JQuery accordion menu.

You can see it live here

Full sources are available here

This is how you add it to the page:

Java

		Map<AccordionLink, List<AccordionLink>> menus = new LinkedHashMap<AccordionLink, List<AccordionLink>>();
		menus.put(new AccordionLink("Menu1", "http://www.menu1.com"),
				Arrays.asList(
						new AccordionLink("11", "http://www.menu11.com"),
						new AccordionLink("12", "http://www.menu12.com"),
						new AccordionLink("13", "http://www.menu13.com")));
		menus.put(new AccordionLink("Menu2", "http://www.menu2.com"),
				Arrays.asList(
						new AccordionLink("21", "http://www.menu21.com"),
						new AccordionLink("22", "http://www.menu22.com"),
						new AccordionLink("23", "http://www.menu23.com")));
		menus.put(new AccordionLink("Menu3", "http://www.menu3.com"),
				Arrays.asList(
						new AccordionLink("31", "http://www.menu31.com"),
						new AccordionLink("32", "http://www.menu32.com"),
						new AccordionLink("33", "http://www.menu33.com")));
		menus.put(new AccordionLink("Menu4", "http://www.menu2.com"),
				Arrays.asList(
						new AccordionLink("41", "http://www.menu41.com"),
						new AccordionLink("42", "http://www.menu42.com"),
						new AccordionLink("43", "http://www.menu43.com")));
		menus.put(new AccordionLink("Menu5", "http://www.menu2.com"),
				Arrays.asList(
						new AccordionLink("51", "http://www.menu51.com"),
						new AccordionLink("52", "http://www.menu52.com"),
						new AccordionLink("53", "http://www.menu53.com")));
		add(new AccordionMenu("menu", menus, true, this));

The important line is add(new AccordionMenu(“menu”, menus, true, this));

HTML

<html xmlns:wicket>
<body>
    <div wicket:id="menu"/>
</body>
</html>

Wicket component code:
AccordionMenu.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns:wicket>
<head>
</head>
<body>
<wicket:panel>
    <!--
    Wicket component:   JQuery Accordion Menu
    Author:             Nova Creator Software
    Website:            www.novacreator.com
    Software provided as is, without any guarantees.
    Free for any type of usage. We just kindly ask to keep this message.
     -->
    <div wicket:id="topdiv" class="menu_list">
        <p wicket:id="repeatItems" class="menu_head">
            <span wicket:id="menuItem"></span>
	        <div class="menu_body">
	             <a wicket:id="menuSubItem">
	                <span wicket:id="menuSubItemName"/>
	             </a>
	        </div>
        </p>
    </div>
</wicket:panel>
</body>
</html>

AccordionMenu.java

package com.novacreator.wicketcomponents.jquery.accordionmenu;

import java.util.List;
import java.util.Map;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.ResourceReference;
import org.apache.wicket.ajax.AjaxEventBehavior;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.markup.html.AjaxFallbackLink;
import org.apache.wicket.behavior.HeaderContributor;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.markup.html.resources.CompressedResourceReference;
import org.apache.wicket.markup.html.resources.JavascriptResourceReference;
import org.apache.wicket.markup.repeater.RepeatingView;
import org.apache.wicket.model.Model;

/*
    Wicket component:   JQuery Accordion Menu
    Author:             Nova Creator Software
    Website:            www.novacreator.com
    Software provided as is, without any guarantees.
    Free for any type of usage. We just kindly ask to keep this message.
 */
@SuppressWarnings("serial")
public class AccordionMenu extends Panel {
	private static final ResourceReference JQUERYJS =
		new JavascriptResourceReference(AccordionMenu.class, "../res/jquery.js");
	private static final ResourceReference ACCORDIONJS =
		new JavascriptResourceReference(AccordionMenu.class, "../res/accordionmenu.js");
	private static final ResourceReference CSS =
		new CompressedResourceReference(AccordionMenu.class, "../res/accordionmenu.css");

	public AccordionMenu(String id, final Map<AccordionLink, List<AccordionLink>> menus, boolean autoExpand, final AccordionMenuListener listener) {
		super(id);

		add(HeaderContributor.forJavaScript(JQUERYJS));
		add(HeaderContributor.forJavaScript(ACCORDIONJS));
		add(HeaderContributor.forCss(CSS));

		WebMarkupContainer topDiv = new WebMarkupContainer("topdiv");
		add(topDiv);
		if(autoExpand) {
			topDiv.add(new AttributeModifier("id", true, new Model("autoexpand")));
		} else {
			topDiv.add(new AttributeModifier("id", true, new Model("noautoexpand")));
		}
		RepeatingView menuItems = new RepeatingView("repeatItems");
		topDiv.add(menuItems);

		for(final AccordionLink menu : menus.keySet()) {
			WebMarkupContainer wmc = new WebMarkupContainer(menuItems.newChildId());
			menuItems.add(wmc);
			wmc.add(new AjaxEventBehavior("onclick"){
				@Override
				protected void onEvent(AjaxRequestTarget target) {
					if(menu.getLink() != null &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; !menu.getLink().isEmpty()) {
						listener.onAccordionMenuClick(menu.getLink(), target);
					}
				}
			});
			wmc.add(new Label("menuItem", menu.getDisplayName()));
			RepeatingView menuSubItems = new RepeatingView("menuSubItem");
			wmc.add(menuSubItems);
			for(final AccordionLink item : menus.get(menu)) {
				AjaxFallbackLink iaf = new AjaxFallbackLink(menuSubItems.newChildId()) {
					@Override
					public void onClick(AjaxRequestTarget target) {
						if(item.getLink() != null &amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp; !item.getLink().isEmpty()) {
							listener.onAccordionMenuClick(item.getLink(), target);
						}
					}
				};
				iaf.add(new Label("menuSubItemName", item.getDisplayName()));
				menuSubItems.add(iaf);
			}
		}
	}
}

AccordionMenuListener.java

package com.novacreator.wicketcomponents.jquery.accordionmenu;

import org.apache.wicket.ajax.AjaxRequestTarget;

/*
Wicket component:   JQuery Accordion Menu
Author:             Nova Creator Software
Website:            www.novacreator.com
Software provided as is, without any guarantees.
Free for any type of usage. We just kindly ask to keep this message.
*/
public interface AccordionMenuListener {
	public void onAccordionMenuClick(String link, AjaxRequestTarget target);
}

AccordionLink.java

package com.novacreator.wicketcomponents.jquery.accordionmenu;

import java.io.Serializable;

/*
Wicket component:   JQuery Accordion Menu
Author:             Nova Creator Software
Website:            www.novacreator.com
Software provided as is, without any guarantees.
Free for any type of usage. We just kindly ask to keep this message.
*/
@SuppressWarnings("serial")
public class AccordionLink implements Serializable {
	private String displayName;
	private String link;

	public AccordionLink(String displayName, String link) {
		this.displayName = displayName;
		this.link = link;
	}

	public String getDisplayName() {
		return displayName;
	}
	public void setDisplayName(String displayName) {
		this.displayName = displayName;
	}
	public String getLink() {
		return link;
	}
	public void setLink(String link) {
		this.link = link;
	}
}

How to prevent IFrame to display your website

No Comments »

If you don’t want your webpage to be displayed inside another website, in an IFrame, use this:

<script type="text/javascript">
<!--
if (top.location.href != self.location.href)
  top.location.href = self.location.href;
//-->
</script>

Java interface contract

No Comments »

Suppose you have an interface defined like this:

interface someInterface {

Object someMethod(Object someObject);

}

First thing you have to know is that interfaces are only public if you define them as such. If you don’t they can only be implemented by classes in that package.

Just like the interfaces themselves, the methods defined in an interface are public no matter if you define them as so. Please also note that you cannot define interface members (methods or variables) as private. All you can do is have them public and/or abstract. Just as a quick reminder, a constant in Java is defined as public static abstract.

By looking at the signature of the method someMethod, it is clear that it requires an Object (someObject) and that it returns a result – an object. This is the contract defined by the interface.

Java is a complex language – defining the method as returning an object allows you to return whatever type of an object you want. You can return a String, a Collection (for instance a List) and, starting from Java 5, even a primitive like int because out of the box that primitive will be wrapped inside an Integer object and unwrapped after the call.

One thing you have to be careful when defining a class that implements this method is that you might be tempted to define it like this:

String someMethod(Integer someInteger).

After all someMethod expects an Object and Integer is an Object, right? Well, in Java all classes extend the Object class, so that should make sense. BUT that would brake the contract. The programmer looking at the interface contract would expect to be able to call someMethod with any object. If you were able to define someMethod expecting an Integer, that method could not possibly accept an Object because Object is not necessarely an Integer! So the answer is NO – when you implement someMethod, you have to follow the signature from the interface, as far as the arguments go. Although YOU CAN call the method with any kind of objects you want, since it just expects an object.

Remember, you can implement the interface by making it return the type of object specified in the signature or objects that extend it, but you have to keep the same objects in the arguments.

How to get IP address in PHP

1 Comment »

Using getenv:

<?php
// Example use of getenv()
$ip = getenv('REMOTE_ADDR');

// Or simply use a Superglobal ($_SERVER or $_ENV)
$ip = $_SERVER['REMOTE_ADDR'];
?>

Please note that the function ‘getenv’ does not work if your Server API is ASAPI (IIS). In this case use $_SERVER["REMOTE_ADDR"].

Here is an interesting function to get the real IP address:

function getRealIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
{
$ip=$_SERVER['HTTP_CLIENT_IP'];
}
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
{
$ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
$ip=$_SERVER['REMOTE_ADDR'];
}
return $ip;
}

or even better

function getIpAddress() {
return (empty($_SERVER['HTTP_CLIENT_IP'])?(empty($_SERVER['HTTP_X_FORWARDED_FOR'])?
$_SERVER['REMOTE_ADDR']:$_SERVER['HTTP_X_FORWARDED_FOR']):$_SERVER['HTTP_CLIENT_IP']);
}

One very important thing is that there is no way to find the IP address of a computer that’s behind the anonymous proxy.

The Simpsons + Apple = Mapple

No Comments »

IBM and Southpark

No Comments »

These days there is the Smart SOA Conference in Las Vegas. Look how the commercial for that looked like: