Skip to content

Commit

Permalink
Add a reproducer for quarkiverse#580 Clients with a class with postpo…
Browse files Browse the repository at this point in the history
…ned initialization in their method signatures cannot be compiled to native
  • Loading branch information
ppalaga committed Mar 16, 2023
1 parent 53d0ce1 commit 69ba2bd
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ 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


# Workaround for https://github.com/quarkusio/quarkus/issues/31646
# Should not be needed with the Quarkus release coming after 3.0.0.Alpha5
quarkus.jaxb.validate-jaxb-context = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <a href="https://github.com/quarkiverse/quarkus-cxf/issues/580">#580</a> properly.
* <p>
* 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);
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ 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


# Workaround for https://github.com/quarkusio/quarkus/issues/31646
# Should not be needed with the Quarkus release coming after 3.0.0.Alpha5
quarkus.jaxb.validate-jaxb-context = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}

}

0 comments on commit 69ba2bd

Please sign in to comment.