Web Services tutorialWeb services in JavaA piece of business logic, located somewhere on the Internet, that is accessible ...
Web Services tutorialJava Web Service Developer PackFree integrated toolkit that allows Java developers to build, test and...
Web Services tutorialService consists ofInterface:Declares the services remote proceduresImplementation class:Implements t...
Web Services tutorialClient codepublic class BookClient {public static void main(String[] args) {BookIF BookOrder = new Bo...
Web Services tutorialJAXR API for XML RegistriesProvides a convenient way toaccess standard business registriesSupports tw...
Web Services tutorialDynamicClient.class.getClassLoader()); Object customerParam =Thread.currentThread().getContextClassLo...
Upcoming SlideShare
Loading in …5
×

Web services in java

494 views

Published on

what is webservices how to use it?

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
494
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Web services in java

  1. 1. Web Services tutorialWeb services in JavaA piece of business logic, located somewhere on the Internet, that is accessible through standard-based Internet protocols such as HTTP or SMTP.CharacteristicsXML basedLoosely CoupledCoarse grainedAbility to be Synchronous or AsynchronousSupports Remote Procedure Calls (RPCs)Supports document exchangeMajor Web Services TechnologiesSimple Object Access Protocol (SOAP)Web Service Description Language (WSDL)Universal Description, Discovery, and Integration (UDDI)Simple web service interactionWhy Java Web ServicesAbility of enterprises using different computing platforms to communicate with each otherJava ensures code portabilityJ2EE ensures scalabilityAPIs hide all the implementation detailsComponents are reusableDevelopment time is substantially reduced Ganapathi
  2. 2. Web Services tutorialJava Web Service Developer PackFree integrated toolkit that allows Java developers to build, test and deploy Web servicesWeb services standards WSDL, SOAP, UDDIAPIs providedJava API for XML Messaging (JAXM)Java API for XML Registries (JAXR)Java API for XML-based RPC (JAX-RPC)Sample Scenario-Online Book storeJAX-RPC API for XML based RPCRPC-based Web service is a collection of procedures that can be called by a remote clientTies, the low-level classes that the server needs to communicate with a remote clientWSDL document used for creating stubs, the low-level classes that are needed by a client tocommunicate with a remote service.Stubs can be static or dynamic.Tools wscompile and wsdeploysimplify our job Ganapathi
  3. 3. Web Services tutorialService consists ofInterface:Declares the services remote proceduresImplementation class:Implements the remote procedures.Configuration files jaxrpc-ri.xml and web.xml contain all the parameters needed to deploy theservice.Client is a Java program which uses the stubs created from the WSDL document of the serviceConfiguration file config.xml contains the location of the WSDL document.Service Interfacepublic interface BookIF {public Book getPriceList();public String orderBook(String BookName, int quantity);}Implementation classpublic class BookImpl implements BookIF {public Book getPriceList() { . . . }public String orderBook(String BookName, int quantity) { . . . }} Ganapathi
  4. 4. Web Services tutorialClient codepublic class BookClient {public static void main(String[] args) {BookIF BookOrder = new BookServiceImpl().getBookIF();Book priceList = BookOrder.getPriceList():for (int i = 0; i <>JAXM API for XML MessagingProvides a standard way to send XML documents over the InternetBased on SOAP and SOAP with Attachments specificationsMessaging provider service, which does the behind-the-scenes work required to transport androute messagesStandalone client also possible for request-response type of messagingVery useful when Enterprise work on shared schemas.(e.g.. Schema for order form in OnlineBook Store)Advantages over JAX-RPCOne-way (asynchronous) messagingRouting of a message to more than one partyReliable messaging with guaranteed deliverySteps1.Setting up Connection with the end-point.2. Creating the SOAP message and populate it.3. Sending the message. Ganapathi
  5. 5. Web Services tutorialJAXR API for XML RegistriesProvides a convenient way toaccess standard business registriesSupports two standards ebXML and UDDIStandards groups have developedschemas for particular kinds of XML documents, and two businesses might for example, agree touse the schema which is stored in the registry.Querying registry-Useful methods1.findOrganizationswhich returns a list of organizations that meet the specified criteria2.findServiceswhich returns a set of services offered by a specified organization3. FindServiceBindingswhich returns the service bindings (information about how to access the service) that aresupported by a specified serviceSimilar methods exist for Managing Registry Data.JAX-WS Dynamic Dispatch with CXFCalling a web service is most often done by using some ws implementation stack like Axis2 orCXF/XFire to generate stubs for your language. The stub code is then linked against, to do theactual calls to the web service, marshall and unmarshall data etc.This posts shows you how to do this completely at runtime, by using the CXF API directly.If you are willing to bind yourself directly to the CXF API (as opposed to using the standardJAX-WS apis), you can do some nice things. It can do the steps of generating stubs, butcompletely at runtime. Look at this code: DynamicClientFactory dcf = DynamicClientFactory.newInstance(); Client client = dcf.createClient("http://host/invoicing.wsdl", Ganapathi
  6. 6. Web Services tutorialDynamicClient.class.getClassLoader()); Object customerParam =Thread.currentThread().getContextClassLoader().loadClass("com.acme.invoicing.Customer").newInstance(); Method setCustIdMethod = customerParam.getClass().getMethod("setCustomerId",String.class); setCustIdMethod.invoke(customerParam, "CUST-42"); Object[] result = client.invoke("doInvoicingOnCustomer", customerParam);Here is a bit of explanation of what happens here: Calling createClient on a DynamicClientFactory instance makes CXF load the WSDL, generate stubs and compile them to class files. They are now available on the current threads context classloader. In this example, the invoicing.wsdl service is supposed to have a method doInvoicingOnCustomer(Customer). The wsdl will have Customer defined, which will make CXF generate a Customer class. You can then call loadClass method to load the Customer class and do a newInstance To call customer.setCustomerId(String), we reflect the method out and invoke the setter with the value "CUST-42". And lastly, we call the doInvoicingOnCustomer remote webservice method, giving the Customer instance as parameterAnd of course. The Object[] output is typed in generated classes too. Ready to be reflectedupon.The above code binds directly to the CXF API. There is also the possibility of using the standardJAX-WS API for this. There are good examples on using the standard JAX-WS API to dodynamic calls: Using Dispatch and Service.Mode.MESSAGE to construct a JAX-WS dynamic call, where you have to provide the complete soap:Envelope part, of the message Using Dispatch and Service.Mode.PAYLOAD to construct a JAX-WS dynamic call, where you "only" have to provide the soap:Body part, of the messageBut I do not like it. The code in the above two links use the rather low-level API ofjavax.xml.soap package to construct the call to the server. It seems like you have to know a lotabout the needed SOAP message format, QNames to use, etc. Ganapathi

×