Tuesday, November 2, 2010

Outlook 2007 and rss feed

Opening rss feed in Outlook from Firefox makes Outlook 2007 convert the url into lowercase, so if you have a camelCase http param, then it wouldn't work.

Solution is to have all lowercase http get param as your feed url.

Monday, October 25, 2010

Using Image as a submit button



name="downloadFormPOST"
method="post"
action="http://theurl"
>




function openElt() {

var jsonRequest =
{
"template": {
"id": [currentQueryParams.identifier],
"class": "com.erdas.rsp.babel.model.CatalogItem"
},
"maxresults": -1,
"profile": "eac-brief"
};

var AjaxObject = {

handleSuccess:function(o) {
var xmlToDownload = o.responseText;
var downloadForm = window.document.forms['downloadFormPOST'];

var xmlInput = document.getElementById("xmlToDownload");
xmlInput.value = xmlToDownload;
downloadForm.submit();

},


handleFailure:function(o) {
},


startRequest:function() {

var jsonString = YAHOO.lang.JSON.stringify(jsonRequest);
YAHOO.util.Connect.initHeader('Accept', 'application/x-vnd.elt+xml; charset=utf-8', true);
YAHOO.util.Connect.asyncRequest('POST',
'http://<%=request.getServerName()%>:<%=request.getServerPort()%>/erdas-apollo/catalog/content/search',
callback,
jsonString
);
}

};


var callback = {
success:AjaxObject.handleSuccess,
failure:AjaxObject.handleFailure,
scope: AjaxObject
};


AjaxObject.startRequest();
}


<%
String xmlToDownload = request.getParameter("xmlToDownload");
if( xmlToDownload != null && !"".equals(xmlToDownload) ) {

response.setContentType("application/x-vnd.elt+xml; charset=utf-8");
String outputExtension = "elt";
String nowStr = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss").format(new Date());
response.setHeader("Content-Disposition", "attachment; filename=results-" + nowStr + "." + outputExtension);
PrintWriter writer = response.getWriter();
writer.println(xmlToDownload);
}
%>

Thursday, October 14, 2010

JBoss NTLM Auth + (Maybe Drupal NTLM Auth)

http://www.ioplex.com/jespa.html for NTLMv2 (http://jcifs.samba.org/ only support NTLMv1)

http://code.google.com/p/jespa-spring/ (for Spring-Framework NTLM), this is for spring-security-3.x

I modified jespa-spring for spring-security-2.x in http://github.com/lydonchandra/jespa-spring2 (just remember to create src/main/java directory and put the source files into it if I haven't done it)


To find domain controller:
echo %LOGONSERVER%

Drupal NTLM auth (this might be NTLMv1)


Tuesday, October 12, 2010

Drupal + OpenLayer + Apollo


1. At Administer > Site building > Modules, enable the PHP filter module.

2. <script src="http://localhost:8080/apollo-client/OpenLayers.js"></script>

<?php
drupal_add_js(
'$(document).ready(function(){

var map = new OpenLayers.Map("myWorldMap");

var wms = new OpenLayers.Layer.WMS(
"OpenLayers WMS",
"http://don_laptop:8080/erdas-apollo/vector/WORLDWIDE",
{layers: "cntry98gen02"}
);

map.addLayers([wms]);
map.zoomToMaxExtent();
});',
'inline'
);
?>

<div id="myWorldMap" style="width: 600px; height: 300px">
</div>


3. Also I needed to avoid cross-domain error because I have AJAX request going from localhost:8082 (drupal) to localhost:8080 (erdas-apollo)

ProxyRequests Off
ProxyPass /apollo-json http://don_laptop:8080/erdas-apollo/catalog/content/search.json
ProxyPassReverse /apollo-json http://don_laptop:8080/erdas-apollo/catalog/content/search.json

Sunday, October 10, 2010

Flushing JAAS aut cache

To disable caching you need to set the DefaultCacheTimeout to 0:
in jboss-service.xml,
<attribute name="DefaultCacheTimeout">0</attribute>

Saturday, October 9, 2010

LDAP JBoss authentication and authorization

<policy>

<application-policy name="apollo">
<authentication>
<login-module code="org.jboss.security.auth.spi.LdapExtLoginModule"
flag="required">
<module-option name="debug">true</module-option>
<module-option name="java.naming.provider.url">ldap://localhost:389/</module-option>
<module-option name="java.naming.security.authentication">simple</module-option>
<module-option name="bindDN">CN=admin,CN=Users,CN=donLaptop,DC=don,DC=com</module-option>
<module-option name="bindCredential">secretpassword</module-option>
<module-option name="baseCtxDN">CN=Users,CN=donLaptop,DC=don,DC=com</module-option>
<!-- <module-option name="baseFilter">(sAMAccountName={0})</module-option> -->
<module-option name="baseFilter">(CN={0})</module-option>
<module-option name="rolesCtxDN">CN=Users,CN=donLaptop,DC=don,DC=com</module-option>
<module-option name="roleFilter">(member={1})</module-option>
<!-- module-option name="roleFilter">(sAMAccountName={0})</module-option -->
<module-option name="roleAttributeID">memberOf</module-option>
<module-option name="roleAttributeIsDN">true</module-option>
<module-option name="roleNameAttributeID">CN</module-option>
<!-- if a default role is needed to be applied to all accounts, it can be achieved by uncommenting the below -->
<!-- module-option name="defaultRole">esp_consumer</module-option -->
<module-option name="roleRecursion">2</module-option>
<module-option name="searchScope">SUBTREE_SCOPE</module-option>
<!-- An empty password is treated as an anonymous login by some ldap servers and this may not be a desirable feature.
Set this to false to reject empty passwords, true to have the ldap server validate the empty password. The default is true. -->
<module-option name="allowEmptyPasswords">false</module-option>
</login-module>
<!--
<login-module code="org.jboss.security.auth.spi.UsersRolesLoginModule"
flag = "required">
<module-option name="usersProperties">props/apollo-users.properties</module-option>
<module-option name="rolesProperties">props/apollo-roles.properties</module-option>
</login-module>
-->
<!-- Need to include ClientLoginModule to propagate caller's subject and security context
Add this line to your login-config.xml to include the ClientLoginModule propogation -->
<login-module code="org.jboss.security.ClientLoginModule" flag="required">
<module-option name="restore-login-identity">true</module-option>
<module-option name="multi-threaded">true</module-option>
</login-module>
</authentication>
</application-policy>
</policy>



