2015. 2. 2. 23:29

Prevent symptom that debugging does not reflect latest source code

Some times eclipse did not seems to launch applications well in debugging. 


You might experience like debugging did not reflect latest source code you just edited. Though you set the break point into the line you want, next step by pressing F6 for stepping over, break point hit the wrong line. 


Mostly this is caused by not saving the source codes. By default, eclipse does not prompt before launching the application though it's not still saved.


To prevent this mistake, I recommend to set the following two option!


1. Save automatically before build


Window > Preferences > General > Workspace


  • Check 'Save automatically before build' like the following:






2. Save required dirty editors before launching : Prompt



Window > Preferences > Run/Debug > Launching


  • Set an option to 'Prompt' like the following for 'Save required dirty editors before launching' option.



This trivial two options will reduce your complaint against eclipse!



2015. 1. 15. 23:24

MVC Execution Flow



Referenced : 열혈강의 자바 웹 개발 워크북

2015. 1. 15. 22:59

JavaBeans, POJO, VO and DTO

JavaBeans


JavaBeans are reusable software components for Java that can be manipulated visually in a builder tool. Practically, they are classes written in the Java programming language conforming to a particular convention. They are used to encapsulate many objects into a single object (the bean), so that they can be passed around as a single bean object instead of as multiple individual objects. A JavaBean is a Java Object that is serializable, has a nullary constructor, and allows access to properties using getter and setter methods.

In order to function as a JavaBean class, an object class must obey certain conventions about method naming, construction, and behavior. These conventions make it possible to have tools that can use, reuse, replace, and connect JavaBeans.

The required conventions are:

  • The class must have a public default constructor. This allows easy instantiation within editing and activation frameworks.
  • The class properties must be accessible using get, set, and other methods (so-called accessor methods and mutator methods), following a standard naming convention. This allows easy automated inspection and updating of bean state within frameworks, many of which include custom editors for various types of properties.
  • The class should be serializable. This allows applications and frameworks to reliably save, store, and restore the bean's state in a fashion that is independent of the VM and platform.

Because these requirements are largely expressed as conventions rather than by implementing interfaces, some developers view JavaBeans as Plain Old Java Objects that follow specific naming 


POJO (Plain Old Java Object)


POJO is an acronym for Plain Old Java Object. The name is used to emphasize that the object in question is an ordinary Java Object, not a special object, and in particular not an Enterprise JavaBean (especially before EJB 3). The term was coined by Martin Fowler, Rebecca Parsons and Josh MacKenzie in September 2000:

"We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely."

The term continues the pattern of older terms for technologies that do not use fancy new features, such as POTS (Plain Old Telephone Service) in telephony, and PODS (Plain Old Data Structures) that are defined in C++ but use only C language features, and POD (Plain Old Documentation) in Perl.

The term has most likely gained widespread acceptance because of the need for a common and easily understood term that contrasts with complicated object frameworks. A JavaBean is a POJO that is serializable, has a no-argument constructor, and allows access to properties using getter and setter methods. An Enterprise JavaBean is not a single class but an entire component model (again, EJB 3 reduces the complexity of Enterprise JavaBeans).

As designs using POJOs have become more commonly-used, systems have arisen that give POJOs some of the functionality used in frameworks and more choice about which areas of functionality are actually needed. Hibernate and Spring are examples.


VO (Value Object)


In Patterns of Enterprise Application Architecture I described Value Object as a small object such as a Money or date range object. Their key property is that they follow value semantics rather than reference semantics.

You can usually tell them because their notion of equality isn't based on identity, instead two value objects are equal if all their fields are equal. Although all fields are equal, you don't need to compare all fields if a subset is unique - for example currency codes for currency objects are enough to test equality.

A general heuristic is that value objects should be entirely immutable. If you want to change a value object you should replace the object with a new one and not be allowed to update the values of the value object itself - updatable value objects lead to aliasing problems.

Early J2EE literature used the term value object to describe a different notion, what I call a Data Transfer Object. They have since changed their usage and use the term Transfer Object instead.

