Eclipse, web projects, building for tc server on Eclipse and for regular Tomcat server
ballikayalar
sevgiinsani
I tend to forget the configuration required for building a Spring based web project for tc server on Eclipse and for regular Tomcat server because I don't do it frequently.

Here are the important points:
- Download Maven (m2eclipse), pivotal tc server, wtp (Jave EE Developer Tools, Java Web Developer Tools,
Web Developer Tools, XML Editors and Tools, XSL Developer Tools, m2e-wtp Maven Integration for WTP),
Spring Tool Suite (necessary ones, you can exclude Dashboard, tc server (previously installed), etc)

- Open Servers view (Views->Servers) and add the local Tomcat.

- If you import an existing Spring MVC Maven project, it may show an error as "HttpServletRequest cannot be resolved to a type" for jsp files.
 This is because the runtime for the web project is not set to the Tomcat installation where HttpServletRequest resides.
 Fix: Project Properties -> Targeted Runtimes -> select the installed Tomcat server.

- To produce the war file:
    You should add the the servlet-api dependency to pom.xml.
    The scope should be provided. Add it from the tomcat group, not maven's own.
  
       org.apache.tomcat
       servlet-api
       6.0.41
       provided
  


- To be able to use Apache Tomcat 8, change catalina.jar:
    org/apache/catalina/util/ServerInfo.properties file
    "http://stackoverflow.com/questions/17868232/how-to-use-tomcat-8-in-eclipse"
 and set installed facet to at least 2.5 in .settings/org.eclipse.wst.common.project.facet.core.xml.
 You can set to 3.0 for example.

    * Spring throws an exception when async support is not mentioned in web.xml (used in WebSocket apps):    workspace, an exception is thrown when the websocket using page is requested from the browser:
    "Async support must be enabled on a servlet and for all filters".

    To overcome, add "true" to all servlets and filters. web.xml version
    must be 3.0. It is explained here: http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html -> Servlet 3 Async Config

- Folders after .war is generated:

   Folder and files after maven install
- Folders before .war is generated. It runs on tc server:
Folder and files for tc server

How to convert a project to a Maven (m2eclipse) Project
ballikayalar
sevgiinsani
If an existing project is a Maven project, it should be converted to a m2eclipse project to be able to use m2eclipse utilities. To do this, right-click on the project --> Configure --> Convert to Maven Project.

Only after this, Maven utilities (build, clean, install, etc) are displayed when right-clicked --> Run As is selected.

A nice blog post about consumption provoking lifestyle
ballikayalar
sevgiinsani
http://www.raptitude.com/2010/07/your-lifestyle-has-already-been-designed/

Installing python modules to Windows 8 (64-bit)
ballikayalar
sevgiinsani
Windows installers for modules may need a registry entry of python. Python installer does not create it automatically. Create a registry entry as explained in this site: http://tech.valgog.com/2010/01/after-installing-64-bit-windows-7-at.html

Even if my python version was for 64-bit, I changed the registry as it is changed for 32-bit version, i.e. not under Wow6432Node. It worked for numpy.

I am copying it in case link dies:
#
# script to register Python 2.0 or later for use with win32all
# and other extensions that require Python registry settings
#
# written by Joakim Loew for Secret Labs AB / PythonWare
#
# source:
#
# modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html
import sys
from _winreg import *
# tweak as necessary
version = sys.version[:3]
installpath = sys.prefix
regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version)
installkey = "InstallPath"
pythonkey = "PythonPath"
pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % (
installpath, installpath, installpath
)
def RegisterPy():
try:
  reg = OpenKey(HKEY_CURRENT_USER, regpath)
except EnvironmentError as e:
  try:
      reg = CreateKey(HKEY_CURRENT_USER, regpath)
      SetValue(reg, installkey, REG_SZ, installpath)
      SetValue(reg, pythonkey, REG_SZ, pythonpath)
      CloseKey(reg)
  except:
      print "*** Unable to register!"
      return
  print "--- Python", version, "is now registered!"
  return
