Skip to content

Commit

Permalink
[#6888] Use @ApplicationScoped instead of @SessionScoped
Browse files Browse the repository at this point in the history
  • Loading branch information
llowinge authored and jamesnetherton committed Jan 7, 2025
1 parent dddddda commit a90f8e7
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 49 deletions.
6 changes: 2 additions & 4 deletions docs/modules/ROOT/pages/reference/extensions/cxf-soap.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ With `camel-quarkus-cxf-soap` (no additional dependencies required), you can use
----
import org.apache.camel.builder.RouteBuilder;
import {javaxOrJakartaPackagePrefix}.enterprise.context.ApplicationScoped;
import {javaxOrJakartaPackagePrefix}.enterprise.context.SessionScoped;
import {javaxOrJakartaPackagePrefix}.enterprise.inject.Produces;
import {javaxOrJakartaPackagePrefix}.inject.Named;
Expand All @@ -89,7 +88,7 @@ public class CxfSoapClientRoutes extends RouteBuilder {
}
@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint beanClient() {
final CxfEndpoint result = new CxfEndpoint();
Expand Down Expand Up @@ -219,7 +218,6 @@ You can enable verbose logging of SOAP messages for both clients and servers wit
import org.apache.camel.builder.RouteBuilder;
import org.apache.cxf.ext.logging.LoggingFeature;
import {javaxOrJakartaPackagePrefix}.enterprise.context.ApplicationScoped;
import {javaxOrJakartaPackagePrefix}.enterprise.context.SessionScoped;
import {javaxOrJakartaPackagePrefix}.enterprise.inject.Produces;
import {javaxOrJakartaPackagePrefix}.inject.Named;
Expand All @@ -240,7 +238,7 @@ public class MyBeans {
LoggingFeature prettyLoggingFeature;
@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint cxfBeanClient() {
final CxfEndpoint result = new CxfEndpoint();
Expand Down
6 changes: 2 additions & 4 deletions extensions/cxf-soap/runtime/src/main/doc/usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ With `camel-quarkus-cxf-soap` (no additional dependencies required), you can use
----
import org.apache.camel.builder.RouteBuilder;
import {javaxOrJakartaPackagePrefix}.enterprise.context.ApplicationScoped;
import {javaxOrJakartaPackagePrefix}.enterprise.context.SessionScoped;
import {javaxOrJakartaPackagePrefix}.enterprise.inject.Produces;
import {javaxOrJakartaPackagePrefix}.inject.Named;
Expand All @@ -38,7 +37,7 @@ public class CxfSoapClientRoutes extends RouteBuilder {
}
@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint beanClient() {
final CxfEndpoint result = new CxfEndpoint();
Expand Down Expand Up @@ -166,7 +165,6 @@ You can enable verbose logging of SOAP messages for both clients and servers wit
import org.apache.camel.builder.RouteBuilder;
import org.apache.cxf.ext.logging.LoggingFeature;
import {javaxOrJakartaPackagePrefix}.enterprise.context.ApplicationScoped;
import {javaxOrJakartaPackagePrefix}.enterprise.context.SessionScoped;
import {javaxOrJakartaPackagePrefix}.enterprise.inject.Produces;
import {javaxOrJakartaPackagePrefix}.inject.Named;
Expand All @@ -187,7 +185,7 @@ public class MyBeans {
LoggingFeature prettyLoggingFeature;
@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint cxfBeanClient() {
final CxfEndpoint result = new CxfEndpoint();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import com.sun.xml.messaging.saaj.soap.ver1_1.Message1_1Impl;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Named;
Expand Down Expand Up @@ -63,7 +62,7 @@ public class CxfSoapClientRoutes extends RouteBuilder {
public void configure() {

from("direct:simpleUriBean")
.to("cxf:bean:soapClientEndpoint?dataFormat=POJO");
.to("cxf:bean:soapClientEndpointPojo");

from("direct:simpleUriAddress")
.to(String.format("cxf://%s?wsdlURL=%s&dataFormat=POJO&serviceClass=%s", calculatorServiceAddress(),
Expand All @@ -85,17 +84,17 @@ public void configure() {
}
}
})
.toD("cxf:bean:soapClientEndpoint?dataFormat=${header.endpointDataFormat}");
.toD("cxf:bean:soapClientEndpoint${header.endpointDataFormat}");

from("direct:operandsAdd")
.setHeader(CxfConstants.OPERATION_NAME).constant("addOperands")
.to("cxf:bean:soapClientEndpoint?dataFormat=POJO");
.to("cxf:bean:soapClientEndpointPojo");

from("direct:basicAuthAdd")
.to("cxf:bean:basicAuthClientEndpoint?dataFormat=POJO&username={{cq.cxf.it.calculator.auth.basic.user}}&password={{cq.cxf.it.calculator.auth.basic.password}}");
.to("cxf:bean:basicAuthAddClientEndpoint?username={{cq.cxf.it.calculator.auth.basic.user}}&password={{cq.cxf.it.calculator.auth.basic.password}}");

from("direct:basicAuthAddAnonymous")
.to("cxf:bean:basicAuthClientEndpoint?dataFormat=POJO");
.to("cxf:bean:basicAuthAddAnonymousClientEndpoint");

}

Expand All @@ -109,10 +108,29 @@ public LoggingFeature loggingFeature() {
}

@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint soapClientEndpoint() {
CxfEndpoint soapClientEndpointPojo() {
return soapClientCxfEndpoint(DataFormat.POJO);
}

@Produces
@ApplicationScoped
@Named("soapClientEndpointRAW")
CxfEndpoint soapClientEndpointRaw() {
return soapClientCxfEndpoint(DataFormat.RAW);
}

@Produces
@ApplicationScoped
@Named("soapClientEndpointCXF_MESSAGE")
CxfEndpoint soapClientEndpointCxfMessage() {
return soapClientCxfEndpoint(DataFormat.CXF_MESSAGE);
}

private CxfEndpoint soapClientCxfEndpoint(DataFormat dataFormat) {
final CxfEndpoint result = new CxfEndpoint();
result.setDataFormat(dataFormat);
result.setServiceClass(CalculatorService.class);
result.setAddress(calculatorServiceAddress());
result.setWsdlURL(calculatorServiceWsdlUrl());
Expand All @@ -121,10 +139,22 @@ CxfEndpoint soapClientEndpoint() {
}

@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint basicAuthClientEndpoint() {
CxfEndpoint basicAuthAddClientEndpoint() {
return basicAuthCxfEndpoint();
}

@Produces
@ApplicationScoped
@Named
CxfEndpoint basicAuthAddAnonymousClientEndpoint() {
return basicAuthCxfEndpoint();
}

private CxfEndpoint basicAuthCxfEndpoint() {
final CxfEndpoint result = new CxfEndpoint();
result.setDataFormat(DataFormat.POJO);
result.setServiceClass(BasicAuthCalculatorService.class);
result.setAddress(serviceBaseUri + "/calculator-ws/BasicAuthCalculatorService");
result.setWsdlURL("wsdl/BasicAuthCalculatorService.wsdl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@

import io.quarkus.runtime.LaunchMode;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.CxfPayload;
import org.apache.camel.component.cxf.common.DataFormat;
import org.apache.camel.component.cxf.jaxws.CxfEndpoint;
import org.apache.camel.converter.jaxp.XmlConverter;
import org.apache.camel.wsdl_first.types.GetPerson;
Expand Down Expand Up @@ -86,9 +86,9 @@ public void configure() {
new ArrayList<SoapHeader>(), elements, null);
exchange.getIn().setBody(payload);
})
.toD("cxf:bean:soapConverterEndpoint?address=${header.address}&dataFormat=PAYLOAD");
.toD("cxf:bean:soapConverterEndpoint?address=${header.address}");

from("cxf:bean:soapConverterEndpoint?dataFormat=PAYLOAD")
from("cxf:bean:soapConverterEndpointConsumer")
.process(exchange -> {
String operation = exchange.getIn().getHeader("operation", String.class);
if ("pojo".equals(operation)) {
Expand Down Expand Up @@ -130,16 +130,24 @@ public void configure() {
}

@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint soapConverterEndpoint() {
final CxfEndpoint result = new CxfEndpoint();
result.setDataFormat(DataFormat.PAYLOAD);
result.getFeatures().add(loggingFeature);
result.setServiceClass(org.apache.camel.wsdl_first.Person.class);
result.setAddress("/PayLoadConvert/RouterPort");
return result;
}

@Produces
@ApplicationScoped
@Named
CxfEndpoint soapConverterEndpointConsumer() {
return soapConverterEndpoint();
}

@Produces
@ApplicationScoped
@Named("loggingFeatureConverter")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@

import io.quarkiverse.cxf.metrics.QuarkusCxfMetricsFeature;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Named;
import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.cxf.common.DataFormat;
import org.apache.camel.component.cxf.jaxws.CxfEndpoint;
import org.apache.camel.quarkus.component.cxf.soap.it.metrics.service.HelloService;
import org.eclipse.microprofile.config.inject.ConfigProperty;
Expand All @@ -39,7 +39,7 @@ public class CxfSoapMetricsRoutes extends RouteBuilder {
public void configure() {

from("direct:clientMetrics")
.to("cxf:bean:clientMetricsEndpoint?dataFormat=POJO");
.to("cxf:bean:clientMetricsEndpoint");

from("cxf:bean:metricsServiceEndpoint")
.process(e -> {
Expand All @@ -56,10 +56,11 @@ public void configure() {
}

@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint clientMetricsEndpoint() {
final CxfEndpoint result = new CxfEndpoint();
result.setDataFormat(DataFormat.POJO);
result.setServiceClass(HelloService.class);
result.setAddress("http://localhost:" + port + "/soapservice/hello-metrics");
result.setWsdlURL("wsdl/MetricsHelloService.wsdl");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import io.quarkus.runtime.LaunchMode;
import jakarta.activation.DataHandler;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Named;
Expand Down Expand Up @@ -111,6 +110,11 @@ public void configure() {
Map<String, Object> headers = exchange.getIn().getHeaders();
String endpointDataFormat = headers.get("endpointDataFormat").toString();
boolean mtomEnabled = Boolean.parseBoolean(headers.get("mtomEnabled").toString());
if (mtomEnabled) {
headers.put("endpointName", "soapClientMtomEnabledEndpoint" + endpointDataFormat);
} else {
headers.put("endpointName", "soapClientMtomDisabledEndpoint" + endpointDataFormat);
}
headers.put("address", getServerUrl() + "/soapservice/mtom-" +
(mtomEnabled ? "enabled" : "disabled") + "-" + endpointDataFormat.toLowerCase() +
"-mode-image-service");
Expand Down Expand Up @@ -142,10 +146,7 @@ public void configure() {
}
}
})
.choice().when(simple("${header.mtomEnabled} == 'true'"))
.toD("cxf:bean:soapClientMtomEnabledEndpoint?address=${header.address}&mtomEnabled=${header.mtomEnabled}&dataFormat=${header.endpointDataFormat}")
.otherwise()
.toD("cxf:bean:soapClientMtomDisabledEndpoint?address=${header.address}&mtomEnabled=${header.mtomEnabled}&dataFormat=${header.endpointDataFormat}");
.toD("cxf:bean:${header.endpointName}?address=${header.address}&mtomEnabled=${header.mtomEnabled}&dataFormat=${header.endpointDataFormat}");

from("cxf:bean:soapMtomEnabledServerPojoModeEndpoint?dataFormat=POJO")
.to("direct:pojoModeProcessor");
Expand Down Expand Up @@ -258,42 +259,56 @@ public LoggingFeature loggingFeature() {
}

@Produces
@SessionScoped
@Named
CxfEndpoint soapClientMtomEnabledEndpoint() {
@ApplicationScoped
@Named("soapClientMtomEnabledEndpointPOJO")
CxfEndpoint soapClientMtomEnabledEndpointPojo() {
return commonCxfEndpoint(true, "");
}

@Produces
@SessionScoped
@Named
CxfEndpoint soapClientMtomDisabledEndpoint() {
@ApplicationScoped
@Named("soapClientMtomEnabledEndpointPAYLOAD")
CxfEndpoint soapClientMtomEnabledEndpointPayload() {
return commonCxfEndpoint(true, "");
}

@Produces
@ApplicationScoped
@Named("soapClientMtomDisabledEndpointPOJO")
CxfEndpoint soapClientMtomDisabledEndpointPojo() {
return commonCxfEndpoint(false, "");
}

@Produces
@SessionScoped
@ApplicationScoped
@Named("soapClientMtomDisabledEndpointPAYLOAD")
CxfEndpoint soapClientMtomDisabledEndpointPayload() {
return commonCxfEndpoint(false, "");
}

@Produces
@ApplicationScoped
@Named
CxfEndpoint soapMtomDisabledServerPayloadModeEndpoint() {
return commonCxfEndpoint(false, "/mtom-disabled-payload-mode-image-service");
}

@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint soapMtomEnabledServerPayloadModeEndpoint() {
return commonCxfEndpoint(true, "/mtom-enabled-payload-mode-image-service");
}

@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint soapMtomEnabledServerPojoModeEndpoint() {
return commonCxfEndpoint(true, "/mtom-enabled-pojo-mode-image-service");
}

@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint soapMtomDisabledServerPojoModeEndpoint() {
return commonCxfEndpoint(false, "/mtom-disabled-pojo-mode-image-service");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.apache.camel.quarkus.component.cxf.soap.rest.it;

import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.context.SessionScoped;
import jakarta.enterprise.inject.Produces;
import jakarta.inject.Inject;
import jakarta.inject.Named;
Expand Down Expand Up @@ -66,7 +65,7 @@ public LoggingFeature loggingFeatureRest() {
}

@Produces
@SessionScoped
@ApplicationScoped
@Named
CxfEndpoint soapClientRestEndpoint() {
final CxfEndpoint result = new CxfEndpoint();
Expand Down
Loading

0 comments on commit a90f8e7

Please sign in to comment.