Wednesday, June 13, 2007
Install Build Essentials for Ubuntu Server 6.10
The default install don't have the essential tools installed for source build. To install the essentials, run the following
apt-get install build-essential
Tuesday, June 12, 2007
Enable Apache Portable Runtime (APR) for Tomcat on Windows
Here are the simple steps to enable APR for Tomcat on Windows.
- Download the tcnative-1.dll from here.
- Put the DLL into system32 folder.
- That is!.
Windows Vista - Disappointing
Just bought a new notebook comes with Windows Vista Home Premium for my wife over the weekend. I am very disappointed with the OS so far. Here are the reasons.
- I am glad it finally comes with address book that is usable and have nothing to do any email client. However, after all this years, with OS X as example, people at Microsoft still don't know how to make an OS that is user friendly. The Windows Contact is not even close to the Contacts in Outlook. For example, how hard it is to put on A-Z index?! Also, why can't Vista make it easy for home user to import addresses from current Outlook contacts? CVS is so techie! I had to help my wife export it from Outlook using CVS file, and later import into Windows Contact.
- Windows Photo Gallery is a joke! First, after you pop in the memory card for your camera into the notebook, it doesn't know what to do with it. There is no dialog for import or whatsoever. You have to open up the Photo Gallery yourself, and import them manually into the Photo Gallery. The worse is that it thinks every import is associated to a single event. So, while importing, it prompts for a tag name, and the tag name is used as the folder name, and all the photos go into this folder. Forget about fixing your photos in the Photo Gallery; it doesn't know how to fix anything! Don't even try to export the photo into smaller size; it doesn't have that functionality! Go get yourself Picasa 2 from Google. It is free and does all the photo things correctly. The best thing is it runs on 2000/XP/Vista.
- Navigation in Vista is a nightmare. Everything is layered deep within who knows what. I felt like I am using the old Mac.
- Many features in Vista are there simply because Microsoft need to claim that Vista has just as many features as other Operating Systems. It is purely marketing, and not considering values and user friendliness of those features.
So, if you think you want Vista because it is pretty, don't get it. Stay with XP, and use all the free software out there that can give you just as many functionalities in Vista
Sunday, June 10, 2007
Creating All Parent Directories
This is the easiest way to create all parent directories.
File folder = new File(fileFolder);
// Returns true if all parent directories are created successfully.
// false otherwise.
folder.mkdirs();
Thursday, June 7, 2007
Generic HTTP Invoker Using URLConnection
Using the URLConnection to invoke any HTTP services, and return the response.
You can this sample to invoke services over HTTP protocol.
- SOAP
- JSON-RPC, or
- Just trying to retrieve a HTML page.
URL url = new URL(urlStr);
URLConnection urlConn = url.openConnection();
// Set the timeout.
urlConn.setConnectionTimeout(timeout * 1000);
urlConn.setReadTimeout(timeout * 1000);
// Specify the MIME type.
// text/xml for SOAP
// text/plain, etc
urlConn.setRequestProperty("Content-type", contentType);
// Expected response MIME.
urlConn.setRequestProperty("Accept", contentType);
// Allow I/O for the connection.
urlConn.setDoInput(true);
urlConn.setDoOutput(true);
// Disable cache
urlConn.setUseCaches(false);
// No user interaction
urlConn.setAllowUserInteraction(false);
// To allow BASIC authentication
// create the Base 64 encoded credential.
String pwd = userId + ":" + password
sun.misc.BASE64Encoder base64Enc = new sun.misc.BASE64Encoder();
String encPwd = base64Enc.encode(pwd.getBytes());
urlConn.setRequestProperty("Authorization", "Basic" + encPwd);
urlConn.connect();
// Sending the request
PrintWriter writer = new PrintWriter(urlConn.getOutputStream());
writer.print(requestContent);
// Reading the response
StringBuffer sb = new StringBuffer();
String line;
while((line = in.readLine()) != null) {
sb.append(line + "\n");
}
toReturn = sb.toString();
Apache Velocity with Dynamic Template
The following code sample demonstrates how to use the Velocity Engine with dynamically create template string.
VelocityContext vctx = new VelocityContext();
// Prepare you context
...
VelocityEngine ve = new VelocityEngine();
// Make Velocity log to Log4J
ve.setProperty(Velocity.RUNTIME_LOG_LOGSYSTEM_CLASS,
"org.apache.velocity.runtime.log.SimpleLog4JLogSystem");
ve.setProperty("runtime.log.logsystem.log4j.category",
VelocityUtil.class.getName());
ve.init();
StringWriter writer = new StringWriter();
ve.evaluate(vctx, writer, VelocityUtil.class.getName(), templateString);
toReturn = writer.getBuffer().toString();
Tuesday, June 5, 2007
Embed ActiveMQ in Spring
Sample configuration to embed ActiveMQ into Spring container.
Enable the Broker
The following bean will bootstrap the broker. Obviously you need to include the configuration file correctly.
The brokerURL will indicate whether network protocols will be used for client-server communication. vm:// will default to memory-to-memory communication.
Enable the Broker
The following bean will bootstrap the broker. Obviously you need to include the configuration file correctly.
<bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
<property name="config" value="classpath:org/apache/activemq/xbean/activemq.xml"></property>
<property name="start" value="true"></property>
</bean>
Create Connection Factory
The brokerURL will indicate whether network protocols will be used for client-server communication. vm:// will default to memory-to-memory communication.
<bean id="jmsFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory" depends-on="broker">
<property name="brokerURL" value="vm://localhost"></property>
</bean>
Create JmsTemplate
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="jmsFactory"></property>
</bean>
Create the Queue
<bean id="eventQueue" class="org.apache.activemq.command.ActiveMQQueue">
<constructor-arg value="DTMS.EVENTS.QUEUE"></constructor-arg>
</bean>
Create Publisher
<bean id="eventPublisher" class="com.yee.Publisher">
<property name="jmsTemplate" ref="jmsTemplate"></property>
<property name="destination" ref="eventQueue"></property>
</bean>
Create Custom Message Listener
<bean id="eventSubscriber" class="com.yee.Subscriber">
<property name="subscribers">
<list>
<bean></bean>
</list>
</property>
</bean>
Create the Message Listener Container
<bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
<property name="connectionFactory" ref="jmsFactory"></property>
<property name="destination" ref="eventQueue"></property>
<property name="concurrentConsumers" value="5"></property>
<property name="messageListener" ref="eventSubscriber"></property>
</bean>
Sample ActiveMQ Configuration
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!-- START SNIPPET: example -->
<beans>
<!-- Allows us to use system properties as variables in this configuration file --><!--
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
-->
<broker brokerName="localhost" useJmx="false" xmlns="http://activemq.org/config/1.0">
<!-- Use the following to set the broker memory limit
<memoryManager>
<usageManager id="memory-manager" limit="20 MB"/>
</memoryManager>
-->
<!-- Use the following to configure how ActiveMQ is exposed in JMX
<managementContext>
<managementContext connectorPort="1099" jmxDomainName="org.apache.activemq"/>
</managementContext>
-->
<!-- In ActiveMQ 4, you can setup destination policies --><!--
<destinationPolicy>
<policyMap><policyEntries>
<policyEntry topic="FOO.>">
<dispatchPolicy>
<strictOrderDispatchPolicy />
</dispatchPolicy>
<subscriptionRecoveryPolicy>
<lastImageSubscriptionRecoveryPolicy />
</subscriptionRecoveryPolicy>
</policyEntry>
</policyEntries></policyMap>
</destinationPolicy>
-->
<persistenceAdapter>
<journaledJDBC journalLogFiles="5" dataDirectory="/WEB-INF/activemq-data"/>
<!-- To use a different datasource, use the following syntax : -->
<!--
<journaledJDBC journalLogFiles="5" dataDirectory="../activemq-data" dataSource="#postgres-ds"/>
-->
</persistenceAdapter>
<!--
<transportConnectors>
<transportConnector name="openwire" uri="tcp://localhost:61616" discoveryUri="multicast://default"/>
<transportConnector name="ssl" uri="ssl://localhost:61617"/>
<transportConnector name="stomp" uri="stomp://localhost:61613"/>
</transportConnectors>
--><networkConnectors>
<!-- by default just auto discover the other brokers --><!--
<networkConnector name="default-nc" uri="multicast://default"/>
--><!--
<networkConnector name="host1 and host2" uri="static://(tcp://host1:61616,tcp://host2:61616)" failover="true"/>
-->
</networkConnectors>
</broker>
<!-- This xbean configuration file supports all the standard spring xml configuration options -->
<!-- Postgres DataSource Sample Setup -->
<!--
<bean id="postgres-ds" class="org.postgresql.ds.PGPoolingDataSource">
<property name="serverName" value="localhost"/>
<property name="databaseName" value="activemq"/>
<property name="portNumber" value="0"/>
<property name="user" value="activemq"/>
<property name="password" value="activemq"/>
<property name="dataSourceName" value="postgres"/>
<property name="initialConnections" value="1"/>
<property name="maxConnections" value="10"/>
</bean>
-->
<!-- MySql DataSource Sample Setup -->
<!--
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost/activemq?relaxAutoCommit=true"/>
<property name="username" value="activemq"/>
<property name="password" value="activemq"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
-->
<!-- Oracle DataSource Sample Setup -->
<!--
<bean id="oracle-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"/>
<property name="url" value="jdbc:oracle:thin:@localhost:1521:AMQDB"/>
<property name="username" value="scott"/>
<property name="password" value="tiger"/>
<property name="poolPreparedStatements" value="true"/>
</bean>
-->
<!-- Embedded Derby DataSource Sample Setup -->
<!--
<bean id="derby-ds" class="org.apache.derby.jdbc.EmbeddedDataSource">
<property name="databaseName" value="derbydb"/>
<property name="createDatabase" value="create"/>
</bean>
-->
</beans>
<!-- END SNIPPET: example -->
Command Prompt Here
Every time I get a new computer, I always have to search the net to find out how to put Command Prompt Here in Windows Explorer.
The following method is the easiest I found.
- Open a new instance of Windows Explorer.
- Go to Tools -> Folder Options -> File Types.
- Look for Extensions = (NONE), and File Types = Folder in the Registered file types.
- Click on Advanced.
- In the Edit File Type dialog, click on New.
- In the New Action dialog set Action = Command Prompt Here, and Application used to perform action = cmd.exe.
- Find your self out from the dialogs.
- Now you should have the Command Prompt Here when you right click on a folder in Windows Explorer.
Subscribe to:
Comments (Atom)