Skip to content

Commit

Permalink
XmlUtil improvements and cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Alberto Codutti <alberto.codutti@eurotech.com>
  • Loading branch information
Coduz committed Feb 26, 2021
1 parent 3ccaaa7 commit abe01b2
Show file tree
Hide file tree
Showing 11 changed files with 320 additions and 322 deletions.
Expand Up @@ -29,7 +29,6 @@
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import javax.xml.stream.XMLStreamException;
import java.io.FileReader;
import java.io.IOException;
import java.net.URL;
Expand Down Expand Up @@ -63,7 +62,7 @@ public CamelKapuaDefaultRouter() {
endPointContainer = XmlUtil.unmarshal(configurationFileReader, EndPointContainer.class);
LOG.info("Default Camel routing | Found {} parent endpoints in the route", endPointContainer.getEndPoints().size());
logLoadedEndPoints(endPointContainer.getEndPoints());
} catch (XMLStreamException | JAXBException | SAXException | IOException e) {
} catch (JAXBException | SAXException | IOException e) {
throw new KapuaRuntimeException(KapuaErrorCodes.INTERNAL_ERROR, e, "Cannot load configuration!");
}

Expand Down
Expand Up @@ -13,11 +13,7 @@
*******************************************************************************/
package org.eclipse.kapua.commons.configuration;

import javax.validation.constraints.NotNull;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;

import org.apache.commons.lang3.tuple.Triple;
import org.eclipse.kapua.KapuaEntityNotFoundException;
import org.eclipse.kapua.KapuaException;
import org.eclipse.kapua.commons.cache.LocalCache;
Expand All @@ -27,8 +23,8 @@
import org.eclipse.kapua.commons.security.KapuaSecurityUtils;
import org.eclipse.kapua.commons.service.internal.AbstractKapuaService;
import org.eclipse.kapua.commons.service.internal.KapuaServiceDisabledException;
import org.eclipse.kapua.commons.service.internal.cache.EntityCache;
import org.eclipse.kapua.commons.service.internal.ServiceDAO;
import org.eclipse.kapua.commons.service.internal.cache.EntityCache;
import org.eclipse.kapua.commons.setting.system.SystemSetting;
import org.eclipse.kapua.commons.setting.system.SystemSettingKey;
import org.eclipse.kapua.commons.util.ResourceUtils;
Expand All @@ -50,7 +46,11 @@
import org.eclipse.kapua.service.config.KapuaConfigurableService;
import org.eclipse.kapua.service.user.User;
import org.eclipse.kapua.service.user.UserService;
import org.xml.sax.SAXException;

import javax.validation.constraints.NotNull;
import javax.xml.bind.JAXBException;
import javax.xml.namespace.QName;
import java.io.IOException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
Expand All @@ -62,10 +62,6 @@
import java.util.Properties;
import java.util.stream.Collectors;

import org.apache.commons.lang3.tuple.Triple;

import org.xml.sax.SAXException;

/**
* Configurable service definition abstract reference implementation.
*/
Expand Down Expand Up @@ -114,7 +110,7 @@ protected AbstractKapuaConfigurableService(String pid, Domain domain, EntityMana
* @return the metadata
* @throws Exception In case of an error
*/
private static KapuaTmetadata readMetadata(String pid) throws JAXBException, SAXException, XMLStreamException, IOException {
private static KapuaTmetadata readMetadata(String pid) throws JAXBException, SAXException, IOException {
URL url = ResourceUtils.getResource(String.format("META-INF/metatypes/%s.xml", pid));

if (url == null) {
Expand Down Expand Up @@ -407,12 +403,12 @@ public void setConfigValues(KapuaId scopeId, KapuaId parentId, Map<String, Objec
boolean preventChange =
// if current user is not root user...
!KapuaSecurityUtils.getSession().getUserId().equals(rootUser.getId()) &&
// current configuration does not allow self edit...
!allowSelfEdit &&
// a configuration for the current logged account is about to be changed...
KapuaSecurityUtils.getSession().getScopeId().equals(scopeId) &&
// and the new value is different from the other one...
!originalValues.get(ad.getId()).equals(values.get(ad.getId()));
// current configuration does not allow self edit...
!allowSelfEdit &&
// a configuration for the current logged account is about to be changed...
KapuaSecurityUtils.getSession().getScopeId().equals(scopeId) &&
// and the new value is different from the other one...
!originalValues.get(ad.getId()).equals(values.get(ad.getId()));

if (preventChange) {
// ... prevent the change!
Expand Down
Expand Up @@ -19,14 +19,11 @@
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
* Xml event bus marshaller implementation
* Json {@link ServiceEventMarshaler} implementation.
*
* @since 1.0
* @since 1.0.0
*/
public class JsonServiceEventMarshaler implements ServiceEventMarshaler {

Expand All @@ -41,7 +38,7 @@ public String getContentType() {
public ServiceEvent unmarshal(String message) throws KapuaException {
try {
return XmlUtil.unmarshalJson(message, ServiceEvent.class, null);
} catch (JAXBException | XMLStreamException | FactoryConfigurationError | SAXException e) {
} catch (JAXBException | SAXException e) {
throw new ServiceEventBusException(e);
}
}
Expand All @@ -50,9 +47,8 @@ public ServiceEvent unmarshal(String message) throws KapuaException {
public String marshal(ServiceEvent kapuaEvent) throws ServiceEventBusException {
try {
return XmlUtil.marshalJson(kapuaEvent);
} catch (JAXBException | IOException e) {
} catch (JAXBException e) {
throw new ServiceEventBusException(e);
}
}

}
Expand Up @@ -19,14 +19,11 @@
import org.xml.sax.SAXException;

import javax.xml.bind.JAXBException;
import javax.xml.stream.FactoryConfigurationError;
import javax.xml.stream.XMLStreamException;
import java.io.IOException;

/**
* Xml event bus marshaller implementation
* XML {@link ServiceEventMarshaler} implementation.
*
* @since 1.0
* @since 1.0.0
*/
public class XmlServiceEventMarshaler implements ServiceEventMarshaler {

Expand All @@ -41,7 +38,7 @@ public String getContentType() {
public ServiceEvent unmarshal(String message) throws KapuaException {
try {
return XmlUtil.unmarshal(message, ServiceEvent.class);
} catch (JAXBException | XMLStreamException | FactoryConfigurationError | SAXException e) {
} catch (JAXBException | SAXException e) {
throw new ServiceEventBusException(e);
}
}
Expand All @@ -50,7 +47,7 @@ public ServiceEvent unmarshal(String message) throws KapuaException {
public String marshal(ServiceEvent kapuaEvent) throws ServiceEventBusException {
try {
return XmlUtil.marshal(kapuaEvent);
} catch (JAXBException | IOException e) {
} catch (JAXBException e) {
throw new ServiceEventBusException(e);
}
}
Expand Down

0 comments on commit abe01b2

Please sign in to comment.