#
#############################################################################
#
# The nms-ldap.properties file is referenced by login-config.xml and is used
# by the NmsLdapLoginModule. This file controls whether LDAP access to a
# directory service is enabled for user passwords (and, optionally, user
# roles), and what parameter values are used.
#
# Contact your directory service administrator to determine the correct
# values to use in this file.
#
# This file is accessed before each attempt to sign in to the NNMi console,
# so its contents may be modified without restarting ovjboss.
#
# Whole line comments are allowed when start with a "#", but "#" characters
# at the end of a line are considered part of the value:
# paramName=paramValue # This string is part of paramName
#
# Any error messages from incorrect configuration of this file are logged to
# /log/nnm/jbossServer.log.
#
# While testing changes to this file, be sure to use "File:Sign Out",
# instead of just closing the browser, to ensure you are fully signed
# out. Doing so prevents the browser from using cached credentials.
#
# For detailed information about configuring LDAP access to a directory
# service, see the HP Network Node Manager i-series Software Deployment and
# Migration Guide.
#
#############################################################################
#


#
# java.naming.provider.url:
#
# The URL for accessing the directory service.
#
# This parameter must be set to enable LDAP access to a directory service.
# If this parameter is not set in this file, LDAP queries are not
# attempted during user sign in.
#
# The value is in the form "ldap://ldap.myco.com" or
# "ldap://ldap.myco.com:636" (which is the same as
# "ldaps://ldap.myco.com:636").
#
# If a port is specified in the URL, the specified port overrides the
# default. If unspecified, port 389 is used for non-SSL connections, or
# port 636 is used for SSL connections (as defined by
# java.naming.security.protocol).
#
# To disable login attempts through LDAP, comment out this parameter.
#
# It is recommended that all User Accounts be deleted from NNMi after
# enabling this feature, and that all Principals be deleted from NNMi after
# disabling this feature. Doing so prevents accidental access through
# previously configured values.
#
#java.naming.provider.url=ldap://ldap.myco.com:389/


#
# java.naming.security.protocol:
#
# If this parameter is set to "ssl", NNMi uses the Secure Sockets Layer
# protocol for communications with the directory service.
#
# Enable SSL if you see an error in the jbossServer.log file that is
# similar to:
# javax.naming.AuthenticationNotSupportedException:
# [LDAP: error code 13 - confidentiality required]
#
# To enable SSL, import your company's trust store certificate into the
# /shared/nnm/certificates/nnm.truststore, with a command such
# as (for UNIX):
#
# /opt/OV/nonOV/jdk/nnm/bin/keytool -storepass ovpass -import \
# -file my_certificate_authority_cert.txt -alias 'nnmi_ldap' \
# -keystore /var/opt/OV/shared/nnm/certificates/nnm.truststore
#
# where my_certificate_authority_cert.txt is a file containing the
# certificate required by the directory service for SSL communication.
#
#java.naming.security.protocol=ssl


#
# bindDN:
# bindCredential:
#
# By default, the request to validate a username and password uses
# anonymous login. However some directory services (such as
# Active Directory Services) disallow anonymous access. Use this to
# provide credentials to the directory service.
# Note that as with any entry in this file, if you want to
# specify a backslash ('\'), it must be escaped as '\\'
#
#bindDN=MyDomain\\Some User Name
#bindCredential=someUserPassword


#############################################################################
#
# The distinguished name that is passed to the directory service for
# authenticating a user is the concatenation of the baseFilter value and the
# baseCtxDN value.
#
# For example, if baseFilter is set to "uid={0}", baseCtxDN is set to
# "ou=People,o=myco.com", and a user signs in to NNMi as "john.doe", then the
# string passed to the directory service is:
# uid=john.doe,ou=People,o=myco.com
#
#############################################################################


#
# baseCtxDN:
#
# Required. The user name search context, which is the fixed portion of the
# distinguished name for the user search.
#
# For an Active Directory server, this might be a value like:
# baseCtxDN=CN=Users,DC=mycompany,DC=com
#
baseCtxDN=ou=People,o=myco.com


#
# baseFilter:
#
# Required. The variable portion of the distinguished name for the user search.
#
# The baseFilter incorporates the user name entered for NNMi signin into the
# format needed for the distinguished name.
#
# The exact user name entered at the NNMi signin dialog is substituted for
# the expression "{0}" anywhere that it appears in the filter.
#
# A common value for baseFilter for OpenLDAP servers is:
# baseFilter=uid={0}
# A common value for baseFilter for Active Directory servers is:
# baseFilter=CN={0}
# or to use the Window NT 4.0 SAM-Account-Name:
# baseFilter=sAMAccountName={0}
#
baseFilter=uid={0}


