-2

I am trying to test SOAP Web Service using SOAP UI. but getting null values even passing those in soap ui while accessing parameters of request in our java method which has mapped endpoint to the operation.

Please find the code as below:

    @PayloadRoot(namespace = NAMESPACE_URI, localPart = "UserList")
        @ResponsePayload
        public JAXBElement<UserListResponse> UserListRequest(@RequestPayload JAXBElement<UserListRequest> request) throws Exception {

            System.out.println("Enters into UserList()");

            try {


                UserListRequest userListRequest = request.getValue();



   System.out.println("Number:"+userListRequest.getNumber());//Getting Number is null even passing passing in SOAP UI



      System.out.println("ID:"+userListRequest.getHeader().getCorrelationID()); //Here also getting java.lang.NullPointerException
//As i am not getting why soap Ui values are not binding and object reference is coming to userListRequest.
                if(userListRequest.getReference().equals("C")) {
                    userListRequest.setNumber(userListRequest.getNumber());
                }
            }
            catch(Exception e) {
                e.printStackTrace();
            }
            return null;
        }

Request XML:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:prim="http://COM.SERVICES.WebServices/UserServices">
   <soapenv:Header/>
   <soapenv:Body>
      <prim:UserList>
         <!--Optional:-->
         <prim:XMLRequest>
            <!--Optional:-->
            <prim:Header>
               <!--Optional:-->
               <prim:MessageID>2</prim:MessageID>
               <!--Optional:-->
               <prim:CorrelationID>2</prim:CorrelationID>
               <!--Optional:-->
               <prim:SystemID>2</prim:SystemID>
               <!--Optional:-->
               <prim:RequestorID>2</prim:RequestorID>
            </prim:Header>
            <prim:Reference>C</prim:Reference>
            <!--Optional:-->
            <prim:Number>1120521877477751</prim:Number>
            <!--Optional:-->
            <prim:Usercount>51</prim:Usercount>
         </prim:XMLRequest>
      </prim:UserList>
   </soapenv:Body>
</soapenv:Envelope>

I am unable to get why it is giving null . Can anyone please help me on this issue to resolve.

Rajeswari Reddy
  • 193
  • 1
  • 6
  • 24
  • the reason for an NPE in a unit test is exactly the same as the reason for an NPE in normal running code. you are trying to access a member of an instance of a class you haven't instantiated yet – Stultuske Apr 16 '18 at 09:40
  • Whics if the line you are having your exception at? – Lajos Arpad Apr 16 '18 at 09:43
  • 1
    Possible duplicate of [What is a NullPointerException, and how do I fix it?](https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how-do-i-fix-it) – f1sh Apr 16 '18 at 09:59

1 Answers1

0

I would advise you to learn about debugging Java in general. When it comes to your mistake, I think it comes from there:

if(userListRequest.getReference().equals("C")) {
    userListRequest.setNumber(userListRequest.getNumber());
}

Your userListRequest's reference is likely null, thus you are trying to call:

