Tech Rocks

Coldfusion
Java
JQuery

An online resource for latest web technologies like Coldfusion, JRun, Pro*C, JQuery, HTML5, PHP, W3C, Java, J2EE, C, C++, ORACLE, PL/SQL, MySql, Ajax, Coldbox, Fusebox, UNIX, JavaScript, NodeJS and much more... contact@tech-rocks.org

Tuesday, December 17, 2013

Enabling SSL on the ColdFusion

Open a command prompt.

 

Execute the following command:
cd C:\ColdFusion8\runtime\jre\bin

Create the keystore with this command:
keytool -genkey -dname "cn=127.0.0.1, ou=CF, o=jeetu, L=Decatur, ST=GA, C=US" -keyalg rsa -keystore mykey

 

If you have previously configured a keystore you might run into this error:
keytool error: java.lang.Exception: Key pair not generated, alias already exists

If you got the “already exists” error run this command to list the keystores:
keytool -list -v | more

If you got the “already exists” error run this command to delete the keystore:
keytool -delete -alias mykey

If you got the “already exists” error re-run the command to create the keystore.

 

Enter in a password when prompted (2 times)

 

Move the keystore file (mykey) to C:\ColdFusion8\runtime\lib\

 

Edit the config file C:\ColdFusion8\runtime\servers\coldfusion\SERVER-INF\jrun.xml with an xml editor of choice. This file is VERY sensitive so be sure to not screw up the syntax of it. You should probably make a copy of it before you edit it.


<!-- Uncomment this service to use SSL with the JRun Web Server
Note that you MUST create your own keystore before using this service -->
<service class="jrun.servlet.http.SSLService" name="SSLService">
<attribute name="enabled">true </attribute>
<attribute name="interface">* </attribute>
<attribute name="port">9100 </attribute>
<attribute name="keyStore">{jrun.rootdir}/lib/mykey </attribute>
<attribute name="keyStorePassword">mypassword </attribute>
<attribute name="trustStore">{jrun.rootdir}/lib/trustStore </attribute>
<attribute name="socketFactoryName">jrun.servlet.http.JRunSSLServerSocketFactory </attribute>
</service>


Restart the ColdFusion application service.

 

Create a test page in the ColdFusion 8 wwwroot and opening it in a web browser using: https://127.0.0.1:9100/testpage.cfm

Wednesday, November 27, 2013

Google Chrome vs Chromium

Google Chrome Chromium Notes
Logo Colorful Blue
Crash reporting Yes, if you turn it on None Please include symbolized backtraces in bug reports if you don't have crash reporting
User metrics Yes, if you turn it on No
Video and audio tags AAC, MP3, Vorbis and Theora Vorbis and Theora by default May vary by distro
Adobe Flash custom (non-free) plugin included in release supports NPAPI plugins, including the one from Adobe
PDF support custom (non-free) plugin included in release downloads and displays with system PDF viewer The Chrome PDF plugin uses 3rd-party non-free code; no Free Software PDF plugin exists that supports all the PDF features we'd like (such as filling in forms). :(
Code Tested by Chrome developers May be modified by distributions Please include distribution information if you report bugs
Sandbox Always on Depending on the distribution (navigate to about:sandbox to confirm)
Package Single deb/rpm Depending on the distribution
Profile Kept in ~/.config/google-chrome Kept in ~/.config/chromium
Cache Kept in ~/.cache/google-chrome Kept in ~/.cache/chromium
Quality Assurance New releases are tested before sending to users Depending on the distribution Distributions are encouraged to track stable channel releases: see http://googlechromereleases.blogspot.com/ , http://omahaproxy.appspot.com/ and http://gsdview.appspot.com/chromium-browser-official/
Google API keys Added by Google Depending on the distribution See http://www.chromium.org/developers/how-tos/api-keys

Monday, November 11, 2013

URL Encoding Codes

Character

Character Name

URL Encoding

ASCII

 

Space

+ or %20

32

a-z

Lower case letters

-

97-122 (&61-&7A)

A-Z

Upper case letters

-

65-90 (&41-&5A)

0-9

Numbers

-

48-57 (&30-&39)

