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

Add a comment 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: 15% [?]

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

Related posts:

  1. Creating Web services using Apache CXF (Part 2): Development We need to set-up the project  environment first. Please download...
  2. Creating Web services using Apache CXF (Part 1) : The Basics. As we discussed in the previous post, CXF is the...
  3. Creating Web services using Apache CXF (Part 3): Configurations We have to declare Spring Context Listener, CXF Servlet, Spring...
  4. Apache CXF- An ultimate web service open source framework : Lets start learning… Apache CXF is an open source services framework which is...
  5. Creating Web Services using CXF (Contract first Approach) Part 2 : WSDL Creation. What is WSDL and what its Structure? A WSDL document...

Related posts brought to you by Yet Another Related Posts Plugin.

  1. June 16th, 2009 at 08:48 | #1
    Subroto

    You should add this code to Client.java:

    factory.getServiceFactory().setDataBinding(new AegisDatabinding());
    

    before factory.create(), because the server is using Aegis data binding.

  2. June 16th, 2009 at 12:45 | #2

    You are right Subroto. :)

  3. June 24th, 2009 at 14:31 | #3

    Thanks for the great post.

    One question appeared – is there any opportunity to unite few services (in some way) in order to have one wsdl file generated?
    For instance, You have service1 and service2 as 2 separate interfaces and as a result have one wsdl for both of them?

    Best,
    Taras

  4. June 24th, 2009 at 15:04 | #4

    Sure You can do that!

  1. |
    June 11th, 2009 at 16:03 | #1

    [...] Creating Web services using Apache CXF (Part 4): Testing. Possibly related posts: (automatically generated)Spring Season in ITSpring Framework 2.1 is [...]

  2. |
    June 11th, 2009 at 16:31 | #2

    [...] « Creating Web services using Apache CXF (Part 2): Development Creating Web services using Apache CXF (Part 4): Testing [...]

  3. |
    June 11th, 2009 at 16:33 | #3

    [...] Creating Web services using Apache CXF (Part 4): Testing « Lijin’s Localhost Trackback on June 11, 2009 at 4:20 [...]

  4. |
    June 11th, 2009 at 16:37 | #4

    [...] Creating Web services using Apache CXF (Part 4): Testing. Possibly related posts: (automatically generated)Apache CXF- An ultimate web service open source [...]

  5. |
    June 15th, 2009 at 12:18 | #5

    [...] Interview Guide « Creating Web services using Apache CXF (Part 4): Testing [...]

  6. |
    July 4th, 2009 at 11:42 | #6

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

  7. |
    July 4th, 2009 at 11:44 | #7

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

  8. |
    July 4th, 2009 at 11:50 | #8

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

  9. |
    July 4th, 2009 at 11:53 | #9

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

  10. |
    July 4th, 2009 at 11:55 | #10

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

  11. |
    July 4th, 2009 at 11:57 | #11

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

  12. |
    July 22nd, 2009 at 03:49 | #12

    [...] 4. Creating Web services using Apache CXF (Part 4): Testing. No Comment var addthis_pub="izwan00"; BOOKMARK This entry was posted on Thursday, June 11th, 2009 at 2:12 pm and is filed under CXF, Celtix, apache, web, webservices. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site. [...]

Comments feed