tumblr counter

Add HTTP Headers To SOAP Request Using CXF

Add HTTP Headers To SOAP Request Using CXF

Add HTTP Headers to a SOAP Request Using CXF explains about step by step details of setting custom http headers to a SOAP Request and retrieve the headers in server side by using CXF.

Message message = PhaseInterceptorChain.getCurrentMessage();
SoapMessage soapMessage = (SoapMessage) message;
List list = soapMessage.getHeaders(); 
for (Header header : list) { 
  System.out.println("Country: "+((Element)header.getObject()).getTextContent()); 
}

On above code, we are getting list of header from SoapMessage

CXF WS-Discovery Example

CXF WS-Discovery Example

CXF WS-Discovery Example explain about configuring WS-Discovery service with Apache CXF.

Web Services Dynamic Discovery (WS-Discovery) is a protocol, which enable dynamic discovery of services available on the local network. By default, WS-Discovery uses a UDP based multicast transport to announce new services

Apache CXF  is a free and open source project, and a fully featured Webservice framework. It helps you building webservices using different front-end API's, like as JAX-RS and JAX-WS.

WS-Discovery is available from Apache CXF 2.7.x onwards.

Reference-> http://cxf.apache.org/docs/ws-discovery.htm

CXF WS-Discovery Client

CXF WS-Discovery Client

CXF WS-Discovery Client explains step by step details of discovering a JAX-WS service using CXF WS-Discovery feature

For Creating Apache CXF WS-Discovery Client, We are using org.apache.cxf.ws.discovery.WSDiscoveryClient. WSDiscoveryClient is an in built CXF class

Which helps us to search the services on the network and invoke the operation on that available service.

 

 

Java ProcessBuilder Example

Java ProcessBuilder Example

In this Java ProcessBuilder Example, We are showing how to run external programs and operating system commands with the help of ProcessBuilder.

We can use this java API if your JDK is above 1.5.

Each process builder manages these process attributes:

  • command, It is a list of string, each string should be a valid operating system command (see the below example)
  • environment, This will returns a copy of the environment of the current process, we are invoked.
  • working directory, It's current working directory of the process.
  • Input/Output, redirectinput/redirectOutput is for redirecting output to other resources (see the below example)

Reference-> http://docs.oracle.com/javase/7/docs/api/java/lang/ProcessBuilder.html

Get/Find All Months Using Java API

Get/Find All Months Using Java API

In this example we are showing How To Display all Months Using Java API

DateFormatSymbols is a public class for encapsulating localizable date-time formatting data, such as the names of the months, the names of the days of the week, and the time zone data. DateFormat and SimpleDateFormat both use DateFormatSymbols to encapsulate this information.

Reference -> http://docs.oracle.com/javase/7/docs/api/java/text/DateFormatSymbols.html

Following are the important methods avaialbe on DateFormatSymbols class

Note

The method DateFormatSymbols.getMonths() returns the array of all months. We can iterate this array and able to view the different months.

The method DateFormatSymbols.getShortMonths() returns the array of all months in short codes. We can iterate this array and able to view the different shortmonths

The method DateFormatSymbols(Locale.FRENCH).getMonths() returns the array of all months in FRENCH Locale. We can iterate this array and able to view the different months in appropriate Locale

The method DateFormatSymbols(Locale.FRENCH).getShortMonths() returns the array of all short months in FRENCH Locale. We can iterate this array and able to view the different shortmonths in FRENCH Locale

 

Java Currency Conversion Example

Java Currency Conversion Example

In this example we are going to implement Currency Conversion Using Java.

For converting money from one currency to another, we need to find the exchange rate between that currencies.

Mostly exchange rates are fluctuating in daily basis. Here we are using Yahoo Finance API online service for finding exchange rates

You can see more features about the API here -> http://finance.yahoo.com/currency-converter

Get/Find All Possible Currencies Using Java API

Get/Find All Possible Currencies Using Java API

In this example we are generating all possible currencies using Java.

Locale.getAvailableLocales()

The method Locale.getAvailableLocales() returns the array of Locale values. We can iterate this array of Locale and able to view the different countries available as per the Locale.

We can also use Currency.getInstance(locale).getCurrencyCode() method to find the currency code for each country

How To Generate UUID In Java

How To Generate UUID In Java

In this example we are generating UUID using java API. We can use this java API if your JDK is above 1.5.

Following are the important methods avaialbe on UUID class

Note String toString(), This method will returns a String object representing this UUID.
int variant(), This method will returns the variant number associated with this UUID.
int version(), This method will returns the version number associated with this UUID.