use of ee.ria.xroad.proxy.util.MessageProcessorBase in project X-Road by nordic-institute.
the class MetadataHandlerTest method shouldReturnProcessorWhenAbleToProcess.
@Test
public void shouldReturnProcessorWhenAbleToProcess() throws Exception {
when(mockRequest.getMethod()).thenReturn("GET");
MetadataHandler handlerToTest = new MetadataHandler(httpClientMock);
MessageProcessorBase result = handlerToTest.createRequestProcessor(LIST_CLIENTS, mockRequest, mockResponse, null);
assertNotNull("Was expecting actual message processor");
assertThat("Message processor is of wrong type", result, instanceOf(MetadataClientRequestProcessor.class));
}
use of ee.ria.xroad.proxy.util.MessageProcessorBase in project X-Road by nordic-institute.
the class ServerProxyHandler method handle.
@Override
public void handle(String target, Request baseRequest, final HttpServletRequest request, final HttpServletResponse response) throws IOException, ServletException {
OpMonitoringData opMonitoringData = new OpMonitoringData(PRODUCER, getEpochMillisecond());
long start = PerformanceLogger.log(log, "Received request from " + request.getRemoteAddr());
if (!SystemProperties.isServerProxySupportClientsPooledConnections()) {
// if the header is added, the connections are closed and cannot be reused on the client side
response.addHeader("Connection", "close");
}
try {
if (!request.getMethod().equalsIgnoreCase("POST")) {
throw new CodedException(X_INVALID_HTTP_METHOD, "Must use POST request method instead of %s", request.getMethod());
}
GlobalConf.verifyValidity();
logProxyVersion(request);
baseRequest.getHttpChannel().setIdleTimeout(idleTimeout);
final MessageProcessorBase processor = createRequestProcessor(request, response, opMonitoringData);
processor.process();
final MessageInfo messageInfo = processor.createRequestMessageInfo();
if (processor.verifyMessageExchangeSucceeded()) {
MonitorAgent.success(messageInfo, new Date(start), new Date());
} else {
MonitorAgent.failure(messageInfo, null, null);
}
} catch (Throwable e) {
// We want to catch serious errors as well
CodedException cex = translateWithPrefix(SERVER_SERVERPROXY_X, e);
log.error("Request processing error ({})", cex.getFaultDetail(), e);
opMonitoringData.setFaultCodeAndString(cex);
opMonitoringData.setResponseOutTs(getEpochMillisecond(), false);
failure(request, response, cex);
} finally {
baseRequest.setHandled(true);
opMonitoringData.setResponseOutTs(getEpochMillisecond(), false);
OpMonitoring.store(opMonitoringData);
PerformanceLogger.log(log, start, "Request handled");
}
}
use of ee.ria.xroad.proxy.util.MessageProcessorBase in project X-Road by nordic-institute.
the class AbstractClientProxyHandler method handle.
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
if (baseRequest.isHandled()) {
// If some handler already processed the request, we do nothing.
return;
}
boolean handled = false;
long start = logPerformanceBegin(request);
OpMonitoringData opMonitoringData = storeOpMonitoringData ? new OpMonitoringData(CLIENT, start) : null;
MessageProcessorBase processor = null;
try {
processor = createRequestProcessor(target, request, response, opMonitoringData);
if (processor != null) {
baseRequest.getHttpChannel().setIdleTimeout(idleTimeout);
handled = true;
processor.process();
success(processor, start, opMonitoringData);
if (log.isTraceEnabled()) {
log.info("Request successfully handled ({} ms)", System.currentTimeMillis() - start);
} else {
log.info("Request successfully handled");
}
}
} catch (CodedException.Fault | ClientException e) {
handled = true;
String errorMessage = e instanceof ClientException ? "Request processing error (" + e.getFaultDetail() + ")" : "Request processing error";
log.error(errorMessage, e);
updateOpMonitoringSoapFault(opMonitoringData, e);
// Exceptions caused by incoming message and exceptions derived from faults sent by serverproxy already
// contain full error code. Thus, we must not attach additional error code prefixes to them.
failure(processor, request, response, e, opMonitoringData);
} catch (CodedExceptionWithHttpStatus e) {
handled = true;
// No need to log faultDetail hence not sent to client.
log.error("Request processing error", e);
// Respond with HTTP status code and plain text error message instead of SOAP fault message.
// No need to update operational monitoring fields here either.
failure(response, e, opMonitoringData);
} catch (Throwable e) {
// We want to catch serious errors as well
handled = true;
// All the other exceptions get prefix Server.ClientProxy...
CodedException cex = translateWithPrefix(SERVER_CLIENTPROXY_X, e);
log.error("Request processing error ({})", cex.getFaultDetail(), e);
updateOpMonitoringSoapFault(opMonitoringData, cex);
failure(processor, request, response, cex, opMonitoringData);
} finally {
baseRequest.setHandled(handled);
if (handled) {
if (storeOpMonitoringData) {
updateOpMonitoringResponseOutTs(opMonitoringData);
OpMonitoring.store(opMonitoringData);
}
logPerformanceEnd(start);
}
}
}
use of ee.ria.xroad.proxy.util.MessageProcessorBase in project X-Road by nordic-institute.
the class MetadataHandlerTest method shouldNotCreateProcessorForUnprocessableRequest.
@Test
public void shouldNotCreateProcessorForUnprocessableRequest() throws Exception {
when(mockRequest.getMethod()).thenReturn("GET");
MetadataHandler handlerToTest = new MetadataHandler(httpClientMock);
MessageProcessorBase returnValue = handlerToTest.createRequestProcessor("something", mockRequest, mockResponse, null);
assertNull("Was expecting a null return value", returnValue);
}
use of ee.ria.xroad.proxy.util.MessageProcessorBase in project X-Road by nordic-institute.
the class MetadataHandlerTest method shouldNotCreateProcessorForPostRequest.
@Test
public void shouldNotCreateProcessorForPostRequest() throws Exception {
when(mockRequest.getMethod()).thenReturn("POST");
MetadataHandler handlerToTest = new MetadataHandler(httpClientMock);
MessageProcessorBase returnValue = handlerToTest.createRequestProcessor("something", mockRequest, mockResponse, null);
assertNull("Was expecting a null return value", returnValue);
}
Aggregations