Tuesday, December 19, 2006

Creating a SOAP message

The first step is to create a message using a MessageFactory object. The SAAJ API provides a default implementation of the MessageFactory class, thus making it easy to get an instance. The following code fragment illustrates getting an instance of the default message factory and then using it to create a message.

MessageFactory factory = MessageFactory.newInstance();
SOAPMessage message = factory.createMessage();
Parts of a Message

A SOAPMessage object is required to have certain elements, and, as stated previously, the SAAJ API simplifies things for you by returning a new SOAPMessage object that already contains these elements. So message, which was created in the preceding line of code, automatically has the following:

I. A SOAPPart object that contains

A. A SOAPEnvelope object that contains

1. An empty SOAPHeader object

2. An empty SOAPBody object


SOAPPart soapPart = message.getSOAPPart();


SOAPEnvelope envelope = soapPart.getEnvelope();

SOAPHeader header = envelope.getHeader();

SOAPBody body = envelope.getBody();

OR you can directly access a soap header llike:

SOAPHeader header = message.getSOAPHeader();

SOAPBody body = message.getSOAPBody();

This example of a SAAJ client does not use a SOAP header, so you can delete it. (You will see more about headers later.) Because all SOAPElement objects, including SOAPHeader objects, are derived from the Node interface, you use the method Node.detachNode to delete header.

header.detachNode();

Adding Content to the Body


SOAPBody body = message.getSOAPBody();

SOAPFactory soapFactory = SOAPFactory.newInstance();

Name bodyName = soapFactory.createName
("GetLastTradePrice", "m", "http://wombat.ztrade.com");


SOAPBodyElement bodyElement = body.addBodyElement(bodyName);

Name name = soapFactory.createName("symbol");

SOAPElement symbol = bodyElement.addChildElement(name);

symbol.addTextNode("SUNW");

The content that you have just added to your SOAPBody object will look like the following when it is sent over the wire:







SUNW







Getting a SOAPConnection Object

SOAPConnectionFactory soapConnectionFactory =
SOAPConnectionFactory.newInstance();


Now you can use soapConnectionFactory to create a SOAPConnection object.

SOAPConnection connection =
soapConnectionFactory.createConnection();


Sending a Message

A SAAJ client calls the SOAPConnection method call on a SOAPConnection object to send a message. The call method takes two arguments: the message being sent and the destination to which the message should go. This message is going to the stock quote service indicated by the URL object endpoint.

java.net.URL endpoint = new URL("http://wombat.ztrade.com/quotes");

SOAPMessage response = connection.call(message, endpoint);

The content of the message you sent is the stock symbol SUNW; the SOAPMessage object response should contain the last stock price for Sun Microsystems, which you will retrieve in the next section.

A connection uses a fair amount of resources, so it is a good idea to close a connection as soon as you are finished using it.

connection.close();

Getting the Content of a Message

To add content to the header, you create a SOAPHeaderElement object. As with all new elements, it must have an associated Name object, which you can create using the message's SOAPEnvelope object or a SOAPFactory object.

For example, suppose you want to add a conformance claim header to the message to state that your message conforms to the WS-I Basic Profile. The following code fragment retrieves the SOAPHeader object from message and adds a new SOAPHeaderElement object to it. This SOAPHeaderElement object contains the correct qualified name and attribute for a WS-I conformance claim header.

SOAPHeader header = message.getSOAPHeader();

Name headerName = soapFactory.createName("Claim","wsi", "http://ws-i.org/schemas/conformanceClaim/");

SOAPHeaderElement headerElement = header.addHeaderElement(headerName);

headerElement.addAttribute(soapFactory.createName("conformsTo"), "http://ws-i.org/profiles/basic1.0/");


conformance claim header has no content. This code produces the following XML header:






For a different kind of header, you might want to add content to headerElement. The following line of code uses the method addTextNode to do this.

headerElement.addTextNode("order");

Thursday, December 14, 2006

Decode Function in Oracle

Oracle/PLSQL: Decode Function
In Oracle/PLSQL, the decode function has the functionality of an IF-THEN-ELSE statement.

The syntax for the decode function is:
decode( expression , search , result [, search , result]... [, default] )
expression is the value to compare.
search is the value that is compared against expression.
result is the value returned, if expression is equal to search.
default is optional.
If no matches are found, the decode will return default. If default is omitted, then the decode statement will return null (if no matches are found).

For Example:

