From 1d7f3daa9d2b1ff09805865b4defb483a0d2c0c1 Mon Sep 17 00:00:00 2001 From: Z14tk0 Date: Mon, 4 Nov 2024 16:14:51 +0100 Subject: [PATCH 1/2] Feature - returning response headers in SearchResult --- midpoint-client-api/pom.xml | 4 ++++ .../midpoint/client/api/SearchResult.java | 2 +- .../client/api/SearchResultMetadata.java | 22 +++++++++++++++++++ .../impl/restjaxb/JaxbSearchResult.java | 12 ++++++++++ .../impl/restjaxb/RestJaxbSearchService.java | 2 +- .../client/impl/restjaxb/TestBasic.java | 10 +++++++++ .../impl/restjaxb/TestIntegrationBasic.java | 8 +++++++ pom.xml | 6 +++++ 8 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResultMetadata.java diff --git a/midpoint-client-api/pom.xml b/midpoint-client-api/pom.xml index f8aa824..51e3977 100644 --- a/midpoint-client-api/pom.xml +++ b/midpoint-client-api/pom.xml @@ -33,5 +33,9 @@ schema-pure-jaxb ${midpoint.version} + + jakarta.ws.rs + jakarta.ws.rs-api + diff --git a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java index fc77e0c..637d3d8 100644 --- a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java +++ b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java @@ -23,6 +23,6 @@ * @author semancik * */ -public interface SearchResult extends List { +public interface SearchResult extends List, SearchResultMetadata { } diff --git a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResultMetadata.java b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResultMetadata.java new file mode 100644 index 0000000..6ca5734 --- /dev/null +++ b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResultMetadata.java @@ -0,0 +1,22 @@ +/* + * Copyright (c) 2017-2020 Evolveum + * + * 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 com.evolveum.midpoint.client.api; + +import jakarta.ws.rs.core.MultivaluedMap; + +public interface SearchResultMetadata { + MultivaluedMap getHeaders(); +} \ No newline at end of file diff --git a/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/JaxbSearchResult.java b/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/JaxbSearchResult.java index 9450202..9095355 100644 --- a/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/JaxbSearchResult.java +++ b/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/JaxbSearchResult.java @@ -21,6 +21,7 @@ import java.util.List; import java.util.ListIterator; +import jakarta.ws.rs.core.MultivaluedMap; import org.apache.cxf.common.util.CollectionUtils; import com.evolveum.midpoint.client.api.SearchResult; @@ -34,6 +35,7 @@ public class JaxbSearchResult implements SearchResult { private List list = null; + private MultivaluedMap headers; public JaxbSearchResult() { } @@ -43,6 +45,16 @@ public JaxbSearchResult(List list) { this.list = list; } + public JaxbSearchResult(List list, MultivaluedMap headers) { + this.list = list; + this.headers = headers; + } + + @Override + public MultivaluedMap getHeaders() { + return headers; + } + @Override public int size() { if (list == null) { diff --git a/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/RestJaxbSearchService.java b/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/RestJaxbSearchService.java index a5e6f2c..b605895 100644 --- a/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/RestJaxbSearchService.java +++ b/midpoint-client-impl-rest-jaxb/src/main/java/com/evolveum/midpoint/client/impl/restjaxb/RestJaxbSearchService.java @@ -84,7 +84,7 @@ public SearchResult get() throws ObjectNotFoundException { Response response = getService().post(path, query, queryParams); if (Status.OK.getStatusCode() == response.getStatus()) { - return new JaxbSearchResult<>(getSearchResultList(response)); + return new JaxbSearchResult<>(getSearchResultList(response), response.getHeaders()); } if (Status.NOT_FOUND.getStatusCode() == response.getStatus()) { diff --git a/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestBasic.java b/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestBasic.java index 1fb8957..5af3f9f 100644 --- a/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestBasic.java +++ b/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestBasic.java @@ -25,6 +25,7 @@ import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; import com.evolveum.prism.xml.ns._public.types_3.ItemPathType; +import jakarta.ws.rs.core.MultivaluedMap; import org.apache.cxf.endpoint.Server; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; @@ -227,6 +228,15 @@ public void test014UserFilterQuerySearchMock() throws Exception { assertEquals(result.size(), 0); } + @Test + public void test015SearchResultResponseHeaders() throws Exception { + Service service = getService(); + + SearchResult searchResult = service.users().search().get(); + + MultivaluedMap responseHeaders = searchResult.getHeaders(); + assertNotNull(responseHeaders); + } @Test public void test011ValuePolicyGet() throws Exception { diff --git a/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestIntegrationBasic.java b/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestIntegrationBasic.java index 902e94b..b231d47 100644 --- a/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestIntegrationBasic.java +++ b/midpoint-client-impl-rest-jaxb/src/test/java/com/evolveum/midpoint/client/impl/restjaxb/TestIntegrationBasic.java @@ -25,6 +25,7 @@ import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType; import com.evolveum.prism.xml.ns._public.types_3.ItemPathType; +import jakarta.ws.rs.core.MultivaluedMap; import org.apache.commons.lang3.StringUtils; import org.testng.AssertJUnit; import org.testng.annotations.BeforeClass; @@ -414,6 +415,13 @@ public void test610searchUserFilterQuery() throws Exception { assertEquals(users.size(), 1); } + @Test + public void test615SearchResultResponseHeaders() throws Exception { + SearchResult searchResult = service.users().search().queryFor(UserType.class).get(); + + MultivaluedMap responseHeaders = searchResult.getHeaders(); + assertNotNull(responseHeaders); + } @Test public void test700addSecurityPolicy() throws Exception { diff --git a/pom.xml b/pom.xml index 97dbcfb..317469d 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ 3.5.2 3.0.0 3.17.0 + 4.0.0 @@ -137,6 +138,11 @@ jakarta.xml.bind-impl ${jaxb.version} + + jakarta.ws.rs + jakarta.ws.rs-api + ${jakarta.ws.rs-api.version} + com.sun.xml.bind jaxb-core From 91bbf64071253e6a99d5305bd4b46eb7228e52fe Mon Sep 17 00:00:00 2001 From: Z14tk0 Date: Tue, 5 Nov 2024 21:43:01 +0100 Subject: [PATCH 2/2] Feature - returning response headers in SearchResult --- .../midpoint/client/api/SearchResult.java | 6 +++-- .../client/api/SearchResultMetadata.java | 22 ------------------- 2 files changed, 4 insertions(+), 24 deletions(-) delete mode 100644 midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResultMetadata.java diff --git a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java index 637d3d8..911848f 100644 --- a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java +++ b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResult.java @@ -19,10 +19,12 @@ import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType; +import jakarta.ws.rs.core.MultivaluedMap; + /** * @author semancik * */ -public interface SearchResult extends List, SearchResultMetadata { - +public interface SearchResult extends List { + MultivaluedMap getHeaders(); } diff --git a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResultMetadata.java b/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResultMetadata.java deleted file mode 100644 index 6ca5734..0000000 --- a/midpoint-client-api/src/main/java/com/evolveum/midpoint/client/api/SearchResultMetadata.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Copyright (c) 2017-2020 Evolveum - * - * 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 com.evolveum.midpoint.client.api; - -import jakarta.ws.rs.core.MultivaluedMap; - -public interface SearchResultMetadata { - MultivaluedMap getHeaders(); -} \ No newline at end of file