Skip to content

Commit

Permalink
Make decoupled-endpoint-base a global option fix #1168
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Jan 4, 2024
1 parent 697d300 commit 920cd1c
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 128 deletions.
128 changes: 64 additions & 64 deletions docs/modules/ROOT/pages/includes/quarkus-cxf.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,70 @@ endif::add-copy-button-to-env-var[]
|`8191`


a| [[quarkus-cxf_quarkus.cxf.decoupled-endpoint-base]]`link:#quarkus-cxf_quarkus.cxf.decoupled-endpoint-base[quarkus.cxf.decoupled-endpoint-base]`


[.description]
--
An URI base to use as a prefix of `quarkus.cxf.client.myClient.decoupled-endpoint`. You will typically want to set this to something like the following:

```
quarkus.cxf.decoupled-endpoint-base = https://api.example.com:${quarkus.http.ssl-port}${quarkus.cxf.path}
# or for plain HTTP
quarkus.cxf.decoupled-endpoint-base = http://api.example.com:${quarkus.http.port}${quarkus.cxf.path}
```

If you invoke your WS client from within a HTTP handler, you can leave this option unspecified and rather set it dynamically on the request context of your WS client using the `org.apache.cxf.ws.addressing.decoupled.endpoint.base` key. Here is an example how to do that from a RESTeasy handler method:

```
import java.util.Map;
import jakarta.inject.Inject;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import jakarta.xml.ws.BindingProvider;
import io.quarkiverse.cxf.annotation.CXFClient;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@Path("/my-rest")
public class MyRestEasyResource {

@Inject
@CXFClient("hello")
HelloService helloService;

@ConfigProperty(name = "quarkus.cxf.path")
String quarkusCxfPath;

@POST
@Path("/hello")
@Produces(MediaType.TEXT_PLAIN)
public String hello(String body, @Context UriInfo uriInfo) throws IOException {

// You may consider doing this only once if you are sure that your service is accessed
// through a single hostname
String decoupledEndpointBase = uriInfo.getBaseUriBuilder().path(quarkusCxfPath);
Map>String, Object< requestContext = ((BindingProvider) helloService).getRequestContext();
requestContext.put("org.apache.cxf.ws.addressing.decoupled.endpoint.base", decoupledEndpointBase);

return wsrmHelloService.hello(body);
}
}
```

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_CXF_DECOUPLED_ENDPOINT_BASE+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_CXF_DECOUPLED_ENDPOINT_BASE+++`
endif::add-copy-button-to-env-var[]
--|string
|


a| [[quarkus-cxf_quarkus.cxf.logging.enabled-for]]`link:#quarkus-cxf_quarkus.cxf.logging.enabled-for[quarkus.cxf.logging.enabled-for]`


Expand Down Expand Up @@ -2437,70 +2501,6 @@ endif::add-copy-button-to-env-var[]
|


a| [[quarkus-cxf_quarkus.cxf.client.-clients-.decoupled-endpoint-base]]`link:#quarkus-cxf_quarkus.cxf.client.-clients-.decoupled-endpoint-base[quarkus.cxf.client."clients".decoupled-endpoint-base]`


[.description]
--
An URI base to use as a prefix of `quarkus.cxf.client.myClient.decoupled-endpoint`. You will typically want to set this to something like the following:

```
quarkus.cxf.client.myClient.decoupled-endpoint-base = https://api.example.com:${quarkus.http.ssl-port}${quarkus.cxf.path}
# or for plain HTTP
quarkus.cxf.client.myClient.decoupled-endpoint-base = http://api.example.com:${quarkus.http.port}${quarkus.cxf.path}
```

If you invoke your WS client from within a HTTP handler, you can leave this option unspecified and rather set it dynamically on the request context of your WS client using the `org.apache.cxf.ws.addressing.decoupled.endpoint.base` key. Here is an example how to do that from a RESTeasy handler method:

```
import java.util.Map;
import jakarta.inject.Inject;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.UriInfo;
import jakarta.xml.ws.BindingProvider;
import io.quarkiverse.cxf.annotation.CXFClient;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@Path("/my-rest")
public class MyRestEasyResource {

@Inject
@CXFClient("hello")
HelloService helloService;

@ConfigProperty(name = "quarkus.cxf.path")
String quarkusCxfPath;

@POST
@Path("/hello")
@Produces(MediaType.TEXT_PLAIN)
public String hello(String body, @Context UriInfo uriInfo) throws IOException {

// You may consider doing this only once if you are sure that your service is accessed
// through a single hostname
String decoupledEndpointBase = uriInfo.getBaseUriBuilder().path(quarkusCxfPath);
Map>String, Object< requestContext = ((BindingProvider) helloService).getRequestContext();
requestContext.put("org.apache.cxf.ws.addressing.decoupled.endpoint.base", decoupledEndpointBase);

return wsrmHelloService.hello(body);
}
}
```

