We help IT Professionals succeed at work.
Get Started

Java if condition check for empty and null values

yescobar01
yescobar01 asked
on
337 Views
Last Modified: 2016-02-02
How can I write a condition in java for a webservice request, In my webservice request I am passing an element that has `SpeedInfo`. In `SpeedInfo` element there is two sub elements `Bandwidth` and `AccessSpeed`.

This is my Request In SoapUI:

         <sch:SpeedInfo>
            <ns:Bandwidth xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1">4000000</ns:Bandwidth>
            <ns:AccessSpeed xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1">4000000</ns:AccessSpeed>
         </sch:SpeedInfo>

Open in new window

My Java condition:

			if (request.getSpeedInfo() == null || (request.getSpeedInfo() == null && request.getSpeedInfo().getBandwidth() == null)){
				throw new Exception(" SpeedInfo Bandwidth must be passed in the request ");
			}

Open in new window

           

I need my condition to check for 3 scenarios:
     1. if <speedInfo> itself is not present

     2. <sch:SpeedInfo> is present, but bandwidth not present:
  
      <sch:SpeedInfo>
          <ns:AccessSpeed xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1">40000000</ns:AccessSpeed>
      </sch:SpeedInfo>

     3. Bandwidth is present but no value  
       <sch:SpeedInfo>
          <ns:Bandwidth xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1"></ns:Bandwidth>
          <ns:AccessSpeed xmlns:ns="http://lpp.att.com/logical/classofservice/schema/v1">40000000</ns:AccessSpeed>
       </sch:SpeedInfo>

Open in new window

Comment
Watch Question
IT Business Systems Analyst / Software Developer
CERTIFIED EXPERT
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE