davidmoten / odata-client

Java client generator for a service described by OData CSDL 4.0 metadata. Includes Microsoft Graph clients (v1.0 and Beta), Graph Explorer client, Analytics for DevOps, Dynamics CRM clients
Apache License 2.0
36 stars 8 forks source link

Unable to call Action that returns HTTP 200 status and just simple Edm.String #473

Closed antonantonovich closed 2 months ago

antonantonovich commented 3 months ago

Hello David,

We have an issue trying to call Action that returns Edm.String and HTTP 200 status. The error is "The api of post GetPreferenceValue gives exception of expectedresponse 201"

I checked that when action returns not collection Edm type -- it uses ActionRequestReturningNonCollection and that request accepts only 201 status.

When we have Action that returns custom type, client uses ActionRequestReturningNonCollectionUnwrapped request and that request allows to have any success status.

davidmoten commented 2 months ago

Sorry, just saw this.

davidmoten commented 2 months ago

Can you give me relevant parts of your metadata xml (or the whole file preferrably) and generated source please?

antonantonovich commented 2 months ago
              <Action Name="GetPreferenceValue" IsBound="false">
                <Parameter Name="prefIntName" Type="Edm.String" Nullable="false">
                    <Annotation Term="Core.Description">
                        <String>Internal name of the Preference</String>
                    </Annotation>
                </Parameter>
                <Parameter Name="containerRef" Type="Edm.String">
                    <Annotation Term="Core.Description">
                        <String>Container Object ID</String>
                    </Annotation>
                </Parameter>
                <ReturnType Type="Edm.String"/>
                <Annotation Term="Core.Description">
                    <String>Get Preference value for input preference and container.If container is not passed,session
                        user specific preference is fetched.
                    </String>
                </Annotation>
            </Action>

Generate client code:

@Action(name = "GetPreferenceValue")
    @JsonIgnore
    public ActionRequestReturningNonCollection<String> getPreferenceValue(String prefIntName, String containerRef) {
        Preconditions.checkNotNull(prefIntName, "prefIntName cannot be null");
        Map<String, TypedObject> _parameters = ParameterMap
            .put("prefIntName", "Edm.String", prefIntName)
            .put("containerRef", "Edm.String", containerRef)
            .build();
        return new ActionRequestReturningNonCollection<String>(this.contextPath.addActionOrFunctionSegment("GetPreferenceValue"), String.class, _parameters);
    }

That action reply with the value and HTTP 200 status from the server side but we have an error on client side because client expects 201 status.

antonantonovich commented 2 months ago

for example, that action works correctly

            <Action Name="QueryDesigns" IsBound="false">
                <Parameter Name="object" Type="DesignDisplayInput" Nullable="false"/>
                <ReturnType Type="Elements" Nullable="false"/>
                <Annotation Term="Core.Description">
                    <String>Query endpoint used by design interface</String>
                </Annotation>
            </Action>
@Action(name = "QueryDesigns")
    @JsonIgnore
    public ActionRequestReturningNonCollectionUnwrapped<Elements> queryDesigns(DesignDisplayInput object) {
        Preconditions.checkNotNull(object, "object cannot be null");
        Map<String, TypedObject> _parameters = ParameterMap
            .put("object", "DesignDisplayInput", object)
            .build();
        return new ActionRequestReturningNonCollectionUnwrapped<Elements>(this.contextPath.addActionOrFunctionSegment("QueryDesigns"), Elements.class, _parameters);
    }

ActionRequestReturningNonCollectionUnwrapped response allows to have HTTP 200 status but ActionRequestReturningNonCollection do not

davidmoten commented 2 months ago

Gotcha, I see that such a post is assumed to be a create action which is not correct. I'll widen it to accept all 2XX codes.

davidmoten commented 2 months ago

0.2.2 is on Maven Central now with the fix. Please give it a try, thanks for the report.

davidmoten commented 2 months ago

closing, reopen as you wish