Archive: ‘apache’ Category

Wink – A framework for RESTful web services from Apache

No comments February 26th, 2010

Apache Wink 1.0 is a complete Java based solution for implementing and consuming REST based Web Services. The goal of the Wink framework is to provide a reusable and extendable set of classes and interfaces that will serve as a foundation on which a developer can efficiently construct applications.

Wink consists of a Server module for developing REST services, and of a Client module for consuming REST services. It cleanly separates the low-level protocol aspects from the application aspects. Therefore, in order to implement and consume REST Web Services the developer only needs to focus on the application business logic and not on the low-level technical details.

This Info has taken from Apache Wink official site: Click Here

REST Web Service design structure

The Wink Server module is a complete implementation of the JAX-RS v1.0 specification. On top of this implementation, the Wink Server module provides a set of additional features that were designed to facilitate the development of RESTful Web services.

The Wink Client module is a Java based framework that provides functionality for communicating with RESTful Web services. The framework is built on top of the JDK HttpURLConnection and adds essential features that facilitate the development of such client applications.

How to create a RESTful service using Wink? [Coming soon - next post :-) ]

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 4% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Creating Web services using Apache CXF (Part 4): Testing

16 comments June 11th, 2009

To test this we can follow the same client program which is given in the CXF site.

Just create a simple Java class and execute it.

   1: package com.your.company.service.client;
   2:
   3: import java.util.List;
   4:
   5: import org.apache.cxf.interceptor.LoggingInInterceptor;
   6: import org.apache.cxf.interceptor.LoggingOutInterceptor;
   7: import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;
   8:
   9: import com.your.company.service.Product;
  10: import com.your.company.service.ProductService;
  11:
  12: public final class Client {
  13:
  14:     private Client() {
  15:     }
  16:
  17:     public static void main(String args[]) throws Exception {
  18:
  19:         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  20:
  21:         factory.getInInterceptors().add(new LoggingInInterceptor());
  22:         factory.getOutInterceptors().add(new LoggingOutInterceptor());
  23:         factory.setServiceClass(ProductService.class);
  24:         factory.setAddress("http://localhost:8080/CXFExample/productservice");
  25:         ProductService client = (ProductService) factory.create();
  26:
  27:         List<Product> products = client.getProducts();
  28:         if (products != null && products.size() > 0)
  29:             System.out.println("Product Name : "
  30:                     + products.get(0).getItemName() + ", Price: "
  31:                     + products.get(0).getPrice());
  32:         System.exit(0);
  33:
  34:     }
  35:
  36: }

Other related posts:

1. Creating Web services using Apache CXF (Part 1) : The Basics.

2. Creating Web services using Apache CXF (Part 2) : Development.

3. Creating Web services using Apache CXF (Part 3) : Configuration.

4. Creating Web services using Apache CXF (Part 4): Testing.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 17% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Creating Web services using Apache CXF (Part 3): Configurations

13 comments June 11th, 2009
  • Web.xml Declarations