You can find some more good material on value objects on the wiki and by Dirk Riehle.


DTO (Data Transfer Object)


Data transfer object (DTO), formerly known as value objects or VO, is a design pattern used to transfer data between software application subsystems. DTOs are often used in conjunction with data access objects to retrieve data from a database.

The difference between data transfer objects and business objects or data access objects is that a DTO does not have any behaviour except for storage and retrieval of its own data (accessors and mutators).

In a traditional EJB architecture, DTOs serve dual purposes: first, they work around the problem that entity beans are not serializable; second, they implicitly define an assembly phase where all data to be used by the view is fetched and marshalled into the DTOs before returning control to the presentation tier.


2015. 1. 13. 23:03

Set up spring MVC development environment using Luna

This guide sets up Spring MVC development environment with maven


1. Download eclipse luna


http://www.eclipse.org/luna/


2. Install STS (Spring Tool Suite)


  • Run eclipse
  • Find the Help > Eclipse Marketplace menu on toolbar
  • Type 'sts' on Search tab
  • Click 'install' button which title is 'Spring Tool Suite (STS) for Eclipse Luna ~~~~
  • Restart eclipse

3. Install maven plugin

  • Find the Help > Eclipse Marketplace menu on toolbar
  • Type 'm2e' on Search tab
  • Click 'install' button which title is 'Maven Integration for Eclipse (Luna) 1.5.0'
    • If this was already installed, the buttons are Update and Uninstall. If so, skip this step.
  • Restart eclipse

4. Create Spring MVC Project

  • File > New > Project
  • Type the spring then select 'Spring Project'
  • Select the 'Spring MVC Project' template and specify a project name
  • Proceed nexts until you met the dialog that asks package name
  • Enter any package name and finish it.



2014. 12. 14. 16:56

Routing with WCF


Here is sample code for routing with WCF.



WCFRoutingServiceTest.zip







Web.config for service 


<?xml version="1.0"?>


<!--

  For more information on how to configure your ASP.NET application, please visit

  http://go.microsoft.com/fwlink/?LinkId=169433

  -->


<configuration>

  <system.web>

    <compilation debug="true" targetFramework="4.0" >

      <assemblies>

        <add assembly="System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

      </assemblies>

    </compilation>

  </system.web>

  <system.serviceModel>

    <serviceHostingEnvironment multipleSiteBindingsEnabled="true">

      <serviceActivations>

        <add relativeAddress="RiskManagementServiceUAT.svc" service="System.ServiceModel.Routing.RoutingService, System.ServiceModel.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

      </serviceActivations>

    </serviceHostingEnvironment>

    <services>

      <!--ROUTING SERVICE -->

      <service name="System.ServiceModel.Routing.RoutingService" behaviorConfiguration="routerConfig">

        <endpoint address=""

                  binding="basicHttpBinding"

                  contract="System.ServiceModel.Routing.IRequestReplyRouter"

                  name="reqReplyEndpoint" />

      </service>

    </services>


    <routing>

      <filters>

        <filter name="matchAll" filterType="MatchAll" />

      </filters>


      <filterTables>

        <filterTable name="routingTable">

          <add filterName="matchAll" endpointName="RiskService" backupList="RiskServiceBackup" />

        </filterTable>

      </filterTables>

      <backupLists>

        <backupList name="RiskServiceBackup">

          <add endpointName="RiskService2"/>

        </backupList>

      </backupLists>

    </routing>


    <behaviors>

      <serviceBehaviors>

        <behavior name="routerConfig">

          <serviceMetadata httpGetEnabled="true" />

          <serviceDebug includeExceptionDetailInFaults="true" />

          <routing routeOnHeadersOnly="false" filterTableName="routingTable" />

        </behavior>

      </serviceBehaviors>

    </behaviors>

    <client>

      <!-- Define the client endpoint(s) to route messages to -->

      <endpoint name="RiskService"

            address="http://localhost:81/Service1.svc"

            binding="basicHttpBinding"

            contract="*" />

      <endpoint name="RiskService2"

            address="http://localhost:82/Service1.svc"

            binding="basicHttpBinding"

            contract="*" />

    </client>

  </system.serviceModel>

  <system.webServer>

    <modules runAllManagedModulesForAllRequests="true"/>

  </system.webServer>