#############################################################################
#
# You can verify the correctness of the above information in an LDAP client
# application, such as Microsoft Internet Explorer 7 or Mozilla Firefox 2.
#
# Enter an RFC 1959-compliant directory service URL with the above
# information, substituting a valid signin id. For instance, using the above
# values, and a signin of john.doe, you could test with a URL similar to:
# ldap://ldap.myco.com:389/uid=john.doe,ou=People,o=myco.com
# which is formed by concatenating the java.naming.provider.url, the
# baseFilter substituted with the signin name, a comma, and the baseCtxDN.
#
# If this URL times out, you probably have an incorrect directory service URL
# or port number.
#
# If you are using Active Directory (which does not allow anonymous binding),
# you can use an LDAP browsing program to verify your values are correct.
#
#############################################################################


#
# defaultRole:
#
# Optional. Use this parameter to specify a default role that applies to any
# directory service user who signs in to NNMi through LDAP. The value of this
# parameter applies regardless of where role mappings are stored (in the NNMi
# database or in the directory service). If a user is also a member of a group
# with an NNMi role attribute, NNMi uses the role with more privileges.
#
# Valid values are the NNMi roles: admin, level2, level1, guest, or client.
#
# If commented out, no default role is used, and the role mapping must
# be defined else the user will not be able to sign in to the NNMi console.
#
#defaultRole=guest


#############################################################################
#
# The remainder of the parameters in this file apply to customers who assign
# NNMi roles in the directory service.
#
# If you maintain NNMi role mapping in the NNMi database, stop here.
#
#############################################################################


#############################################################################
#
# After a user has been authenticated, NNMi queries the groups to which that
# user belongs to determine the NNMi roles that the user will have in NNMi.
# (When a user is assigned multiple roles, NNMi uses the role with more
# privileges.)
#
# The distinguished name that is passed to the directory service for
# identifying the groups to which a user belongs is the concatenation of the
# roleFilter value and the rolesCtxDN value.
#
# For example, if roleFilter is set to "member={1}", rolesCtxDN is set to
# "ou=Groups,o=myco.com", and the authenticated user distinguished name is
# "john.doe@myco.com", then the string passed to the directory service is:
# member=john.doe@myco.com,ou=Groups,o=myco.com
#
# All group distinguished names which have an attribute (uidAttributeID)
# that match the authenticated user will be used to assign the roles for
# the user. Any matching groups will use an attribute (roleAttributeID)
# to determine the role for the user.
#
#############################################################################


#
# rolesCtxDN:
#
# The group name search context, which is the fixed portion of the
# distinguished name for the user group search.
#
# This parameter must be set to enable directory service queries for NNMi
# role assignments through LDAP. If this parameter is not set in this file,
# LDAP queries for user roles are not attempted during user sign in.
#
# To disable directory service queries for NNMi role assignments through LDAP,
# comment out this parameter. The remaining values in this file will not be
# used.
#
# For a faster search, you can identify one or more directory service groups
# that contain NNMi roles. If the group names form a pattern, you can specify
# a wildcard. For example, if the directory service includes groups named
# "USERS-NNMi-administrators", "USERS-NNMi-level1Operators", and so forth,
# you could use a search context similar to:
# rolesCtxDN=cn=USERS-NNMi-*,ou=Groups,o=myco.com
# For an Active Directory server, this might be a value like:
# rolesCtxDN=CN=Users,DC=myco,DC=com
# which might be the same as baseCtxDN because Active Directory configurations
# sometime stores Groups and Users at the same level.
#
#rolesCtxDN=ou=Groups,o=myco.com


#
# roleFilter:
#
# The variable portion of the distinguished name for the user group search.
#
# The user name entered for signin is substituted for the expression {0}
# anywhere that it appears in the filter.
#
# The distinguished name of the authenticated user is substituted for the
# expression {1} anywhere that it appears in the filter.
#
# An example role filter that matches on the (short) user name entered for
# signin is: member={0}
#
# An example role filter that matches on the authenticated (full) user
# distinguished name is: member={1}
#
roleFilter=member={1}


#############################################################################
#
# You can verify the correctness of the group query by passing a URL
# similar to the following, and entering it into a web browser, unless
# your directory server does not allow anonymous authentication (as
# is the default case for Active Directory). An example is:
# ldap://ldap.myco.com:389/ou=Groups,o=myco.com??sub?(cn=SOME-PATTERN-*)
# which is formed by concatenating the java.naming.provider.url, the
# baseCtxDN, and an optional search context limiter.
#
# If you are using Active Directory, you can use an LDAP browsing program
# to verify your values are correct.
#
#############################################################################


#
# roleAttributeIsDN:
# roleAttributeID:
# roleNameAttributeID:
#
# roleAttributeIsDN is a flag indicating whether the user's role attribute
# contains the fully distinguished name of a role object, or the users's role
# attribute contains the role name.
# In certain directory schemas (for example, Microsoft Active Directory),
# role (group) attributes in the user object are stored as distinguished names
# to role objects instead of as simple names, in which case, this property
# should be set to roleAttributeIsDN=true
# In non-Active Directory cases, false is the correct value
# of roleAttributeIsDN.
#
#
# If roleAttributeIsDN=false, the role name is taken directly from the
# value of the user's role attribute (roleAttributeID).
# For non-Active Directory servers, it is recommended that a group be created
# with an additional attribute called "roleName" that contains a value of
# admin (for Administrator role), level2 (for Level 2 Operator role),
# level1 (for Level 1 Operator role), guest (for Guest role), or
# client (if required when using the NNMi SDK and integrations). In such
# a case, you would use
# roleAttributeID=roleName
# This attribute is the name of the attribute in the group, which is
# set to a different value for each NNMi role-defining group.
#
#
# If roleAttributeIsDN=true, the following definitions apply.
# roleAttributeID is the name of the attribute in the group that stores the NNMi role value that
# applies to the members of the directory server group. For Active Directory,
# this is usually:
# roleAttributeID=memberOf
# The role attribute (roleNameAttributeID) represents
# the distinguished name of a role object, and the role name is taken from the
# value of the "roleAttributeID" attribute of the corresponding group
# specified by roleNameAttributeID.
# This is also useful if you are unable to change the schema to add an attribute
# (such as roleName), and just want the name of the group to be the role. In
# that case, you could use roleNameAttributeID=name or
# roleNameAttributeID=CN to actually use the name of the group as the nnmi
# role. This implies that you created groups specifically called admin, level2,
# level1, guest or client.
#
# In some Active Directory implementations you cannot create a new attribute
# to store the NNMi role. Active Directory groups have an "info" attribute
# you can change (often named "Notes" in the Active Directory
# configuration). In this case you would set the "info" attribute
# in your Level 2 Group in Active Directory to "level2", and use
# roleNameAttributeID=info
#
roleAttributeIsDN=false
roleAttributeID=nnmiRole
#
# Active Directory instead uses roleAttributeIsDN=true
# In this case, the actual attribute to get the role is two hops
# away, using roleAttributeID to find the DN which actually contains
# the attribute.
#
#roleAttributeIsDN=true
#roleAttributeID=memberOf
#roleNameAttributeID=info