`

Accent Grave

%60

96

~

Tilde

%7E

126

!

Exclamation

%21

33

@

At

-

64 (&40)

#

Number Sign

%23

35

$

Dollar Sign

%24

36

%

Percent

%25

37

^

Circumflex

%5E

94

&

Ampersand

%26

38

*

Asterisk

-

42 (&2A)

(

Open Parenthesis

%28

40

)

Close Parenthesis

%29

41

-

Hyphen

-

45 (&2D)

_

Underscore

-

95 (&5F)

=

Equals

%3D

61

+

Plus

%2B

43

\

Back Slash *

%5C

92

|

Bar

%7C

124

[

Left Bracket

%5B

91

]

Right Bracket

%5D

93

{

Left Brace

%7B

123

}

Right Brace

%7D

125

;

Semi-colon

%3B

59

:

Colon

%3A

58

'

Single Quote

%27

39

"

Double Quote *

%22

34

,

Comma

%2C

44

.

Period

-

46 (&2E)

<

Less Than

%3C

60

>

Greater Than

%3E

62

/

Forward Slash

-

47 (&2F)

?

Question Mark

%3F

63

Tuesday, October 22, 2013

Open source in-memory data grid vs Oracle Coherence

Hazelcast is the leading open source in-memory data grid it provides java developers an easy-to-use and powerful solution for data distribution that can be used as a clustering solution, a distributed cache and a NoSQL key-value store. For Enterprise customers needing hundreds of nodes of distributed in-memory computing, our off-heap elastic memory provide highly scalable, highly available, low latency and highly predictable clustered memory and distributed computing.

 

Click here for more info

Spring JSR-250 Annotations

Spring has JSR-250 based annotations which include @PostConstruct, @PreDestroy and @Resource annotations.

  • @PostConstruct: This annotation can be used as an alternate of initialization callback.

  • @PreDestroy: This annotation can be used as an alternate of destruction callback.

  • @Resource : This annotation can be used on fields or setter methods. The @Resource annotation takes a 'name' attribute which will be interpreted as the bean name to be injected. You can say, it follows by-name autowiring semantics.

Spring Bean Auto wiring

The Spring container is able to autowire relationships between collaborating beans. This means that it is possible to automatically let Spring resolve collaborators (other beans) for your bean by inspecting the contents of the BeanFactory without using <constructor-arg> and <property> elements.

 

The autowiring functionality has five modes which can be used to instruct Spring container to use autowiring for dependency injection:

  • no: This is default setting which means no autowiring and you should use explicit bean reference for wiring. You have nothing to do special for this wiring. This is what you already have seen in Dependency Injection chapter.

  • byName: Autowiring by property name. Spring container looks at the properties of the beans on which autowire attribute is set to byName in the XML configuration file. It then tries to match and wire its properties with the beans defined by the same names in the configuration file.

  • byType: Autowiring by property datatype. Spring container looks at the properties of the beans on which autowire attribute is set to byType in the XML configuration file. It then tries to match and wire a property if its type matches with exactly one of the beans name in configuration file. If more than one such beans exist, a fatal exception is thrown.

  • constructor: Similar to byType, but type applies to constructor arguments. If there is not exactly one bean of the constructor argument type in the container, a fatal error is raised.

  • autodetect: Spring first tries to wire using autowire by constructor, if it does not work, Spring tries to autowire by byType.

  •  

    Limitations of autowiring are:

  • Overriding possibility: You can still specify dependencies using <constructor-arg> and <property> settings which will always override autowiring.

  • Primitive data types: You cannot autowire so-called simple properties such as primitives, Strings, and Classes.

  • Confusing nature: Autowiring is less exact than explicit wiring, so if possible prefer using explicit wiring.

  •  

    Annotation wiring is not turned on in the Spring container by default. So, before we can use annotation-based wiring, we will need to enable it in our Spring configuration file by configuring <context:annotation-config/>.

     

    Note: null and empty string values can be injected in Spring

    Inject Java Collection in Spring

    Spring offers four types of collection configuration elements which are as follows:

    • <list>: This helps in wiring i.e. injecting a list of values, allowing duplicates.

    • <set>: This helps in wiring a set of values but without any duplicates.

    • <map>: This can be used to inject a collection of name-value pairs where name and value can be of any type.

    • <props>: This can be used to inject a collection of name-value pairs where the name and value are both Strings.

    Spring Bean Lifecycle

    • Instantiate - First the spring container finds the bean's definition from the XML file and instantiates the bean..

    • Populate properties - Using the dependency injection, spring populates all of the properties as specified in the bean definition..

    • Set Bean Name - If the bean implements BeanNameAware interface, spring passes the bean's id to setBeanName() method.

    • Set Bean factory - If Bean implements BeanFactoryAware interface, spring passes the beanfactory to setBeanFactory() method.

    • Pre Initialization - Also called postprocess of bean. If there are any bean BeanPostProcessors associated with the bean, Spring calls postProcesserBeforeInitialization() method.

    • Initialize beans - If the bean implements IntializingBean,its afterPropertySet() method is called. If the bean has init method declaration, the specified initialization method is called.

    • Post Initialization - If there are any BeanPostProcessors associated with the bean, their postProcessAfterInitialization() methods will be called.

    • Ready to use - Now the bean is ready to use by the application.

    • Destroy - If the bean implements DisposableBean , it will call the destroy() method .

    Spring Container - configuration metadata

    There are following three important methods to provide configuration metadata to the Spring Container:

    • XML based configuration file.

    • Annotation-based configuration

    • Java-based configuration

    Spring Bean

    The objects that form the backbone of your application and that are managed by the Spring IoC container are called beans. A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container. These beans are created with the configuration metadata that you supply to the container, for example, in the form of XML <bean/> definitions.

     

    The bean definition contains the information called configuration metadata which is needed for the container to know the followings:

    • How to create a bean
    • Bean's lifecycle details
    • Bean's dependencies

     

    When defining a <bean> in Spring, you have the option of declaring a scope for that bean. For example, to force Spring to produce a new bean instance each time one is needed, you should declare the bean's scope attribute to be prototype. Similar way if you want Spring to return the same bean instance each time one is needed, you should declare the bean's scope attribute to be singleton.

     

    The Spring Framework supports following five scopes, three of which are available only if you use a web-aware ApplicationContext.

    • singleton: This scopes the bean definition to a single instance per Spring IoC container.
    • prototype: This scopes a single bean definition to have any number of object instances.
    • request: This scopes a bean definition to an HTTP request. Only valid in the context of a web-aware Spring ApplicationContext.
    • session: This scopes a bean definition to an HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.
    • global-session: This scopes a bean definition to a global HTTP session. Only valid in the context of a web-aware Spring ApplicationContext.

    The default scope of bean is Singleton for Spring framework and No, singleton beans are not thread-safe in Spring framework.

     

    Inner beans in Spring

    A <bean/> element inside the <property/> or <constructor-arg/> elements defines a so-called inner bean. An inner bean definition does not require a defined id or name; the container ignores these values. It also ignores the scope flag. Inner beans are always anonymous and they are always scoped as prototypes.

     

    To add a bean in spring application

    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <bean id="helloWorld" class="com.jeetu.HelloWorld">
    <property name="message" value="Hello World!"/>
    </bean>

    </beans>