You could use the decode function in an SQL statement as follows:
SELECT supplier_name,
decode(supplier_id,
10000,
'IBM',
10001,
'Microsoft',
10002,
'Hewlett Packard',
'Gateway') result
FROM suppliers;
The above decode statement is equivalent to the following IF-THEN-ELSE statement:
IF supplier_id = 10000 THEN result := 'IBM';
ELSIF supplier_id = 10001 THEN result := 'Microsoft';
ELSIF supplier_id = 10002 THEN result := 'Hewlett Packard';
ELSE result := 'Gateway';
END IF;
The decode function will compare each supplier_id value, one by one.
Frequently Asked Questions
Question: One of our viewers wanted to know how to use the decode function to compare two dates (ie: date1 and date2), where if date1 > date2, the decode function should return date2. Otherwise, the decode function should return date1.
Answer: To accomplish this, use the decode function as follows:
decode((date1 - date2) - abs(date1 - date2), 0, date2, date1)
The formula below would equal 0, if date1 is greater than date2:
(date1 - date2) - abs(date1 - date2)
Question: I would like to know if it's possible to use decode for ranges of numbers, ie 1-10 = 'category 1', 11-20 = 'category 2', rather than having to individually decode each number.
Answer: Unfortunately, you can not use the decode for ranges of numbers. However, you can try to create a formula that will evaluate to one number for a given range, and another number for the next range, and so on.
For example:
SELECT supplier_id,
decode(trunc ((supplier_id - 1) / 10),
0,
'category 1',
1,
'category 2',
2,
'category 3',
'unknown') result
FROM suppliers;
In this example, based on the formula:
trunc ((supplier_id - 1) / 10
The formula will evaluate to 0, if the supplier_id is between 1 and 10.The formula will evaluate to 1, if the supplier_id is between 11 and 20.The formula will evaluate to 2, if the supplier_id is between 21 and 30.
and so on...
Question: I need to write a decode statement that will return the following:
If yrs_of_service <>= 1 and <> 5 then return 0.06
How can I do this?
Answer: You will need to create a formula that will evaluate to a single number for each one of your ranges.
For example:
SELECT emp_name,
decode(trunc (( yrs_of_service + 3) / 4),
0,
0.04,
1,
0.04,
0.06) as perc_value
FROM employees;
Helpful Tip: One of our viewers suggested combining the SIGN function with the DECODE function as follows:
The date example above could be modified as follows:
DECODE(SIGN(date1-date2), 1, date2, date1)
The SIGN/DECODE combination is also helpful for numeric comparisons e.g. Sales Bonuses
DECODE(SIGN(actual-target), -1, 'NO Bonus for you', 0,'Just made it', 1, 'Congrats, you are a winner'

Wednesday, December 13, 2006

making direct db conn

it didnt get published for some reason hopefully it will now.
import="java.sql.PreparedStatement
import="java.sql.Statement

import="java.util.Hashtable

import="javax.naming.InitialContext"


import="java.text.DecimalFormat"


import="javax.naming.Context"

import="com.jpmchase.srgt.util.SrgtProperties"

Connection conn = null;Statement s = null;
ResultSet rs = null;
PreparedStatement ps = null;
List result = null;
String prividerURL=null;
//Getting the url and datasource from srgtProperties file
String providerURL=SrgtProperties.getProperty("perf_url");
String jndiDS=SrgtProperties.getProperty("perf_srgt_ds");
System.out.println("Provider URL is :"+providerURL);
Hashtable ht = new Hashtable();
ht.put(Context.PROVIDER_URL,providerURL);
ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
InitialContext ctx = new InitialContext(ht);
javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup(jndiDS);
conn=ds.getConnection();
ps = conn.prepareStatement(sqlBuff.toString());

Monday, December 4, 2006

SCDJWS Exam Objectives

Exam Objectives

Section 1: XML Web Service Standards
1.1 Given XML documents, schemas, and fragments determine whether their syntax and form are correct (according to W3C schema) and whether they conform to the WS-I Basic Profile 1.0a.
1.2 Describe the use of XML schema in J2EE Web services.
1.3 Describe the use of namespaces in an XML document.

Section 2: SOAP 1.1 Web Service Standards

2.1 List and describe the encoding types used in a SOAP message.
2.2 Describe how SOAP message header blocks are used and processed.
2.3 Describe the function of each element contained in a SOAP message, the SOAP binding to HTTP, and how to represent faults that occur when processing a SOAP message.
2.4 Create a SOAP message that contains an attachment.
2.5 Describe the restrictions placed on the use of SOAP by the WS-I Basic Profile 1.0a.
2.6 Describe the function of SOAP in a Web service interaction and the advantages and disadvantages of using SOAP messages.

Section 3: Describing and Publishing (WSDL and UDDI)

3.1 Explain the use of WSDL in Web services, including a description of WSDL's basic elements, binding mechanisms and the basic WSDL operation types as limited by the WS-I Basic Profile 1.0a.
3.2 Describe how W3C XML Schema is used as a typing mechanism in WSDL 1.1.
3.3 Describe the use of UDDI data structures. Consider the requirements imposed on UDDI by the WS-I Basic Profile 1.0a.
3.4 Describe the basic functions provided by the UDDI Publish and Inquiry APIs to interact with a UDDI business registry.

Section 4: JAX-RPC

4.1 Explain the service description model, client connection types, interaction modes, transport mechanisms/protocols, and endpoint types as they relate to JAX-RPC.
4.2 Given a set of requirements for a Web service, such as transactional needs, and security requirements, design and develop Web service applications that use servlet-based endpoints and EJB based endpoints.
4.3 Given an set of requirements, design and develop a Web sevice client, such as a J2EE client and a stand-alone Java client, using the appropriate JAX-RPC client connection style.
4.4 Given a set of requirements, develop and configure a Web service client that accesses a stateful Web service.
4.5 Explain the advantages and disadvantages of a WSDL to Java vs. a Java to WSDL development approach.
4.6 Describe the advantages and disadvantages of web service applications that use either synchronous/request response, one-way RPC, or non-blocking RPC invocation modes.
4.7 Use the JAX-RPC Handler API to create a SOAP message handler, describe the function of a handler chain, and describe the role of SAAJ when creating a message handler. Section


5: SOAP and XML Processing APIs (JAXP, JAXB, and SAAJ)


5.1 Describe the functions and capabilities of the APIs included within JAXP.
5.2 Given a scenario, select the proper mechanism for parsing and processing the information in an XML document.
5.3 Describe the functions and capabilities of JAXB, including the JAXB process flow, such as XML-to-Java and Java-to-XML, and the binding and validation mechanisms provided by JAXB.
5.4 Use the SAAJ APIs to create and manipulate a SOAP message.

Section 6: JAXR

6.1 Describe the function of JAXR in Web service architectural model, the two basic levels of business registry functionality supported by JAXR, and the function of the basic JAXR business objects and how they map to the UDDI data structures.
6.2 Use JAXR to connect to a UDDI business registry, execute queries to locate services that meet specific requirements, and publish or update information about a business service. Section

7: J2EE Web Services

7.1 Identify the characteristics of and the services and APIs included in the J2EE platform.
7.2 Explain the benefits of using the J2EE platform for creating and deploying Web service applications.
7.3 Describe the functions and capabilities of the JAXP, DOM, SAX, JAXR, JAX-RPC, and SAAJ in the J2EE platform.
7.4 Describe the role of the WS-I Basic Profile when designing J2EE Web services.

Section 8: Security

8.1 Explain basic security mechanisms including: transport level security, such as basic and mutual authentication and SSL, message level security, XML encryption, XML Digital Signature, and federated identity and trust.
8.2 Identify the purpose and benefits of Web services security oriented initiatives and standards such as Username Token Profile, SAML, XACML, XKMS, WS-Security, and the Liberty Project.
8.3 Given a scenario, implement J2EE based web service web-tier and/or EJB-tier basic security mechanisms, such as mutual authentication, SSL, and access control.
8.4 Describe factors that impact the security requirements of a Web service, such as the relationship between the client and service provider, the type of data being exchanged, the message format, and the transport mechanism.

Section 9: Developing Web Services

9.1 Describe the steps required to configure, package, and deploy J2EE Web services and service clients, including a description of the packaging formats, such as .ear, .war, .jar, deployment descriptor settings, the associated Web services description file, RPC mapping files, and service reference elements used for EJB and servlet endpoints.
9.2 Given a set of requirements, develop code to process XML files using the SAX, DOM, XSLT, and JAXB APIs.
9.3 Given an XML schema for a document style Web service create a WSDL file that describes the service and generate a service implementation.
9.4 Given a set of requirements, develop code to create an XML-based, document style, Web service using the JAX-RPC APIs.
9.5 Implement a SOAP logging mechanism for testing and debugging a Web service application using J2EE Web Service APIs.
9.6 Given a set of requirements, develop code to handle system and service exceptions and faults received by a Web services client.

Section 10: General Design and Architecture


10.1 Describe the characteristics of a service oriented architecture and how Web services fits to this model.
10.2Given a scenario, design a J2EE service using the business delegate, service locator, and/or proxy client-side design patterns and the adapter, command, Web service broker, and/or faade server-side patterns.
10.3 Describe alternatives for dealing with issues that impact the quality of service provided by a Web service and methods to improve the system reliability, maintainability, security, and performance of a service.
10.4 Describe how to handle the various types of return values, faults, errors, and exceptions that can occur during a Web service interaction.
10.5 Describe the role that Web services play when integrating data, application functions, or business processes in a J2EE application.
10.6 Describe how to design a stateless Web service that exposes the functionality of a stateful business process.

Section 11: Endpoint Design and Architecture


11.1 Given a scenario, design Web service applications using information models that are either procedure-style or document-style.
11.2 Describe the function of the service interaction and processing layers in a Web service.
11.3 Describe the tasks performed by each phase of an XML-based, document oriented, Web service application, including the consumption, business processing, and production phases.
11.4 Design a Web service for an asynchronous, document-style process and describe how to refactor a Web service from a synchronous to an asynchronous model.
11.5 Describe how the characteristics, such as resource utilization, conversational capabilities, and operational modes, of the various types of Web service clients impact the design of a Web service or determine the type of client that might interact with a particular service.