if (QueryValue(reg, installkey) == installpath and
  QueryValue(reg, pythonkey) == pythonpath):
  CloseKey(reg)
  print "=== Python", version, "is already registered!"
  return
CloseKey(reg)
print "*** Unable to register!"
print "*** You probably have another Python installation!"
if __name__ == "__main__":
RegisterPy()
or just inject the following REG file into your registry if you are using python 2.6 installed in C:\Python26 directory

1
2
3
4
5
6
7
8
9
10
11
12
13
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Python]
[HKEY_CURRENT_USER\Software\Python\Pythoncore]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6]
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6\InstallPath]
@="C:\\Python26"
[HKEY_CURRENT_USER\Software\Python\Pythoncore\2.6\PythonPath]
@="C:\\Python26;C:\\Python26\\Lib\\;C:\\Python26\\DLLs\\"

I changed the version to my python version and used the second method.

Injecting registry entry is simple. Just save the lines to a text file with .reg extension and double-click it.

The worst mistake in the history of the human race
ballikayalar
sevgiinsani
http://www.ditext.com/diamond/mistake.html
http://www.nytimes.com/2013/10/23/opinion/bittman-now-this-is-natural-food.html?_r=0&adxnnl=1&ref=opinion&adxnnlx=1382525110-00zAc3VYZs6Qnh1g8dJNyA

which command equivalent in Windows
ballikayalar
sevgiinsani
WMIC /OUTPUT:C:\ProcessList.txt PROCESS get Caption,Commandline,Processid

Open C:\ProcessList.txt. It should contain the command-line parameters etc.

Serendipity vs safety
ballikayalar
sevgiinsani
A good article about loss of chance element in life by Frank Bruni of NY Times:

http://www.nytimes.com/2013/09/03/opinion/bruni-traveling-without-seeing.html?ref=frankbruni&_r=0



Opening google maps in AVD and a few basic commands
ballikayalar
sevgiinsani
First, we need to have an AVD created with Google APIs.

It is done from Android SDK Manager.Install an SDK that suits with Google APIs.

You can either create a new AVD with our new SDK or edit an existing one and set the SDK to the version (target) to Google APIs - API Level .

Then you may need to install the files com.android.vending_2.2.6.apk and com.google.android.gms-1.apk.

I installed thos apks to an AVD which did not have Google APIs. The Google Maps app did not appear. Later, I changed the target as explained above. Google Maps appeared after the change. So, I am not sure whether Maps is installed by default.

Install command is: adb install com.android.vending-1.apk

Here is a tutorial for developing an app that uses maps: http://www.javacodegeeks.com/2011/02/android-google-maps-tutorial.html

Not related to the issue above, I wanted give some basic commands to work with AVDs.

android list targets
monitor: opens DDMS tool
emulator -avd htc_desire_s (or “emulator -avd -partition-size 500 -no-audio -no-boot-anim)
adb -s shell: serial number is the code given when "adb devices" is run. For this to run the AVD, that AVD should be started using emulator command.
adb devices: shows the serial numbers of the currently running emulators or connected real android devices.

HTTP request using a proxy
ballikayalar
sevgiinsani
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.getCredentialsProvider.setCredentials(new AuthScope("some.host.com", 8080), new UserPasswordCredentials("username", "password"));

HttpRequestBase method = new HttpGet(url);
method.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, 8080);

HttpResponse response = httpClient.executeMethod(method);
Tags: ,

Spring JSR-303 bean validation - 2
ballikayalar
sevgiinsani
If you want to do the validation manually, e.g. when you are using Apache CXF for REST service instead of Spring MVC, you can still validate the incoming object.

Use an org.springframework.validation.Validator and org.springframework.validation.BeanPropertyBindingResult.

@POST
@Path("/info")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public String getResponse(ContextQuery query) {
// 2nd parameter is just the name of the valiable
BeanPropertyBindingResult bindRes = new BeanPropertyBindingResult(query, "query");
validator.validate(query, bindRes);

if (bindRes.hasErrors()) {
//handle errors as explained in the previous post.
}
}

You are viewing sevgiinsani