throw correct exception if target address violates rfc standard

Signed-off-by: Michael Hirsch <michael.hirsch@bosch-si.com>
This commit is contained in:
Michael Hirsch
2016-06-21 16:36:01 +02:00
parent 2e23ed3871
commit bf1ca010c7
4 changed files with 83 additions and 55 deletions

View File

@@ -0,0 +1,42 @@
/**
* Copyright (c) 2015 Bosch Software Innovations GmbH and others.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*/
package org.eclipse.hawkbit.repository.exception;
import org.eclipse.hawkbit.exception.SpServerError;
import org.eclipse.hawkbit.exception.SpServerRtException;
/**
* Exception which is thrown when trying to set an invalid target address.
*/
public class InvalidTargetAddressException extends SpServerRtException {
/**
*
*/
private static final long serialVersionUID = 1L;
/**
* @param message
* the message for this exception
*/
public InvalidTargetAddressException(final String message) {
super(message, SpServerError.SP_REPO_INVALID_TARGET_ADDRESS);
}
/**
*
* @param message
* the message for this exception
* @param cause
* the cause for this exception
*/
public InvalidTargetAddressException(final String message, final Throwable cause) {
super(message, SpServerError.SP_REPO_INVALID_TARGET_ADDRESS, cause);
}
}

View File

@@ -37,6 +37,7 @@ import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import org.eclipse.hawkbit.repository.exception.InvalidTargetAddressException;
import org.eclipse.hawkbit.repository.jpa.model.helper.SystemSecurityContextHolder;
import org.eclipse.hawkbit.repository.jpa.model.helper.TenantConfigurationManagementHolder;
import org.eclipse.hawkbit.repository.model.DistributionSet;
@@ -173,10 +174,16 @@ public class JpaTargetInfo implements Persistable<Long>, TargetInfo {
* @throws IllegalArgumentException
* If the given string violates RFC&nbsp;2396
*/
@Override
public void setAddress(final String address) {
// check if this is a real URI
if (address != null) {
URI.create(address);
try {
URI.create(address);
} catch (final IllegalArgumentException e) {
throw new InvalidTargetAddressException(
"The given address " + address + " violates the RFC-2396 specification", e);
}
}
this.address = address;