Consuming a Web Service(SOAP and RESTful) in Java. Cheat Sheet For Consuming Services in Java



Similar documents
Overview of Web Services API

How to use the Eclipse IDE for Java Application Development

Onset Computer Corporation

Sophos Mobile Control Network Access Control interface guide

Introduction to Java. Module 12: Networking (Java Sockets) Prepared by Costantinos Costa for EPL 233. ΕΠΛ233 Αντικειμενοστρεφής Προγραμματισμός 1

Capario B2B EDI Transaction Connection. Technical Specification for B2B Clients

Hello World RESTful web service tutorial

Author: Gennaro Frazzingaro Universidad Rey Juan Carlos campus de Mostòles (Madrid) GIA Grupo de Inteligencia Artificial

Building Web Services with Apache Axis2

SETTING UP YOUR JAVA DEVELOPER ENVIRONMENT

Lesson: All About Sockets

Java Access to Oracle CRM On Demand. By: Joerg Wallmueller Melbourne, Australia

HOBOlink Web Services V2 Developer s Guide

CHAPTER 10: WEB SERVICES

Liferay, Alfresco, SSO and LDAP Full Integration

WIRIS quizzes web services Getting started with PHP and Java

A Sample OFBiz application implementing remote access via RMI and SOAP Table of contents

Introduction to Mobile Phone. Programming in Java Me

Brekeke PBX Web Service

Tutorial - How to Use Lotus Domino Web Services in Java Development

Building and Using Web Services With JDeveloper 11g

Amazon Glacier. Developer Guide API Version

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

Address Phone & Fax Internet

Module 13 Implementing Java EE Web Services with JAX-WS

IT6503 WEB PROGRAMMING. Unit-I

Publishing, Consuming, Deploying and Testing Web Services

See the Developer s Getting Started Guide for an introduction to My Docs Online Secure File Delivery and how to use it programmatically.

Network Communication

ResellerPlus - Bulk Http API Specification. (This Document gives details on how to send messages via the Bulk HTTP API for the RouteSms SMPP System)

Web Services API Developer Guide

13 File Output and Input

Web Services using Tomcat and Eclipse

WA2099 Introduction to Java using RAD 8.0 EVALUATION ONLY. Student Labs. Web Age Solutions Inc.

Web Services in.net (1)

Overview. About Interstitial Ads: About Banner Ads: About Offer-Wall Ads: ADAttract Account & ID

Creating a Simple, Multithreaded Chat System with Java

DEVELOPING CONTRACT - DRIVEN WEB SERVICES USING JDEVELOPER. The purpose of this tutorial is to develop a java web service using a top-down approach.

T320 E-business technologies: foundations and practice

Intruduction to Groovy & Grails programming languages beyond Java

MSDG Services Integration Document Draft Ver 1.2

COMPUTACIÓN ORIENTADA A SERVICIOS (PRÁCTICA) Dr. Mauricio Arroqui EXA-UNICEN

How to Create an Android Application using Eclipse on Windows 7

Division of Informatics, University of Edinburgh

An Android-based Instant Message Application

Building a Multi-Threaded Web Server

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Selenium Automation set up with TestNG and Eclipse- A Beginners Guide

How to develop your own app

Tutorial on OpenCV for Android Setup

Hadoop Basics with InfoSphere BigInsights

Consuming, Providing & Publishing WS

Database Access from a Programming Language: Database Access from a Programming Language

Database Access from a Programming Language:

European Access Point for Truck Parking Data

Getting Started with the Internet Communications Engine

How To - Configure Web Filter Policy

RPC over XML. Web services with Java. How to install it? Reference implementation. Setting the environment variables. Preparing the system

Consuming and Producing Web Services with Web Tools. Christopher M. Judd. President/Consultant Judd Solutions, LLC

Study of Development of Java Applications in Eclipse Environment and Development of Java Based Calendar Application with Notifications

Hello World. by Elliot Khazon

Creating Web Services in NetBeans

Eclipse with Mac OSX Getting Started Selecting Your Workspace. Creating a Project.

JDBC. It is connected by the Native Module of dependent form of h/w like.dll or.so. ex) OCI driver for local connection to Oracle

EJB 3.0 and IIOP.NET. Table of contents. Stefan Jäger / stefanjaeger@bluewin.ch

Ready, Set, Go Getting started with Tuscany

Configuration Guide - OneDesk to SalesForce Connector

How To Use Blackberry Web Services On A Blackberry Device

Generating Open For Business Reports with the BIRT RCP Designer

Scanner. It takes input and splits it into a sequence of tokens. A token is a group of characters which form some unit.

Oracle Service Bus Examples and Tutorials

02267: Software Development of Web Services

Lecture J - Exceptions

Using ilove SharePoint Web Services Workflow Action

IRF2000 IWL3000 SRC1000 Application Note - Develop your own Apps with OSGi - getting started

Web Server Logs Analyze Using the XML Technologies

Tutorial for Creating Resources in Java - Client

Implementing a Web Service Client using Java

