use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class TypeMappers method converterFor.
public NeoValueConverter converterFor(Type javaType) throws ProcedureException {
NeoValueConverter converter = javaToNeo.get(javaType);
if (converter != null) {
return converter;
}
if (javaType instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) javaType;
Type rawType = pt.getRawType();
if (rawType == List.class) {
Type type = pt.getActualTypeArguments()[0];
return toList(converterFor(type), type);
} else if (rawType == Map.class) {
Type type = pt.getActualTypeArguments()[0];
if (type != String.class) {
throw new ProcedureException(Status.Procedure.ProcedureRegistrationFailed, "Maps are required to have `String` keys - but this map has `%s` keys.", type.getTypeName());
}
return TO_MAP;
}
}
throw javaToNeoMappingError(javaType);
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeModeFunction.
@Test
public void shouldFailNicelyWhenUnsafeAPISafeModeFunction() throws Throwable {
//When
List<CallableUserFunction> procList = compiler.compileFunction(FunctionWithUnsafeAPI.class);
verify(log).warn("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration.");
assertThat(procList.size(), equalTo(1));
try {
procList.get(0).apply(new BasicContext(), new Object[0]);
fail();
} catch (ProcedureException e) {
assertThat(e.getMessage(), containsString("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration."));
}
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ResourceInjectionTest method shouldFailNicelyWhenUnsafeAPISafeMode.
@Test
public void shouldFailNicelyWhenUnsafeAPISafeMode() throws Throwable {
//When
List<CallableProcedure> procList = compiler.compileProcedure(ProcedureWithUnsafeAPI.class, Optional.empty(), false);
verify(log).warn("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration.");
assertThat(procList.size(), equalTo(1));
try {
procList.get(0).apply(new BasicContext(), new Object[0]);
fail();
} catch (ProcedureException e) {
assertThat(e.getMessage(), containsString("org.neo4j.kernel.impl.proc.listCoolPeople is not " + "available due to having restricted access rights, check configuration."));
}
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class UserFunctionsTest method shouldMakeContextAvailable.
@Test
public void shouldMakeContextAvailable() throws Throwable {
// Given
Key<String> someKey = key("someKey", String.class);
procs.register(new CallableUserFunction.BasicUserFunction(signature) {
@Override
public Object apply(Context ctx, Object[] input) throws ProcedureException {
return ctx.get(someKey);
}
});
BasicContext ctx = new BasicContext();
ctx.put(someKey, "hello, world");
// When
Object result = procs.callFunction(ctx, signature.name(), new Object[0]);
// Then
assertThat(result, equalTo("hello, world"));
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ReflectiveProcedureTest method shouldLoadWhiteListedProcedure.
@Test
public void shouldLoadWhiteListedProcedure() throws Throwable {
// Given
ProcedureConfig config = new ProcedureConfig(Config.defaults().with(genericMap(procedure_whitelist.name(), "org.neo4j.kernel.impl.proc.listCoolPeople")));
Log log = mock(Log.class);
ReflectiveProcedureCompiler procedureCompiler = new ReflectiveProcedureCompiler(new TypeMappers(), components, components, log, config);
// When
CallableProcedure proc = procedureCompiler.compileProcedure(SingleReadOnlyProcedure.class, Optional.empty(), false).get(0);
// When
RawIterator<Object[], ProcedureException> result = proc.apply(new BasicContext(), new Object[0]);
// Then
assertEquals(result.next()[0], "Bonnie");
}
Aggregations