Thursday, July 16, 2009

Using javax.swing.JDialog




public class MyDiaglog extends JDialog {
private JButton jButton1 = new JButton();
private JTextField jTextField1 = new JTextField();

public MyDiaglog() {
this(null, "", false);
setVisible(true);
}

public MyDiaglog(Frame parent, String title, boolean modal) {
super(parent, title, modal);
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}

private void jbInit() throws Exception {
this.setSize( new Dimension( 400, 300 ) );
this.getContentPane().setLayout( null );
jButton1.setText("jButton1");
jButton1.setBounds(new Rectangle(270, 50, 73, 22));
jTextField1.setBounds(new Rectangle(130, 85, 110, 20));
this.getContentPane().add(jTextField1, null);
this.getContentPane().add(jButton1, null);
jButton1.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
}
private void jButton1_actionPerformed(ActionEvent e)
{
jTextField1.setText("hello");
}
}

using ThreadLocal()


Have you ever needed variables that were local to the scope of a thread, where each thread managed its storage, and it would be impossible for one thread to access the state information of another thread?


import java.util.Random;

public class ThreadLocal1 {

// Define/create thread local variable
static ThreadLocal threadLocal =
new ThreadLocal();
// Create class variable
static volatile int counter = 0;
// For random number generation
static Random random = new Random();

// Displays thread local variable, counter,
// and thread name
private static void displayValues() {
System.out.println (
threadLocal.get() + "\t" + counter +
"\t" + Thread.currentThread().getName());
}

public static void main (String args[]) {

// Each thread increments counter
// Displays variable info
// And sleeps for the random amount of time
// Before displaying info again
Runnable runner = new Runnable() {
public void run() {
synchronized(ThreadLocal1.class) {
counter++;
}
threadLocal.set(
new Integer(random.nextInt(1000)));
displayValues();
try {
Thread.sleep (
((Integer)threadLocal.get()).intValue());
displayValues();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};

// Increment counter, access thread local from
// a different thread, and display the values
synchronized(ThreadLocal1.class) {
counter++;
}
threadLocal.set(
new Integer(random.nextInt(1000)));
displayValues();

// Here's where the other threads
// are actually created
for (int i=0; i<5; i++) {
Thread t = new Thread(runner);
t.start();
}
}
}

Wednesday, June 24, 2009

JSR-227 Standard Data Binding & Data Access Facility

The JSR-227 is the result of Oracle work and development of the ADF Data Binding model.

What is JSR-227: http://www.oracle.com/technology/tech/java/newsletter/articles/jsr227_interview.html

There is some concerns about the scope of this JSR:
http://www.theserverside.com/news/thread.tss?thread_id=20274

But if you use ADF Data binding you may want to see this video:
http://www.parleys.com/display/PARLEYS/Home#slide=17;talk=7857;title=JSR-227%20Standard%20Data%20Binding

Friday, June 5, 2009

Web Service Security using Security Token Service (STS)

Securing a single web service can be done at transport level using SSL or at message level using the web Services Security protocol (WS-Security). Both of these solutions may involve the creation and use of cryptographic certificates (x509) on client and server.

if this approach works fine in an end point to end point perspective it may quickly becomes difficult to maintain this solution at an enterprise level when the number of services increase in volume and when web services are distributed in different locations.

Maintenance, monitoring, and administration becomes a key factor at a enterprise level.

The need for a integrated security solution for web services is increasing.

The following links introduce an enterprise solutions based on the security Token Service solution (STS).

Very good white paper (read the introduction part): Web Service Security Guide for Enhancements 3.0 (source Microsoft)
http://msdn.microsoft.com/en-us/library/aa480545.aspx


Single Sign On Service based on tokens

http://www.theserverside.com/tt/articles/article.tss?l=Systinet-web-services-part-6
http://www.sun.com/software/products/opensso_enterprise/index.xml

The token standard: SAML http://en.wikipedia.org/wiki/SAML_2.0

Token aware Firewalls: http://www.layer7tech.com/main/products/xml-firewall.html


Other good articles a bit older:

web service Security, part 1
http://www.xml.com/pub/a/ws/2003/03/04/security.html
web service Security, part 2
http://webservices.xml.com/pub/a/ws/2003/04/01/security.html
web service Security, part 3
http://webservices.xml.com/pub/a/ws/2003/05/13/security.html
web service Security, part 4
http://webservices.xml.com/pub/a/ws/2003/07/22/security.html

Thursday, May 21, 2009

Oracle Magazine Archives

http://www.oracle.com/technology/oramag/oracle/index.html

Oracle Securing Web services

A web service can be secured at the transport level (eg https) or at the message level (WS-Security).

Setting https on Oc4j standalone
https:
http://technology.amis.nl/blog/268/quick-and-easy-ssl-in-oc4j-standalone
http://tugdualgrall.blogspot.com/2006/10/using-https-with-web-services.html
http://www.coderanch.com/t/224567/Web-Services/java/Connecting-HTTPS-webservice-through-oracle

Note that when setting default-web-site.xml and secure-web-site.xml make also sure to include shared="true" to the applications or web services that need to support https.



Finally when generating the keystore file and answering to the question what is your first and last name, put there the domain of the application server.

WS-Security:

http://www.oracle.com/technology/oramag/oracle/05-jan/o15web.html
http://www.oracle.com/technology/oramag/oracle/05-mar/o25web.html


Also when oc4j supports http and https and you want to be able to switch from http to https without restarting a session you will follow these instruction to update to orion-web.xml of the application:

Set the cookie domain if shared="true" and the default ports are not used. When the client interacts with a Web server over separate ports, the cookie believes that each separate port denotes a separate Web site. If you use the default ports of 80 for HTTP and 443 for HTTPS, the client recognizes these as two different ports of the same Web site and creates only a single cookie. However, if you use nondefault ports, the client does not recognize these ports as part of the same Web site and will create separate cookies for each port, unless you specify the cookie domain.
Cookie domains track the client's communication across multiple servers within a DNS domain. If you use nondefault ports for a shared environment with HTTP and HTTPS, set cookie-domain in the element in the orion-web.xml file for the application. The cookie-domain attribute contains the DNS domain with at least two components of the domain name provided:

The top down web service approach with Jdeveloper

Create xml schema and WSDL file and then generate the java classes from it.

http://www.oracle.com/technology/obe/obe1013jdev/10131/10131_wstopdown/wstopdown.htm

Tuesday, April 28, 2009

Convert Java Calendar to XMLGregorianCalendar

DatatypeFactory dtf = DatatypeFactory.newInstance();
XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendar();
Calendar cal = Calendar.getInstance();
xgc.setYear(cal.get(Calendar.YEAR));
xgc.setDay(cal.get(Calendar.DAY_OF_MONTH));
xgc.setMonth(cal.get(Calendar.MONTH)+ 1);
xgc.setHour(cal.get(Calendar.HOUR_OF_DAY));
xgc.setMinute(cal.get(Calendar.MINUTE));
xgc.setSecond(cal.get(Calendar.SECOND));
xgc.setMillisecond(cal.get(Calendar.MILLISECOND));
// Calendar ZONE_OFFSET and DST_OFFSET fields are in milliseconds.
int offsetInMinutes = (cal.get(Calendar.ZONE_OFFSET) + cal.get(Calendar.DST_OFFSET)) / (60 * 1000);xgc.setTimezone(offsetInMinutes);



Simpler option:


GregorianCalendar gc = new GregorianCalendar();
DatatypeFactory dtf = DatatypeFactory.newInstance();
XMLGregorianCalendar xgc = dtf.newXMLGregorianCalendargc);
==================================================