-
Notifications
You must be signed in to change notification settings - Fork 5.1k
CAMEL-22549: Replace deprecated Exchange getOut/hasOut/setOut with getMessage #22358
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
97d3545
e3c6911
3480212
54ae9b5
dafc1c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,9 +43,7 @@ public void process(Exchange exchange) throws Exception { | |
|
|
||
| Message in = exchange.getIn(); | ||
| clearMessageHeaders(in); | ||
| Message out = exchange.getOut(); | ||
| out.copyFrom(in); | ||
| out.setHeader(config.getSignatureHeaderName(), new Base64().encode(signature)); | ||
| exchange.getMessage().setHeader(config.getSignatureHeaderName(), new Base64().encode(signature)); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pattern: removed redundant The old code did: Message out = exchange.getOut(); // creates OUT, copies headers from IN
out.copyFrom(in); // copies body+headers from IN to OUT again
out.setHeader(..., signature); // sets the signature header
|
||
| } | ||
|
|
||
| protected Signature initSignatureService(Exchange exchange) throws Exception { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,10 +64,8 @@ public void process(Exchange exchange) throws Exception { | |
| Source src = exchange.getIn().getBody(StreamSource.class); | ||
|
|
||
| OutputStream out = transform(userAgent, outputFormat, src); | ||
| exchange.getOut().setBody(out); | ||
|
|
||
| // propagate headers | ||
| exchange.getOut().setHeaders(headers); | ||
| exchange.getMessage().setBody(out); | ||
| exchange.getMessage().setHeaders(headers); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pattern: removed redundant header propagation The old code saved |
||
| } | ||
|
|
||
| private String getOutputFormat(Exchange exchange) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,6 @@ | |
| import org.apache.camel.Exchange; | ||
| import org.apache.camel.InvalidPayloadException; | ||
| import org.apache.camel.support.DefaultProducer; | ||
| import org.apache.camel.support.MessageHelper; | ||
| import org.apache.camel.util.ObjectHelper; | ||
| import org.influxdb.InfluxDB; | ||
| import org.influxdb.dto.BatchPoints; | ||
|
|
@@ -99,13 +98,11 @@ private void doQuery(Exchange exchange, String dataBaseName) { | |
| String query = calculateQuery(exchange); | ||
| Query influxdbQuery = new Query(query, dataBaseName); | ||
| QueryResult resultSet = connection.query(influxdbQuery); | ||
| MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); | ||
| exchange.getMessage().setBody(resultSet); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pattern: removed
Same pattern in: |
||
| } | ||
|
|
||
| private void doPing(Exchange exchange) { | ||
| Pong result = connection.ping(); | ||
| MessageHelper.copyHeaders(exchange.getIn(), exchange.getOut(), true); | ||
| exchange.getMessage().setBody(result); | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,7 +18,6 @@ | |
|
|
||
| import org.apache.camel.Exchange; | ||
| import org.apache.camel.Expression; | ||
| import org.apache.camel.Message; | ||
| import org.apache.camel.support.DefaultProducer; | ||
| import org.apache.camel.util.ObjectHelper; | ||
| import org.jooq.Configuration; | ||
|
|
@@ -71,8 +70,7 @@ public void process(Exchange exchange) { | |
| result = context.fetch(querySQL); | ||
| } | ||
|
|
||
| Message target = exchange.getPattern().isOutCapable() ? exchange.getOut() : exchange.getIn(); | ||
| target.setBody(result); | ||
| exchange.getMessage().setBody(result); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pattern:
Same pattern in: |
||
| break; | ||
| case NONE: | ||
| DSLContext context = DSL.using(dbConfig); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,7 +30,6 @@ | |
| import org.apache.camel.ExchangePropertyKey; | ||
| import org.apache.camel.Processor; | ||
| import org.apache.camel.support.DefaultConsumer; | ||
| import org.apache.camel.support.ExchangeHelper; | ||
| import org.apache.camel.util.IOHelper; | ||
| import org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder; | ||
| import org.apache.mina.core.filterchain.IoFilter; | ||
|
|
@@ -385,7 +384,7 @@ private Exchange createExchange(IoSession session, Object payload) { | |
| exchange.getIn().setHeader(MinaConstants.MINA_IOSESSION, session); | ||
| exchange.getIn().setHeader(MinaConstants.MINA_LOCAL_ADDRESS, session.getLocalAddress()); | ||
| exchange.getIn().setHeader(MinaConstants.MINA_REMOTE_ADDRESS, session.getRemoteAddress()); | ||
| MinaPayloadHelper.setIn(exchange, payload); | ||
| MinaPayloadHelper.setPayload(exchange, payload); | ||
| return exchange; | ||
| } | ||
|
|
||
|
|
@@ -440,20 +439,15 @@ public void messageReceived(IoSession session, Object object) throws Exception { | |
| // If there's a response to send, send it. | ||
| // | ||
| boolean disconnect = getEndpoint().getConfiguration().isDisconnect(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pattern: removed The old code checked |
||
| Object response; | ||
| if (exchange.hasOut()) { | ||
| response = MinaPayloadHelper.getOut(getEndpoint(), exchange); | ||
| } else { | ||
| response = MinaPayloadHelper.getIn(getEndpoint(), exchange); | ||
| } | ||
| Object response = MinaPayloadHelper.getResponsePayload(getEndpoint(), exchange); | ||
|
|
||
| boolean failed = exchange.isFailed(); | ||
| if (failed && !getEndpoint().getConfiguration().isTransferExchange()) { | ||
| if (exchange.getException() != null) { | ||
| response = exchange.getException(); | ||
| } else { | ||
| // failed and no exception, must be a fault | ||
| response = exchange.getOut().getBody(); | ||
| response = exchange.getMessage().getBody(); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -466,12 +460,8 @@ public void messageReceived(IoSession session, Object object) throws Exception { | |
| } | ||
|
|
||
| // should session be closed after complete? | ||
| Boolean close; | ||
| if (ExchangeHelper.isOutCapable(exchange)) { | ||
| close = exchange.getOut().getHeader(MinaConstants.MINA_CLOSE_SESSION_WHEN_COMPLETE, Boolean.class); | ||
| } else { | ||
| close = exchange.getIn().getHeader(MinaConstants.MINA_CLOSE_SESSION_WHEN_COMPLETE, Boolean.class); | ||
| } | ||
| Boolean close | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same pattern: |
||
| = exchange.getMessage().getHeader(MinaConstants.MINA_CLOSE_SESSION_WHEN_COMPLETE, Boolean.class); | ||
|
|
||
| // should we disconnect, the header can override the configuration | ||
| if (close != null) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,7 +32,7 @@ private MinaPayloadHelper() { | |
| //Utility Class | ||
| } | ||
|
|
||
| public static Object getIn(MinaEndpoint endpoint, Exchange exchange) { | ||
| public static Object getRequestPayload(MinaEndpoint endpoint, Exchange exchange) { | ||
| if (endpoint.getConfiguration().isTransferExchange()) { | ||
| // we should transfer the entire exchange over the wire (includes in/out) | ||
| return DefaultExchangeHolder.marshal(exchange); | ||
|
|
@@ -42,32 +42,22 @@ public static Object getIn(MinaEndpoint endpoint, Exchange exchange) { | |
| } | ||
| } | ||
|
|
||
| public static Object getOut(MinaEndpoint endpoint, Exchange exchange) { | ||
| public static Object getResponsePayload(MinaEndpoint endpoint, Exchange exchange) { | ||
| if (endpoint.getConfiguration().isTransferExchange()) { | ||
| // we should transfer the entire exchange over the wire (includes in/out) | ||
| return DefaultExchangeHolder.marshal(exchange); | ||
| } else { | ||
| // normal transfer using the body only | ||
| return exchange.getOut().getBody(); | ||
| return exchange.getMessage().getBody(); | ||
| } | ||
| } | ||
|
|
||
| public static void setIn(Exchange exchange, Object payload) { | ||
| public static void setPayload(Exchange exchange, Object payload) { | ||
| if (payload instanceof DefaultExchangeHolder) { | ||
| DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) payload); | ||
| } else { | ||
| // normal transfer using the body only | ||
| exchange.getIn().setBody(payload); | ||
| } | ||
| } | ||
|
|
||
| public static void setOut(Exchange exchange, Object payload) { | ||
| if (payload instanceof DefaultExchangeHolder) { | ||
| DefaultExchangeHolder.unmarshal(exchange, (DefaultExchangeHolder) payload); | ||
| } else { | ||
| // normal transfer using the body only and preserve the headers | ||
| exchange.getOut().setHeaders(exchange.getIn().getHeaders()); | ||
| exchange.getOut().setBody(payload); | ||
| exchange.getMessage().setBody(payload); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The old |
||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -125,7 +125,7 @@ public T outMessage(final Function<Message, Object> function) { | |
| return delegate.expression(new ExpressionAdapter() { | ||
| @Override | ||
| public Object evaluate(Exchange exchange) { | ||
| return function.apply(exchange.getOut()); | ||
| return function.apply(exchange.getMessage()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These methods ( |
||
| } | ||
| }); | ||
| } | ||
|
|
@@ -215,7 +215,7 @@ public T outBody(final Function<Object, Object> function) { | |
| return delegate.expression(new ExpressionAdapter() { | ||
| @Override | ||
| public Object evaluate(Exchange exchange) { | ||
| return function.apply(exchange.getOut().getBody()); | ||
| return function.apply(exchange.getMessage().getBody()); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -228,8 +228,8 @@ public T outBody(final BiFunction<Object, Map<String, Object>, Object> function) | |
| @Override | ||
| public Object evaluate(Exchange exchange) { | ||
| return function.apply( | ||
| exchange.getOut().getBody(), | ||
| exchange.getOut().getHeaders()); | ||
| exchange.getMessage().getBody(), | ||
| exchange.getMessage().getHeaders()); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -241,7 +241,7 @@ public <B> T outBody(Class<B> expectedType, final Function<B, Object> function) | |
| return delegate.expression(new ExpressionAdapter() { | ||
| @Override | ||
| public Object evaluate(Exchange exchange) { | ||
| return function.apply(exchange.getOut().getBody(expectedType)); | ||
| return function.apply(exchange.getMessage().getBody(expectedType)); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -254,8 +254,8 @@ public <B> T outBody(Class<B> expectedType, final BiFunction<B, Map<String, Obje | |
| @Override | ||
| public Object evaluate(Exchange exchange) { | ||
| return function.apply( | ||
| exchange.getOut().getBody(expectedType), | ||
| exchange.getOut().getHeaders()); | ||
| exchange.getMessage().getBody(expectedType), | ||
| exchange.getMessage().getHeaders()); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,7 +79,9 @@ private void addData() { | |
| Exchange copy = (Exchange) body; | ||
| exchange.setException(copy.getException()); | ||
| exchange.setIn(copy.getIn()); | ||
| if (copy.hasOut()) { | ||
| @SuppressWarnings("deprecation") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Pattern: exchange reconstruction — kept deprecated API with This code reconstructs a full exchange by copying IN, OUT, properties, and exception from a received exchange. This inherently requires the in/out distinction: if the source exchange has a separate OUT message, it must be transferred as-is to preserve the exchange state. This cannot be safely replaced with |
||
| boolean hasOut = copy.hasOut(); | ||
| if (hasOut) { | ||
| exchange.setOut(copy.getOut()); | ||
| } | ||
| exchange.getProperties().clear(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pattern: simple
getOut().setBody()→getMessage().setBody()getOut()lazily creates a new OUT message (copying headers from IN).getMessage()returns the current message (OUT if one exists, otherwise IN). Since no OUT was previously created here,getOut()was creating an OUT just to set a body on it —getMessage()achieves the same result without the unnecessary OUT message creation.Same pattern applies to:
BeanIODataFormat,BindyFixedLengthDataFormat,PGPKeyAccessDataFormat,HL7DataFormat,JcrProducer,Soap11/12DataFormatAdapter,SoapDataFormat,RocketMQReplyManagerSupport,SinkConverter.