From e698a469570dfddf2bd8c9cff49de4958f411f04 Mon Sep 17 00:00:00 2001 From: Peter Palaga Date: Wed, 15 Mar 2023 13:48:52 +0100 Subject: [PATCH] Add a reproducer for #580 Clients with a class with postponed initialization in their method signatures cannot be compiled to native --- .../calculator-client/application.properties | 5 ++ .../cxf/client/it/CxfClientResource.java | 13 +++++ .../ClientWithRuntimeInitializedPayload.java | 37 +++++++++++++ .../cxf/client/it/rtinit/Operands.java | 51 ++++++++++++++++++ .../cxf/client/it/rtinit/Result.java | 53 +++++++++++++++++++ .../src/main/resources/application.properties | 5 ++ .../cxf/client/it/CxfClientTest.java | 14 +++++ 7 files changed, 178 insertions(+) create mode 100644 integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/ClientWithRuntimeInitializedPayload.java create mode 100644 integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/Operands.java create mode 100644 integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/Result.java diff --git a/docs/modules/ROOT/examples/calculator-client/application.properties b/docs/modules/ROOT/examples/calculator-client/application.properties index 599d0c5d4..eb8f47230 100644 --- a/docs/modules/ROOT/examples/calculator-client/application.properties +++ b/docs/modules/ROOT/examples/calculator-client/application.properties @@ -21,3 +21,8 @@ quarkus.cxf.client.codeFirstClient.service-interface=io.quarkiverse.cxf.client.i quarkus.cxf.client.codeFirstClient.endpoint-namespace=http://www.jboss.org/eap/quickstarts/wscalculator/Calculatorrr quarkus.cxf.client.codeFirstClient.endpoint-name=CalculatorService +quarkus.cxf.client.clientWithRuntimeInitializedPayload.client-endpoint-url=${cxf.it.calculator.baseUri}/calculator-ws/CalculatorService +quarkus.cxf.client.clientWithRuntimeInitializedPayload.service-interface=io.quarkiverse.cxf.client.it.rtinit.ClientWithRuntimeInitializedPayload +quarkus.cxf.client.clientWithRuntimeInitializedPayload.endpoint-namespace=http://www.jboss.org/eap/quickstarts/wscalculator/Calculator +quarkus.cxf.client.clientWithRuntimeInitializedPayload.endpoint-name=CalculatorService +quarkus.native.additional-build-args=--initialize-at-run-time=io.quarkiverse.cxf.client.it.rtinit.Operands\\,io.quarkiverse.cxf.client.it.rtinit.Result diff --git a/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CxfClientResource.java b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CxfClientResource.java index 82e3cc05b..72ed70b22 100644 --- a/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CxfClientResource.java +++ b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/CxfClientResource.java @@ -17,6 +17,7 @@ import io.quarkiverse.cxf.CXFClientInfo; import io.quarkiverse.cxf.annotation.CXFClient; +import io.quarkiverse.cxf.client.it.rtinit.ClientWithRuntimeInitializedPayload; @Path("/cxf/client") public class CxfClientResource { @@ -45,6 +46,10 @@ public class CxfClientResource { @Named("org.jboss.eap.quickstarts.wscalculator.calculator.CalculatorService") CXFClientInfo calculatorClientInfo; + @Inject + @CXFClient("clientWithRuntimeInitializedPayload") // name used in application.properties + ClientWithRuntimeInitializedPayload clientWithRuntimeInitializedPayload; + @GET @Path("/calculator/{client}/multiply") @Produces(MediaType.TEXT_PLAIN) @@ -63,6 +68,14 @@ public int codeFirstClient(@QueryParam("a") int a, @QueryParam("b") int b) { return codeFirstClient.multiply(a, b); } + @GET + @Path("/clientWithRuntimeInitializedPayload/addOperands") + @Produces(MediaType.TEXT_PLAIN) + public int clientWithRuntimeInitializedPayload(@QueryParam("a") int a, @QueryParam("b") int b) { + return clientWithRuntimeInitializedPayload.addOperands(new io.quarkiverse.cxf.client.it.rtinit.Operands(a, b)) + .getResult(); + } + @GET @Path("/calculator/{client}/addOperands") @Produces(MediaType.TEXT_PLAIN) diff --git a/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/ClientWithRuntimeInitializedPayload.java b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/ClientWithRuntimeInitializedPayload.java new file mode 100644 index 000000000..5a6b9dc4e --- /dev/null +++ b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/ClientWithRuntimeInitializedPayload.java @@ -0,0 +1,37 @@ +/* + * JBoss, Home of Professional Open Source + * Copyright 2015, Red Hat, Inc. and/or its affiliates, and individual + * contributors by the @authors tag. See the copyright.txt in the + * distribution for a full listing of individual contributors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package io.quarkiverse.cxf.client.it.rtinit; + +import jakarta.jws.WebMethod; +import jakarta.jws.WebService; + +/** + * We declare {@link Operands} and {@link Result} as runtime initialized in {@code application.properties} to make + * sure that we fixed #580 properly. + *

