use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class DefaultInstallersProvider method setManualProxy.
/**
* Sets the proxy manually
*
* @param installer the installer that requires configuration
*/
private void setManualProxy(final HttpSwordInstaller installer) {
// set the host
if (isNotBlank(this.proxyHost)) {
installer.setProxyHost(this.proxyHost);
}
// set the port
if (isNotBlank(this.proxyPort)) {
try {
final Integer p = Integer.parseInt(this.proxyPort);
installer.setProxyPort(p.intValue());
} catch (final NumberFormatException e) {
throw new StepInternalException("Unable to parse port number " + this.proxyPort, e);
}
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class ImageController method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse response) throws ServletException, IOException {
try {
final String pathToImage = req.getRequestURI().substring(req.getContextPath().length() + req.getServletPath().length());
final File image = new File(this.localSource, pathToImage);
if (!image.exists()) {
// fetch from web and write out
download(image, pathToImage, response);
return;
}
LOGGER.trace("Returning image locally stored at: ", image.getAbsolutePath());
writeImage(image, response);
} catch (final StepInternalException ex) {
LOGGER.warn("An exception has occurred - image cannot be sent back", ex);
}
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class FrontController method getControllerMethod.
/**
* Returns the method to be invoked upon the controller
*
* @param methodName the method name
* @param controllerInstance the instance of the controller
* @param args the list of arguments, required to resolve the correct method if they have arguments
* @param cacheKey the key to retrieve in the cache
* @return the method to be invoked
*/
Method getControllerMethod(final String methodName, final Object controllerInstance, final Object[] args, final String cacheKey) {
final Class<?> controllerClass = controllerInstance.getClass();
// retrieve method from cache, or put in cache if not there
Method controllerMethod = this.methodNames.get(cacheKey);
if (controllerMethod == null) {
try {
final Class<?>[] classes = getClasses(args);
controllerMethod = controllerClass.getMethod(methodName, classes);
// put method in cache
this.methodNames.put(cacheKey, controllerMethod);
} catch (final NoSuchMethodException e) {
throw new StepInternalException("Unable to find matching method for " + methodName, e);
}
}
return controllerMethod;
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class FrontControllerTest method testDoGetHasException.
/**
* tests what happens when doGet catches an exception
*/
@Test
public void testDoGetHasException() {
final HttpServletRequest request = mock(HttpServletRequest.class);
final HttpServletResponse response = mock(HttpServletResponse.class);
final StepInternalException testException = new StepInternalException("A test exception");
final FrontController fc = spy(this.fcUnderTest);
final StepRequest parsedRequest = new StepRequest("blah", "SomeController", "someMethod", new String[] { "arg1", "arg2" });
// TODO remove this/
doNothing().when(fc).handleError(response, testException, mock(HttpServletRequest.class));
// do the test
fc.doGet(request, response);
}
use of com.tyndalehouse.step.core.exceptions.StepInternalException in project step by STEPBible.
the class RequestUtils method validateSession.
/**
* validates a session
*
* @param sessionProvider provides the client session
*/
public static void validateSession(final Provider<ClientSession> sessionProvider) {
LOGGER.warn("Attempting to validate session from external call");
try {
final ClientSession clientSession = sessionProvider.get();
final String requiredPassword = System.getProperty("step.setup.password");
if (StringUtils.isNotBlank(requiredPassword)) {
// check request has this parameter
if (!requiredPassword.equals(clientSession.getParam("step.setup.password"))) {
LOGGER.warn("DENYING ACCESS");
throw new StepInternalException("This functionality is not available");
}
}
final String ipAddress = clientSession.getIpAddress();
final InetAddress addr = InetAddress.getByName(ipAddress);
// Check if the address is a valid special local or loop back
if (addr.isAnyLocalAddress() || addr.isLoopbackAddress()) {
return;
}
// Check if the address is defined on any interface
try {
if (NetworkInterface.getByInetAddress(addr) != null) {
return;
}
} catch (final SocketException e) {
LOGGER.warn("Socket error: ", e);
}
LOGGER.warn("DENYING ACCESS TO IP ADDRESS [{}]", ipAddress);
throw new StepInternalException("This functionality is not available");
} catch (final UnknownHostException e) {
throw new StepInternalException("Failed to initialise ip addresses", e);
}
}
Aggregations