Developing Web Services with Apache CXF and Axis2

Using Oracle Cloud to Power Your Application Development Lifecycle

NetBeans and GlassFish v 2.1 Creating a Healthcare Facility Visual Web Application

Using BAC Hadoop Cluster

Tutorial on Basic Android Setup

Java Web Services SDK

Step 4: Configure a new Hadoop server This perspective will add a new snap-in to your bottom pane (along with Problems and Tasks), like so:

Creating Web Services Applications with IntelliJ IDEA

Issues in Information Systems

Software Development with UML and Java 2 SDJ I2, Spring 2010

Configuring Load Balancing

Copy the.jar file into the plugins/ subfolder of your Eclipse installation. (e.g., C:\Program Files\Eclipse\plugins)

WEB SERVICES TECHNICAL GUIDE FOR DEVELOPERS

Android Development Tutorial. Nikhil Yadav CSE40816/ Pervasive Health Fall 2011

Mobile App Design Project #1 Java Boot Camp: Design Model for Chutes and Ladders Board Game

Android Application Repackaging

Installing the ASP.NET VETtrak APIs onto IIS 5 or 6

Transcription:

Consuming a Web Service(SOAP and RESTful) in Java Cheat Sheet For Consuming Services in Java This document will provide a user the capability to create an application to consume a sample web service (Both SOAP and RESTful) in Java using the following technologies 1> Eclipse IDE Karan Moodbidri and Amey Gawde 7/25/2013

Prerequisites : Before we start with the process of consuming web services Eclipse IDE (Kepler preferred - Can be Downloaded from here - Link ) Consuming a Web Service in Java Open Eclipse IDE Click on New Go to the Pop up Option 'Other' Search for Dynamic Web Project

Select The same options as in the image Click Next

Click Next Click Finish Click on Project Click on New Click On other

Select Web Service Client Enter WSDL Link in the Textbox Click Next Click Finish

Now we need to write Code to Consume the Service. Click on Project Right Click on Java Resources in the Project Tree Structure Click on New Click on Class Select the Same options as given in the Picture Click on Finish You will have a java program open in front of you Go to java resources Go into src Check the name of the package other than the package you created Go into the package

Remember to Check the name of the file with Proxy in the end. Now import the WS package into your java program

Now Create an object of the proxy class you previously checked Call the function of the web service with the object of the proxy class and print it. Code should look like this: public static void main(string[] args) throws RemoteException { // TODO Auto-generated method stub WeatherSoapProxy wc = new WeatherSoapProxy(); System.out.println(wc.getCityForecastByZIP("14623").getForecastResult() [0].getTemperatures().getMorningLow()); } Run the program You have successfully Created a web client for the SOAP service.

Creating Client for RESTful Services Open Eclipse IDE Click on New Go to the Pop up Option 'Other' Search for Dynamic Web Project

Select The same options as in the image Click Next

Click Next Click Finish Click on Project Right Click on Java Resources in the Project Tree Structure Click on New Click on Class Select the Same options as given in the Picture

Click on Finish You will have a java program open in front of you You will need to include the following two packages import com.sun.jersey.api.client.client; import com.sun.jersey.api.client.webresource; Follow the code given Below : Note: The String held by variable apicall should be the URL to the RESTful Service. Client client = Client.create(); String apicall = null; apicall = "http://www.examplerestapi/q="; WebResource webresource = client.resource(apicall); String outputstring = webresource.get(string.class); System.out.println(outputString); You have created a client for your RESTful Service. We can Consume a REST based Service without using the Jersey API. I will be providing the instructions Below.

We would First Create a a Normal Java Project. For that, Click File Click New Click Java Project Enter the Name of the project Click Finish Right Click On Project Click on New Click on Class Select the Same options as given in the Picture

Click on Finish Now I would go through the code First we will create a URL variable to store the URL for the Rest Service. Example code : URL url = new URL("http://www.omdbapi.com/?s=Titanic"); We open a HTTP Connection on that URL. We set the requestmethod to "GET" and we connect to the Rest Service. Example Code: HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setrequestmethod("get"); connection.connect(); We now to have read data from the rest service input stream Example Code: BufferedReader bufferreader = new BufferedReader(new InputStreamReader(connection.getInputStream()));

Then we read the data from the stream into s String buffer to printed onto the console. Example Code: String str; StringBuffer stringbuffer = new StringBuffer(); while ((str = bufferreader.readline())!= null) { stringbuffer.append(str); stringbuffer.append("\n"); } System.out.println(stringBuffer.toString()); We have successfully consumed a service. The code entire code is as below. : URL url = new URL("http://www.omdbapi.com/?s=Titanic"); HttpURLConnection connection = (HttpURLConnection)url.openConnection(); connection.setrequestmethod("get"); connection.connect(); BufferedReader bufferreader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String str; StringBuffer stringbuffer = new StringBuffer(); while ((str = bufferreader.readline())!= null) { stringbuffer.append(str); stringbuffer.append("\n"); } System.out.println(stringBuffer.toString());