if (null.equals("C"))    {
    // Your treatment

To tackle the problem, put the oracle (= static member) on the left of your comparison:

if ("C".equals(userListRequest.getReference()))    {
  userListRequest.setNumber(userListRequest.getNumber());
}

It won't make your reference not null, but it won't crash anymore.


EDIT

For your null issue while binding SoapUI to Java, check this answer which may help you find out what the problem is. It may come from your model itself. Now that you posted your request, we can see that the Reference object is there, in the XML Tree:

UserList
    XMLRequest
        Reference

From what I see there, it should look like this:

userList.getXMLRequest.getReference();

However, you try to retrieve:

userListRequest.getReference();

I don't know how you wrote your POJO model, but something is off there. Try to check if this architecture is correctly implemented, before anything else.

Yassine Badache
  • 1,810
  • 1
  • 19
  • 38
  • and what if userListRequest itself is null? – Stultuske Apr 16 '18 at 09:45
  • and why automatically assume the OP uses eclipse? – Stultuske Apr 16 '18 at 09:53
  • I am passing values but why it is giving null that is i am not getting. Please help me on this @Yassine Badache – Rajeswari Reddy Apr 16 '18 at 09:54
  • 1
    About `userListRequest`: he uses `System.out.println("Number:"+userListRequest.getNumber());` and it does not crash, so `userListRequest` is not nul there. About Eclipse, my bad, indeed. For your value passing, I can't help you, Rajeswari. It may come from your configuration, from your SOAP modelization, from your linking between SoapUI and Java. There are a lot that you could explore for this problem. – Yassine Badache Apr 16 '18 at 09:56
  • @RajeswariReddy have you debugged your code? perhaps you don't pass what you assume you pass. Check the stacktrace for the line on which the exception is thrown, and add a breakpoint on it – Stultuske Apr 16 '18 at 09:57
  • That's okay but due to that null it is giving error right as not geeting the values which has paased in SOAP UI.That is i am expecting error.Once values coming then error will not thrown. Please help on this. @Yassine Badache – Rajeswari Reddy Apr 16 '18 at 09:59
  • I already told you why I cannot help you about the whole issue. Your question was "I am unable to get why it is giving null pointer exception", and I answered that. For the rest, you'll have to work on the points I told you previously. I'm sorry. – Yassine Badache Apr 16 '18 at 10:01
  • @RajeswariReddy with what more can we help? both Yassine and I basically already have told you what to do to find the problem, we can't solve it for you, though – Stultuske Apr 16 '18 at 10:01
  • Why giving null even passing values in SOAP UI. That is what i am expecting. the above solution is just to remove exception but not resolving my problem. please help if you have any idea on why giving null. @Stultuske – Rajeswari Reddy Apr 16 '18 at 10:07
  • @RajeswariReddy we do not know what you pass. we do not know your configuration. understanding what is null, should give you enough to re-check your input. – Stultuske Apr 16 '18 at 10:10
  • I edited the answer with a useful link, check it out @RajeswariReddy. – Yassine Badache Apr 16 '18 at 10:12
  • @RajeswariReddy since you don't provide nearly enough information for us to be able to look further.. what do you expect from us? – Stultuske Apr 16 '18 at 10:31
  • What is the information you required till @Stultuske. Please try to resolve the issue why it is coming null even if passing in SOAP UI. – Rajeswari Reddy Apr 16 '18 at 10:58
  • 1
    @RajeswariReddy NOT. but since you don't show what it is you pass, or how you have configured everything, we can't say anything about that. Either way: it's not as if the JVM just says "I want to screw this dudes monday", if it was correctly passed, it wouldn't be null. check the types, check the way of how you pass/accept/configure the param, debug and check the value on actual receiving it – Stultuske Apr 16 '18 at 11:04
  • I added request xml to my question.Please check and help me on this.@Stultuske – Rajeswari Reddy Apr 16 '18 at 11:42
  • But getXMLRequest is not coming. However userList request is coming means its not null even values are not coming. Still facing issue to get request xml values from SOAP UI. Please help on this and let me know any other code you required to debug this. Thanks @Yassine Badache – Rajeswari Reddy Apr 17 '18 at 04:38
  • and request.getValue(); giving UserListRequest@2.when trying to get userList.getXMLRequest.getReference(); and it is giving null.@Yassine Badache – Rajeswari Reddy Apr 17 '18 at 07:31
  • 1
    Since you're averse to trying the debugger that I and others have suggested you try, you might want to do this as you enter the method instead.... System.out.println(request.toString()); or System.out.println(request);. By debugging or send the request object to the console will allow you to see what is being passed in. If you can share that, then people may be more willing to help. – Chris Adams Apr 18 '18 at 13:53
  • Why input values are not binding to java object while testing from SOAP Ui. Any idea @ Yassine Badache – Rajeswari Reddy Apr 23 '18 at 06:50