1.18.2018

How to reset Postgres Primary Key Sequence?

In Postgres auto incrementing primary keys are defined using SERIAL PRIMARY KEY. These primary keys are tied to a sequence when defined and hence we need to ALTER the sequence . . .

ALTER SEQUENCE ca_kw_kw_id_seq RESTART WITH 1;
UPDATE ca_kw SET kw_id=nextval('ca_kw_kw_id_seq');

How to Exit from Postgres Command Line?

\q is your command to quit.

I tried to guess the first time by running quit, exit, Ctrl+c with out any luck. Hope this saves some time for others.

How to connect to a Postgres instance from Command Line / Terminal?

The following steps will explain on how to connect to your Postgres instance from command line or terminal if you are using Mac.

1. Make sure you have Postgres installed
2. From command line run the following command

psql -h localhost -p5432 -U superuser postgres

options:
-h host
-p port (default 5432)
-U username (default your machine login)
database (default postgres)

3. Enter the password when prompted for. This is either the one you created during Postgres installation or your machine login password
4. Now Type "helpfor help or \h for help with SQL commands or \? for help with psql commands

1.09.2018

Node js Timezone using Moment

There seems to be no better way of manipulating timezones in javascript. So far I found Moment.js library to be decent. I used it in my node.js projects.

Easy install: Assuming you have node/npm installed, to install moment js library run npm install moment from command line.

Straightforward code:

var moment = require('moment-timezone');
moment.tz.setDefault('America/Chicago'); // default is UTC if you don't set anything
var formattedDate = moment('2018-01-09').format('YYYY-MM-DD'); //formats and converts to the default timezone set above
console.log(formattedDate);

Simple and and easy to use. Have fun manipulating date-time in your javascript code.

11.03.2013

Spring + Hibernate + @Transaction

Error : "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"

Assuming everything is in place as per the docs/tutorials out there one could almost miss this little thing.

only looks for @Transactional on beans in the same application context it is defined in.
This means that, if you put in a WebApplicationContext for a DispatcherServlet, it only checks for @Transactional beans in your controllers, and not your services.


10.03.2013

Spring Scheduling

Use of annotations -  @EnableScheduling and @Scheduled
@EnableScheduling - Enables Spring's scheduled task execution capability. Declare this annotation on @Configuration classes and this enables detection of @Scheduled
@Configuration
 @EnableScheduling
 public class AppConfig {
     // various @Bean definitions
 }
 