+ * The addOperands() operation is copied from + * https://github.com/l2x6/calculator-ws/blob/1.0/src/main/java/org/jboss/as/quickstarts/wscalculator/CalculatorService.java + * CXF should be able to use this to produce a partial client communicating with a compatible service endpoint. + */ +@WebService(targetNamespace = ClientWithRuntimeInitializedPayload.TARGET_NS, name = "CalculatorService") +public interface ClientWithRuntimeInitializedPayload { + + public static final String TARGET_NS = "http://www.jboss.org/eap/quickstarts/wscalculator/Calculator"; + + @WebMethod + public Result addOperands(Operands arg0); +} diff --git a/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/Operands.java b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/Operands.java new file mode 100644 index 000000000..a2b72048a --- /dev/null +++ b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/Operands.java @@ -0,0 +1,51 @@ + +package io.quarkiverse.cxf.client.it.rtinit; + +import java.util.Objects; + +public class Operands { + private int a; + private int b; + + public Operands() { + } + + public Operands(int a, int b) { + super(); + this.a = a; + this.b = b; + } + + public int getA() { + return a; + } + + @Override + public int hashCode() { + return Objects.hash(a, b); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Operands other = (Operands) obj; + return a == other.a && b == other.b; + } + + public void setA(int a) { + this.a = a; + } + + public int getB() { + return b; + } + + public void setB(int b) { + this.b = b; + } +} \ No newline at end of file diff --git a/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/Result.java b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/Result.java new file mode 100644 index 000000000..4ea8bad6a --- /dev/null +++ b/integration-tests/client/src/main/java/io/quarkiverse/cxf/client/it/rtinit/Result.java @@ -0,0 +1,53 @@ + +package io.quarkiverse.cxf.client.it.rtinit; + +import java.util.Objects; + +public class Result { + private int result; + + private Operands operands; + + public Result() { + } + + public Result(int result, Operands operands) { + super(); + this.result = result; + this.operands = operands; + } + + public int getResult() { + return result; + } + + public void setResult(int result) { + this.result = result; + } + + public Operands getOperands() { + return operands; + } + + public void setOperands(Operands operands) { + this.operands = operands; + } + + @Override + public int hashCode() { + return Objects.hash(operands, result); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Result other = (Result) obj; + return Objects.equals(operands, other.operands) && result == other.result; + } + +} \ No newline at end of file diff --git a/integration-tests/client/src/main/resources/application.properties b/integration-tests/client/src/main/resources/application.properties index 599d0c5d4..eb8f47230 100644 --- a/integration-tests/client/src/main/resources/application.properties +++ b/integration-tests/client/src/main/resources/application.properties @@ -21,3 +21,8 @@ quarkus.cxf.client.codeFirstClient.service-interface=io.quarkiverse.cxf.client.i quarkus.cxf.client.codeFirstClient.endpoint-namespace=http://www.jboss.org/eap/quickstarts/wscalculator/Calculatorrr quarkus.cxf.client.codeFirstClient.endpoint-name=CalculatorService +quarkus.cxf.client.clientWithRuntimeInitializedPayload.client-endpoint-url=${cxf.it.calculator.baseUri}/calculator-ws/CalculatorService +quarkus.cxf.client.clientWithRuntimeInitializedPayload.service-interface=io.quarkiverse.cxf.client.it.rtinit.ClientWithRuntimeInitializedPayload +quarkus.cxf.client.clientWithRuntimeInitializedPayload.endpoint-namespace=http://www.jboss.org/eap/quickstarts/wscalculator/Calculator +quarkus.cxf.client.clientWithRuntimeInitializedPayload.endpoint-name=CalculatorService +quarkus.native.additional-build-args=--initialize-at-run-time=io.quarkiverse.cxf.client.it.rtinit.Operands\\,io.quarkiverse.cxf.client.it.rtinit.Result diff --git a/integration-tests/client/src/test/java/io/quarkiverse/cxf/client/it/CxfClientTest.java b/integration-tests/client/src/test/java/io/quarkiverse/cxf/client/it/CxfClientTest.java index dccb27c7f..295512df3 100644 --- a/integration-tests/client/src/test/java/io/quarkiverse/cxf/client/it/CxfClientTest.java +++ b/integration-tests/client/src/test/java/io/quarkiverse/cxf/client/it/CxfClientTest.java @@ -182,4 +182,18 @@ void wsdlIncluded() throws IOException { } + /** + * Test whether a code-first client (without WSDL) works properly. + */ + @Test + void clientWithRuntimeInitializedPayload() { + RestAssured.given() + .queryParam("a", 7) + .queryParam("b", 8) + .get("/cxf/client/clientWithRuntimeInitializedPayload/addOperands") + .then() + .statusCode(200) + .body(is("15")); + } + }