heartin's blog

Check if a Binary Tree is Balanced in O(N) time complexity

Problem statement

Check if a Binary Tree is Balanced in O(N) time complexity.

Assumption: Heights of two subtrees of any node should never differ by more than one, to consider a tree as balanced.

 

Approach

We can use a recursive function that will return the height of its subtree, or a special integer (-1) if the node is not balanced.

In every recusrive call, 

if node is null, then return 0.

SOAP Faults

We have already seen what SOAP faults are and how they are reprecented in the WSDL and SOAP message in the WSDL and SOAP overview notes respectively. Here we will try to consolidate the basic information related to SOAP faults.

Java application exceptions can be mapped to SOAP faults in WSDL/SOAP message.

 

Fault element in SOAP message

  • A SOAP message can have fault elements within it.

  • Fault elements contain errors and status information.

  • Fault is an optional element.

[Lab] SOAP Fault Demo

Java application exceptions can be mapped to SOAP faults in WSDL/SOAP message.

 

Problem statement

We will create a simple web service class with a single method that will accept an integer and check if it is even. If even we will return “Received even N” where N is the received even number.

If received number is not even, then we will throw a custom exception NotEvenNumberException that extends Exception.

Check if a Binary Tree is a Binary Search Tree (BST) using Property of Binary Tree

Approach

  • For a BST, all left nodes should be less than or equal to current node and current node must be less than all right nodes.

  • We will have a recursive function that checks if this property is true for every node and all its sub trees:

    • If the method get null node, it may return true, and should be first checked (exit condition for the recursion).

    • Check if 'left nodes is less than or equal to current node and current node must be less than all right nodes.

Check if a Binary Tree is a Binary Search Tree (BST) using Inorder Traversal

Approach

  • You can traverse the tree in in-order way, and see if the elements are assending.

    • You may either put the elements into an array and see if the array is sorted in assending way,

    • or while traversing see if the current element is always greater than or equal to previous element.

      • return false is current data is less than previously printed data.

      • may use a static variable to hold the last printed value.

 

Using Eclipse Web Services Explorer for Testing and Explorig SOAP Web Services

The Web Services Explorer is a tool available within Eclipse and can be used to test SOAP web services. 

 

The Web Services Explorer primarily has below funtionalities:

  • Browsing and invoking Web services via their WSDL and XSD.

  • Biscovering Web services in WS-Inspection 1.0 documents, and in UDDI v2 or v3 registries using the UDDI v2 protocol.

  • Publishing Web services to UDDI v2 or v3 registries using the UDDI v2 protocol.

 

Using SOAP UI Tool for Testing SOAP Web Services

SoapUI is an open-source web service testing application for SOAP and REST web services.

Its functionality covers web service inspection, invoking, development, simulation and mocking, functional testing, load and compliance testing.

A commercial version, SoapUI Pro, which mainly focuses on features designed to enhance productivity, is also available. 

 

[Lab-Extras] Common Issues While Deploying JAX-WS RI Web Service in Apache Tomcat

Issue 1

java.lang.ClassNotFoundException:

     com.sun.xml.ws.transport.http.servlet.WSServletContextListener

 

Solution

Copy “jaxws-rt.jar” from JAX-WS RI zip (downloaded from https://jax-ws.java.net/) to Tomcat library folder “{$TOMCAT}/lib“.

 

Issue 2

Server startup failed and below errors were observed in logs:

SEVERE: A child container failed during start

[Lab] Developing Bottum-up SOAP Web Service in Tomcat Container using JAX-WS RI

We did not had to do any extra configurations for deploying our web service class in Glassfish server. This is because Java EE 5 and above compliant application servers such as Glassfish, comply to JSR 109 (Web services 1.2/1.3) and JSR 224 (JAX-WS 2.0/2.1/2.2).

Additional SOAP Binding Attributes and Attribute Combinations

The @SOAPBinding annotation can be used to configure the soap binding styles.

You can use the @SOAPBinding annotation on the SEI and any of its methods. The settings of the method’s annotation takes precedence.

 

The @SOAPBinding annotation has three attributes: Style, Use and ParameterStyle.

  • Values for style can be Style.DOCUMENT (Default) or Style.RPC.

  • Values for use are Use.Literal (Default) or Use.Encoded.

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!