#############################################################################
#
# The following two attributes are used to enable Incident Assignment
#
#############################################################################


#
# userRoleFilterList:
#
# A semicolon-separated list of NNMi roles whose associated users can be
# assigned incidents in the NNMi console. The roles in this list apply only
# to directory service user names authenticated through LDAP.
# If this value is incorrect, sign in will find the correct user Role,
# but selecting an Incident and picking Actions -> Assign Incident... will
# bring up a dialog with no users.
#
# Valid values are the NNMi roles: admin, level2, level1, guest, or client.
#
userRoleFilterList=admin;level2;level1


#
# uidAttributeID:
#
# The name of the attribute in the group that stores the directory service user ID.
# The value of this attribute is used to locate the user's role. It is
# usually the attribute portion of roleFilter. This attribute is used for
# looking up the list of users for Incident assignment.
# If this value is incorrect, sign in will find the correct user Role,
# but selecting an Incident and picking Actions -> Assign Incident... will
# bring up a dialog with no users.
#
uidAttributeID=member

#############################################################################
#
# The following only needs to be modified if you are finding timeouts
# when accessing a distant directory server.
#
#############################################################################


#
# searchTimeLimit
#
# If you have a slow responding directory service, you may get errors like:
# javax.naming.TimeLimitExceededException: [LDAP: error code 3 - Timelimit Exceeded]
# in this case, you can increase the searchTimeLimit. This value is
# in milliseconds. The default value is 10000 (10 seconds)
#
#searchTimeLimit=10000

Tuesday, September 21, 2010

Abusing? javascript functional powers

Javascript being a functional language makes it very easy to pass functions around as param to other function.

However when we do that we might lose readability of the code

Consider this:

mapcar1 is just another function, same as dojo.forEach in functionality.

The code in bold has lots of redirection and very hard to debug as it calls the callback if something is successful etc.

withTransforms : function (transforms, callback, errorCallback, config) {

if (reqNeeded) {

var trs = mapcar1 (
function (t) {

return {
"toSrs" : t.to
};
},
transforms);

var callbacks =
{
success : callback,
failure :this.cbWithTransformsFailed,
b4Success : this.cbB4SuccessWithTransforms,
scope : this
};

this.ajaxTool.post (
getWebappBaseUrl () + "/transformGeometry.do",
{
"transformRequests" : trs
},
callbacks,
config);

} else {

callback (
mapcar1 (
function (t) {

return t.geometry;
},
transforms));
}
},

Sunday, September 19, 2010

Java Hidden Iterator causing ConcurrentModificationException

The " System.out.println("DEBUG: added ten elements to " + set);" effectively compiles into a HiddenIterator that iterates the "set", and this is not thread-safe.

Work around is to wrap "set" into a synchronizedSet

public class HiddenIterator {
@GuardedBy("this")
private final Set set = new HashSet();

public synchronized void add(Integer i) { set.add(i); }
public synchronized void remove(Integer i) { set.remove(i); }

public void addTenThings() {
Random r = new Random();
for (int i = 0; i < 10; i++)
add(r.nextInt());
System.out.println("DEBUG: added ten elements to " + set);
}
}

Wednesday, September 15, 2010

Weblogic + maven2 + war

1. Add the following to your pom.xml, making sure you have the correct path to weblogic
[...]
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<configuration>
<container>
<containerId>weblogic103x</containerId>
<home>C:OracleMiddlewarewlserver_10.3</home>
</container>
</configuration>
</plugin>
[...]

2. mvn cargo:start

Tuesday, July 13, 2010

Erdas apollo catalog searching new properties

As described in the Apollo Advantage guide

modify the queryables.xml

and then

modify the babel-types-infos.js

{
"name" : "properties.newlyAddedProperty",
"title" : "my newly added property",
"type" : "string",
"autoLike" : true
}


So the json query posted to the backend will be

{
"maxresults": 15,
"start": 0,
"profile": "eac-brief",
"orderby": ["class asc", "registrationDate desc"],
"maxresultcount": 501,
"template": {
"wmsEnabled": {
"_op": "eq",
"value": true,
"type": "boolean"
},
"properties": {
"anzlic": {
"value": "messi*",
"_op": "like",
"type": "string"
}
},
"class": "com.erdas.rsp.babel.model.imagery.ImageReference",
"nameQualifier": "babel://coverages"
}
}

Wednesday, June 30, 2010

SqlJdbcDriver 3.0 + ERDAS APOLLO 2010.1 + SQL Server 2008

By default, ERDAS Apollo 2010.1 uses SqlJdbcDriver 2.0, where the jar files are:
1 .../jboss/server/default/lib/jdbc-driver-2.0.jar and sqljdbc.jar
2 .../erdas-apollo.ear/lib/jdbc-driver-2.0.jar