</configuration>



client.config for silverlight client  


<configuration>

    <system.serviceModel>

        <bindings>

            <basicHttpBinding>

                <binding name="BasicHttpBinding_IService1" maxBufferSize="2147483647"

                    maxReceivedMessageSize="2147483647">

                    <security mode="None" />

                </binding>

            </basicHttpBinding>

        </bindings>

        <client>

            <endpoint address="http://localhost/RiskManagementServiceUAT.svc" binding="basicHttpBinding"

                bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"

                name="BasicHttpBinding_IService1" />

        </client>

    </system.serviceModel>

</configuration> 


* I updated source to make someone to understand better.



WCFRoutingServiceTest_updated.zip



* Address filter decides where to go using client's ip address. Like the sticky session under L4 load balancer, address filter ensures client to be directed to same was.



WCFRoutingServiceTest_addressfilter.zip



References:


2014. 12. 12. 05:34

Web Garden and Web Farm

Web Garden 


Web application deployed on a server with multiple processors


Web Farm


Web application deployed on multiple server


References : http://www.youtube.com/watch?v=z4rpYK4DNoI

2014. 12. 4. 12:14

Inversion Of Control (= Hollywood Principle)

Simply it means,



"Don't call us, we'll call you."



In case of the library, you would call its API but, A framework would call your implementation. In addition, a framework would control to create and destroy an object instead of you.


Template method which is one of the GOF patterns is very related to this.


  • Helpful sites:


http://martinfowler.com/bliki/InversionOfControl.html

http://vandbt.tistory.com/43

2014. 11. 29. 05:46

Stop thread using own flag and interrupt method

Here is the sample code that explains how to stop thread using own flag and interrupt method respectively.


public class Main {

	static interface IClosableThread {
		void start();

		void close();
	}

	static class StopThreadUsingFlag extends Thread implements IClosableThread {
		private boolean stopThis = false;

		public void run() {
			try {
				while (this.stopThis == false) {
					System.out.print(".");
					Thread.sleep(500);
				}
			} catch (InterruptedException e) {
			}

			System.out.println();
			System.out.println("Finished!");
		}

		public void close() {
			this.stopThis = true;

			try {
				this.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	static class StopThreadUsingInterrupt extends Thread implements
			IClosableThread {
		public void run() {
			try {
				while (!this.isInterrupted()) {
					System.out.print(".");
					Thread.sleep(500);
				}
			} catch (InterruptedException e) {
			}

			System.out.println();
			System.out.println("Finished!");
		}

		public void close() {
			this.interrupt();

			try {
				this.join();
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) {
		System.out.println("Hello, Java!");

		IClosableThread thread = new Main.StopThreadUsingFlag();
		thread.start();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		thread.close();

		thread = new Main.StopThreadUsingInterrupt();
		thread.start();
		try {
			Thread.sleep(3000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		thread.close();

	}
}


2014. 11. 29. 05:38

AsEclipse extension

When using eclipse, ctrl + o is very usefull to move to the member within a file. AsEclipse supports this feature. 


Here are the description for AsEclipse and link to it.


AsEclipse is an add-in for MS Visual Studio, which enables you to use some convenient Eclipse editing functions in MS Visual Studio with almost the same shortcut keys. No matter whether you are familiar with Eclipse, AsEclipse will be helpful in coding with VS.

https://visualstudiogallery.msdn.microsoft.com/99ede732-544c-4f3b-8e38-49e4b8395075/


2014. 11. 29. 05:16

Shortcut to "Navigate to ..."

To find something like class, function, or file in a solution, "Navigate to..." is very useful. 


Ctrl + , 


lets you direct to that dialog.