We have to declare Spring Context Listener, CXF Servlet, Spring Context Location and URL Mapping.

   1: <?xml version="1.0" encoding="UTF-8"?>
   2: <web-app id="services" version="2.5"
   3:     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
   4:     xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   5:     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
   6:         http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
   7:
   8:     <!-- Adding the Spring Context Listener. It will help to init Spring Context -->
   9:     <listener>
  10:         <listener-class> org.springframework.web.context.ContextLoaderListener
  11:         </listener-class>
  12:     </listener>
  13:
  14:     <!-- Context file location of Spring -->
  15:     <context-param>
  16:         <param-name>contextConfigLocation</param-name>
  17:         <param-value>/WEB-INF/applicationContext.xml</param-value>
  18:     </context-param>
  19:
  20:     <!-- CXF Servlet -->
  21:     <servlet>
  22:         <servlet-name>CXFServlet</servlet-name>
  23:         <servlet-class> org.apache.cxf.transport.servlet.CXFServlet
  24:         </servlet-class>
  25:     </servlet>
  26:
  27:     <!-- Mapping with a URL Pattern -->
  28:     <servlet-mapping>
  29:         <servlet-name>CXFServlet</servlet-name>
  30:         <url-pattern>/*</url-pattern>
  31:     </servlet-mapping>
  32: </web-app>
  • Application Context configurations
   1: <?xml version="1.0" encoding="UTF-8"?>
   2: <beans xmlns="http://www.springframework.org/schema/beans"
   3:     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
   4:     xmlns:cxf="http://cxf.apache.org/core" xmlns:jaxws="http://cxf.apache.org/jaxws"
   5:     xsi:schemaLocation="http://www.springframework.org/schema/beans
   6:         http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
   7:         http://www.springframework.org/schema/context
   8:         http://www.springframework.org/schema/context/spring-context-2.5.xsd
   9:         http://cxf.apache.org/core
  10:         http://cxf.apache.org/schemas/core.xsd
  11:         http://cxf.apache.org/jaxws
  12:         http://cxf.apache.org/schemas/jaxws.xsd"
  13:     default-autowire="byName">
  14:
  15:     <!-- Load CXF modules from cxf.jar -->
  16:     <import resource="classpath:META-INF/cxf/cxf.xml" />
  17:     <import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
  18:     <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
  19:
  20:     <!-- The service bean -->
  21:     <bean id="productServiceImpl" class="com.your.company.service.ProductServiceImpl" />
  22:
  23:     <!-- Aegis data binding -->
  24:     <bean id="aegisBean" class="org.apache.cxf.aegis.databinding.AegisDatabinding"
  25:         scope="prototype" />
  26:     <bean id="aegis-service" class="org.apache.cxf.jaxws.support.JaxWsServiceFactoryBean"
  27:         scope="prototype">
  28:         <property name="dataBinding" ref="aegisBean" />
  29:         <property name="serviceConfigurations">
  30:             <list>
  31:                 <bean class="org.apache.cxf.jaxws.support.JaxWsServiceConfiguration" />
  32:                 <bean class="org.apache.cxf.aegis.databinding.AegisServiceConfiguration" />
  33:                 <bean class="org.apache.cxf.service.factory.DefaultServiceConfiguration" />
  34:             </list>
  35:         </property>
  36:     </bean>
  37:
  38:     <!-- Service endpoint -->
  39:     <jaxws:endpoint id="productService"
  40:         implementorClass="com.your.company.service.ProductServiceImpl"
  41:         implementor="#productServiceImpl" address="/productservice">
  42:         <jaxws:serviceFactory>
  43:             <ref bean="aegis-service" />
  44:         </jaxws:serviceFactory>
  45:     </jaxws:endpoint>
  46:
  47:         <!-- Enable message logging using the CXF logging feature -->
  48:     <cxf:bus>
  49:         <cxf:features>
  50:             <cxf:logging />
  51:         </cxf:features>
  52:     </cxf:bus>
  53: </beans>

Create a WAR out of this Project and deploy it in Apache Tomcat. And try to access the WSDL URL

http://localhost:8080/CXFExample/ProductService?wsdl.

Other related posts:

1. Creating Web services using Apache CXF (Part 1) : The Basics.

2. Creating Web services using Apache CXF (Part 2) : Development.

3. Creating Web services using Apache CXF (Part 3) : Configuration.

4. Creating Web services using Apache CXF (Part 4): Testing.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 22% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Creating Web services using Apache CXF (Part 2): Development

15 comments June 10th, 2009

We need to set-up the project  environment first. Please download the following JARs.

Versions Used :

CXF 2.2.2           Download Link : CXF Site Download Link

Spring 2.5.6       Download Link : SpringSource Download site

The following jars are required for all CXF usage: But you will be getting it through CXF Download.
- cxf.jar
- commons-logging.jar
- geronimo-activation.jar (Or the Sun equivalent) [6]
- geronimo-annotation.jar (Or the Sun equivalent) [6]
- geronimo-javamail.jar (Or the Sun equivalent) [6]
- geronimo-stax-api.jar (Or the Sun equivalent) [6]
- neethi.jar
- jaxb-api.jar  [6]
- jaxb-impl.jar
- XmlSchema.jar
- wstx-asl.jar  [6]
- wsdl4j.jar

The following jars are required for XML catalog support:
- xml-resolver.jar

For Java2WSDL and WSDL2Java:
- The above jars
- jaxb-xjc.jar
- velocity.jar
- commons-collections.jar
- commons-lang.jar

For JAX-WS support:
- geronimo-ws-metadata.jar [6]
- geronimo-jaxws_2.1_spec-1.0.jar (Or the Sun equivalent) [6]
- saaj-api.jar [6]
- saaj-impl.jar [6]
- asm.jar (semi-optional, helps with performance of wrapper types and is
required when adding JAXB annotations onto the SEI methods and
parameters.)

For XML Configuration support:
- aopalliance.jar
- spring-beans.jar
- spring-context.jar
- spring-core.jar
- spring.web.jar
- FastInfoset.jar

For standalone HTTP support:
- geronimo-servlet.jar
- jetty.jar
- jetty-util.jar
- sl4j.jar & sl4j-jdk14.jar (optional – but improves logging)
For Aegis support:
- jdom.jar (optional, if you want to map xsd:anyType to JDOM)

For WS-Security support:
- bcprov-jdk15.jar
- xalan.jar
- serializer.jar
- wss4j.jar
- xmlsec.jar

For HTTP Binding support:
- jra.jar
- jettison.jar (Needed for JSON services only)

For JAX-RS support:
- abdera*
- axiom*
- jsr311-api.jar
- jettison.jar (Needed for JSON services only)

For JMS transport
- geronimo-jms.jar (Or the Sun equivalent)
- spring-jms.jar

For CORBA support:
- antlr.jar

If you want to use Aegis databinding which is providing by CXF then:

Download :jdom-1.0.jar

For Spring you can download its latest version say 2.5.

Step 2: Creating a Project

  • Open your IDE ( I am using Eclipse) and create a Web project. Lets say with Name CXFExample.

Project

  • Create a package say “com.your.company.service”
  • Create a POJO class with a name say “Product”. And include some properties like productName etc.
   1: package com.your.company.service;
   2:
   3: import org.apache.cxf.aegis.type.java5.IgnoreProperty;
   4:
   5: public final class Product {
   6:     private String itemName;
   7:     private String category;
   8:     private double price;
   9:     private String details;
  10:
  11:     public Product() {
  12:     }
  13:
  14:     public Product(String itemName, String category, double price,
  15:             String details) {
  16:         this.itemName = itemName;
  17:         this.category = category;
  18:         this.price = price;
  19:         this.details = details;
  20:     }
  21:
  22:     public String getItemName() {
  23:         return itemName;
  24:     }
  25:
  26:     public void setItemName(String itemName) {
  27:         this.itemName = itemName;
  28:     }
  29:
  30:     public String getCategory() {
  31:         return category;
  32:     }
  33:
  34:     public void setCategory(String category) {
  35:         this.category = category;
  36:     }
  37:
  38:     public double getPrice() {
  39:         return price;
  40:     }
  41:
  42:     public void setPrice(double price) {
  43:         this.price = price;
  44:     }
  45:
  46:     @IgnoreProperty
  47:     public String getDetails() {
  48:         return details;
  49:     }
  50:
  51:     public void setDetails(String details) {
  52:         this.details = details;
  53:     }
  54:
  55: }

Note that we used one Annotation from Aegis. Its just to get some idea about that annotation. As you know Aegis is using for data binding. As the annotation denotes if we are mentioning it is not needed in the WSDL file.

  • Creating the Service Interface
   1: package com.your.company.service;
   2:
   3: import java.util.List;
   4:
   5: import javax.jws.WebParam;
   6: import javax.jws.WebService;
   7:
   8: @WebService
   9: public interface ProductService {
  10:
  11:     List<Product> getProducts();
  12:
  13:     void addProduct(@WebParam(name = "product") Product product);
  14:
  15:     public void addProducts(@WebParam(name = "products") List<Product> products);
  16:
  17: }

Here we are using @WebService annotation and @WebParam Annotations. They are JAX-WS annotations.

@WebService is using to denote this Interface as the Web Service Interface. So while creating WSDL file this will consider.

@WebParam is using to name the Arguments in the WSDL file. Default it will be like Arg0, Arg1 etc. But if we are giving some names then that will be more identifiable in the WSDL.

  • Create the Service Implementation class
   1: package com.your.company.service;
   2:
   3: import java.util.ArrayList;
   4: import java.util.List;
   5:
   6: import javax.jws.WebParam;
   7: import javax.jws.WebService;
   8:
   9: @WebService(endpointInterface = "edu.web.service.ProductService")
  10: public final class ProductServiceImpl implements ProductService {
  11:
  12:     public List<Product> getProducts() {
  13:         List<Product> products = new ArrayList<Product>();
  14:         products.add(new Product("SpringInAction", "Manning", 200,
  15:                 "Book about Spring"));
  16:         products.add(new Product("EJB3InAction", "Manning", 200,
  17:                 "Book about EJB3"));
  18:         return products;
  19:     }
  20:
  21:     @Override
  22:     public void addProduct(Product product) {
  23:         System.out.println(product);
  24:     }
  25:
  26:     @Override
  27:     public void addProducts(@WebParam(name = "products") List<Product> products) {
  28:         for (Product product : products) {
  29:             System.out.println(product);
  30:         }
  31:     }
  32: }

Here we are writing the Impls of our Interface methods. @WebService annotation is marking this class as a web service implementation

In the next PART we will be discussing about the Configurations.

Other related posts:

1. Creating Web services using Apache CXF (Part 1) : The Basics.

2. Creating Web services using Apache CXF (Part 2) : Development.

3. Creating Web services using Apache CXF (Part 3) : Configuration.

4. Creating Web services using Apache CXF (Part 4): Testing.

.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 24% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

Creating Web services using Apache CXF (Part 1) : The Basics.

16 comments June 10th, 2009

As we discussed in the previous post, CXF is the combination of two projects: Celtix developed by IONA and XFire developed by Codehaus working together at the Apache Software Foundation.

If you want an Enterprise support  for CXF then please find the following links.

Open Source FUSE Services Framework – based on CXF

FUSE open source community

FUSE Forums

CXF Developer Advantages

  • If you know Spring then CXF is too easy for you. All its configurations are in a Spring xml file. Internally CXF is reading this Spring XML as its Configuration file.JAX-WS encompasses many different areas:
    • Generating WSDL from Java classes and generating Java classes from WSDL
    • Provider API which allows you to create simple messaging receiving server endpoints
    • Dispatch API which allows you to send raw XML messages to server endpoints
  • CXF implements the JAX-WS APIs which make building web services easy.
  • Aegis Databinding (2.0.x) is a databinding library that makes development of code-first web services incredibly easy.
  • CXF enables the development of RESTful services via annotations using the HTTP Binding.

It has a lot many features more to say. Once you got your project requirements and clear with the approach which you want to follow then please have a look on this feature list. I think you definitely will choose CXF without any doubt. [I am exerting some of the features from its own site]

General
  • High Performance
  • Extensible
  • Intuitive & Easy to Use
Support for Standards
  • JAX-WS, JAX-WSA, JSR-181, and SAAJ
  • SOAP 1.1, 1.2, WS-I Basic Profile, WS-Security, WS-Addressing, WS-RM and WS-Policy
  • WSDL 1.1 and 2.0
  • MTOM
Multiple Transports, Bindings, Data Bindings, and Formats
  • Bindings: SOAP, REST/HTTP
  • Data bindings: JAXB 2.0, Aegis, XMLBeans. (Castor and JiBX will be supported in a later version of CXF)
  • Formats: XML, JSON
  • Transports: HTTP, Servlet, JMS, and Jabber transports
  • Extensibility API allows additional bindings for CXF, enabling additional message format support such as CSV and fixed record length
Flexible Deployment
  • Lightweight containers: deploy services in Tomcat or Spring-based containers
  • JBI integration: deploy as a service engine in a JBI container such as ServiceMix, OpenESB or Petals
  • SCA integration: deploy in an SCA container such as Tuscany
  • J2EE integration: deploy services in J2EE application servers such as Geronimo, JOnAS, JBoss, WebLogic, and WebSphere
  • Standalone Java client/server
Support for Multiple Programming Languages
  • Full support for JAX-WS 2.0 client/server programming model
  • JAX-WS 2.0 synchronous, asynchronous and one-way API’s
  • JAX-WS 2.0 Dynamic Invocation Interface (DII) API
  • Support for wrapped and non-wrapped styles
  • XML messaging API
  • Support for JavaScript and ECMAScript 4 XML (E4X) – both client and server
  • Support for CORBA with Yoko
  • Support for SCA withTuscany
  • Support for JBI with ServiceMix
Code Generation
  • Java to WSDL
  • WSDL to Java
  • XSD to WSDL
  • WSDL to XML
  • WSDL to SOAP
  • WSDL to service

Other related posts:

1. Creating Web services using Apache CXF (Part 1) : The Basics.

2. Creating Web services using Apache CXF (Part 2) : Development.

3. Creating Web services using Apache CXF (Part 3) : Configuration.

4. Creating Web services using Apache CXF (Part 4): Testing.

Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 37% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This