initial public commit
This commit is contained in:
@ -0,0 +1,64 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest;
|
||||
|
||||
import org.apache.camel.Body;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
@Path("/")
|
||||
public class ManagementService {
|
||||
|
||||
@POST
|
||||
@Path("/create")
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public String create(@Body String body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/update")
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public String update(@Body String body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/delete")
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public String delete(@Body String body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/clean")
|
||||
@Produces("application/json")
|
||||
public String clean() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest;
|
||||
|
||||
import org.apache.camel.Body;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.Produces;
|
||||
|
||||
@Path("/")
|
||||
public class SubscriptionService {
|
||||
|
||||
@POST
|
||||
@Path("/subscribe")
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public String subscribe(@Body String body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/unsubscribe")
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public String unsubscribe(@Body String body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/publish")
|
||||
@Consumes("application/json")
|
||||
@Produces("application/json")
|
||||
public String publish(@Body String body) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,389 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest;
|
||||
|
||||
import org.hibernate.exception.ConstraintViolationException;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import ru.entaxy.esb.system.common.osgi.OSGIUtils;
|
||||
import ru.entaxy.esb.system.core.events.common.SubscriptionType;
|
||||
import ru.entaxy.esb.system.core.events.jpa.EventTopicService;
|
||||
import ru.entaxy.esb.system.core.events.jpa.SystemSubscriptionService;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.EventTopic;
|
||||
import ru.entaxy.esb.system.core.events.jpa.entity.SystemSubscription;
|
||||
import ru.entaxy.esb.system.core.events.rest.exception.*;
|
||||
import ru.entaxy.esb.system.core.events.rest.response.CreateTopicResponse;
|
||||
import ru.entaxy.esb.system.core.permission.common.PermissionConstants;
|
||||
import ru.entaxy.esb.system.core.permission.jpa.PermissionService;
|
||||
import ru.entaxy.esb.system.core.permission.jpa.entity.Permission;
|
||||
import ru.entaxy.esb.system.jpa.SystemService;
|
||||
import ru.entaxy.esb.system.jpa.entity.System;
|
||||
|
||||
import javax.persistence.NoResultException;
|
||||
import javax.persistence.PersistenceException;
|
||||
import javax.ws.rs.ForbiddenException;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TopicProcessor {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(TopicProcessor.class);
|
||||
|
||||
private SystemService systemService;
|
||||
private SystemSubscriptionService systemSubscriptionService;
|
||||
private EventTopicService eventTopicService;
|
||||
private PermissionService permissionService;
|
||||
|
||||
public CreateTopicResponse registerTopic(String login, String topicName,
|
||||
List<String> possibleSubscribers, List<String> possiblePublishers) throws TopicAlreadyExist {
|
||||
CreateTopicResponse response = null;
|
||||
|
||||
try {
|
||||
Optional<EventTopic> topicOpt = getEventTopicService().fetchByName(topicName);
|
||||
boolean restoring = false;
|
||||
EventTopic topic = null;
|
||||
if (topicOpt.isPresent()) {
|
||||
topic = topicOpt.get();
|
||||
if (topic.isDeleted()) {
|
||||
//restore
|
||||
restoring = true;
|
||||
getEventTopicService().markAsDeleted(topic.getId(), false);
|
||||
} else {
|
||||
throw new TopicAlreadyExist();
|
||||
}
|
||||
} else {
|
||||
topic = getEventTopicService().add(topicName, login);
|
||||
}
|
||||
|
||||
Map<String, List<String>> subscriberErrors = registerSystemsPermission(topic, possibleSubscribers, PermissionConstants.ACTION_SUBSCRIBE);
|
||||
|
||||
Map<String, List<String>> publisherErrors = registerSystemsPermission(topic, possiblePublishers, PermissionConstants.ACTION_PUBLISH);
|
||||
|
||||
response = new CreateTopicResponse();
|
||||
response.setTitle(restoring ? "Topic restored" : "Topic created");
|
||||
response.setTopicName(topic.getName());
|
||||
response.setSubscriberErrors(subscriberErrors);
|
||||
response.setPublisherErrors(publisherErrors);
|
||||
|
||||
// if (restoring) {
|
||||
// throw new TopicDeletedStateException();
|
||||
// }
|
||||
|
||||
} catch (PersistenceException e) {
|
||||
if (e.getCause() instanceof ConstraintViolationException) {
|
||||
throw new TopicAlreadyExist(e);
|
||||
}
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
public CreateTopicResponse updateTopic(String login, String topicName,
|
||||
List<String> possibleSubscribers, List<String> possiblePublishers) throws TopicNotFound {
|
||||
CreateTopicResponse response = null;
|
||||
try {
|
||||
EventTopic topic = getEventTopicService().getByName(topicName);
|
||||
|
||||
topic = getEventTopicService().update(topic.getId(), topic.getName(), login);
|
||||
|
||||
Map<String, List<String>> subscriberErrors = registerSystemsPermission(
|
||||
topic,
|
||||
possibleSubscribers,
|
||||
PermissionConstants.ACTION_SUBSCRIBE);
|
||||
|
||||
Map<String, List<String>> publisherErrors = registerSystemsPermission(
|
||||
topic,
|
||||
possiblePublishers,
|
||||
PermissionConstants.ACTION_PUBLISH);
|
||||
|
||||
response = new CreateTopicResponse();
|
||||
response.setTitle(topic.isDeleted() ? "Topic restored" : "Topic updated");
|
||||
response.setTopicName(topic.getName());
|
||||
response.setSubscriberErrors(subscriberErrors);
|
||||
response.setPublisherErrors(publisherErrors);
|
||||
|
||||
if (topic.isDeleted()) {
|
||||
getEventTopicService().markAsDeleted(topic.getId(), false);
|
||||
}
|
||||
|
||||
} catch (NoResultException e) {
|
||||
LOG.error("Topic not found", e);
|
||||
throw new TopicNotFound(e);
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
private Map<String, List<String>> registerSystemsPermission(EventTopic topic, List<String> systemUuids, String action) {
|
||||
Map<String, List<String>> errorHolder = new HashMap<>();
|
||||
|
||||
if (systemUuids != null && !systemUuids.isEmpty()) {
|
||||
List<String> notFoundSystems = new ArrayList<>();
|
||||
Map<Long, System> passedSystemMap = new HashMap<>();
|
||||
|
||||
for (String uuid : systemUuids) {
|
||||
try {
|
||||
System system = getSystemService().getByUuid(uuid);
|
||||
LOG.debug("System " + uuid + " " + (system != null ? system.getName() : "null") + " for " + action);
|
||||
passedSystemMap.put(system.getId(), system);
|
||||
} catch (NoResultException e) {
|
||||
LOG.error(e.getMessage() + " system uuid=" + uuid);
|
||||
notFoundSystems.add(uuid);
|
||||
}
|
||||
}
|
||||
|
||||
List<Long> passedSystemIds = new ArrayList<Long>(passedSystemMap.keySet());
|
||||
|
||||
List<List<String>> systemSubjectsToAdd = new ArrayList<>();
|
||||
List<Permission> permissionToDelete = new ArrayList<>();
|
||||
|
||||
List<Permission> permissionsOld = getPermissionService().get(topic.getId(), PermissionConstants.TYPE_EVENT_TOPIC, action);
|
||||
if (permissionsOld != null && !permissionsOld.isEmpty()) {
|
||||
for (Permission permission : permissionsOld) {
|
||||
if (PermissionConstants.TYPE_SYSTEM.equals(permission.getSubjectType())
|
||||
&& !passedSystemIds.contains(Long.valueOf(permission.getSubjectId()))) {
|
||||
permissionToDelete.add(permission);
|
||||
}
|
||||
}
|
||||
List<Long> currentSystemIdsWithPermission = permissionsOld.stream()
|
||||
.map(p -> Long.valueOf(p.getSubjectId()))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
for (long systemId : passedSystemIds) {
|
||||
if (!currentSystemIdsWithPermission.contains(systemId)) {
|
||||
systemSubjectsToAdd.add(Arrays.asList(String.valueOf(systemId), PermissionConstants.TYPE_SYSTEM, action));
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
for (long systemId : passedSystemMap.keySet()) {
|
||||
systemSubjectsToAdd.add(Arrays.asList(String.valueOf(systemId), PermissionConstants.TYPE_SYSTEM, action));
|
||||
}
|
||||
}
|
||||
|
||||
//Add new permissions
|
||||
List<Permission> permissions = getPermissionService().addAll(topic.getId(), PermissionConstants.TYPE_EVENT_TOPIC, systemSubjectsToAdd);
|
||||
|
||||
//Delete old permissions
|
||||
for (Permission permission : permissionToDelete) {
|
||||
getPermissionService().remove(permission.getId());
|
||||
}
|
||||
|
||||
|
||||
// List<Long> systemsWithPermission = permissions.stream()
|
||||
// .map(p ->Long.valueOf(p.getSubjectId()))
|
||||
// .collect(Collectors.toList());
|
||||
// List<String> systemsWithoutPermission = passedSystemMap.entrySet().stream()
|
||||
// .filter(e -> !systemsWithPermission.contains(e.getKey()))
|
||||
// .map(e -> e.getValue().getUuid())
|
||||
// .collect(Collectors.toList());
|
||||
if (!notFoundSystems.isEmpty()) {
|
||||
errorHolder.put("systemNotFound", notFoundSystems);
|
||||
}
|
||||
// errorHolder.put("permissionCreateSystemError", systemsWithoutPermission);
|
||||
} else {
|
||||
//if not passed remove all permission for current object action
|
||||
getPermissionService().remove(topic.getId(), PermissionConstants.TYPE_EVENT_TOPIC, action);
|
||||
}
|
||||
|
||||
return errorHolder;
|
||||
}
|
||||
|
||||
public void restoreTopic() {
|
||||
|
||||
}
|
||||
|
||||
public void deleteTopic(String topicName) throws TopicNotFound {
|
||||
EventTopic topic = null;
|
||||
try {
|
||||
topic = getEventTopicService().getByNameAndDeleted(topicName, false);
|
||||
} catch (NoResultException e) {
|
||||
LOG.error("Topic not found", e);
|
||||
throw new TopicNotFound(e);
|
||||
}
|
||||
|
||||
getEventTopicService().markAsDeleted(topic.getId(), true);
|
||||
|
||||
}
|
||||
|
||||
public SystemSubscription getExistingSubscription(String systemUUID, String topicName) throws Exception {
|
||||
System System = null;
|
||||
try {
|
||||
System = getSystemService().getByUuid(systemUUID);
|
||||
} catch (NoResultException e) {
|
||||
LOG.error("System not found", e);
|
||||
throw new SystemNotFound(e);
|
||||
}
|
||||
|
||||
EventTopic topic = getActualTopic(topicName);
|
||||
|
||||
SystemSubscription systemSubscription = null;
|
||||
try {
|
||||
systemSubscription = getSystemSubscriptionService()
|
||||
.getBySystemAndTopic(System.getId(), topic.getId());
|
||||
} catch (NoResultException e) {
|
||||
/* keep silence */
|
||||
}
|
||||
|
||||
return systemSubscription;
|
||||
}
|
||||
|
||||
public SystemSubscription subscribe(String systemUUID, String topicName, String subscriptionType) throws Exception {
|
||||
SubscriptionType type = null;
|
||||
try {
|
||||
type = SubscriptionType.valueOf(subscriptionType.toUpperCase());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new UnknownSubscriptionType(e);
|
||||
}
|
||||
|
||||
System system = null;
|
||||
try {
|
||||
system = getSystemService().getByUuid(systemUUID);
|
||||
} catch (NoResultException e) {
|
||||
LOG.error("System not found", e);
|
||||
throw new SystemNotFound(e);
|
||||
}
|
||||
|
||||
try {
|
||||
EventTopic topic = getEventTopicService().getByNameAndDeleted(topicName, false);
|
||||
|
||||
return registerConsumer(topic, system, type);
|
||||
} catch (NoResultException e) {
|
||||
LOG.error("Topic not found", e);
|
||||
throw new TopicNotFound(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
LOG.error("No permission to subscribe", e);
|
||||
throw new ForbiddenException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void restoreSubscription(SystemSubscription subscription) {
|
||||
getSystemSubscriptionService().markAsDeleted(subscription.getId(), false);
|
||||
}
|
||||
|
||||
private SystemSubscription registerConsumer(EventTopic topic, System system, SubscriptionType type) throws Exception {
|
||||
SystemSubscription systemSubscription = null;
|
||||
try {
|
||||
systemSubscription = getSystemSubscriptionService()
|
||||
.getBySystemAndTopic(system.getId(), topic.getId());
|
||||
} catch (NoResultException e) {
|
||||
/* keep silence */
|
||||
}
|
||||
if (systemSubscription != null) {
|
||||
if (!systemSubscription.getType().equals(type)) {
|
||||
systemSubscription.setType(type);
|
||||
getSystemSubscriptionService().update(systemSubscription);
|
||||
// throw new SubscriptionTypeModificationException();
|
||||
}
|
||||
} else {
|
||||
systemSubscription = getSystemSubscriptionService().add(system, topic,
|
||||
type);
|
||||
}
|
||||
|
||||
return systemSubscription;
|
||||
}
|
||||
|
||||
public SystemSubscription unsubscribe(String systemUUID, String topicName) throws Exception {
|
||||
System system = null;
|
||||
try {
|
||||
system = getSystemService().getByUuid(systemUUID);
|
||||
} catch (NoResultException e) {
|
||||
LOG.error("System not found " + systemUUID, e);
|
||||
throw new SystemNotFound(e);
|
||||
}
|
||||
|
||||
EventTopic topic = getActualTopic(topicName);
|
||||
|
||||
if (system != null && topic != null) {
|
||||
try {
|
||||
SystemSubscription systemSubscription = getSystemSubscriptionService()
|
||||
.getBySystemAndTopic(system.getId(), topic.getId());
|
||||
getSystemSubscriptionService().markAsDeleted(systemSubscription.getId(), true);
|
||||
|
||||
return systemSubscription;
|
||||
} catch (NoResultException e) {
|
||||
LOG.warn("Subscription not found for system=" + systemUUID + " topic=" + topicName, e);
|
||||
throw new SubscriptionNotFound();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public EventTopic getTopic(String topicName) throws TopicNotFound {
|
||||
try {
|
||||
return getEventTopicService().getByName(topicName);
|
||||
} catch (NoResultException e) {
|
||||
LOG.error("Topic not found", e);
|
||||
throw new TopicNotFound(e);
|
||||
}
|
||||
}
|
||||
|
||||
public EventTopic getActualTopic(String topicName) throws TopicNotFound {
|
||||
try {
|
||||
return getEventTopicService().getByNameAndDeleted(topicName, false);
|
||||
} catch (NoResultException e) {
|
||||
LOG.error("Topic not found", e);
|
||||
throw new TopicNotFound(e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<SystemSubscription> getTopicSubscriptions(EventTopic topic) throws TopicNotFound {
|
||||
return getSystemSubscriptionService().getByTopic(topic.getId());
|
||||
}
|
||||
|
||||
public SystemService getSystemService() {
|
||||
if (systemService == null) {
|
||||
systemService = (SystemService) OSGIUtils.getServiceReference(
|
||||
FrameworkUtil.getBundle(TopicProcessor.class).getBundleContext(),
|
||||
SystemService.class.getName());
|
||||
}
|
||||
return systemService;
|
||||
}
|
||||
|
||||
public SystemSubscriptionService getSystemSubscriptionService() {
|
||||
if (systemSubscriptionService == null) {
|
||||
systemSubscriptionService = (SystemSubscriptionService) OSGIUtils.getServiceReference(
|
||||
FrameworkUtil.getBundle(TopicProcessor.class).getBundleContext(),
|
||||
SystemSubscriptionService.class.getName());
|
||||
}
|
||||
return systemSubscriptionService;
|
||||
}
|
||||
|
||||
public EventTopicService getEventTopicService() {
|
||||
if (eventTopicService == null) {
|
||||
eventTopicService = (EventTopicService) OSGIUtils.getServiceReference(
|
||||
FrameworkUtil.getBundle(TopicProcessor.class).getBundleContext(),
|
||||
EventTopicService.class.getName());
|
||||
}
|
||||
return eventTopicService;
|
||||
}
|
||||
|
||||
public PermissionService getPermissionService() {
|
||||
if (permissionService == null) {
|
||||
permissionService = (PermissionService) OSGIUtils.getServiceReference(
|
||||
FrameworkUtil.getBundle(TopicProcessor.class).getBundleContext(),
|
||||
PermissionService.class.getName());
|
||||
}
|
||||
return permissionService;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.aggregation;
|
||||
|
||||
import org.apache.camel.AggregationStrategy;
|
||||
import org.apache.camel.Exchange;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class ResponseAggregator implements AggregationStrategy {
|
||||
|
||||
private static final Logger LOG = LoggerFactory.getLogger(ResponseAggregator.class);
|
||||
|
||||
@Override
|
||||
public Exchange aggregate(Exchange oldExchange, Exchange newExchange) {
|
||||
LOG.debug("oldExchange " + (oldExchange != null));
|
||||
LOG.debug("newExchange " + (newExchange != null));
|
||||
|
||||
if (oldExchange == null) {
|
||||
oldExchange = newExchange;
|
||||
oldExchange.getIn().setBody("[" + oldExchange.getIn().getBody(String.class));
|
||||
} else if (newExchange != null) {
|
||||
String oldBody = oldExchange.getIn().getBody(String.class);
|
||||
String newBody = newExchange.getIn().getBody(String.class);
|
||||
oldExchange.getIn().setBody(oldBody + "," + newBody);
|
||||
}
|
||||
if (newExchange.getProperty("CamelSplitComplete", Boolean.class)) {
|
||||
oldExchange.getIn().setBody(oldExchange.getIn().getBody(String.class) + "]");
|
||||
}
|
||||
return oldExchange;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.exception;
|
||||
|
||||
public class SubscriptionNotFound extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 1438059417921228582L;
|
||||
|
||||
public SubscriptionNotFound() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SubscriptionNotFound(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public SubscriptionNotFound(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SubscriptionNotFound(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SubscriptionNotFound(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.exception;
|
||||
|
||||
public class SubscriptionTypeModificationException extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -1621510117561995906L;
|
||||
|
||||
public SubscriptionTypeModificationException() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SubscriptionTypeModificationException(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public SubscriptionTypeModificationException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SubscriptionTypeModificationException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SubscriptionTypeModificationException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.exception;
|
||||
|
||||
public class SystemNotFound extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -5204253149870905318L;
|
||||
|
||||
public SystemNotFound() {
|
||||
super();
|
||||
}
|
||||
|
||||
public SystemNotFound(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public SystemNotFound(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public SystemNotFound(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public SystemNotFound(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.exception;
|
||||
|
||||
public class TopicAlreadyExist extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -2731202383081783015L;
|
||||
|
||||
public TopicAlreadyExist() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TopicAlreadyExist(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public TopicAlreadyExist(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public TopicAlreadyExist(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TopicAlreadyExist(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.exception;
|
||||
|
||||
public class TopicNotFound extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 5093239116981997713L;
|
||||
|
||||
public TopicNotFound() {
|
||||
super();
|
||||
}
|
||||
|
||||
public TopicNotFound(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public TopicNotFound(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public TopicNotFound(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public TopicNotFound(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.exception;
|
||||
|
||||
public class UnknownSubscriptionType extends Exception {
|
||||
|
||||
private static final long serialVersionUID = 5233193990834603868L;
|
||||
|
||||
public UnknownSubscriptionType() {
|
||||
super();
|
||||
}
|
||||
|
||||
public UnknownSubscriptionType(String message, Throwable cause, boolean enableSuppression,
|
||||
boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
|
||||
public UnknownSubscriptionType(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public UnknownSubscriptionType(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public UnknownSubscriptionType(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.response;
|
||||
|
||||
public class CleanResponse extends Response {
|
||||
|
||||
private int topicDeleted;
|
||||
|
||||
public int getTopicDeleted() {
|
||||
return topicDeleted;
|
||||
}
|
||||
|
||||
public void setTopicDeleted(int topicDeleted) {
|
||||
this.topicDeleted = topicDeleted;
|
||||
}
|
||||
|
||||
public static CleanResponse getInstance(String title, int topicDeleted) {
|
||||
CleanResponse response = new CleanResponse();
|
||||
|
||||
response.setTitle(title);
|
||||
response.setTopicDeleted(topicDeleted);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,58 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.response;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class CreateTopicResponse extends JsonSuccessResponse {
|
||||
|
||||
private Map<String, List<String>> subscriberErrors;
|
||||
private Map<String, List<String>> publisherErrors;
|
||||
|
||||
public Map<String, List<String>> getSubscriberErrors() {
|
||||
return subscriberErrors;
|
||||
}
|
||||
|
||||
public void setSubscriberErrors(Map<String, List<String>> subscriberErrors) {
|
||||
this.subscriberErrors = subscriberErrors;
|
||||
}
|
||||
|
||||
public Map<String, List<String>> getPublisherErrors() {
|
||||
return publisherErrors;
|
||||
}
|
||||
|
||||
public void setPublisherErrors(Map<String, List<String>> publisherErrors) {
|
||||
this.publisherErrors = publisherErrors;
|
||||
}
|
||||
|
||||
public static CreateTopicResponse getInstance(String title, String topicName,
|
||||
Map<String, List<String>> subscriberErrors, Map<String, List<String>> publisherErrors) {
|
||||
CreateTopicResponse response = new CreateTopicResponse();
|
||||
|
||||
response.setTitle(title);
|
||||
response.setTopicName(topicName);
|
||||
response.setSubscriberErrors(subscriberErrors);
|
||||
response.setPublisherErrors(publisherErrors);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.response;
|
||||
|
||||
public class JsonErrorResponse extends Response {
|
||||
|
||||
private String detail;
|
||||
private String reason;
|
||||
|
||||
public String getDetail() {
|
||||
return detail;
|
||||
}
|
||||
|
||||
public void setDetail(String detail) {
|
||||
this.detail = detail;
|
||||
}
|
||||
|
||||
public String getReason() {
|
||||
return reason;
|
||||
}
|
||||
|
||||
public void setReason(String reason) {
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
public static JsonErrorResponse getInstance(String title, String detail, String reason) {
|
||||
JsonErrorResponse response = new JsonErrorResponse();
|
||||
response.setTitle(title);
|
||||
response.setDetail(detail);
|
||||
response.setReason(reason);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.response;
|
||||
|
||||
public class JsonSuccessResponse extends Response {
|
||||
|
||||
private String topicName;
|
||||
|
||||
public String getTopicName() {
|
||||
return topicName;
|
||||
}
|
||||
|
||||
public void setTopicName(String topicName) {
|
||||
this.topicName = topicName;
|
||||
}
|
||||
|
||||
public static JsonSuccessResponse getInstance(String title, String topicName) {
|
||||
JsonSuccessResponse response = new JsonSuccessResponse();
|
||||
response.setTitle(title);
|
||||
response.setTopicName(topicName);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.response;
|
||||
|
||||
public abstract class Response {
|
||||
|
||||
private String title;
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* events-rest
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2021 EmDev LLC
|
||||
* ==========
|
||||
* 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.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
package ru.entaxy.esb.system.core.events.rest.response;
|
||||
|
||||
public class SubscriptionResponse extends JsonSuccessResponse {
|
||||
|
||||
private String systemUUID;
|
||||
private String subscriptionType;
|
||||
|
||||
public String getSystemUUID() {
|
||||
return systemUUID;
|
||||
}
|
||||
|
||||
public void setSystemUUID(String systemUUID) {
|
||||
this.systemUUID = systemUUID;
|
||||
}
|
||||
|
||||
public String getSubscriptionType() {
|
||||
return subscriptionType;
|
||||
}
|
||||
|
||||
public void setSubscriptionType(String subscriptionType) {
|
||||
this.subscriptionType = subscriptionType;
|
||||
}
|
||||
|
||||
public static SubscriptionResponse getInstance(String title, String topicName, String systemUUID, String subscriptionType) {
|
||||
SubscriptionResponse response = new SubscriptionResponse();
|
||||
response.setTitle(title);
|
||||
response.setTopicName(topicName);
|
||||
response.setSystemUUID(systemUUID);
|
||||
response.setSubscriptionType(subscriptionType);
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
@ -0,0 +1,894 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
~~~~~~licensing~~~~~~
|
||||
events-rest
|
||||
==========
|
||||
Copyright (C) 2020 - 2021 EmDev LLC
|
||||
==========
|
||||
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.
|
||||
~~~~~~/licensing~~~~~~
|
||||
-->
|
||||
|
||||
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"
|
||||
xmlns:camelcxf="http://camel.apache.org/schema/blueprint/cxf"
|
||||
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
|
||||
|
||||
<cm:property-placeholder
|
||||
persistent-id="ru.entaxy.esb.system.event.rest" update-strategy="reload">
|
||||
<cm:default-properties>
|
||||
<cm:property name="service.host" value="http://localhost"/>
|
||||
|
||||
<cm:property name="service.port.management" value="9090"/>
|
||||
<cm:property name="service.root.path.management" value="/topic-management"/>
|
||||
|
||||
<cm:property name="service.port.subscription" value="9092"/>
|
||||
<cm:property name="service.root.path.subscription" value="/topic-subscription"/>
|
||||
|
||||
<cm:property name="mode.dev" value="false"/>
|
||||
</cm:default-properties>
|
||||
</cm:property-placeholder>
|
||||
|
||||
<reference id="pooledConnectionFactory" interface="javax.jms.ConnectionFactory"/>
|
||||
|
||||
<bean id="jms" class="org.apache.camel.component.jms.JmsComponent">
|
||||
<property name="connectionFactory" ref="pooledConnectionFactory"/>
|
||||
</bean>
|
||||
|
||||
<bean id="topicProcessor" class="ru.entaxy.esb.system.core.events.rest.TopicProcessor"/>
|
||||
|
||||
<reference id="systemInterceptor"
|
||||
interface="org.apache.cxf.phase.PhaseInterceptor"
|
||||
filter="(type=system)"
|
||||
timeout="30000"
|
||||
availability="mandatory"/>
|
||||
<reference id="serviceInterceptor"
|
||||
interface="org.apache.cxf.phase.PhaseInterceptor"
|
||||
filter="(type=service)"
|
||||
timeout="30000"
|
||||
availability="mandatory"/>
|
||||
<reference id="authInterceptor" interface="org.apache.cxf.phase.PhaseInterceptor"
|
||||
filter="(type=authentication)"/>
|
||||
|
||||
<camelcxf:rsServer id="rsManagement"
|
||||
address="${service.host}:${service.port.management}${service.root.path.management}"
|
||||
serviceClass="ru.entaxy.esb.system.core.events.rest.ManagementService"
|
||||
loggingFeatureEnabled="true" loggingSizeLimit="50">
|
||||
<camelcxf:inInterceptors>
|
||||
<ref component-id="authInterceptor"/>
|
||||
<ref component-id="serviceInterceptor"/>
|
||||
</camelcxf:inInterceptors>
|
||||
</camelcxf:rsServer>
|
||||
|
||||
<camelcxf:rsServer id="rsSubscription"
|
||||
address="${service.host}:${service.port.subscription}${service.root.path.subscription}"
|
||||
serviceClass="ru.entaxy.esb.system.core.events.rest.SubscriptionService"
|
||||
loggingFeatureEnabled="true" loggingSizeLimit="50">
|
||||
<camelcxf:inInterceptors>
|
||||
<ref component-id="authInterceptor"/>
|
||||
<ref component-id="systemInterceptor"/>
|
||||
</camelcxf:inInterceptors>
|
||||
</camelcxf:rsServer>
|
||||
|
||||
|
||||
<bean id="subscriptionResponse" class="ru.entaxy.esb.system.core.events.rest.response.SubscriptionResponse"/>
|
||||
|
||||
<bean id="responseAggregator" class="ru.entaxy.esb.system.core.events.rest.aggregation.ResponseAggregator"/>
|
||||
|
||||
<reference id="permissionChecker"
|
||||
interface="ru.entaxy.esb.system.core.permission.handler.PermissionChecker"
|
||||
timeout="30000"
|
||||
availability="mandatory"/>
|
||||
|
||||
<camelContext id="rest-context" xmlns="http://camel.apache.org/schema/blueprint">
|
||||
|
||||
<route id="eventManagement">
|
||||
<from uri="cxfrs:bean:rsManagement?bindingStyle=SimpleConsumer"/>
|
||||
<log message="Events topic management operation ${header.operationName}" loggingLevel="DEBUG"/>
|
||||
<toD uri="direct:${header.operationName}"/>
|
||||
</route>
|
||||
|
||||
<route id="eventSubscription">
|
||||
<from uri="cxfrs:bean:rsSubscription?bindingStyle=SimpleConsumer"/>
|
||||
<log message="Events topic subscription operation ${header.operationName}" loggingLevel="DEBUG"/>
|
||||
<toD uri="direct:${header.operationName}"/>
|
||||
</route>
|
||||
|
||||
<route id="topicCreate">
|
||||
<from uri="direct:create"/>
|
||||
<log message="Received - create: ${body}" loggingLevel="TRACE"/>
|
||||
|
||||
<!-- JSON -->
|
||||
<!-- { "topicName": "boomNews" } -->
|
||||
|
||||
<doTry>
|
||||
<setProperty name="topicName">
|
||||
<jsonpath>$.topicName</jsonpath>
|
||||
</setProperty>
|
||||
<setProperty name="possibleSubscribers">
|
||||
<jsonpath suppressExceptions="true">$.possibleSubscribers</jsonpath>
|
||||
</setProperty>
|
||||
<setProperty name="possiblePublishers">
|
||||
<jsonpath suppressExceptions="true">$.possiblePublishers</jsonpath>
|
||||
</setProperty>
|
||||
<doCatch>
|
||||
<exception>org.apache.camel.ExpressionEvaluationException</exception>
|
||||
<log message="CreateTopic: Body is not JSON" loggingLevel="ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.topicName} != null && ${exchangeProperty.topicName} != ""
|
||||
&& ${header.X-ForwardedUser} != null && ${header.X-ForwardedUser} != ""
|
||||
</simple>
|
||||
<log message="CreateTopic: ${exchangeProperty.topicName}" loggingLevel="TRACE"/>
|
||||
|
||||
<doTry>
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="registerTopic(${header.X-ForwardedUser}, ${exchangeProperty.topicName}, ${exchangeProperty.possibleSubscribers}, ${exchangeProperty.possiblePublishers})"/>
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.DELETED}</simple>
|
||||
<!-- Restore ropic -->
|
||||
<to uri="direct:restoreSubscriberRoutes"/>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>200</constant>
|
||||
</setHeader>
|
||||
</when>
|
||||
<otherwise>
|
||||
<setProperty name="BODY_HOLDER">
|
||||
<simple>${body}</simple>
|
||||
</setProperty>
|
||||
<!-- Create topic in broker -->
|
||||
<setBody>
|
||||
<constant>null</constant>
|
||||
</setBody>
|
||||
<toD uri="jms:topic:${exchangeProperty.topicName}?exchangePattern=InOnly"/>
|
||||
|
||||
<setBody>
|
||||
<simple>${exchangeProperty.BODY_HOLDER}</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>201</constant>
|
||||
</setHeader>
|
||||
</otherwise>
|
||||
</choice>
|
||||
|
||||
<marshal>
|
||||
<json library="Gson"/>
|
||||
</marshal>
|
||||
|
||||
<doCatch>
|
||||
<exception>ru.entaxy.esb.system.core.events.rest.exception.TopicAlreadyExist</exception>
|
||||
<setBody>
|
||||
<simple>{ "title": "Topic already exists", "topicName": "${exchangeProperty.topicName}"
|
||||
}
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>200</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>java.lang.Exception</exception>
|
||||
<log message="Subscription: Unknown exception ${exception.stacktrace}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Internal Server Error", "detail": "Unknown exception", "reason":
|
||||
"${exception.message}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>500</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
</when>
|
||||
<otherwise>
|
||||
<log message="CreateTopic: Bad request" loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Incorrect input parameters", "detail": "Cannot parse incoming JSON or login
|
||||
not defined" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>400</constant>
|
||||
</setHeader>
|
||||
</otherwise>
|
||||
</choice>
|
||||
|
||||
</route>
|
||||
|
||||
<route>
|
||||
<from uri="direct:checkTopic"/>
|
||||
<doTry>
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="getTopic(${exchangeProperty.topicName})"/>
|
||||
|
||||
<setProperty name="DELETED">
|
||||
<simple resultType="boolean">${body.deleted}</simple>
|
||||
</setProperty>
|
||||
|
||||
<doCatch>
|
||||
<exception>java.lang.Exception</exception>
|
||||
<!-- do nothing -->
|
||||
</doCatch>
|
||||
</doTry>
|
||||
</route>
|
||||
|
||||
|
||||
<route id="topicUpdate">
|
||||
<from uri="direct:update"/>
|
||||
<log message="Received - update: ${body}" loggingLevel="TRACE"/>
|
||||
<doTry>
|
||||
<setProperty name="topicName">
|
||||
<jsonpath>$.topicName</jsonpath>
|
||||
</setProperty>
|
||||
<setProperty name="possibleSubscribers">
|
||||
<jsonpath suppressExceptions="true">$.possibleSubscribers</jsonpath>
|
||||
</setProperty>
|
||||
<setProperty name="possiblePublishers">
|
||||
<jsonpath suppressExceptions="true">$.possiblePublishers</jsonpath>
|
||||
</setProperty>
|
||||
<doCatch>
|
||||
<exception>org.apache.camel.ExpressionEvaluationException</exception>
|
||||
<log message="UpdateTopic: Body is not JSON ${exception.stacktrace}" loggingLevel="ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.topicName} != null && ${exchangeProperty.topicName} != ""
|
||||
&& ${header.X-ForwardedUser} != null && ${header.X-ForwardedUser} != ""
|
||||
</simple>
|
||||
<log message="UpdateTopic: ${exchangeProperty.topicName}" loggingLevel="TRACE"/>
|
||||
|
||||
<doTry>
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="getTopic(${exchangeProperty.topicName})"/>
|
||||
|
||||
<setProperty name="DELETED">
|
||||
<simple resultType="boolean">${body.deleted}</simple>
|
||||
</setProperty>
|
||||
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="updateTopic(${header.X-ForwardedUser}, ${exchangeProperty.topicName}, ${exchangeProperty.possibleSubscribers}, ${exchangeProperty.possiblePublishers})"/>
|
||||
|
||||
<when>
|
||||
<simple>${exchangeProperty.DELETED}</simple>
|
||||
<to uri="direct:restoreSubscriberRoutes"/>
|
||||
</when>
|
||||
|
||||
<marshal>
|
||||
<json library="Gson"/>
|
||||
</marshal>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>200</constant>
|
||||
</setHeader>
|
||||
|
||||
<doCatch>
|
||||
<exception>java.lang.Exception</exception>
|
||||
<log message="Subscription: Unknown exception ${exception.stacktrace}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Internal Server Error", "detail": "Unknown exception", "reason":
|
||||
"${exception.message}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>500</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
</when>
|
||||
<otherwise>
|
||||
<log message="CreateTopic: Bad request" loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Incorrect input parameters", "detail": "Cannot parse incoming JSON or login
|
||||
not defined" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>400</constant>
|
||||
</setHeader>
|
||||
</otherwise>
|
||||
</choice>
|
||||
|
||||
</route>
|
||||
|
||||
<route id="restoreSubscriberRoutes">
|
||||
<from uri="direct:restoreSubscriberRoutes"/>
|
||||
<setProperty name="BODY_HOLDER">
|
||||
<simple>${body}</simple>
|
||||
</setProperty>
|
||||
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="getTopic(${exchangeProperty.topicName})"/>
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="getTopicSubscriptions(${body})"/>
|
||||
|
||||
<to uri="direct-vm:prepareSubscriberRoutes"/>
|
||||
|
||||
<setBody>
|
||||
<simple>${exchangeProperty.BODY_HOLDER}</simple>
|
||||
</setBody>
|
||||
</route>
|
||||
|
||||
<route id="topicDelete">
|
||||
<from uri="direct:delete"/>
|
||||
<log message="Received - delete: ${body}" loggingLevel="TRACE"/>
|
||||
<doTry>
|
||||
<setProperty name="topicName">
|
||||
<jsonpath>$.topicName</jsonpath>
|
||||
</setProperty>
|
||||
<doCatch>
|
||||
<exception>org.apache.camel.ExpressionEvaluationException</exception>
|
||||
<log message="CreateTopic: Body is not JSON" loggingLevel="ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.topicName} != null && ${exchangeProperty.topicName} != ""
|
||||
&& ${header.X-ForwardedUser} != null && ${header.X-ForwardedUser} != ""
|
||||
</simple>
|
||||
<log message="DeleteTopic: ${exchangeProperty.topicName}" loggingLevel="TRACE"/>
|
||||
|
||||
<doTry>
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="getActualTopic(${exchangeProperty.topicName})"/>
|
||||
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="getTopicSubscriptions(${body})"/>
|
||||
|
||||
<to uri="direct-vm:deleteSubscriberRoutes"/>
|
||||
|
||||
<bean
|
||||
ref="topicProcessor"
|
||||
method="deleteTopic(${exchangeProperty.topicName})"/>
|
||||
|
||||
<bean
|
||||
beanType="ru.entaxy.esb.system.core.events.rest.response.JsonSuccessResponse"
|
||||
method="getInstance('Topic mark as deleted', ${exchangeProperty.topicName})"/>
|
||||
<marshal>
|
||||
<json library="Gson"/>
|
||||
</marshal>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>200</constant>
|
||||
</setHeader>
|
||||
|
||||
<doCatch>
|
||||
<exception>ru.entaxy.esb.system.core.events.rest.exception.TopicNotFound</exception>
|
||||
<setBody>
|
||||
<simple>{ "title": "Topic not registered", "topicName": "${exchangeProperty.topicName}"
|
||||
}
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>400</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>java.lang.Exception</exception>
|
||||
<log message="Subscription: Unknown exception ${exception.stacktrace}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Internal Server Error", "detail": "Unknown exception", "reason":
|
||||
"${exception.message}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>500</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
</when>
|
||||
<otherwise>
|
||||
<log message="CreateTopic: Bad request" loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Incorrect input parameters", "detail": "Cannot parse incoming JSON or login
|
||||
not defined" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>400</constant>
|
||||
</setHeader>
|
||||
</otherwise>
|
||||
</choice>
|
||||
</route>
|
||||
|
||||
<route id="topicClean">
|
||||
<from uri="direct:clean"/>
|
||||
<log message="Received - clean command" loggingLevel="TRACE"/>
|
||||
|
||||
<doTry>
|
||||
<to uri="direct-vm:cleanProcess"/>
|
||||
|
||||
<bean
|
||||
beanType="ru.entaxy.esb.system.core.events.rest.response.CleanResponse"
|
||||
method="getInstance('Cleaned', ${body})"/>
|
||||
|
||||
<marshal>
|
||||
<json library="Gson"/>
|
||||
</marshal>
|
||||
<doCatch>
|
||||
<exception>java.lang.Exception</exception>
|
||||
<log message="Subscription: Unknown exception ${exception.stacktrace}" loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Internal Server Error", "detail": "Unknown exception", "reason":
|
||||
"${exception.message}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>500</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
</route>
|
||||
|
||||
<route id="topicSubscribe">
|
||||
<from uri="direct:subscribe"/>
|
||||
<log message="Received - subscribe: ${body}" loggingLevel="TRACE"/>
|
||||
|
||||
<!-- JSON -->
|
||||
<!-- {"topicName": "boom","subscriptionType": "PUSH"("PULL")} -->
|
||||
|
||||
<setProperty name="subscribe">
|
||||
<simple resultType="java.lang.Boolean">true</simple>
|
||||
</setProperty>
|
||||
|
||||
<to uri="direct:prepareSubscription"/>
|
||||
</route>
|
||||
|
||||
<route id="topicUnsubscribe">
|
||||
<from uri="direct:unsubscribe"/>
|
||||
<convertBodyTo type="java.lang.String"/>
|
||||
<log message="Received - unsubscribe: ${body}" loggingLevel="TRACE"/>
|
||||
|
||||
<!-- JSON -->
|
||||
<!-- {"topicName": "boom"} -->
|
||||
|
||||
<setProperty name="subscribe">
|
||||
<simple resultType="java.lang.Boolean">false</simple>
|
||||
</setProperty>
|
||||
|
||||
<to uri="direct:prepareSubscription"/>
|
||||
</route>
|
||||
|
||||
<route id="prepareSubscription">
|
||||
<from uri="direct:prepareSubscription"/>
|
||||
|
||||
<doTry>
|
||||
<setProperty name="systemUuids">
|
||||
<jsonpath>$.systemUuids</jsonpath>
|
||||
</setProperty>
|
||||
<doCatch>
|
||||
<exception>org.apache.camel.ExpressionEvaluationException</exception>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<doTry>
|
||||
<setProperty name="topicName">
|
||||
<jsonpath>$.topicName</jsonpath>
|
||||
</setProperty>
|
||||
<doCatch>
|
||||
<exception>org.apache.camel.ExpressionEvaluationException</exception>
|
||||
<log message="CreateSubscription: Body is not JSON" loggingLevel="ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.systemUuids} != null && ${exchangeProperty.systemUuids} != ""
|
||||
</simple>
|
||||
<!-- TODO improve get serviceName-->
|
||||
<setProperty name="serviceName">
|
||||
<simple>{{service.root.path.subscription}}</simple>
|
||||
</setProperty>
|
||||
<setProperty name="serviceName">
|
||||
<simple>${exchangeProperty.serviceName.substring(1)}</simple>
|
||||
</setProperty>
|
||||
|
||||
<log message="ServiceName ${exchangeProperty.serviceName}" loggingLevel="DEBUG"/>
|
||||
<log message="X-ForwardedUserId ${headers.X-ForwardedUserId}" loggingLevel="DEBUG"/>
|
||||
|
||||
<setProperty name="permissionCheck">
|
||||
<simple>bean-fix:permissionChecker?method=check(${headers.X-ForwardedUserId}, 'account',
|
||||
${exchangeProperty.serviceName}, 'service', 'manage')
|
||||
</simple>
|
||||
</setProperty>
|
||||
|
||||
<!-- <toD uri="permission:checkException?objectId=${headers.X-ForwardedUserId}&objectType=account&subjectId=${exchangeProperty.serviceName}&subjectType=service&action=manage" /> -->
|
||||
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.permissionCheck}</simple>
|
||||
|
||||
<split strategyRef="responseAggregator">
|
||||
<jsonpath>$.systemUuids</jsonpath>
|
||||
|
||||
<log message="Subscribe ${body}" loggingLevel="TRACE"/>
|
||||
<doTry>
|
||||
<setHeader name="X-SystemUuid">
|
||||
<jsonpath>$.systemUuid</jsonpath>
|
||||
</setHeader>
|
||||
<setProperty name="subscriptionType">
|
||||
<jsonpath>$.subscriptionType</jsonpath>
|
||||
</setProperty>
|
||||
<doCatch>
|
||||
<exception>org.apache.camel.ExpressionEvaluationException</exception>
|
||||
<log message="CreateSubscription: Body is not JSON" loggingLevel="ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<to uri="direct:subscription"/>
|
||||
</split>
|
||||
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>200</constant>
|
||||
</setHeader>
|
||||
|
||||
<log message="X-SystemUuid after process ${headers.X-SystemUuid}" loggingLevel="TRACE"/>
|
||||
</when>
|
||||
<otherwise>
|
||||
<log message="Subscription: Account ${headers.X-ForwardedUser} without MANAGE permission"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Forbidden", "detail": "No MANAGE permission" }</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>403</constant>
|
||||
</setHeader>
|
||||
</otherwise>
|
||||
</choice>
|
||||
|
||||
</when>
|
||||
|
||||
<otherwise>
|
||||
<doTry>
|
||||
<setProperty name="subscriptionType">
|
||||
<jsonpath>$.subscriptionType</jsonpath>
|
||||
</setProperty>
|
||||
<doCatch>
|
||||
<exception>org.apache.camel.ExpressionEvaluationException</exception>
|
||||
<!-- <log message="CreateSubscription: Body is not JSON" loggingLevel="ERROR"/> -->
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<to uri="direct:subscription"/>
|
||||
</otherwise>
|
||||
</choice>
|
||||
</route>
|
||||
|
||||
<route id="subscription">
|
||||
<from uri="direct:subscription"/>
|
||||
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.topicName} != null && ${exchangeProperty.topicName} != ""
|
||||
&& ${header.X-SystemUuid} != null && ${header.X-SystemUuid} != ""
|
||||
</simple>
|
||||
<log message="Subscription: subscribe ${exchangeProperty.subscribe} to ${exchangeProperty.topicName} system ${header.X-SystemUuid}"
|
||||
loggingLevel="INFO"/>
|
||||
|
||||
<doTry>
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.subscribe}</simple>
|
||||
|
||||
<log message="Title ${bean:subscriptionResponse.title}" loggingLevel="TRACE"/>
|
||||
|
||||
<to uri="direct:checkExistingSubscription"/>
|
||||
|
||||
<setProperty name="responseTitle">
|
||||
<constant>Subscription created</constant>
|
||||
</setProperty>
|
||||
|
||||
<when>
|
||||
<simple>${exchangeProperty.ALREADY_EXIST} == false</simple>
|
||||
<bean ref="topicProcessor"
|
||||
method="subscribe(${header.X-SystemUuid}, ${header.topicName}, ${exchangeProperty.subscriptionType})"/>
|
||||
<to uri="direct-vm:prepareSubscriberConsumer"/>
|
||||
</when>
|
||||
<when>
|
||||
<simple>${exchangeProperty.DELETED}</simple>
|
||||
<bean ref="topicProcessor" method="restoreSubscription(${body})"/>
|
||||
|
||||
<to uri="direct-vm:prepareSubscriberRoute"/>
|
||||
<setProperty name="responseTitle">
|
||||
<constant>Subscription restored</constant>
|
||||
</setProperty>
|
||||
</when>
|
||||
|
||||
<bean
|
||||
beanType="ru.entaxy.esb.system.core.events.rest.response.SubscriptionResponse"
|
||||
method="getInstance(${exchangeProperty.responseTitle}, ${exchangeProperty.topicName}, ${header.X-SystemUuid}, ${exchangeProperty.subscriptionType})"/>
|
||||
|
||||
<marshal>
|
||||
<json library="Gson"/>
|
||||
</marshal>
|
||||
<!-- <setBody><simple>{ "title": "Subscription created", "topicName": "${exchangeProperty.topicName}", "systemUUID": "${header.X-SystemUuid}", "subscriptionType": "${exchangeProperty.subscriptionType}"}</simple></setBody> -->
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>201</constant>
|
||||
</setHeader>
|
||||
</when>
|
||||
<otherwise>
|
||||
<bean ref="topicProcessor"
|
||||
method="unsubscribe(${header.X-SystemUuid}, ${exchangeProperty.topicName})"/>
|
||||
<to uri="direct-vm:deleteSubscriberRoute"/>
|
||||
|
||||
<bean
|
||||
beanType="ru.entaxy.esb.system.core.events.rest.response.SubscriptionResponse"
|
||||
method="getInstance('Subscription mark as deleted', ${exchangeProperty.topicName}, ${header.X-SystemUuid}, ${null})"/>
|
||||
|
||||
<marshal>
|
||||
<json library="Gson"/>
|
||||
</marshal>
|
||||
<!-- <setBody><simple>{ "title": "Subscription deleted", "topicName": "${exchangeProperty.topicName}", "systemUUID": "${header.X-SystemUuid}"}</simple></setBody> -->
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>200</constant>
|
||||
</setHeader>
|
||||
</otherwise>
|
||||
</choice>
|
||||
|
||||
<doCatch>
|
||||
<exception>ru.entaxy.esb.system.core.events.rest.exception.SubscriptionNotFound</exception>
|
||||
<setBody>
|
||||
<simple>{ "title": "Subscription not found", "topicName":
|
||||
"${exchangeProperty.topicName}", "systemUUID": "${header.X-SystemUuid}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>404</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>ru.entaxy.esb.system.core.events.rest.exception.TopicNotFound</exception>
|
||||
<setBody>
|
||||
<simple>{ "title": "Topic not registered", "topicName": "${exchangeProperty.topicName}"
|
||||
}
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>400</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>ru.entaxy.esb.system.core.events.rest.exception.SystemNotFound</exception>
|
||||
<log message="Subscription: System not found ${header.X-SystemUuid}" loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Internal Server Error", "detail": "System not found
|
||||
${header.X-SystemUuid}", "reason": "${exception.message}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>500</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>ru.entaxy.esb.system.core.events.rest.exception.UnknownSubscriptionType
|
||||
</exception>
|
||||
<log message="Subscription: Unknown subscription type ${header.subscriptionType}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Internal Server Error", "detail": "Unknown subscription type
|
||||
${exchangeProperty.subscriptionType}", "reason": "${exception.message}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>500</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>javax.ws.rs.ForbiddenException</exception>
|
||||
<log message="Subscription: No permission to subscribe to topic ${header.topicName} for system ${header.X-SystemName}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Forbidden", "detail": "No permission to subscribe for system
|
||||
${header.X-SystemUuid}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>403</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>java.lang.Exception</exception>
|
||||
<log message="Subscription: Unknown exception ${exception.stacktrace}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Internal Server Error", "detail": "Unknown exception", "reason":
|
||||
"${exception.message}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>500</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
</when>
|
||||
<otherwise>
|
||||
<log message="Subscription: Bad request" loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Incorrect input parameters", "detail": "Cannot parse incoming JSON or system
|
||||
not defined" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>400</constant>
|
||||
</setHeader>
|
||||
</otherwise>
|
||||
</choice>
|
||||
</route>
|
||||
|
||||
<route id="checkExistingSubscription">
|
||||
<from uri="direct:checkExistingSubscription"/>
|
||||
<bean ref="topicProcessor"
|
||||
method="getExistingSubscription(${header.X-SystemUuid}, ${exchangeProperty.topicName})"/>
|
||||
|
||||
<setProperty name="ALREADY_EXIST">
|
||||
<simple resultType="java.lang.Boolean">false</simple>
|
||||
</setProperty>
|
||||
<when>
|
||||
<simple>${body} != null && ${exchangeProperty.subscriptionType} != null</simple>
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${body.getType().equalsName(${exchangeProperty.subscriptionType})} == false</simple>
|
||||
<to uri="direct-vm:deleteSubscriberConsumer"/>
|
||||
</when>
|
||||
<otherwise>
|
||||
<setProperty name="ALREADY_EXIST">
|
||||
<simple resultType="java.lang.Boolean">true</simple>
|
||||
</setProperty>
|
||||
</otherwise>
|
||||
</choice>
|
||||
</when>
|
||||
|
||||
<when>
|
||||
<simple>${body} != null</simple>
|
||||
<setProperty name="DELETED">
|
||||
<simple resultType="java.lang.Boolean">${body.deleted}</simple>
|
||||
</setProperty>
|
||||
</when>
|
||||
</route>
|
||||
|
||||
<route id="publishing">
|
||||
<from uri="direct:publish"/>
|
||||
<log message="Received - publish: ${body}" loggingLevel="TRACE"/>
|
||||
<!-- JSON -->
|
||||
<!-- { "topicName": "boomNews", "message": "messageText" } -->
|
||||
|
||||
<doTry>
|
||||
<setProperty name="topicName">
|
||||
<jsonpath>$.topicName</jsonpath>
|
||||
</setProperty>
|
||||
<setProperty name="message">
|
||||
<jsonpath>$.message</jsonpath>
|
||||
</setProperty>
|
||||
<doCatch>
|
||||
<exception>org.apache.camel.ExpressionEvaluationException</exception>
|
||||
<log message="Publishing: Body is not JSON" loggingLevel="ERROR"/>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
<choice>
|
||||
<when>
|
||||
<simple>${exchangeProperty.topicName} != null && ${exchangeProperty.topicName} != ""
|
||||
&& ${exchangeProperty.message} != null && ${exchangeProperty.message} != ""
|
||||
&& ${header.X-SystemUuid} != null && ${header.X-SystemUuid} != ""
|
||||
</simple>
|
||||
|
||||
<doTry>
|
||||
<log
|
||||
message="Publishing: ${exchangeProperty.topicName} message ${exchangeProperty.message}"
|
||||
loggingLevel="DEBUG"/>
|
||||
|
||||
<bean ref="topicProcessor" method="getActualTopic(${header.topicName})"/>
|
||||
|
||||
<toD uri="permission:checkException?objectId=${body.getId()}&objectType=event-topic&subjectId=${header.X-SystemId}&subjectType=system&action=publish"/>
|
||||
|
||||
<setHeader name="ENTAXY_Source">
|
||||
<simple>${header.X-SystemName}</simple>
|
||||
</setHeader>
|
||||
<setHeader name="ENTAXY_SourceType">
|
||||
<constant>system.name</constant>
|
||||
</setHeader>
|
||||
|
||||
<setBody>
|
||||
<simple>${exchangeProperty.message}</simple>
|
||||
</setBody>
|
||||
<toD uri="jms:topic:${exchangeProperty.topicName}?exchangePattern=InOnly"/>
|
||||
|
||||
<bean
|
||||
beanType="ru.entaxy.esb.system.core.events.rest.response.JsonSuccessResponse"
|
||||
method="getInstance('Message published', ${exchangeProperty.topicName})"/>
|
||||
|
||||
<marshal>
|
||||
<json library="Gson"/>
|
||||
</marshal>
|
||||
<!-- <setBody> -->
|
||||
<!-- <simple>{ "title": "Message published", "topicName": "${exchangeProperty.topicName}" }</simple> -->
|
||||
<!-- </setBody> -->
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>200</constant>
|
||||
</setHeader>
|
||||
|
||||
<doCatch>
|
||||
<exception>ru.entaxy.esb.system.core.events.rest.exception.TopicNotFound</exception>
|
||||
<setBody>
|
||||
<simple>{ "title": "Topic not registered", "topicName": "${exchangeProperty.topicName}"
|
||||
}
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>400</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>java.lang.IllegalAccessException</exception>
|
||||
<log message="Subscription: No permission to publish to topic ${header.topicName} for system ${header.X-SystemName}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Forbidden", "detail": "No permission to publishing" }</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>403</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
<doCatch>
|
||||
<exception>java.lang.Exception</exception>
|
||||
<log message="Subscription: Unknown exception ${exception.stacktrace}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Internal Server Error", "detail": "Unknown exception", "reason":
|
||||
"${exception.message}" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>500</constant>
|
||||
</setHeader>
|
||||
</doCatch>
|
||||
</doTry>
|
||||
|
||||
</when>
|
||||
<otherwise>
|
||||
<log message="Publishing: Bad request ${body}"
|
||||
loggingLevel="ERROR"/>
|
||||
<setBody>
|
||||
<simple>{ "title": "Incorrect input parameters", "detail": "Cannot parse incoming JSON or system
|
||||
not defined" }
|
||||
</simple>
|
||||
</setBody>
|
||||
<setHeader name="Exchange.HTTP_RESPONSE_CODE">
|
||||
<constant>400</constant>
|
||||
</setHeader>
|
||||
</otherwise>
|
||||
</choice>
|
||||
</route>
|
||||
|
||||
</camelContext>
|
||||
|
||||
</blueprint>
|
Reference in New Issue
Block a user