9

When I generate a stub (using Eclipse Oxygen, top-down, Axis1), the function are generated like these:

public TokenNamespace.ideas.mace.TokenResponse getToken(TokenNamespace.ideas.mace.TokenRequest tokenRequest) throws java.rmi.RemoteException {
    return null;
}

public TokenNamespace.ideas.mace.TokenResponse getToken2(TokenNamespace.ideas.mace.TokenRequest tokenRequest, boolean stopOnAnyError, TokenNamespace.ideas.mace.EACommand[] command, TokenNamespace.ideas.mace.HttpHeader[] httpHeader) throws java.rmi.RemoteException {
    return null;
}

Why is TokenRequest class kept intact, while BatchCommand and HttpHeaders are dismantled?

I tried adding more sub-elements under HttpHeaders and BatchCommand, but they just get split up as additional parameters. I can't spot any difference between their declarations and getToken's.

KC Wong
  • 2,410
  • 1
  • 18
  • 26

1 Answers1

4

If you are talking about getToken2() method then actually they are not dismantled rather if you see httpheaders is actually an array of httpheader so in java code it is converted to an array of httpheaders as parameter to getToken2 and same is the case for the CommandBatch.

And

If you are talking about why they are dismantled from getToken() method then the solution is as given below.

This is because in the wsdl file you have not defined the parameters for getToken() method

For example you have this

<portType name="TokenService">
        <operation name="getToken" parameterOrder="getToken">
            <input message="tns:TokenService_getToken" />
            <output message="tns:TokenService_getTokenResponse" />
        </operation>
        <operation name="getToken2" parameterOrder="getToken batchCommand httpHeaders">
            <input message="tns:TokenService_getToken2" />
            <output message="tns:TokenService_getTokenResponse" />
        </operation>
    </portType>

You should update it like below

<portType name="TokenService">
        <operation name="getToken" parameterOrder="getToken batchCommand httpHeaders">
            <input message="tns:TokenService_getToken" />
            <output message="tns:TokenService_getTokenResponse" />
        </operation>
        <operation name="getToken2" parameterOrder="getToken batchCommand httpHeaders">
            <input message="tns:TokenService_getToken2" />
            <output message="tns:TokenService_getTokenResponse" />
        </operation>
    </portType>

That is your operation getToken should define the required parameters in the parameterOrder attribute.

And also change the message from

<message name="TokenService_getToken">
        <part element="tns:httpHeaders" name="httpHeaders" />
    </message>

to

<message name="TokenService_getToken">
        <part element="tns:getToken" name="getToken" />
        <part element="tns:batchCommand" name="batchCommand" />
        <part element="tns:httpHeaders" name="httpHeaders" />
    </message>

After that it generates the code correctly.

You can further take a look at this answer It is explaining how maxOccurs attribute is used. If it is not specified then an element will occur only once. So that is why getToken has not been changed into an array like the other parameters and rather replaced by the one occurrence of the TokenRequest which is indeed what is contained within getToken complexType. That is a single occurrence of TokenRequest

muasif80
  • 5,586
  • 4
  • 32
  • 45
  • getToken (the old API) has one parameter, while getToken2 (the new API) has 3. The question I have is why the parameter types BatchCommand and HttpHeaders are not included in generated code, but getToken is. If the code generator decides to optimize and omit BatchCommand and HttpHeaders, it should apply the same logic to getToken and extract its fields into separate parameters. – KC Wong Nov 27 '17 at 09:46
  • The httpHeaders and EACommand are re-presentable as collections of other types and there maxOccurs is unbounded therefore they are changed into arrays. Whereas maxOccurs for getToken is not specified so it defaults to 1 and therefore it is not changed into an array in the Java code. This is the correct explanation. – muasif80 Dec 04 '17 at 01:39
  • Furthermore getToken is actually holding one single instance of TokenRequest in the complexType definition so in java it is converted to that single instance of TokenRequest. @KCWong – muasif80 Dec 04 '17 at 01:51