ifdef::add-copy-button-to-env-var[]
Environment variable: env_var_with_copy_button:+++QUARKUS_CXF_CLIENT__CLIENTS__DECOUPLED_ENDPOINT_BASE+++[]
endif::add-copy-button-to-env-var[]
ifndef::add-copy-button-to-env-var[]
Environment variable: `+++QUARKUS_CXF_CLIENT__CLIENTS__DECOUPLED_ENDPOINT_BASE+++`
endif::add-copy-button-to-env-var[]
--|string
|


a| [[quarkus-cxf_quarkus.cxf.client.-clients-.proxy-server]]`link:#quarkus-cxf_quarkus.cxf.client.-clients-.proxy-server[quarkus.cxf.client."clients".proxy-server]`


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public class CXFClientInfo {

private final boolean secureWsdlAccess;

public CXFClientInfo(CXFClientData other, CxfClientConfig config, String configKey) {
public CXFClientInfo(CXFClientData other, CxfConfig cxfConfig, CxfClientConfig config, String configKey) {
Objects.requireNonNull(config);
this.sei = other.getSei();
this.soapBinding = config.soapBinding().orElse(other.getSoapBinding());
Expand Down Expand Up @@ -231,7 +231,7 @@ public CXFClientInfo(CXFClientData other, CxfClientConfig config, String configK
this.version = config.version();
this.browserType = config.browserType().orElse(null);
this.decoupledEndpoint = config.decoupledEndpoint().orElse(null);
this.decoupledEndpointBase = config.decoupledEndpointBase().orElse(null);
this.decoupledEndpointBase = cxfConfig.decoupledEndpointBase().orElse(null);
this.proxyServer = config.proxyServer().orElse(null);
this.proxyServerPort = config.proxyServerPort().orElse(null);
this.nonProxyHosts = config.nonProxyHosts().orElse(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -285,64 +285,6 @@ public interface CxfClientConfig {
*/
Optional<String> decoupledEndpoint();

/**
* An URI base to use as a prefix of {@code quarkus.cxf.client.myClient.decoupled-endpoint}. You will typically
* want to set this to something like the following:
*
* <pre>
* quarkus.cxf.client.myClient.decoupled-endpoint-base = https://api.example.com:${quarkus.http.ssl-port}${quarkus.cxf.path}
* # or for plain HTTP
* quarkus.cxf.client.myClient.decoupled-endpoint-base = http://api.example.com:${quarkus.http.port}${quarkus.cxf.path}
* </pre>
*
* If you invoke your WS client from within a HTTP handler, you can leave this option unspecified and rather
* set it dynamically on the request context of your WS client using the
* {@code org.apache.cxf.ws.addressing.decoupled.endpoint.base} key. Here is an example how to do that from a
* RESTeasy handler method:
*
* <pre>
* import java.util.Map;
* import jakarta.inject.Inject;
* import jakarta.ws.rs.POST;
* import jakarta.ws.rs.Path;
* import jakarta.ws.rs.Produces;
* import jakarta.ws.rs.core.Context;
* import jakarta.ws.rs.core.MediaType;
* import jakarta.ws.rs.core.UriInfo;
* import jakarta.xml.ws.BindingProvider;
* import io.quarkiverse.cxf.annotation.CXFClient;
* import org.eclipse.microprofile.config.inject.ConfigProperty;
*
* &#64;Path("/my-rest")
* public class MyRestEasyResource {
*
* &#64;Inject
* &#64;CXFClient("hello")
* HelloService helloService;
*
* &#64;ConfigProperty(name = "quarkus.cxf.path")
* String quarkusCxfPath;
*
* &#64;POST
* &#64;Path("/hello")
* &#64;Produces(MediaType.TEXT_PLAIN)
* public String hello(String body, &#64;Context UriInfo uriInfo) throws IOException {
*
* // You may consider doing this only once if you are sure that your service is accessed
* // through a single hostname
* String decoupledEndpointBase = uriInfo.getBaseUriBuilder().path(quarkusCxfPath);
* Map&gt;String, Object&lt; requestContext = ((BindingProvider) helloService).getRequestContext();
* requestContext.put("org.apache.cxf.ws.addressing.decoupled.endpoint.base", decoupledEndpointBase);
*
* return wsrmHelloService.hello(body);
* }
* }
* </pre>
*
* @since 2.7.0
*/
public Optional<String> decoupledEndpointBase();

/**
* Specifies the address of proxy server if one is used.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ public static CXFClientInfo selectorCXFClientInfo(

if (configKey != null && !configKey.isEmpty()) {
if (config.isClientPresent(configKey)) {
return new CXFClientInfo(meta, config.getClient(configKey), configKey);
return new CXFClientInfo(meta, config, config.getClient(configKey), configKey);
}
// If config-key is present and not default: This is an error:
throw exceptionSupplier.get();
Expand All @@ -434,9 +434,9 @@ public static CXFClientInfo selectorCXFClientInfo(
LOGGER.warnf(
"No configuration found for quarkus.cxf.*.service-interface = %s and alternative = false. Using the values from the service instead: %s.",
meta.getSei(), meta);
return new CXFClientInfo(meta, config.internal().client(), null);
return new CXFClientInfo(meta, config, config.internal().client(), null);
case 1:
return new CXFClientInfo(meta, config.clients().get(keylist.get(0)), keylist.get(0));
return new CXFClientInfo(meta, config, config.clients().get(keylist.get(0)), keylist.get(0));
default:
throw new IllegalStateException("quarkus.cxf.*.service-interface = " + meta.getSei()
+ " with alternative = false expected once, but found " + keylist.size() + " times in "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,64 @@
@ConfigRoot(phase = ConfigPhase.RUN_TIME)
public interface CxfConfig {

/**
* An URI base to use as a prefix of {@code quarkus.cxf.client.myClient.decoupled-endpoint}. You will typically
* want to set this to something like the following:
*
* <pre>
* quarkus.cxf.decoupled-endpoint-base = https://api.example.com:${quarkus.http.ssl-port}${quarkus.cxf.path}
* # or for plain HTTP
* quarkus.cxf.decoupled-endpoint-base = http://api.example.com:${quarkus.http.port}${quarkus.cxf.path}
* </pre>
*
* If you invoke your WS client from within a HTTP handler, you can leave this option unspecified and rather
* set it dynamically on the request context of your WS client using the
* {@code org.apache.cxf.ws.addressing.decoupled.endpoint.base} key. Here is an example how to do that from a
* RESTeasy handler method:
*
* <pre>
* import java.util.Map;
* import jakarta.inject.Inject;
* import jakarta.ws.rs.POST;
* import jakarta.ws.rs.Path;
* import jakarta.ws.rs.Produces;
* import jakarta.ws.rs.core.Context;
* import jakarta.ws.rs.core.MediaType;
* import jakarta.ws.rs.core.UriInfo;
* import jakarta.xml.ws.BindingProvider;
* import io.quarkiverse.cxf.annotation.CXFClient;
* import org.eclipse.microprofile.config.inject.ConfigProperty;
*
* &#64;Path("/my-rest")
* public class MyRestEasyResource {
*
* &#64;Inject
* &#64;CXFClient("hello")
* HelloService helloService;
*
* &#64;ConfigProperty(name = "quarkus.cxf.path")
* String quarkusCxfPath;
*
* &#64;POST
* &#64;Path("/hello")
* &#64;Produces(MediaType.TEXT_PLAIN)
* public String hello(String body, &#64;Context UriInfo uriInfo) throws IOException {
*
* // You may consider doing this only once if you are sure that your service is accessed
* // through a single hostname
* String decoupledEndpointBase = uriInfo.getBaseUriBuilder().path(quarkusCxfPath);
* Map&gt;String, Object&lt; requestContext = ((BindingProvider) helloService).getRequestContext();
* requestContext.put("org.apache.cxf.ws.addressing.decoupled.endpoint.base", decoupledEndpointBase);
*
* return wsrmHelloService.hello(body);
* }
* }
* </pre>
*
* @since 2.7.0
*/
public Optional<String> decoupledEndpointBase();

/**
* Choose the path of each web services.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Global settings
quarkus.cxf.decoupled-endpoint-base = http://localhost:${quarkus.http.test-port}${quarkus.cxf.path}

# Global WS-RM settings
quarkus.cxf.rm.namespace = http://docs.oasis-open.org/ws-rx/wsrm/200702
quarkus.cxf.rm.retransmission-interval = 1000
Expand All @@ -10,4 +13,3 @@ quarkus.cxf.client.wsrm.out-interceptors = #messageLossSimulator
quarkus.cxf.client.wsrm.in-interceptors = #inMessageRecorder
quarkus.cxf.client.wsrm.connection = keep-alive
quarkus.cxf.client.wsrm.decoupled-endpoint = /wsrm/decoupled-endpoint
quarkus.cxf.client.wsrm.decoupled-endpoint-base = http://localhost:${quarkus.http.test-port}${quarkus.cxf.path}

0 comments on commit 920cd1c

Please sign in to comment.