You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2022/12/01 06:06:14 UTC
[isis] branch master updated: ISIS-3275: re-implement OutboxClient on top of RestClient (1)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new bb003fe6c1 ISIS-3275: re-implement OutboxClient on top of RestClient (1)
bb003fe6c1 is described below
commit bb003fe6c141f4da0619b9f87f634e3e09d12db9
Author: Andi Huber <ah...@apache.org>
AuthorDate: Thu Dec 1 07:06:06 2022 +0100
ISIS-3275: re-implement OutboxClient on top of RestClient (1)
---
.../executionoutbox/restclient/api/Jsonable.java | 27 -------
.../restclient/api/OutboxClient.java | 28 ++++---
.../executionoutbox/restclient/api/_Jaxb.java | 92 ----------------------
.../restclient/api/delete/DeleteMessage.java | 30 +------
.../restclient/api/delete/IntValue.java | 7 +-
.../restclient/api/delete/StringValue.java | 7 +-
.../api/deleteMany/DeleteManyMessage.java | 27 +------
7 files changed, 29 insertions(+), 189 deletions(-)
diff --git a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/Jsonable.java b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/Jsonable.java
deleted file mode 100644
index 55984f3dc5..0000000000
--- a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/Jsonable.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.causeway.extensions.executionoutbox.restclient.api;
-
-public interface Jsonable {
-
- String asJson();
-
-}
diff --git a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/OutboxClient.java b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/OutboxClient.java
index 899641a951..3b6063e560 100644
--- a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/OutboxClient.java
+++ b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/OutboxClient.java
@@ -31,6 +31,8 @@ import javax.ws.rs.client.Entity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriBuilder;
+import org.apache.causeway.applib.util.schema.InteractionsDtoUtils;
+import org.apache.causeway.commons.internal.resources._Json;
import org.apache.causeway.extensions.executionoutbox.restclient.api.delete.DeleteMessage;
import org.apache.causeway.extensions.executionoutbox.restclient.api.deleteMany.DeleteManyMessage;
import org.apache.causeway.schema.common.v2.InteractionType;
@@ -73,7 +75,7 @@ public class OutboxClient {
* for debugging
* @param connectTimeoutInSecs
*/
- public OutboxClient withConnectTimeoutInSecs(int connectTimeoutInSecs) {
+ public OutboxClient withConnectTimeoutInSecs(final int connectTimeoutInSecs) {
clientBuilder.connectTimeout(connectTimeoutInSecs, TimeUnit.SECONDS);
return this;
}
@@ -82,7 +84,7 @@ public class OutboxClient {
* for debugging
* @param readTimeoutInSecs
*/
- public OutboxClient withReadTimeoutInSecs(int readTimeoutInSecs) {
+ public OutboxClient withReadTimeoutInSecs(final int readTimeoutInSecs) {
clientBuilder.readTimeout(readTimeoutInSecs, TimeUnit.SECONDS);
return this;
}
@@ -158,46 +160,46 @@ public class OutboxClient {
public void delete(final String interactionId, final int sequence) {
- val jsonable = new DeleteMessage(interactionId, sequence);
- invoke(jsonable, deleteUriBuilder);
+ val entity = new DeleteMessage(interactionId, sequence);
+ invoke(entity, deleteUriBuilder);
}
public void deleteMany(final List<InteractionDto> interactionDtos) {
- InteractionsDto interactionsDto = new InteractionsDto();
+ val interactionsDto = new InteractionsDto();
interactionDtos.forEach(interactionDto -> {
addTo(interactionsDto, interactionDto);
});
- val jsonable = new DeleteManyMessage(_Jaxb.toXml(interactionsDto));
- invoke(jsonable, deleteManyUriBuilder);
+ val entity = new DeleteManyMessage(InteractionsDtoUtils.toXml(interactionsDto));
+ invoke(entity, deleteManyUriBuilder);
}
- private void addTo(InteractionsDto interactionsDto, InteractionDto orig) {
- InteractionDto copy = new InteractionDto();
+ private void addTo(final InteractionsDto interactionsDto, final InteractionDto orig) {
+ val copy = new InteractionDto();
copy.setInteractionId(orig.getInteractionId());
setMemberExecution(copy, orig);
interactionsDto.getInteractionDto().add(copy);
}
- private void setMemberExecution(InteractionDto copy, InteractionDto orig) {
+ private void setMemberExecution(final InteractionDto copy, final InteractionDto orig) {
val memberExecutionDto = newMemberExecutionDto(orig);
memberExecutionDto.setSequence(orig.getExecution().getSequence());
copy.setExecution(memberExecutionDto);
}
- private MemberExecutionDto newMemberExecutionDto(InteractionDto orig) {
+ private MemberExecutionDto newMemberExecutionDto(final InteractionDto orig) {
val execution = orig.getExecution();
return execution.getInteractionType() == InteractionType.ACTION_INVOCATION
? new ActionInvocationDto()
: new PropertyEditDto();
}
- private void invoke(Jsonable entity, UriBuilder uriBuilder) {
+ private void invoke(final Object entity, final UriBuilder uriBuilder) {
ensureInitialized();
- val json = entity.asJson();
+ val json = _Json.toString(entity);
Client client = null;
try {
diff --git a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/_Jaxb.java b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/_Jaxb.java
deleted file mode 100644
index a72762c655..0000000000
--- a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/_Jaxb.java
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you 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 org.apache.causeway.extensions.executionoutbox.restclient.api;
-
-import java.io.CharArrayWriter;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-import javax.xml.bind.JAXBContext;
-import javax.xml.bind.JAXBException;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-
-
-
-/**
- * Helper methods for converting {@link javax.xml.bind.annotation.XmlRootElement}-annotated class to-and-from XML. Intended primarily for
- * test use only (the {@link JAXBContext} is not cached).
- *
- * <p>
- * For example usage, see <a href="https://github.com/causewayaddons/causeway-module-publishmq">Causeway addons' publishmq module</a> (non-ASF)
- * </p>
- */
-class _Jaxb {
-
- private _Jaxb(){}
-
- static <T> T fromXml(
- final Reader reader,
- final Class<T> dtoClass) {
- Unmarshaller un = null;
- try {
- un = jaxbContextFor(dtoClass).createUnmarshaller();
- return (T) un.unmarshal(reader);
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- }
- }
-
- static <T> String toXml(final T dto) {
- final CharArrayWriter caw = new CharArrayWriter();
- toXml(dto, caw);
- return caw.toString();
- }
-
- static <T> void toXml(final T dto, final Writer writer) {
- Marshaller m = null;
- try {
- final Class<?> aClass = dto.getClass();
- m = jaxbContextFor(aClass).createMarshaller();
- m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
- m.marshal(dto, writer);
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- }
- }
-
- private static Map<Class<?>, JAXBContext> jaxbContextByClass = new ConcurrentHashMap<>();
-
- private static <T> JAXBContext jaxbContextFor(final Class<T> dtoClass) {
- JAXBContext jaxbContext = jaxbContextByClass.get(dtoClass);
- if(jaxbContext == null) {
- try {
- jaxbContext = JAXBContext.newInstance(dtoClass);
- } catch (JAXBException e) {
- throw new RuntimeException(e);
- }
- jaxbContextByClass.put(dtoClass, jaxbContext);
- }
- return jaxbContext;
- }
-}
diff --git a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/DeleteMessage.java b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/DeleteMessage.java
index 5c47a3d0b8..ec82d8f310 100644
--- a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/DeleteMessage.java
+++ b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/DeleteMessage.java
@@ -20,41 +20,19 @@
package org.apache.causeway.extensions.executionoutbox.restclient.api.delete;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectWriter;
-
-import org.apache.causeway.extensions.executionoutbox.restclient.api.Jsonable;
-
import lombok.Getter;
-public class DeleteMessage implements Jsonable {
+@lombok.Value
+public class DeleteMessage {
- private static final ObjectWriter writer;
-
- static {
- final ObjectMapper mapper = new ObjectMapper();
- writer = mapper.writer().withDefaultPrettyPrinter();
- }
-
- @Getter
- private final StringValue interactionId;
- @Getter
- private final IntValue sequence;
+ @Getter private final StringValue interactionId;
+ @Getter private final IntValue sequence;
public DeleteMessage(final String interactionId, final int sequence) {
this.interactionId = new StringValue(interactionId);
this.sequence = new IntValue(sequence);
}
- public String asJson() {
- try {
- return writer.writeValueAsString(this);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- }
-
@Override
public String toString() {
return "[DELETE MESSAGE] \n" +
diff --git a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/IntValue.java b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/IntValue.java
index 37841dfafe..cc2c71f82e 100644
--- a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/IntValue.java
+++ b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/IntValue.java
@@ -20,11 +20,12 @@
package org.apache.causeway.extensions.executionoutbox.restclient.api.delete;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor
public class IntValue {
+
public final Integer value;
- public IntValue(final Integer value) {
- this.value = value;
- }
@Override
public String toString() {
diff --git a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/StringValue.java b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/StringValue.java
index 18fcab4c60..4a48080ef8 100644
--- a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/StringValue.java
+++ b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/delete/StringValue.java
@@ -20,14 +20,13 @@
package org.apache.causeway.extensions.executionoutbox.restclient.api.delete;
+import lombok.RequiredArgsConstructor;
+
+@RequiredArgsConstructor
public class StringValue {
public final String value;
- public StringValue(final String value) {
- this.value = value;
- }
-
@Override
public String toString() {
return String.valueOf(value);
diff --git a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/deleteMany/DeleteManyMessage.java b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/deleteMany/DeleteManyMessage.java
index cdcf1dce02..0ef5bbd91f 100644
--- a/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/deleteMany/DeleteManyMessage.java
+++ b/extensions/core/executionoutbox/restclient/src/main/java/org/apache/causeway/extensions/executionoutbox/restclient/api/deleteMany/DeleteManyMessage.java
@@ -20,38 +20,17 @@
package org.apache.causeway.extensions.executionoutbox.restclient.api.deleteMany;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.ObjectWriter;
-
-import org.apache.causeway.extensions.executionoutbox.restclient.api.Jsonable;
-
import lombok.Getter;
-public class DeleteManyMessage implements Jsonable {
+@lombok.Value
+public class DeleteManyMessage {
- private static final ObjectWriter writer;
-
- static {
- final ObjectMapper mapper = new ObjectMapper();
- writer = mapper.writer().withDefaultPrettyPrinter();
- }
-
- @Getter
- private final StringValue interactionsDtoXml;
+ @Getter private final StringValue interactionsDtoXml;
public DeleteManyMessage(final String interactionsDtoXml) {
this.interactionsDtoXml = new StringValue(interactionsDtoXml);
}
- public String asJson() {
- try {
- return writer.writeValueAsString(this);
- } catch (JsonProcessingException e) {
- throw new RuntimeException(e);
- }
- }
-
@Override
public String toString() {
return "[DELETE MANY MESSAGE] \n" +