Avatar of yescobar01
yescobar01

asked on 

Java if condition check for empty and null values

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

Java

Avatar of undefined
Last Comment
yescobar01
ASKER CERTIFIED SOLUTION
Avatar of mccarl
mccarl
Flag of Australia image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of yescobar01
yescobar01

ASKER

so will have to test a request where bandwidth is empty.

Bandwidth is an Integer type.
   public Integer getBandwidth() {
        return bandwidth;
    }

Open in new window



this is one of the scenarios that I will be testing on my request:
  <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">1000000</ns:AccessSpeed>
		</sch:SpeedInfo>

Open in new window

Avatar of yescobar01
yescobar01

ASKER

this is the error I am getting

org.apache.cxf.interceptor.Fault: Unmarshalling Error: cvc-datatype-valid.1.2.1: '' is not a valid value for 'integer'. 
	at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:908)
	at org.apache.cxf.jaxb.JAXBEncoderDecoder.unmarshall(JAXBEncoderDecoder.java:712)

Open in new window

Java
Java

Java is a platform-independent, object-oriented programming language and run-time environment, designed to have as few implementation dependencies as possible such that developers can write one set of code across all platforms using libraries. Most devices will not run Java natively, and require a run-time component to be installed in order to execute a Java program.

102K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo