use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.
the class ORecordSerializerBinaryDebug method deserializeDebug.
public ORecordSerializationDebug deserializeDebug(final byte[] iSource, ODatabaseDocumentInternal db) {
ORecordSerializationDebug debugInfo = new ORecordSerializationDebug();
OImmutableSchema schema = ((OMetadataInternal) db.getMetadata()).getImmutableSchemaSnapshot();
BytesContainer bytes = new BytesContainer(iSource);
if (bytes.bytes[0] != 0)
throw new OSystemException("Unsupported binary serialization version");
bytes.skip(1);
try {
final String className = readString(bytes);
debugInfo.className = className;
} catch (RuntimeException ex) {
debugInfo.readingFailure = true;
debugInfo.readingException = ex;
debugInfo.failPosition = bytes.offset;
return debugInfo;
}
debugInfo.properties = new ArrayList<ORecordSerializationDebugProperty>();
int last = 0;
String fieldName;
int valuePos;
OType type;
while (true) {
ORecordSerializationDebugProperty debugProperty = new ORecordSerializationDebugProperty();
OGlobalProperty prop = null;
try {
final int len = OVarIntSerializer.readAsInteger(bytes);
if (len != 0)
debugInfo.properties.add(debugProperty);
if (len == 0) {
// SCAN COMPLETED
break;
} else if (len > 0) {
// PARSE FIELD NAME
fieldName = stringFromBytes(bytes.bytes, bytes.offset, len).intern();
bytes.skip(len);
valuePos = readInteger(bytes);
type = readOType(bytes);
} else {
// LOAD GLOBAL PROPERTY BY ID
final int id = (len * -1) - 1;
debugProperty.globalId = id;
prop = schema.getGlobalPropertyById(id);
valuePos = readInteger(bytes);
debugProperty.valuePos = valuePos;
if (prop != null) {
fieldName = prop.getName();
if (prop.getType() != OType.ANY)
type = prop.getType();
else
type = readOType(bytes);
} else {
continue;
}
}
debugProperty.name = fieldName;
debugProperty.type = type;
if (valuePos != 0) {
int headerCursor = bytes.offset;
bytes.offset = valuePos;
try {
debugProperty.value = deserializeValue(bytes, type, new ODocument());
} catch (RuntimeException ex) {
debugProperty.faildToRead = true;
debugProperty.readingException = ex;
debugProperty.failPosition = bytes.offset;
}
if (bytes.offset > last)
last = bytes.offset;
bytes.offset = headerCursor;
} else
debugProperty.value = null;
} catch (RuntimeException ex) {
debugInfo.readingFailure = true;
debugInfo.readingException = ex;
debugInfo.failPosition = bytes.offset;
return debugInfo;
}
}
return debugInfo;
}
use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.
the class ORecordFactoryManager method declareRecordType.
public void declareRecordType(byte iByte, String iName, Class<? extends ORecord> iClass, final ORecordFactory iFactory) {
if (recordTypes[iByte] != null)
throw new OSystemException("Record type byte '" + iByte + "' already in use : " + recordTypes[iByte].getName());
recordTypeNames[iByte] = iName;
recordTypes[iByte] = iClass;
recordFactories[iByte] = iFactory;
}
use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.
the class OChannelBinaryAsynchClient method createException.
@SuppressWarnings("unchecked")
private static RuntimeException createException(final String iClassName, final String iMessage, final Exception iPrevious) {
RuntimeException rootException = null;
Constructor<?> c = null;
try {
final Class<RuntimeException> excClass = (Class<RuntimeException>) Class.forName(iClassName);
if (iPrevious != null) {
try {
c = excClass.getConstructor(String.class, Throwable.class);
} catch (NoSuchMethodException e) {
c = excClass.getConstructor(String.class, Exception.class);
}
}
if (c == null)
c = excClass.getConstructor(String.class);
} catch (Exception e) {
// UNABLE TO REPRODUCE THE SAME SERVER-SIDE EXCEPTION: THROW AN SYSTEM EXCEPTION
rootException = OException.wrapException(new OSystemException(iMessage), iPrevious);
}
if (c != null)
try {
final Exception cause;
if (c.getParameterTypes().length > 1)
cause = (Exception) c.newInstance(iMessage, iPrevious);
else
cause = (Exception) c.newInstance(iMessage);
rootException = OException.wrapException(new OSystemException("Data processing exception"), cause);
} catch (InstantiationException ignored) {
} catch (IllegalAccessException ignored) {
} catch (InvocationTargetException ignored) {
}
return rootException;
}
use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.
the class OTokenHandlerImpl method getSignedWebToken.
public byte[] getSignedWebToken(final ODatabaseDocument db, final OSecurityUser user) {
final ByteArrayOutputStream tokenByteOS = new ByteArrayOutputStream(1024);
final OrientJwtHeader header = new OrientJwtHeader();
header.setAlgorithm("HS256");
header.setKeyId("");
final OJwtPayload payload = createPayload(db, user);
header.setType(getPayloadType(payload));
try {
byte[] bytes = serializeWebHeader(header);
tokenByteOS.write(OBase64Utils.encodeBytesToBytes(bytes, 0, bytes.length, OBase64Utils.URL_SAFE));
tokenByteOS.write(JWT_DELIMITER);
bytes = serializeWebPayload(payload);
tokenByteOS.write(OBase64Utils.encodeBytesToBytes(bytes, 0, bytes.length, OBase64Utils.URL_SAFE));
byte[] unsignedToken = tokenByteOS.toByteArray();
tokenByteOS.write(JWT_DELIMITER);
bytes = signToken(header, unsignedToken);
tokenByteOS.write(OBase64Utils.encodeBytesToBytes(bytes, 0, bytes.length, OBase64Utils.URL_SAFE));
} catch (Exception ex) {
throw OException.wrapException(new OSystemException("Error on token parsing"), ex);
}
return tokenByteOS.toByteArray();
}
use of com.orientechnologies.common.exception.OSystemException in project orientdb by orientechnologies.
the class OTokenHandlerImpl method verifyTokenSignature.
private boolean verifyTokenSignature(final OJwtHeader header, final byte[] base, final int baseOffset, final int baseLength, final byte[] signature) {
final Mac mac = threadLocalMac.get();
try {
mac.init(getKeyProvider().getKey(header));
mac.update(base, baseOffset, baseLength);
final byte[] calculatedSignature = mac.doFinal();
boolean valid = MessageDigest.isEqual(calculatedSignature, signature);
if (!valid) {
OLogManager.instance().warn(this, "Token signature failure: %s", OBase64Utils.encodeBytes(base));
}
return valid;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw OException.wrapException(new OSystemException("Token signature cannot be verified"), e);
} finally {
mac.reset();
}
}
Aggregations