http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/NodeResponse.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/NodeResponse.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/NodeResponse.java index 7db1b33..be71b95 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/NodeResponse.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/manager/NodeResponse.java @@ -16,22 +16,20 @@ */ package org.apache.nifi.cluster.manager; -import com.sun.jersey.api.client.ClientResponse; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.nifi.cluster.protocol.NodeIdentifier; -import org.apache.nifi.stream.io.StreamUtils; import org.apache.nifi.web.api.entity.Entity; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import javax.ws.rs.HttpMethod; +import javax.ws.rs.ProcessingException; import javax.ws.rs.WebApplicationException; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.StreamingOutput; -import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -57,29 +55,28 @@ public class NodeResponse { private static final Logger logger = LoggerFactory.getLogger(NodeResponse.class); private final String httpMethod; private final URI requestUri; - private final ClientResponse clientResponse; + private final Response response; private final NodeIdentifier nodeId; private Throwable throwable; private boolean hasCreatedResponse = false; private final Entity updatedEntity; private final long requestDurationNanos; private final String requestId; - private byte[] bufferedResponse; - public NodeResponse(final NodeIdentifier nodeId, final String httpMethod, final URI requestUri, final ClientResponse clientResponse, final long requestDurationNanos, final String requestId) { + public NodeResponse(final NodeIdentifier nodeId, final String httpMethod, final URI requestUri, final Response response, final long requestDurationNanos, final String requestId) { if (nodeId == null) { throw new IllegalArgumentException("Node identifier may not be null."); } else if (StringUtils.isBlank(httpMethod)) { throw new IllegalArgumentException("Http method may not be null or empty."); } else if (requestUri == null) { throw new IllegalArgumentException("Request URI may not be null."); - } else if (clientResponse == null) { + } else if (response == null) { throw new IllegalArgumentException("ClientResponse may not be null."); } this.nodeId = nodeId; this.httpMethod = httpMethod; this.requestUri = requestUri; - this.clientResponse = clientResponse; + this.response = response; this.throwable = null; this.updatedEntity = null; this.requestDurationNanos = requestDurationNanos; @@ -99,7 +96,7 @@ public class NodeResponse { this.nodeId = nodeId; this.httpMethod = httpMethod; this.requestUri = requestUri; - this.clientResponse = null; + this.response = null; this.throwable = throwable; this.updatedEntity = null; this.requestDurationNanos = -1L; @@ -113,7 +110,7 @@ public class NodeResponse { this.nodeId = example.nodeId; this.httpMethod = example.httpMethod; this.requestUri = example.requestUri; - this.clientResponse = example.clientResponse; + this.response = example.response; this.throwable = example.throwable; this.updatedEntity = updatedEntity; this.requestDurationNanos = example.requestDurationNanos; @@ -145,7 +142,7 @@ public class NodeResponse { * so that we don't read the client's input stream as part of creating * the response in the getResponse() method */ - return clientResponse.getStatus(); + return response.getStatus(); } } @@ -160,24 +157,19 @@ public class NodeResponse { } public synchronized void bufferResponse() { - bufferedResponse = new byte[clientResponse.getLength()]; try { - StreamUtils.fillBuffer(clientResponse.getEntityInputStream(), bufferedResponse); - } catch (final IOException e) { + response.bufferEntity(); + } catch (final ProcessingException e) { this.throwable = e; } } public synchronized InputStream getInputStream() { - if (bufferedResponse == null) { - return clientResponse.getEntityInputStream(); - } - - return new ByteArrayInputStream(bufferedResponse); + return response.readEntity(InputStream.class); } - public ClientResponse getClientResponse() { - return clientResponse; + public Response getClientResponse() { + return response; } @@ -241,12 +233,12 @@ public class NodeResponse { } // set the status - final ResponseBuilder responseBuilder = Response.status(clientResponse.getStatus()); + final ResponseBuilder responseBuilder = Response.status(response.getStatus()); // set the headers - for (final String key : clientResponse.getHeaders().keySet()) { - final List<String> values = clientResponse.getHeaders().get(key); - for (final String value : values) { + for (final String key : response.getHeaders().keySet()) { + final List<Object> values = response.getHeaders().get(key); + for (final Object value : values) { if (key.equalsIgnoreCase("transfer-encoding") || key.equalsIgnoreCase("content-length")) { /* * do not copy the transfer-encoding header (i.e., chunked encoding) or
http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/spring/ThreadPoolRequestReplicatorFactoryBean.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/spring/ThreadPoolRequestReplicatorFactoryBean.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/spring/ThreadPoolRequestReplicatorFactoryBean.java index 8943276..90b05aa 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/spring/ThreadPoolRequestReplicatorFactoryBean.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/main/java/org/apache/nifi/cluster/spring/ThreadPoolRequestReplicatorFactoryBean.java @@ -17,8 +17,6 @@ package org.apache.nifi.cluster.spring; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.config.DefaultClientConfig; import org.apache.nifi.cluster.coordination.ClusterCoordinator; import org.apache.nifi.cluster.coordination.http.replication.RequestCompletionCallback; import org.apache.nifi.cluster.coordination.http.replication.ThreadPoolRequestReplicator; @@ -31,6 +29,8 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContextAware; +import javax.ws.rs.client.Client; + public class ThreadPoolRequestReplicatorFactoryBean implements FactoryBean<ThreadPoolRequestReplicator>, ApplicationContextAware { private ApplicationContext applicationContext; private NiFiProperties nifiProperties; @@ -47,7 +47,7 @@ public class ThreadPoolRequestReplicatorFactoryBean implements FactoryBean<Threa final int corePoolSize = nifiProperties.getClusterNodeProtocolCorePoolSize(); final int maxPoolSize = nifiProperties.getClusterNodeProtocolMaxPoolSize(); final int maxConcurrentRequests = nifiProperties.getClusterNodeMaxConcurrentRequests(); - final Client jerseyClient = WebUtils.createClient(new DefaultClientConfig(), SslContextFactory.createSslContext(nifiProperties)); + final Client jerseyClient = WebUtils.createClient(null, SslContextFactory.createSslContext(nifiProperties)); final String connectionTimeout = nifiProperties.getClusterNodeConnectionTimeout(); final String readTimeout = nifiProperties.getClusterNodeReadTimeout(); http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/StandardHttpResponseMapperSpec.groovy ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/StandardHttpResponseMapperSpec.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/StandardHttpResponseMapperSpec.groovy index 23bf2ca..f2d3a24 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/StandardHttpResponseMapperSpec.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/StandardHttpResponseMapperSpec.groovy @@ -16,7 +16,9 @@ */ package org.apache.nifi.cluster.coordination.http -import com.sun.jersey.api.client.ClientResponse +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector import org.apache.nifi.cluster.manager.NodeResponse import org.apache.nifi.cluster.protocol.NodeIdentifier import org.apache.nifi.util.NiFiProperties @@ -34,13 +36,10 @@ import org.apache.nifi.web.api.entity.FunnelEntity import org.apache.nifi.web.api.entity.FunnelsEntity import org.apache.nifi.web.api.entity.LabelEntity import org.apache.nifi.web.api.entity.LabelsEntity -import org.codehaus.jackson.map.ObjectMapper -import org.codehaus.jackson.map.SerializationConfig -import org.codehaus.jackson.map.annotate.JsonSerialize -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector import spock.lang.Specification import spock.lang.Unroll +import javax.ws.rs.core.Response import java.text.NumberFormat @Unroll @@ -60,12 +59,12 @@ class StandardHttpResponseMapperSpec extends Specification { def responseMapper = new StandardHttpResponseMapper(NiFiProperties.createBasicNiFiProperties(null,null)) def requestUri = new URI('http://server/resource') def requestId = UUID.randomUUID().toString() - def Map<ClientResponse, Map<String, Integer>> mockToRequestEntity = [:] + def Map<Response, Map<String, Integer>> mockToRequestEntity = [:] def nodeResponseSet = nodeResponseData.collect { int n = it.node - def clientResponse = Mock(ClientResponse) - mockToRequestEntity.put clientResponse, it - new NodeResponse(new NodeIdentifier("cluster-node-$n", 'addr', n, 'sktaddr', n * 10, 'stsaddr', n * 100, n * 1000, false, null), "get", requestUri, clientResponse, 500L, requestId) + def response = Mock(Response) + mockToRequestEntity.put response, it + new NodeResponse(new NodeIdentifier("cluster-node-$n", 'addr', n, 'sktaddr', n * 10, 'stsaddr', n * 100, n * 1000, false, null), "get", requestUri, response, 500L, requestId) } as Set when: @@ -73,8 +72,8 @@ class StandardHttpResponseMapperSpec extends Specification { then: mockToRequestEntity.entrySet().forEach { - ClientResponse mockClientResponse = it.key - _ * mockClientResponse.getStatus() >> it.value.status + Response response = it.key + _ * response.getStatus() >> it.value.status } 0 * _ returnedResponse == expectedStatus @@ -90,21 +89,20 @@ class StandardHttpResponseMapperSpec extends Specification { def "MergeResponses: #responseEntities.size() HTTP 200 #httpMethod responses for #requestUriPart"() { given: "json serialization setup" def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); and: "setup of the data to be used in the test" def responseMerger = new StandardHttpResponseMapper(NiFiProperties.createBasicNiFiProperties(null,null)) def requestUri = new URI("http://server/$requestUriPart") def requestId = UUID.randomUUID().toString() - def Map<ClientResponse, Object> mockToRequestEntity = [:] + def Map<Response, Object> mockToRequestEntity = [:] def n = 0 def nodeResponseSet = responseEntities.collect { ++n - def clientResponse = Mock(ClientResponse) - mockToRequestEntity.put clientResponse, it - new NodeResponse(new NodeIdentifier("cluster-node-$n", 'addr', n, 'sktaddr', n * 10, 'stsaddr', n * 100, n * 1000, false, null), "get", requestUri, clientResponse, 500L, requestId) + def response = Mock(Response) + mockToRequestEntity.put response, it + new NodeResponse(new NodeIdentifier("cluster-node-$n", 'addr', n, 'sktaddr', n * 10, 'stsaddr', n * 100, n * 1000, false, null), "get", requestUri, response, 500L, requestId) } as Set when: @@ -112,10 +110,10 @@ class StandardHttpResponseMapperSpec extends Specification { then: mockToRequestEntity.entrySet().forEach { - ClientResponse mockClientResponse = it.key + Response response = it.key def entity = it.value - _ * mockClientResponse.getStatus() >> 200 - 1 * mockClientResponse.getEntity(_) >> entity + _ * response.getStatus() >> 200 + 1 * response.readEntity(_) >> entity } responseEntities.size() == mockToRequestEntity.size() 0 * _ http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/StatusHistoryEndpointMergerSpec.groovy ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/StatusHistoryEndpointMergerSpec.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/StatusHistoryEndpointMergerSpec.groovy index 350269d..232c562 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/StatusHistoryEndpointMergerSpec.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/endpoints/StatusHistoryEndpointMergerSpec.groovy @@ -16,19 +16,19 @@ */ package org.apache.nifi.cluster.coordination.http.endpoints -import com.sun.jersey.api.client.ClientResponse +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector import org.apache.nifi.cluster.manager.NodeResponse import org.apache.nifi.cluster.protocol.NodeIdentifier import org.apache.nifi.util.NiFiProperties import org.apache.nifi.web.api.dto.status.StatusHistoryDTO import org.apache.nifi.web.api.entity.StatusHistoryEntity -import org.codehaus.jackson.map.ObjectMapper -import org.codehaus.jackson.map.SerializationConfig -import org.codehaus.jackson.map.annotate.JsonSerialize -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector import spock.lang.Specification import spock.lang.Unroll +import javax.ws.rs.core.Response + class StatusHistoryEndpointMergerSpec extends Specification { def setup() { @@ -44,21 +44,20 @@ class StatusHistoryEndpointMergerSpec extends Specification { def "Merge component details based on permission"() { given: "json serialization setup" def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); and: "setup of the data to be used in the test" def merger = new StatusHistoryEndpointMerger(2) def requestUri = new URI("http://server/$requestUriPart") def requestId = UUID.randomUUID().toString() - def Map<ClientResponse, Object> mockToRequestEntity = [:] + def Map<Response, Object> mockToRequestEntity = [:] def n = 0 def nodeResponseSet = responseEntities.collect { ++n - def clientResponse = Mock(ClientResponse) - mockToRequestEntity.put clientResponse, it - new NodeResponse(new NodeIdentifier("cluster-node-$n", 'addr', n, 'sktaddr', n * 10, 'stsaddr', n * 100, n * 1000, false, null), "get", requestUri, clientResponse, 500L, requestId) + def response = Mock(Response) + mockToRequestEntity.put response, it + new NodeResponse(new NodeIdentifier("cluster-node-$n", 'addr', n, 'sktaddr', n * 10, 'stsaddr', n * 100, n * 1000, false, null), "get", requestUri, response, 500L, requestId) } as Set when: @@ -66,10 +65,10 @@ class StatusHistoryEndpointMergerSpec extends Specification { then: mockToRequestEntity.entrySet().forEach { - ClientResponse mockClientResponse = it.key + Response response = it.key def entity = it.value - _ * mockClientResponse.getStatus() >> 200 - 1 * mockClientResponse.getEntity(_) >> entity + _ * response.getStatus() >> 200 + 1 * response.readEntity(_) >> entity } responseEntities.size() == mockToRequestEntity.size() 0 * _ http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java index cc71b9b..4bb7b67 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestResponseUtils.java @@ -17,9 +17,11 @@ package org.apache.nifi.cluster.coordination.http.replication; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.apache.nifi.cluster.manager.NodeResponse; +import org.apache.nifi.cluster.protocol.NodeIdentifier; +import org.junit.Test; +import javax.ws.rs.core.Response; import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; @@ -28,12 +30,9 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.apache.nifi.cluster.manager.NodeResponse; -import org.apache.nifi.cluster.protocol.NodeIdentifier; -import org.junit.Test; -import org.mockito.Mockito; - -import com.sun.jersey.api.client.ClientResponse; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; public class TestResponseUtils { @@ -46,7 +45,7 @@ public class TestResponseUtils { final NodeIdentifier id4 = new NodeIdentifier("4", "localhost", 8400, "localhost", 8401, "localhost", 8402, 8403, false); final URI uri = new URI("localhost:8080"); - final ClientResponse clientResponse = Mockito.mock(ClientResponse.class); + final Response clientResponse = mock(Response.class); responses.put(id1, new NodeResponse(id1, "GET", uri, clientResponse, TimeUnit.MILLISECONDS.toNanos(80), "1")); responses.put(id2, new NodeResponse(id1, "GET", uri, clientResponse, TimeUnit.MILLISECONDS.toNanos(92), "1")); responses.put(id3, new NodeResponse(id1, "GET", uri, clientResponse, TimeUnit.MILLISECONDS.toNanos(3), "1")); http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java index 214a509..836751c 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/coordination/http/replication/TestThreadPoolRequestReplicator.java @@ -16,13 +16,6 @@ */ package org.apache.nifi.cluster.coordination.http.replication; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientHandlerException; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.ClientResponse.Status; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.core.header.InBoundHeaders; -import com.sun.jersey.core.header.OutBoundHeaders; import org.apache.commons.collections4.map.MultiValueMap; import org.apache.nifi.authorization.user.NiFiUser; import org.apache.nifi.authorization.user.NiFiUserDetails; @@ -41,6 +34,7 @@ import org.apache.nifi.web.api.entity.Entity; import org.apache.nifi.web.api.entity.ProcessorEntity; import org.apache.nifi.web.security.ProxiedEntitiesUtils; import org.apache.nifi.web.security.token.NiFiAuthenticationToken; +import org.glassfish.jersey.client.ClientRequest; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; @@ -52,7 +46,11 @@ import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; import javax.ws.rs.HttpMethod; -import java.io.ByteArrayInputStream; +import javax.ws.rs.ProcessingException; +import javax.ws.rs.client.ClientBuilder; +import javax.ws.rs.client.Invocation; +import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response.Status; import java.net.SocketTimeoutException; import java.net.URI; import java.net.URISyntaxException; @@ -71,6 +69,8 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestThreadPoolRequestReplicator { @@ -103,7 +103,7 @@ public class TestThreadPoolRequestReplicator { final NodeResponse nodeResponse = response.awaitMergedResponse(3, TimeUnit.SECONDS); assertEquals(8000, nodeResponse.getNodeId().getApiPort()); - assertEquals(ClientResponse.Status.FORBIDDEN.getStatusCode(), nodeResponse.getStatus()); + assertEquals(Response.Status.FORBIDDEN.getStatusCode(), nodeResponse.getStatus()); assertNull(replicator.getClusterResponse(response.getRequestIdentifier())); }, Status.FORBIDDEN, 0L, null); @@ -139,7 +139,7 @@ public class TestThreadPoolRequestReplicator { final NodeResponse nodeResponse = response.awaitMergedResponse(3, TimeUnit.SECONDS); assertEquals(8000, nodeResponse.getNodeId().getApiPort()); - assertEquals(ClientResponse.Status.OK.getStatusCode(), nodeResponse.getStatus()); + assertEquals(Response.Status.OK.getStatusCode(), nodeResponse.getStatus()); assertNull(replicator.getClusterResponse(response.getRequestIdentifier())); }); @@ -165,7 +165,7 @@ public class TestThreadPoolRequestReplicator { SecurityContextHolder.getContext().setAuthentication(authentication); replicator.replicate(nodeIds, HttpMethod.GET, uri, entity, new HashMap<>(), true, true); - }, ClientResponse.Status.OK, 0L, null, "<" + userIdentity + "><" + proxyIdentity1 + "><" + proxyIdentity2 +">"); + }, Response.Status.OK, 0L, null, "<" + userIdentity + "><" + proxyIdentity1 + "><" + proxyIdentity2 +">"); } @Test(timeout = 15000) @@ -194,7 +194,7 @@ public class TestThreadPoolRequestReplicator { assertTrue(response.isComplete()); assertNotNull(response.getMergedResponse()); assertNull(replicator.getClusterResponse(response.getRequestIdentifier())); - }, Status.OK, 1000, new ClientHandlerException(new SocketTimeoutException())); + }, Status.OK, 1000, new ProcessingException(new SocketTimeoutException())); } @Test(timeout = 15000) @@ -228,18 +228,18 @@ public class TestThreadPoolRequestReplicator { final NodeIdentifier nodeId = new NodeIdentifier("1", "localhost", 8100, "localhost", 8101, "localhost", 8102, 8103, false); nodeIds.add(nodeId); - final ClusterCoordinator coordinator = Mockito.mock(ClusterCoordinator.class); - Mockito.when(coordinator.getConnectionStatus(Mockito.any(NodeIdentifier.class))).thenReturn(new NodeConnectionStatus(nodeId, NodeConnectionState.CONNECTED)); + final ClusterCoordinator coordinator = mock(ClusterCoordinator.class); + when(coordinator.getConnectionStatus(Mockito.any(NodeIdentifier.class))).thenReturn(new NodeConnectionStatus(nodeId, NodeConnectionState.CONNECTED)); final AtomicInteger requestCount = new AtomicInteger(0); final NiFiProperties props = NiFiProperties.createBasicNiFiProperties(null, null); - final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, new Client(), coordinator, "1 sec", "1 sec", null, null, props) { + final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, ClientBuilder.newClient(), coordinator, "1 sec", "1 sec", null, null, props) { @Override - protected NodeResponse replicateRequest(final WebResource.Builder resourceBuilder, final NodeIdentifier nodeId, final String method, - final URI uri, final String requestId, Map<String, String> givenHeaders, final StandardAsyncClusterResponse response) { + protected NodeResponse replicateRequest(final Invocation invocation, final NodeIdentifier nodeId, final String method, + final URI uri, final String requestId, Map<String, String> givenHeaders, final StandardAsyncClusterResponse response) { // the resource builder will not expose its headers to us, so we are using Mockito's Whitebox class to extract them. - final OutBoundHeaders headers = (OutBoundHeaders) Whitebox.getInternalState(resourceBuilder, "metadata"); - final Object expectsHeader = headers.getFirst(ThreadPoolRequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); + final ClientRequest requestContext = (ClientRequest) Whitebox.getInternalState(invocation, "requestContext"); + final Object expectsHeader = requestContext.getHeaders().getFirst(ThreadPoolRequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); final int statusCode; if (requestCount.incrementAndGet() == 1) { @@ -251,7 +251,8 @@ public class TestThreadPoolRequestReplicator { } // Return given response from all nodes. - final ClientResponse clientResponse = new ClientResponse(statusCode, new InBoundHeaders(), new ByteArrayInputStream(new byte[0]), null); + final Response clientResponse = mock(Response.class); + when(clientResponse.getStatus()).thenReturn(statusCode); return new NodeResponse(nodeId, method, uri, clientResponse, -1L, requestId); } }; @@ -277,8 +278,8 @@ public class TestThreadPoolRequestReplicator { } private ClusterCoordinator createClusterCoordinator() { - final ClusterCoordinator coordinator = Mockito.mock(ClusterCoordinator.class); - Mockito.when(coordinator.getConnectionStatus(Mockito.any(NodeIdentifier.class))).thenAnswer(new Answer<NodeConnectionStatus>() { + final ClusterCoordinator coordinator = mock(ClusterCoordinator.class); + when(coordinator.getConnectionStatus(Mockito.any(NodeIdentifier.class))).thenAnswer(new Answer<NodeConnectionStatus>() { @Override public NodeConnectionStatus answer(InvocationOnMock invocation) throws Throwable { return new NodeConnectionStatus(invocation.getArgumentAt(0, NodeIdentifier.class), NodeConnectionState.CONNECTED); @@ -303,9 +304,9 @@ public class TestThreadPoolRequestReplicator { otherState.add(new NodeIdentifier("3", "localhost", 8300, "localhost", 8301, "localhost", 8302, 8303, false)); nodeMap.put(NodeConnectionState.CONNECTING, otherState); - Mockito.when(coordinator.getConnectionStates()).thenReturn(nodeMap); + when(coordinator.getConnectionStates()).thenReturn(nodeMap); final NiFiProperties props = NiFiProperties.createBasicNiFiProperties(null, null); - final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, new Client(), coordinator, "1 sec", "1 sec", null, null, props) { + final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, ClientBuilder.newClient(), coordinator, "1 sec", "1 sec", null, null, props) { @Override public AsyncClusterResponse replicate(Set<NodeIdentifier> nodeIds, String method, URI uri, Object entity, Map<String, String> headers, boolean indicateReplicated, boolean verify) { @@ -363,19 +364,20 @@ public class TestThreadPoolRequestReplicator { final ClusterCoordinator coordinator = createClusterCoordinator(); final AtomicInteger requestCount = new AtomicInteger(0); final NiFiProperties props = NiFiProperties.createBasicNiFiProperties(null, null); - final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, new Client(), coordinator, "1 sec", "1 sec", null, null, props) { + final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, ClientBuilder.newClient(), coordinator, "1 sec", "1 sec", null, null, props) { @Override - protected NodeResponse replicateRequest(final WebResource.Builder resourceBuilder, final NodeIdentifier nodeId, final String method, + protected NodeResponse replicateRequest(final Invocation invocation, final NodeIdentifier nodeId, final String method, final URI uri, final String requestId, Map<String, String> givenHeaders, final StandardAsyncClusterResponse response) { // the resource builder will not expose its headers to us, so we are using Mockito's Whitebox class to extract them. - final OutBoundHeaders headers = (OutBoundHeaders) Whitebox.getInternalState(resourceBuilder, "metadata"); - final Object expectsHeader = headers.getFirst(ThreadPoolRequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); + final ClientRequest requestContext = (ClientRequest) Whitebox.getInternalState(invocation, "requestContext"); + final Object expectsHeader = requestContext.getHeaders().getFirst(ThreadPoolRequestReplicator.REQUEST_VALIDATION_HTTP_HEADER); final int requestIndex = requestCount.incrementAndGet(); assertEquals(ThreadPoolRequestReplicator.NODE_CONTINUE, expectsHeader); if (requestIndex == 1) { - final ClientResponse clientResponse = new ClientResponse(150, new InBoundHeaders(), new ByteArrayInputStream(new byte[0]), null); + final Response clientResponse = mock(Response.class); + when(clientResponse.getStatus()).thenReturn(150); return new NodeResponse(nodeId, method, uri, clientResponse, -1L, requestId); } else { final IllegalClusterStateException explanation = new IllegalClusterStateException("Intentional Exception for Unit Testing"); @@ -563,7 +565,7 @@ public class TestThreadPoolRequestReplicator { private void withReplicator(final WithReplicator function) { - withReplicator(function, ClientResponse.Status.OK, 0L, null); + withReplicator(function, Response.Status.OK, 0L, null); } private void withReplicator(final WithReplicator function, final Status status, final long delayMillis, final RuntimeException failure) { @@ -573,9 +575,9 @@ public class TestThreadPoolRequestReplicator { private void withReplicator(final WithReplicator function, final Status status, final long delayMillis, final RuntimeException failure, final String expectedRequestChain) { final ClusterCoordinator coordinator = createClusterCoordinator(); final NiFiProperties nifiProps = NiFiProperties.createBasicNiFiProperties(null, null); - final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, new Client(), coordinator, "1 sec", "1 sec", null, null, nifiProps) { + final ThreadPoolRequestReplicator replicator = new ThreadPoolRequestReplicator(2, 5, 100, ClientBuilder.newClient(), coordinator, "1 sec", "1 sec", null, null, nifiProps) { @Override - protected NodeResponse replicateRequest(final WebResource.Builder resourceBuilder, final NodeIdentifier nodeId, final String method, + protected NodeResponse replicateRequest(final Invocation invocation, final NodeIdentifier nodeId, final String method, final URI uri, final String requestId, Map<String, String> givenHeaders, final StandardAsyncClusterResponse response) { if (delayMillis > 0L) { try { @@ -589,14 +591,15 @@ public class TestThreadPoolRequestReplicator { throw failure; } - final OutBoundHeaders headers = (OutBoundHeaders) Whitebox.getInternalState(resourceBuilder, "metadata"); - final Object proxiedEntities = headers.getFirst(ProxiedEntitiesUtils.PROXY_ENTITIES_CHAIN); + final ClientRequest requestContext = (ClientRequest) Whitebox.getInternalState(invocation, "requestContext"); + final Object proxiedEntities = requestContext.getHeaders().getFirst(ProxiedEntitiesUtils.PROXY_ENTITIES_CHAIN); // ensure the request chain is in the request Assert.assertEquals(expectedRequestChain, proxiedEntities); // Return given response from all nodes. - final ClientResponse clientResponse = new ClientResponse(status, new InBoundHeaders(), new ByteArrayInputStream(new byte[0]), null); + final Response clientResponse = mock(Response.class); + when(clientResponse.getStatus()).thenReturn(status.getStatusCode()); return new NodeResponse(nodeId, method, uri, clientResponse, -1L, requestId); } }; http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ConnectionEntityMergerSpec.groovy ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ConnectionEntityMergerSpec.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ConnectionEntityMergerSpec.groovy index 3f81975..ffa3429 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ConnectionEntityMergerSpec.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ConnectionEntityMergerSpec.groovy @@ -16,19 +16,15 @@ */ package org.apache.nifi.cluster.manager +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector import org.apache.nifi.cluster.protocol.NodeIdentifier import org.apache.nifi.web.api.dto.ConnectionDTO -import org.apache.nifi.web.api.dto.ControllerConfigurationDTO import org.apache.nifi.web.api.dto.PermissionsDTO import org.apache.nifi.web.api.dto.status.ConnectionStatusDTO import org.apache.nifi.web.api.dto.status.ConnectionStatusSnapshotDTO import org.apache.nifi.web.api.entity.ConnectionEntity -import org.apache.nifi.web.api.entity.ConnectionsEntity -import org.apache.nifi.web.api.entity.ControllerConfigurationEntity -import org.codehaus.jackson.map.ObjectMapper -import org.codehaus.jackson.map.SerializationConfig -import org.codehaus.jackson.map.annotate.JsonSerialize -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector import spock.lang.Specification import spock.lang.Unroll @@ -38,9 +34,9 @@ class ConnectionEntityMergerSpec extends Specification { def "Merge"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)) + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def entity = nodeEntityMap.entrySet().first().value when: http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy index 8b2c76c..b6bfd65 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/ControllerServiceEntityMergerSpec.groovy @@ -16,21 +16,16 @@ */ package org.apache.nifi.cluster.manager +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector import org.apache.nifi.cluster.protocol.NodeIdentifier import org.apache.nifi.controller.service.ControllerServiceState -import org.apache.nifi.web.api.dto.ConnectionDTO import org.apache.nifi.web.api.dto.ControllerServiceDTO import org.apache.nifi.web.api.dto.ControllerServiceReferencingComponentDTO import org.apache.nifi.web.api.dto.PermissionsDTO -import org.apache.nifi.web.api.dto.status.ConnectionStatusDTO -import org.apache.nifi.web.api.dto.status.ConnectionStatusSnapshotDTO -import org.apache.nifi.web.api.entity.ConnectionEntity import org.apache.nifi.web.api.entity.ControllerServiceEntity import org.apache.nifi.web.api.entity.ControllerServiceReferencingComponentEntity -import org.codehaus.jackson.map.ObjectMapper -import org.codehaus.jackson.map.SerializationConfig -import org.codehaus.jackson.map.annotate.JsonSerialize -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector import spock.lang.Specification import spock.lang.Unroll @@ -38,9 +33,9 @@ import spock.lang.Unroll class ControllerServiceEntityMergerSpec extends Specification { def "MergeComponents"() { def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)) + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def entity = nodeEntityMap.entrySet().first().value when: http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/LabelEntityMergerSpec.groovy ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/LabelEntityMergerSpec.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/LabelEntityMergerSpec.groovy index 5ebdf0e..028c864 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/LabelEntityMergerSpec.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/LabelEntityMergerSpec.groovy @@ -16,14 +16,13 @@ */ package org.apache.nifi.cluster.manager +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector import org.apache.nifi.cluster.protocol.NodeIdentifier import org.apache.nifi.web.api.dto.LabelDTO import org.apache.nifi.web.api.dto.PermissionsDTO import org.apache.nifi.web.api.entity.LabelEntity -import org.codehaus.jackson.map.ObjectMapper -import org.codehaus.jackson.map.SerializationConfig -import org.codehaus.jackson.map.annotate.JsonSerialize -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector import spock.lang.Specification import spock.lang.Unroll @@ -32,9 +31,9 @@ class LabelEntityMergerSpec extends Specification { def "Merge"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)) + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def entity = nodeEntityMap.entrySet().first().value when: http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/PermissionBasedStatusMergerSpec.groovy ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/PermissionBasedStatusMergerSpec.groovy b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/PermissionBasedStatusMergerSpec.groovy index b64b1fa..f45c888 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/PermissionBasedStatusMergerSpec.groovy +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/java/org/apache/nifi/cluster/manager/PermissionBasedStatusMergerSpec.groovy @@ -16,10 +16,11 @@ */ package org.apache.nifi.cluster.manager -import org.apache.nifi.cluster.protocol.NodeIdentifier +import com.fasterxml.jackson.annotation.JsonInclude +import com.fasterxml.jackson.databind.ObjectMapper +import com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector import org.apache.nifi.web.api.dto.status.ConnectionStatusDTO import org.apache.nifi.web.api.dto.status.ConnectionStatusSnapshotDTO -import org.apache.nifi.web.api.dto.status.ControllerStatusDTO import org.apache.nifi.web.api.dto.status.PortStatusDTO import org.apache.nifi.web.api.dto.status.PortStatusSnapshotDTO import org.apache.nifi.web.api.dto.status.ProcessGroupStatusDTO @@ -28,10 +29,6 @@ import org.apache.nifi.web.api.dto.status.ProcessorStatusDTO import org.apache.nifi.web.api.dto.status.ProcessorStatusSnapshotDTO import org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusDTO import org.apache.nifi.web.api.dto.status.RemoteProcessGroupStatusSnapshotDTO -import org.codehaus.jackson.map.ObjectMapper -import org.codehaus.jackson.map.SerializationConfig -import org.codehaus.jackson.map.annotate.JsonSerialize -import org.codehaus.jackson.xc.JaxbAnnotationIntrospector import spock.lang.Specification import spock.lang.Unroll @@ -40,9 +37,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge ConnectionStatusDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -70,9 +67,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge ConnectionStatusSnapshotDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -102,9 +99,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge PortStatusDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -130,9 +127,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge PortStatusSnapshotDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -158,9 +155,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge ProcessGroupStatusDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -184,9 +181,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge ProcessGroupStatusSnapshotDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -215,9 +212,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge ProcessorStatusDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -243,9 +240,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge ProcessorStatusSnapshotDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -273,9 +270,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge RemoteProcessGroupStatusDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: @@ -301,9 +298,9 @@ class PermissionBasedStatusMergerSpec extends Specification { def "Merge RemoteProcessGroupStatusSnapshotDTO"() { given: def mapper = new ObjectMapper(); - def jaxbIntrospector = new JaxbAnnotationIntrospector(); - def SerializationConfig serializationConfig = mapper.getSerializationConfig(); - mapper.setSerializationConfig(serializationConfig.withSerializationInclusion(JsonSerialize.Inclusion.NON_NULL).withAnnotationIntrospector(jaxbIntrospector)); + mapper.setDefaultPropertyInclusion(JsonInclude.Value.construct(JsonInclude.Include.NON_NULL, JsonInclude.Include.ALWAYS)); + mapper.setAnnotationIntrospector(new JaxbAnnotationIntrospector(mapper.getTypeFactory())); + def merger = new StatusMerger() when: http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/resources/logback-test.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/resources/logback-test.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/resources/logback-test.xml index 0f5adc8..79db284 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/resources/logback-test.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster/src/test/resources/logback-test.xml @@ -41,9 +41,6 @@ <!-- Logger for managing logging statements for jetty --> <logger name="org.mortbay" level="INFO"/> - <!-- Suppress non-error messages due to excessive logging by class --> - <logger name="com.sun.jersey.spi.container.servlet.WebComponent" level="ERROR"/> - <logger name="org.apache.nifi.processors.standard" level="DEBUG"/> <root level="INFO"> http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml index 549927d..0daced4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/pom.xml @@ -104,8 +104,14 @@ <artifactId>bcprov-jdk15on</artifactId> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> + <groupId>com.sun.xml.bind</groupId> + <artifactId>jaxb-impl</artifactId> + <version>2.2.3-1</version> + </dependency> + <dependency> + <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> + <version>${jersey.version}</version> </dependency> <dependency> <groupId>org.apache.nifi</groupId> http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java index 5d65f89..56a230f 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/controller/FlowController.java @@ -16,39 +16,6 @@ */ package org.apache.nifi.controller; -import static java.util.Objects.requireNonNull; - -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URL; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.UUID; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledFuture; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.stream.Collectors; - -import javax.net.ssl.SSLContext; - import org.apache.commons.collections4.Predicate; import org.apache.commons.lang3.StringUtils; import org.apache.nifi.action.Action; @@ -252,7 +219,37 @@ import org.apache.zookeeper.server.quorum.QuorumPeerConfig.ConfigException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.sun.jersey.api.client.ClientHandlerException; +import javax.net.ssl.SSLContext; +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.UUID; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; +import java.util.concurrent.locks.Lock; +import java.util.concurrent.locks.ReentrantReadWriteLock; +import java.util.stream.Collectors; + +import static java.util.Objects.requireNonNull; public class FlowController implements EventAccess, ControllerServiceProvider, ReportingTaskProvider, QueueProvider, Authorizable, ProvenanceAuthorizableFactory, NodeTypeProvider, IdentifierLookup, ReloadComponent { @@ -4402,7 +4399,7 @@ public class FlowController implements EventAccess, ControllerServiceProvider, R for (final RemoteProcessGroup remoteGroup : remoteGroups) { try { remoteGroup.refreshFlowContents(); - } catch (final CommunicationsException | ClientHandlerException e) { + } catch (final CommunicationsException e) { LOG.warn("Unable to communicate with remote instance {} due to {}", remoteGroup, e.toString()); if (LOG.isDebugEnabled()) { LOG.warn("", e); http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/RemoteNiFiUtils.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/RemoteNiFiUtils.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/RemoteNiFiUtils.java index f19ce11..f7db4af 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/RemoteNiFiUtils.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/RemoteNiFiUtils.java @@ -16,14 +16,15 @@ */ package org.apache.nifi.remote; -import com.sun.jersey.api.client.Client; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.WebResource; -import com.sun.jersey.core.util.MultivaluedMapImpl; import org.apache.nifi.web.util.WebUtils; +import org.glassfish.jersey.client.ClientConfig; +import org.glassfish.jersey.client.ClientProperties; import javax.net.ssl.SSLContext; -import javax.ws.rs.core.MediaType; +import javax.ws.rs.client.Client; +import javax.ws.rs.client.Entity; +import javax.ws.rs.core.MultivaluedHashMap; +import javax.ws.rs.core.Response; import java.net.URI; public class RemoteNiFiUtils { @@ -38,16 +39,17 @@ public class RemoteNiFiUtils { } private Client getClient(final SSLContext sslContext) { + final ClientConfig clientConfig = new ClientConfig(); + clientConfig.property(ClientProperties.READ_TIMEOUT, READ_TIMEOUT); + clientConfig.property(ClientProperties.CONNECT_TIMEOUT, CONNECT_TIMEOUT); + final Client client; if (sslContext == null) { - client = WebUtils.createClient(null); + client = WebUtils.createClient(clientConfig); } else { - client = WebUtils.createClient(null, sslContext); + client = WebUtils.createClient(clientConfig, sslContext); } - client.setReadTimeout(READ_TIMEOUT); - client.setConnectTimeout(CONNECT_TIMEOUT); - return client; } @@ -57,17 +59,14 @@ public class RemoteNiFiUtils { * @param baseApiUri uri to register with * @return response */ - public ClientResponse issueRegistrationRequest(String baseApiUri) { + public Response issueRegistrationRequest(String baseApiUri) { final URI uri = URI.create(String.format("%s/controller/users", baseApiUri)); // set up the query params - MultivaluedMapImpl entity = new MultivaluedMapImpl(); + MultivaluedHashMap entity = new MultivaluedHashMap(); entity.add("justification", "A Remote instance of NiFi has attempted to create a reference to this NiFi. This action must be approved first."); - // create the web resource - WebResource webResource = client.resource(uri); - - // get the client utils and make the request - return webResource.type(MediaType.APPLICATION_FORM_URLENCODED).entity(entity).post(ClientResponse.class); + // get the resource + return client.target(uri).request().post(Entity.form(entity)); } } http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java index 3080195..2b2e1fb 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/main/java/org/apache/nifi/remote/StandardRemoteProcessGroup.java @@ -79,11 +79,6 @@ import org.apache.nifi.web.api.dto.PortDTO; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.sun.jersey.api.client.ClientHandlerException; -import com.sun.jersey.api.client.ClientResponse; -import com.sun.jersey.api.client.ClientResponse.Status; -import com.sun.jersey.api.client.UniformInterfaceException; - /** * Represents the Root Process Group of a remote NiFi Instance. Holds * information about that remote instance, as well as {@link IncomingPort}s and @@ -94,8 +89,8 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup { private static final Logger logger = LoggerFactory.getLogger(StandardRemoteProcessGroup.class); // status codes - private static final int UNAUTHORIZED_STATUS_CODE = Status.UNAUTHORIZED.getStatusCode(); - private static final int FORBIDDEN_STATUS_CODE = Status.FORBIDDEN.getStatusCode(); + private static final int UNAUTHORIZED_STATUS_CODE = Response.Status.UNAUTHORIZED.getStatusCode(); + private static final int FORBIDDEN_STATUS_CODE = Response.Status.FORBIDDEN.getStatusCode(); private final String id; @@ -879,7 +874,7 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup { } finally { writeLock.unlock(); } - } catch (final ClientHandlerException | UniformInterfaceException e) { + } catch (final IOException e) { throw new CommunicationsException(e); } } @@ -1195,7 +1190,7 @@ public class StandardRemoteProcessGroup implements RemoteProcessGroup { // attempt to issue a registration request in case the target instance is a 0.x final boolean isApiSecure = apiClient.getBaseUrl().toLowerCase().startsWith("https"); final RemoteNiFiUtils utils = new RemoteNiFiUtils(isApiSecure ? sslContext : null); - final ClientResponse requestAccountResponse = utils.issueRegistrationRequest(apiClient.getBaseUrl()); + final Response requestAccountResponse = utils.issueRegistrationRequest(apiClient.getBaseUrl()); if (Response.Status.Family.SUCCESSFUL.equals(requestAccountResponse.getStatusInfo().getFamily())) { logger.info("{} Issued a Request to communicate with remote instance", this); } else { http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml index da1adf0..6ab98ab 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-resources/src/main/resources/conf/logback.xml @@ -112,12 +112,10 @@ <logger name="org.eclipse.jetty" level="INFO"/> <!-- Suppress non-error messages due to excessive logging by class or library --> - <logger name="com.sun.jersey.spi.container.servlet.WebComponent" level="ERROR"/> - <logger name="com.sun.jersey.spi.spring" level="ERROR"/> <logger name="org.springframework" level="ERROR"/> <!-- Suppress non-error messages due to known warning about redundant path annotation (NIFI-574) --> - <logger name="com.sun.jersey.spi.inject.Errors" level="ERROR"/> + <logger name="org.glassfish.jersey.internal.Errors" level="ERROR"/> <!-- Logger for capturing user events. We do not want to propagate these http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/pom.xml index 374b5a0..eda40da 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/pom.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-site-to-site/pom.xml @@ -51,8 +51,9 @@ <artifactId>nifi-framework-core-api</artifactId> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> + <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> + <version>${jersey.version}</version> </dependency> <dependency> <groupId>javax.mail</groupId> http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/pom.xml index dc71d6a..92199a6 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/pom.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/pom.xml @@ -74,29 +74,24 @@ <artifactId>jetty-servlets</artifactId> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-client</artifactId> - <scope>compile</scope> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> </dependency> <dependency> - <groupId>com.sun.jersey.contribs</groupId> - <artifactId>jersey-spring</artifactId> - <scope>compile</scope> + <groupId>org.glassfish.jersey.core</groupId> + <artifactId>jersey-client</artifactId> </dependency> <dependency> - <groupId>com.sun.jersey.contribs</groupId> - <artifactId>jersey-multipart</artifactId> - <scope>compile</scope> + <groupId>org.glassfish.jersey.media</groupId> + <artifactId>jersey-media-json-jackson</artifactId> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-server</artifactId> - <scope>compile</scope> + <groupId>org.glassfish.jersey.media</groupId> + <artifactId>jersey-media-multipart</artifactId> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-json</artifactId> - <scope>compile</scope> + <groupId>org.glassfish.jersey.ext</groupId> + <artifactId>jersey-spring4</artifactId> </dependency> <dependency> <groupId>org.aspectj</groupId> http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java index 9c1c5b3..be737c5 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java @@ -858,7 +858,8 @@ public class JettyServer implements NiFiServer { if (flowService != null && flowService.isRunning()) { flowService.stop(false); } - throw new Exception("Unable to load flow due to: " + e, e); + logger.error("Unable to load flow due to: " + e, e); + throw new Exception("Unable to load flow due to: " + e); // cannot wrap the exception as they are not defined in a classloader accessible to the caller } } http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/pom.xml ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/pom.xml b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/pom.xml index e61bfa8..c1a1c39 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/pom.xml +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/pom.xml @@ -281,34 +281,28 @@ <scope>provided</scope> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-server</artifactId> + <groupId>javax.ws.rs</groupId> + <artifactId>javax.ws.rs-api</artifactId> <scope>provided</scope> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> + <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <scope>provided</scope> </dependency> <dependency> - <groupId>com.sun.jersey</groupId> - <artifactId>jersey-json</artifactId> + <groupId>org.glassfish.jersey.media</groupId> + <artifactId>jersey-media-json-jackson</artifactId> <scope>provided</scope> </dependency> <dependency> - <groupId>com.sun.jersey.contribs</groupId> - <artifactId>jersey-spring</artifactId> + <groupId>org.glassfish.jersey.media</groupId> + <artifactId>jersey-media-multipart</artifactId> <scope>provided</scope> - <exclusions> - <exclusion> - <groupId>org.springframework</groupId> - <artifactId>spring</artifactId> - </exclusion> - </exclusions> </dependency> <dependency> - <groupId>com.sun.jersey.contribs</groupId> - <artifactId>jersey-multipart</artifactId> + <groupId>org.glassfish.jersey.ext</groupId> + <artifactId>jersey-spring4</artifactId> <scope>provided</scope> </dependency> <dependency> http://git-wip-us.apache.org/repos/asf/nifi/blob/6baea8cc/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiWebApiResourceConfig.java ---------------------------------------------------------------------- diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiWebApiResourceConfig.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiWebApiResourceConfig.java new file mode 100644 index 0000000..0881cdf --- /dev/null +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-web-api/src/main/java/org/apache/nifi/web/NiFiWebApiResourceConfig.java @@ -0,0 +1,137 @@ +/* + * 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.nifi.web; + +import org.apache.nifi.web.api.config.AccessDeniedExceptionMapper; +import org.apache.nifi.web.api.config.AdministrationExceptionMapper; +import org.apache.nifi.web.api.config.AuthenticationCredentialsNotFoundExceptionMapper; +import org.apache.nifi.web.api.config.AuthorizationAccessExceptionMapper; +import org.apache.nifi.web.api.config.ClusterExceptionMapper; +import org.apache.nifi.web.api.config.IllegalArgumentExceptionMapper; +import org.apache.nifi.web.api.config.IllegalClusterResourceRequestExceptionMapper; +import org.apache.nifi.web.api.config.IllegalClusterStateExceptionMapper; +import org.apache.nifi.web.api.config.IllegalNodeDeletionExceptionMapper; +import org.apache.nifi.web.api.config.IllegalNodeDisconnectionExceptionMapper; +import org.apache.nifi.web.api.config.IllegalNodeReconnectionExceptionMapper; +import org.apache.nifi.web.api.config.IllegalStateExceptionMapper; +import org.apache.nifi.web.api.config.InvalidAuthenticationExceptionMapper; +import org.apache.nifi.web.api.config.InvalidRevisionExceptionMapper; +import org.apache.nifi.web.api.config.MutableRequestExceptionMapper; +import org.apache.nifi.web.api.config.NiFiCoreExceptionMapper; +import org.apache.nifi.web.api.config.NoClusterCoordinatorExceptionMapper; +import org.apache.nifi.web.api.config.NoConnectedNodesExceptionMapper; +import org.apache.nifi.web.api.config.NoResponseFromNodesExceptionMapper; +import org.apache.nifi.web.api.config.NodeDisconnectionExceptionMapper; +import org.apache.nifi.web.api.config.NodeReconnectionExceptionMapper; +import org.apache.nifi.web.api.config.NotFoundExceptionMapper; +import org.apache.nifi.web.api.config.ResourceNotFoundExceptionMapper; +import org.apache.nifi.web.api.config.ThrowableMapper; +import org.apache.nifi.web.api.config.UnknownNodeExceptionMapper; +import org.apache.nifi.web.api.config.ValidationExceptionMapper; +import org.apache.nifi.web.api.config.WebApplicationExceptionMapper; +import org.apache.nifi.web.api.filter.RedirectResourceFilter; +import org.apache.nifi.web.util.ObjectMapperResolver; +import org.glassfish.jersey.jackson.JacksonFeature; +import org.glassfish.jersey.jackson.internal.jackson.jaxrs.base.JsonMappingExceptionMapper; +import org.glassfish.jersey.jackson.internal.jackson.jaxrs.base.JsonParseExceptionMapper; +import org.glassfish.jersey.media.multipart.MultiPartFeature; +import org.glassfish.jersey.message.GZipEncoder; +import org.glassfish.jersey.server.ResourceConfig; +import org.glassfish.jersey.server.filter.EncodingFilter; +import org.springframework.context.ApplicationContext; +import org.springframework.web.context.support.WebApplicationContextUtils; + +import javax.servlet.ServletContext; +import javax.ws.rs.core.Context; + +public class NiFiWebApiResourceConfig extends ResourceConfig { + + public NiFiWebApiResourceConfig(@Context ServletContext servletContext) { + // get the application context to register the rest endpoints + final ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext); + + // request support + register(RedirectResourceFilter.class); + register(MultiPartFeature.class); + + // jackson + register(JacksonFeature.class); + register(ObjectMapperResolver.class); + + // rest api + register(ctx.getBean("flowResource")); + register(ctx.getBean("resourceResource")); + register(ctx.getBean("controllerResource")); + register(ctx.getBean("siteToSiteResource")); + register(ctx.getBean("dataTransferResource")); + register(ctx.getBean("snippetResource")); + register(ctx.getBean("templateResource")); + register(ctx.getBean("controllerServiceResource")); + register(ctx.getBean("reportingTaskResource")); + register(ctx.getBean("processGroupResource")); + register(ctx.getBean("processorResource")); + register(ctx.getBean("connectionResource")); + register(ctx.getBean("flowfileQueueResource")); + register(ctx.getBean("remoteProcessGroupResource")); + register(ctx.getBean("inputPortResource")); + register(ctx.getBean("outputPortResource")); + register(ctx.getBean("labelResource")); + register(ctx.getBean("funnelResource")); + register(ctx.getBean("provenanceResource")); + register(ctx.getBean("provenanceEventResource")); + register(ctx.getBean("countersResource")); + register(ctx.getBean("systemDiagnosticsResource")); + register(ctx.getBean("accessResource")); + register(ctx.getBean("accessPolicyResource")); + register(ctx.getBean("tenantsResource")); + + // exception mappers + register(AccessDeniedExceptionMapper.class); + register(AuthorizationAccessExceptionMapper.class); + register(InvalidAuthenticationExceptionMapper.class); + register(AuthenticationCredentialsNotFoundExceptionMapper.class); + register(AdministrationExceptionMapper.class); + register(ClusterExceptionMapper.class); + register(IllegalArgumentExceptionMapper.class); + register(IllegalClusterResourceRequestExceptionMapper.class); + register(IllegalClusterStateExceptionMapper.class); + register(IllegalNodeDeletionExceptionMapper.class); + register(IllegalNodeDisconnectionExceptionMapper.class); + register(IllegalNodeReconnectionExceptionMapper.class); + register(IllegalStateExceptionMapper.class); + register(InvalidRevisionExceptionMapper.class); + register(JsonMappingExceptionMapper.class); + register(JsonParseExceptionMapper.class); + register(MutableRequestExceptionMapper.class); + register(NiFiCoreExceptionMapper.class); + register(NoConnectedNodesExceptionMapper.class); + register(NoClusterCoordinatorExceptionMapper.class); + register(NoResponseFromNodesExceptionMapper.class); + register(NodeDisconnectionExceptionMapper.class); + register(NodeReconnectionExceptionMapper.class); + register(ResourceNotFoundExceptionMapper.class); + register(NotFoundExceptionMapper.class); + register(UnknownNodeExceptionMapper.class); + register(ValidationExceptionMapper.class); + register(WebApplicationExceptionMapper.class); + register(ThrowableMapper.class); + + // gzip + EncodingFilter.enableFor(this, GZipEncoder.class); + } + +}