Hence if the new sqljdbc_xa.dll is installed in the SQLServer Binn directory, it should be backward compatible with the jdbc-driver-2.0.jar

The .../erdas-apollo.ear/lib/jdbc-driver-2.0.jar is required for the DataManager application to function.

To upgrade Apollo2010.1 to use SqlJdbcDriver3.0, some manual copy and paste have to be done.
1. Download the SqlJdbcDriver 2.0 from microsoft website http://www.microsoft.com/downloads/details.aspx?FamilyID=%20a737000d-68d0-4531-b65d-da0f2a735707&displaylang=en

2. Shutdown jboss.

3. Extract the files and copy sqljdbc.jar into
- .../jboss/server/default/lib/ (overwrite the existing one, if any)
- and .../erdas-apollo.ear/lib/

4. Delete the existing
- .../jboss/server/default/lib/jdbc-driver-2.0.jar and
- .../erdas-apollo.ear/lib/jdbc-driver-2.0.jar

5. Start Jboss.

6. Verify users can login from Datamanager and erdas-apollo can connect to the database by looking at the jboss server.log

Tuesday, June 29, 2010

ERDAS Apollo 2010 + SQL Server 2008 Express

- Download SQL Server 2008 Express from http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=58ce885d-508b-45c8-9fd3-118edd8e6fff and then install it.

- Enable tcp/ip port (I use port 1433) in "SQL Server Configuration Manager" -> "SQL Server Network Configuration" -> Protocols for SQLEXPRESS => TCP/IP : {enabled, Right-Click/Properties: TCP Port: 1433}.
Test with: "telnet localhost 1433" or change localhost to server's ip address

- Create database for apollo

create database apollo on
(name = apollo_dat, FILENAME = 'E:\work\apollo.mdf', size = 200MB, FILEGROW
TH=5)
LOG ON (name='apollo_log', FILENAME = 'E:\work\apollo_log.ldf', size=200MB, FILEGROWTH=5)
GO

- Supply the params to APOLLO installer.

- If you get

javax.transaction.xa.XAException, refer to my previous post:

http://lydonchandra.blogspot.com/2010/06/javaxtransactionxaxaexception.html

@@

javax.transaction.xa.XAException

Issue:

javax.transaction.xa.XAException: com.microsoft.sqlserver.jdbc.SQLServerException: Failed to create the XA control connection. Error: "Could not find stored procedure 'master..xp_sqljdbc_xa_init_ex'."

Resolution:

1. Ensure Microsoft Distributed Transaction Coordinator is installed and running on every SQL Server machine that will participate in distributed transactions.

a. From Control Panel, open Administrative Tools, and then open Component Services. You can also click the Start button, click Run, type dcomcnfg in the Open box, and then press OK to open Component Services.

b. Expand Component Services, Computers and right-click My Computer, and then select Properties.

c. Click the MSDTC tab, and then click Security Configuration.

d. Select the Enable XA Transactions check box, and then click OK. This will cause a MS DTC service restart.

e. Click OK again to close the Properties dialog box, and then close Component Services.

f. Stop and then restart SQL Server to ensure that it syncs up with the MS DTC changes

2. Install the Microsoft SQL Server JDBC driver 2.0 from the url in the reference section.

3. Copy the sqljdbc_xa.dll from this directory to the Binn directory of every SQL Server machine that will participate in distributed transactions.

4. Execute the database script xa_install.sql on every SQL Server machine that will participate in distributed transactions.


5. Check that apollo db user has execute permission to the "master" database because xa_install.sql installs procedures in the master database.


Reference:

http://msdn.microsoft.com/en-us/library/aa342335.aspx
http://www.microsoft.com/downloads/details.aspx?FamilyID=99B21B65-E98F-4A61-B811-19912601FDC9&displaylang=en

Tuesday, June 8, 2010

Erdas Apollo 2010 Change server name

Recently I changed the computer name that hosts Erdas Apollo 2010, and services stop working.
So I basically did
1. search and replace on the *.xml, *.fac, *.txt that refer to old-computer-name and replace them with new-computer-name
2. search and replace on apollo-client.war
Because this is effectively a zip file, I had to unzip it, did search and replace, zip it again, and place it in \APOLLO2010\jboss\server\default\deploy directory

Monday, June 7, 2010

FAZ position

Entry price: ~15.50 to $16.00 (Currently quite far from MA)
Target1: $20
Target2: $25
Stop: $13.98
Reward2RiskRatio: 4/2

US Stockmarket 1 year view