@Scheduled - Three flavors 
@Scheduled(fixedDelay =30000)
public void execute() {//Do Something here }
@Scheduled(fixedRate=30000)
public void execute() {//Do Something here }
@Scheduled(cron="0 0 * * * *")
public void execute() {//Do Something here} 
 



Cron expressions

  • "0 0 * * * *" = the top of every hour of every day.
  • "*/10 * * * * *" = every ten seconds.
  • "0 0 8-10 * * *" = 8, 9 and 10 o'clock of every day.
  • "0 0/30 8-10 * * *" = 8:00, 8:30, 9:00, 9:30 and 10 o'clock every day.
  • "0 0 9-17 * * MON-FRI" = on the hour nine-to-five weekdays
  • "0 0 0 25 12 ?" = every Christmas Day at midnight
  • "0 30 14 * * ?"=every day at 2:30 PM

4.26.2012

CLASSPATH

-classpath option with a SDK
Enables you to set the CLASSPATH for each individual application.


CLASSPATH environment variable
CLASSPATH available for all applications by default.

The CLASSPATH environment variable is modified with the set command. 
set CLASSPATH=path1;path2 ...
Wildcard character *
Equivalent to specifying a list of all the files in the directory with the extension .jar or .JAR. For example, the class path entry srb/* specifies all JAR files in the directory named srb.
Subdirectories are not searched


Precede the CLASSPATH with a period(.)
Causes java.lang.NoClassDefFoundError Applies only when the JAR file is in the current directory.

Note:You do not need to reboot. Bring up a new command prompt.


Ref: http://docs.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html

12.01.2011

WSDL

Web Service Description Language - XML based | Location | Description


Key Elements
types
Data types | XML Schema
message
Data Elements(request & response) of an Operation
porttype Equals to a Class in Java
Description | List of Operations(methods) | Messages(request & response) Involved
binding
Message format | Protocol details

11.30.2011

Java Web Services


Specifications/APIs
JAX-RPC - Specification/API for Java developers to develop SOAP based interoperable web services. This API is now obsolete
JAX-WS - Successor to JAX-RPC. It requires Java 5.0, and is not backwards-compatible to JAX-RPC
JAX-RS - Java API for RESTful web services
SAAJ - API for using SOAP envelopes with or without attachments. It operates on a lower level than JAX-RPC or JAX-WS, both of which will use SOAP envelopes based on SAAJ if needed

Apache Axis/Axis2
Apache CXF
Apache SOAP
JWSDP - Sun Java Webservices Developer Pack, is an implementation of JAX-RPC, SAAJ and various other XML Java technologies. It is now deprecated in favor of the Metro stack.
Metro - Web services stack used in GlassFish?. It supports SAAJ, JAX-WS, WS-Security and other standards.
Jersey - Jersey is the reference implementation of the JAX-RS API, as defined in the JSR-311
GlassFish - Open source reference implementation of J2EE 5 with JAX-WS
Spring Web Services

Web Service

Definitions
  • A service is a software component provided through a network-accessible endpoint. The service consumer and provider use messages to exchange invocation request and response information in the form of self-containing documents that make very few assumptions about the technological capabilities of the receiver.
  • Web services is a computing technique that exploits XML to exchange data or information between computers and computer programs.
  • A Web service is a software component that is described in XML and Web Services Description Language (WSDL). You can access Web services through standard network protocols, typically SOAP over HTTP.
  • A software system designed to support interoperable machine-to-machine interaction over a network.
Platform
 XML + HTTP
Platform elements
SOAP (Simple Object Access Protocol)
           XML based |  Protocol | Platform & Language Independent
UDDI (Universal Description, Discovery and Integration)

           Directory | Register | Search 
WSDL (Web Services Description Languagehttp://srbtechlog.blogspot.com/2011/12/wsdl.html
           XML based | Location | Description


Types of Web Services

11.29.2011

Axis vs Axis2 vs CXF vs Spring Webservices

Axis or the Axis1.x - Open source webservice framework, implementation of the SOAP server, APIs for generating client/server side code for webservices.
Also ref: http://srbtechlog.blogspot.com/2011/06/apache-axis-commands.html


Axis2 - the next level of Axis1.x
Favors stand alone webservice applications.
Supported Data Bindings:XMLBeans, JiBX, JaxMe and JaxBRI, ADB(Axis native Data Binding)
JaxME and JaxBRI are still considered experimental in Axis2 1.2
Supports WS-Addressing, WS-RM, WS-Security, and WS-I BasicProfile.


CXF - Celtix + XFire
Emphasizes code-first/contract-last design
Spring friendly
Supported Data Bindings:JAXB and Aegis; support for XMLBeans, JiBX and Castor will come in CXF 2.1.
Supports WS-Addressing, WS-Policy, WS-RM, WS-Security, and WS-I BasicProfile.


Spring Web Services
Document driven
Contract-first/code-last SOAP Services
Loose coupling between contract and implementation
Supports JAXB 1 and 2, Castor, XMLBeans, JiBX, and XStream
Implements WS-Security, Integrates with Spring Security (Acegi)


Axis2 can be configured to work with Spring
Integration takes place when Spring supplies one of its pre-loaded beans to the Axis2 Message Receiver defined in the AAR services.xml. Axis2 typically uses reflection to instantiate the ServiceClass defined in the services.xml used by the Message Receiver. Alternatively, you can define a ServiceObjectSupplier that will supply the Object.
Ref: http://axis.apache.org/axis2/java/core/docs/spring.html

6.22.2011

JAX-RPC vs JAX-WS vs JAX-B

JAX-RPC - Java API for XML-based RPC is an API intended for Web service accessibility and interoperability through Java APIs.
JAX-WS 2.0 is an evolution to JAX-RPC.
JAXB constitutes a convenient framework for processing XML documents.
JAX-WS uses JAXB (the Java Architecture for XML Binding) 2.0, to do its data mapping.
JAX-RPC has it's own data mapping feature.
JAX-RPC 2.0 was renamed JAX-WS 2.0 
JAX-RPC 1 is deprecated with Java EE 6
Mapping arrays from XML to Java differs between JAX-RPC and JAXB - JAXB uses the new generic Java feature.

How to fix a corrupted workspace ?


Recently my workspace started behaving a little weird, it was all functional last week but wasn't responding at all when I tried bringing it up on a slow Monday morning. Thought would give it more time as it's Monday, but no luck ...finally, after spending a couple of hours on google, landed at this post 'Recovering a corrupted Eclipse Workspace' by James Hawes.

Listing the same here for future reference.
  • Shutdown/kill Eclipse/RAD
  • Navigate to your workspace
  • Navigate to /.metadata/.plugins/ (C:\rad\workspace\.metadata\.plugins)
  • remove org.eclipse.core.resources (command: rm -r -f org.eclipse.core.resources)
  • Start Eclipse/RAD in clean mode (Right click on the RAD/Eclipse shortcut-> properties-> change the target to include a -clean at the end. eg: "C:\IBM\RAD75\eclipse.exe -product com.ibm.rational.rad.product.v75.ide -clean" )
  • Launch the corrupted workspace
  • Re-import your projects; you should be able to re-import all projects straight from the same workspace directory.
  • Let the workspace refresh..clean..build…DONE!

Apache Axis Commands

The following are the commands to generate a wsdl from a Java Interface/Class and Java Classes (Server/Client) from a WSDl.


Before getting started download the latest Axis from the Apache site and unzip it to your C drive. Now place your wsdl/xsds in the following directory: "C:\axis-1_4\wsdl" and open command prompt and change the directory to this 'wsdl' directory where you just dropped your wsdl/xsd.  ( cd "C:\axis-1_4\wsdl" ).

Also change your calsspath to include Axis and then run the following command(s).

:::: JAVA 2 WSDL ::::

java org.apache.axis.wsdl.Java2WSDL -o srb.wsdl -l"http://www.blogger.com:8080/services/srb" -n "urn:srbService" -p"com.blogger.service.srb" "urn:srbService" com.blogger.service.srb.SRBService
Note: The generated wsdl file also contains the xsd, you need manually separate the xsd if you prefer a separate xsd file.

:::: WSDL 2 JAVA ::::

java org.apache.axis.wsdl.WSDL2Java fileName.wsdl --wrapArrays

java org.apache.axis.wsdl.WSDL2Java --server-side --skeletonDeploy true fileName.wsdl




1.28.2009

a funky clock on the home page

Adding a pretty little clock on to.....wherever you like.....



Adding these is so simple.
Go to the following link
Get A Clock
and view all the available clocks and click on the "View Html Tag" button.
Copy the java script and thats it. Your clock is all set.

So try to be on time from now !!