My uneducated guess for SPY in a year time (Jun 2011)
- It will be sitting ard $85 to $95, which is just the trading range in April-June 2009 before it broke out of resistance.
- It is a bearish view because:
- The governments around the world are running out of stimulus money
- Austerity programs in Europe will take place
- BRIC (Brazil, Russia, India, and China) are tightening their economy to control inflation (especially property prices in China)
- Very high level of debt among developed countries ( as detailed in http://www.debtdeflation.com/blogs/)
- refer to Nouriel Roubini http://www.youtube.com/watch?v=f7RjqfdRQDQ

Sunday, June 6, 2010

Erjang on OSX 10.6.x

A few obstacles I was having when trying to setup Erjang on OSX 10.6.x
1. Perl version
Erjang requires perl 5.10.0, and the default perl on the system is 5.8.x.
Perl 5.10.x is installed on the system however, so all I have to do is to modify build.xml,
replacing executable="perl" with executable="perl5.10.0"
2. Erlang environment vars
To make it easy, I add a soft link /sw that points to /opt/local

Then I can just do
./erl.sh -pa ./src/main/erl -noshell -s ring main

Wednesday, May 19, 2010

Dojo generate colors

The one that I want is in

dojox.color.Generator.monochromatic ({ base:myColor, num:6 })
http://bugs.dojotoolkit.org/browser/dojox/trunk/color/Generator.js?rev=14628

This monochromatic function does NOT do what I want
dojo.require("dojox.color.Palette");
var colors = dojox.color.Palette.generators.monochromatic ({ base:myColor, num:6 });




Tuesday, May 18, 2010

Dojo How to ColorPalette + TooltipDialog + DropDownButton

function changeColor(selectColor) {
console.log("color: " + selectColor);
}

dojo.addOnLoad( function() {
var censusContainer = new dijit.layout.BorderContainer({
style: "width: 30%; height: 30%",
gutters: false,
design: "headline"
},"censusContainerId");


var paramsContent = new dijit.layout.ContentPane();
var colorPalette = new dijit.ColorPalette({onChange:changeColor});
var colorPalette2 = new dijit.ColorPalette({onChange:changeColor});
censusContainer.addChild(colorPalette);
var dropDownButton = new dijit.form.DropDownButton({label: "drop", dropDown: colorPalette2});
censusContainer.addChild(dropDownButton);
censusContainer.startup();
}

HTML:

<body class="tundra">
<div id="censusContainerId" region="top" >Region top</div>
<div dojoType="dijit.ColorPalette" onChange="changeColor"></div>
</body>

Thursday, May 13, 2010

Erlang parse file

Trying to parse csv file with the following contents

INTC,07-May-2010 16:51,21.31,21.31,21.31,21.31,200\n
INTC,07-May-2010 16:47,21.31,21.31,21.31,21.31,100\n
INTC,07-May-2010 16:42,21.31,21.31,21.31,21.31,300\n

The erlang code


getCompanyEff(Filename,Company) ->
{ok,Device} = file:open(Filename,read),
getLinesCompany(Device,[],Company).

getLinesCompany(Device,Accum,Company) ->
case io:get_line(Device,"") of
eof -> Accum;
Line ->
case regexp:first_match(Line, Company ++ ",*") of
{match,_,_} -> getLinesCompany(Device, [Line|Accum], Company);
nomatch -> getLinesCompany(Device, Accum, Company)
end
end.

and to execute:
erl> module:getCompanyEff("/path/to/file", "CompanyName").

Monday, May 10, 2010

HTML 5 postMessage (Cross-Domain Message) on Firefox 3.6.3

This only works in Firefox because IE uses attachEvent(). You can always use dojo.connect( window, 'message', func() ) so it works in Firefox and IE.

A (http://localhost/cross.htm) has an iframe containing B (http://otherdomain/cross.htm)

After the iframe is loaded in A, then a message is sent to it (containing string 'Hello'). The origin is checked in B, and if it matches an alert is displayed.

on A (http://localhost/cross.htm)
<script type="text/javascript">
function iframeload() {
var o = document.getElementById('crossid').contentWindow;
o.postMessage('Hello', "http://otherdomain/cross.htm");
}
</script>

<iframe id="crossid" onload="iframeload();" src="http://otherdomain/cross.htm" width="700px" height="700px">
</iframe>


on B (http://otherdomain/cross.htm)
window.addEventListener('message',function(e) {
if (e.origin == 'http://localhost') {
if (e.data == 'Hello') {
alert(e.data);
e.source.postMessage('Hello');
} else {
alert(e.data);
}
}
}, false);

Friday, May 7, 2010

Javascript for loop + closure

This for loop uses closure to get the value of i for every iteration.
Without closure, every element in divvar will get the last value of x(length-1) from iteration.

for( var i=0;i<divvar.length;i++ ) {
(
function(x) { // -> capture looping variable
divvar[x].onclick = function() {
console.debug("clicked:", x);
}
}
)(i); // -> pass in looping variable
}

Compare this to the standar loop without closure

for( var i=0;i<divvar.length;i++ ) {
divvar[i].onclick = function() {
console.debug("clicked:", i);
};
}

Or we can use dojo.forEach to fix this

Thursday, May 6, 2010

ESRI ArcXML get service info

HTTP POST to http://xxx/IMS/servlet/com.esri.esrimap.Esrimap?ServiceName=six_combo&CustomService=query

ARCXML service info:

<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<REQUEST>
<GET_SERVICE_INFO fields="false" envelope="false" renderer="false" extensions="true" acetateinfo="false" />
</REQUEST>
</ARCXML>

The response:
<?xml version="1.0" encoding="UTF-8"?>
<ARCXML version="1.1">
<RESPONSE>
<SERVICEINFO>
<ENVIRONMENT>
<LOCALE language="en" country="AU" />
<UIFONT name="Arial" color="0,0,0" size="12" style="regular" />
<SEPARATORS cs=" " ts=";"/>
<CAPABILITIES forbidden="" disabledtypes="" returngeometry="xmlmode"/>
<SCREEN dpi="74"/>
</ENVIRONMENT>
<PROPERTIES>
<FEATURECOORDSYS string="GEOGCS["GCS_GDA_1994",DATUM["D_GDA_1994",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]" id="4283" />
<FILTERCOORDSYS string="GEOGCS["GCS_GDA_1994",DATUM["D_GDA_1994",SPHEROID["GRS_1980",6378137.0,298.257222101]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]]" id="4283" />
<ENVELOPE minx="140.05983881892" miny="-37.740334035" maxx="154.575951211079" maxy="-27.924909045" name="Initial_Extent" />
<ENVELOPE minx="140.05983881892" miny="-37.740334035" maxx="154.575951211079" maxy="-27.924909045" name="Extent_Limit" />
<MAPUNITS units="decimal_degrees" />
<LEGEND/>
</PROPERTIES>
<LAYERINFO type="featureclass" visible="true" name="Suburb Labels" id="Suburb_Label_1" minscale="0.0000308686210057027" maxscale="0.000308686210057027">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.Suburb.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.suburbname" type="12" size="40" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.postcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.state" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Local Government Area Labels" id="LocalGovernmentArea_Label_1" minscale="0.000246948968045622" maxscale="0.000926058630171081">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.LocalGovernmentArea.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.lganame" type="12" size="60" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.councilname" type="12" size="80" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.abscode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.ltocode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.vgcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.wbcode" type="4" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="false" name="Locality Labels" id="Locality_Label_1" maxscale="0.0000000308686210057027">
<FCLASS type="point">
<FIELD name="delivsdm:geodb.placepoint.topoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.objectmoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.featuremoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.classsubtype" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.featurereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.attributereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.capturesourcecode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.capturemethodcode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.planimetricaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.placepoint.verticalaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.placepoint.operationalstatus" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.generalnameoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.generalname" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.alternativelabel" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.placetype" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.population" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.popsourcedate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.placesignificance" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.placepoint.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
<EXTENSION type="StoredQuery">
<STOREDQUERIES>
<STOREDQUERY name="generalname">
<QUERY subfields="" where="generalname LIKE '[%var%]%'" >
</QUERY>
<SQVAR name="[%var%]" position="0">
<FIELD name="delivsdm:geodb.placepoint.generalname" type="12" />
</SQVAR>
</STOREDQUERY>
</STOREDQUERIES>
</EXTENSION>

</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Road Labels" id="RoadSegment_Label_1">
<FCLASS type="line">
<FIELD name="delivsdm:geodb.RoadSegment.topoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.objectmoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.featuremoddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.classsubtype" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.featurereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.attributereliabilitydate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.capturesourcecode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.capturemethodcode" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.planimetricaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.RoadSegment.verticalaccuracy" type="6" size="6" precision="2" />
<FIELD name="delivsdm:geodb.RoadSegment.operationalstatus" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnameoid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnamebase" type="12" size="50" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnametype" type="12" size="20" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadnamesuffix" type="12" size="10" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.functionhierarchy" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.roadontype" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.surface" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.lanecount" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.RoadSegment.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Town Labels" id="Town_Label_1" minscale="0.000246948968045622">
<FCLASS type="point">
<FIELD name="OBJECTID" type="8" size="10" precision="0" />
<FIELD name="NAME" type="12" size="32" precision="0" />
<FIELD name="POSTCODE" type="8" size="10" precision="0" />
<FIELD name="POP_1996" type="8" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="#ID#" type="-99" size="16" precision="0" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Local Government Area" id="LocalGovernmentArea_1" minscale="0.000246948968045622" maxscale="0.000926058630171081">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.LocalGovernmentArea.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.lganame" type="12" size="60" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.councilname" type="12" size="80" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.abscode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.ltocode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.vgcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.wbcode" type="4" size="10" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.LocalGovernmentArea.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Suburbs" id="Suburb_1" minscale="0.0000308686210057027" maxscale="0.000308686210057027">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.Suburb.cadid" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.createdate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.modifieddate" type="91" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.suburbname" type="12" size="40" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.postcode" type="4" size="10" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.state" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.Suburb.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="Topographic Map Index" id="Topographic_Map_Index_1" maxscale="0.000617372420114054">
<FCLASS type="polygon">
<FIELD name="delivsdm:geodb.topomapindex.mapnumber" type="12" size="10" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.maptitle" type="12" size="32" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.nominalpresentationscale" type="4" size="8" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.mgazone" type="5" size="5" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.hundredkmapnumber" type="4" size="5" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.presentationformat" type="5" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="delivsdm:geodb.topomapindex.objectid" type="-99" size="16" precision="0" />
<FIELD name="SE_Area(shape)" type="8" size="16" precision="8" />
<FIELD name="SE_Length(shape)" type="8" size="16" precision="8" />
</FCLASS>
</LAYERINFO>

<LAYERINFO type="featureclass" visible="true" name="NSW Border" id="Border_1" minscale="0.00617372420114054">
<FCLASS type="line">
<FIELD name="IGDS_CLASS" type="4" size="5" precision="0" />
<FIELD name="IGDS_COLOR" type="4" size="5" precision="0" />
<FIELD name="GROUP" type="4" size="5" precision="0" />
<FIELD name="IGDS_STYLE" type="4" size="5" precision="0" />
<FIELD name="WEIGHT" type="4" size="5" precision="0" />
<FIELD name="#SHAPE#" type="-98" size="0" precision="0" />
<FIELD name="#ID#" type="-99" size="16" precision="0" />
</FCLASS>
</LAYERINFO>

</SERVICEINFO>
</RESPONSE>
</ARCXML>

Thursday, April 29, 2010

ArcGIS Polygon Search

--Polygon Search for Transport Spending
Filter Geometry: {"rings":[[[272276.48887,6179999.947118772],[385469.50589442987,6361478.599097537]]]}
Geometry Type: Polygon
Input Spatial Reference (WKID): 28356
Spatial Relationship: contains
Where clause: empty

I found this by sniffing the traffic of a page that I created by copying and pasting the html in http://resources.esri.com/help/9.3/arcgisserver/apis/javascript/arcgis/help/jssamples_start.htm#jssamples/util_simplify.html

Monday, April 12, 2010

Installing Erdas Professional 2010 on Amazon EC2

Erdas Professional can only be installed on Windows platform.
1.Basic 64-bit  Microsoft Windows Server 2008 Basic 64-bit Microsoft Windows Server 2008 (AMI Id: ami-cdc22ea4)
2. Download Erdas Apollo Professional 2010 from Erdas website (http://www.erdas.com/Products/ERDASProductInformation/tabid/84/currentid/3148/objectid/3148/default.aspx), you will need to register, and an instruction of how to download it from ftp.erdas.com will be given.
3. Install PostgreSQL (at least 8.3) and PostGIS extension 1.5
4. Create a new database using template_postgis. The username/password/database info will need to be entered into Apollo installation window at some point.
5. Download and install the Erdas net-License Manager (http://www.erdas.com/Products/ERDASProductInformation/tabid/84/currentid/3148/objectid/3148/~/tabid/84/currentid/2491/default.aspx)
6. Request evaluation license from Erdas websites, and follow the instruction of how to install it.
7. Once the license file is installed, you should be able to access http://your-amazon-ec2:8080/apollo-client and http://your-amazon-ec2:8080/erdas-apollo.

Thursday, March 18, 2010

mod_wsgi + apache

mod_wsgi

sudo vim /etc/sysconfig/apache2
sudo /usr/sbin/rcapache2 restart

Monday, March 15, 2010

Netstat + find process Id

Many a times you would get a "Bind Exception", "Address already in use" kind of errors and need to find the process that's using the port. For example say the port is 8080. The following command will get you the pid and program name as well.

netstat -nlept | grep "8080"

The result might look something like this...

Proto Recv-Q Send-Q Local Address Foreign Address State User Inode PID/Program name
tcp6 0 0 :::8080 :::* LISTEN 1000 994652 4024/java
Where 4024 is the pid and it's a java app.

Friday, March 12, 2010

IBM Cloud

It looks like arbitraty ports are firewalled by IBM (other than port 80 and 22 and maybe some others), so when I wanted to connect to one of my machine in the IBM Cloud on port 18080 http for example, I have to setup a reverse proxy for it.

<Proxy http://mywebsite:18080 >
Order deny,allow
Deny from all
Allow from 123.123.123.123
</Proxy>

ProxyRequests Off
ProxyPass / http://localhost:18080/
ProxyPassReverse / http://localhost:18080/

Sunday, March 7, 2010

Javascript stop event bubbling and stop browser default action

// stop event bubbling
function stopBubble(e) {
if( e && e.stopPropagation ) {
e.stopPropagation();
} else {
//IE
window.event.cancleBubble = true;
}
}

// stop browser default action, i.e, clicking an html link will open up that link.
function stopDefault(e) {
if( e && e.preventDefault )
//Other than IE
e.preventDefault();
else
//IE
window.event.returnValue = false;
}

function loadLi() {
var li = document.getElementsByTagName("li");
//alert(li.length);
for ( var i = 0; i < li.length; i++ ) {
li[i].onmouseover = function() {
this.style.backgroundColor = 'blue';
};

li[i].onmouseout = function() {
this.style.backgroundColor = 'white';
};
}
}

function loadAnchor() {
var anchor = document.getElementsByTagName("a");
for ( var i = 0; i < anchor.length; i++ ) {

anchor[i].onmouseover = function(e) {
this.style.backgroundColor = 'red';
stopBubble(e);
};

anchor[i].onmouseout = function(e) {
this.style.backgroundColor = 'white';
stopBubble(e);
};

anchor[i].onclick = function(e) {
iframe.src = this.href;
return stopDefault(e);
}
}
}

Spring Framework + RMI + JBoss

Use RMI port 1199 (other than the default port 1099, JBoss RMI) with org.springframework.remoting.rmi.RmiServiceExporter.

<bean id="escortLocationService" class="com.don.remoting.EscortLocationServiceImpl" >
</bean>

<bean id="rmi" class="org.springframework.remoting.rmi.RmiServiceExporter" >
<property name="service" ref="escortLocationService" />
<property name="serviceName" value="EscortLocationService" />
<property name="serviceInterface" value="com.don.remoting.EscortLocationService" />
<property name="registryPort" value="1199"/>
</bean>

<bean id="escortLocationServiceClient" class="org.springframework.remoting.rmi.RmiProxyFactoryBean">
<property name="serviceUrl" value="rmi://127.0.0.1:1199/EscortLocationService" />
<property name="serviceInterface" value="com.don.remoting.EscortLocationService" />
</bean>

<bean id="escortLocationClient" class="com.don.remoting.EscortLocationClient" >
<property name="escortLocationService" ref="escortLocationServiceClient" />
</bean>

Friday, March 5, 2010

Oracle multiple case select statement

In a table, I have 3 columns (checkbox1, checkbox2, checkbox3) representing values about "Where does the knowledge come from?".
if checkbox1 == 1, that means the knowledge comes from "My_Course",
checkbox2 -> Internet,
checkbox3 -> Staff.

if the checkbox1,2,3 == 0, then it's empty string.

Basically I want to concatenate values from multiple columns into one value "Know_from_where":

select student_type,
(case checkbox1
when 1 then 'My_Course, '
when 0 then '' end ) ||
(case checkbox2
when 1 then 'Internet, '
when 0 then ''
end ) ||
(case checkbox3
when 1 then 'Staff, '
when 0 then '' end ) Know_From_Where
from infolit

Wednesday, March 3, 2010

springsource tool suite oracle jdbc driver + maven2 depend


<repository>

<id>repo1 maven org</id>

<name>repo1 maven org</name>

<url>http://repo1.maven.org/maven2</url>

</repository>



<dependency>

<groupid>ojdbc</groupid>

<artifactid>ojdbc</artifactid>

<version>14</version>

</dependency>




Then you have to download ojdbc14.jar from oracle website (or wherever) and do:
mvn install:install-file -DgroupId=ojdbc -DartifactId=ojdbc -Dversion=14 -Dpackaging=jar -Dfile=/path/to/ojdbc14.jar

Xml re-generated using http://www.simplebits.com/cgi-bin/simplecode.pl?mode=process