use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.
the class RegistrationInterceptor method handleRequest.
@Override
public Outcome handleRequest(Exchange exc) throws Exception {
Request request = exc.getRequest();
if (!request.isPOSTRequest())
return ErrorMessages.returnErrorBadRequest(exc);
User user;
try {
user = new ObjectMapper().readValue(request.getBodyAsStringDecoded(), User.class);
} catch (IOException e) {
return ErrorMessages.returnErrorBadRequest(exc);
}
try (Connection connection = userDataProvider.getDatasource().getConnection()) {
try (ResultSet rs = connection.createStatement().executeQuery(getIsAccountNameAvailableSQL(user))) {
if (rs.next() && rs.getInt(1) != 0)
return ErrorMessages.returnErrorUserAlreadyExists(exc);
}
if (!SecurityUtils.isHashedPassword(user.getPassword()))
user.setPassword(SecurityUtils.createPasswdCompatibleHash(user.getPassword()));
connection.createStatement().executeUpdate(getInsertAccountIntoDatabaseSQL(user));
}
// TODO: Save user mit flag if confirmated
// TODO: Send Confirmation Email
// TODO: PreparedStatements gegen SQL-Injection verwenden??????
exc.setResponse(Response.ok().build());
return Outcome.RETURN;
}
use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.
the class ClusterBalancerTest method getExchangeWithOutSession.
private Exchange getExchangeWithOutSession() throws IOException {
Exchange exc = new Exchange(null);
Request res = new Request();
res.setHeader(getHeader());
res.setBodyContent(getByteArrayData(getClass().getResourceAsStream("/getBank.xml")));
exc.setRequest(res);
exc.setOriginalRequestUri("/axis2/services/BLZService");
return exc;
}
use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.
the class MessageAnalyserTest method getRequest.
private Exchange getRequest(String path) throws IOException {
Exchange exc = new Exchange(null);
Request req = new Request();
req.create("POST", "http://test", "HTTP/", new Header(), getClass().getClassLoader().getResourceAsStream(path));
exc.setRequest(req);
return exc;
}
use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.
the class WebSocketStompReassembler method convertToExchange.
private Exchange convertToExchange(WebSocketFrame wsStompFrame) throws IOException, EndOfStreamException {
byte[] realPayload = new byte[(int) wsStompFrame.getPayloadLength()];
System.arraycopy(wsStompFrame.getPayload(), 0, realPayload, 0, (int) wsStompFrame.getPayloadLength());
if (wsStompFrame.getPayloadLength() == 0)
throw new IOException("Empty STOMP frame.");
ByteArrayInputStream bais = new ByteArrayInputStream(wsStompFrame.getPayload(), 0, (int) wsStompFrame.getPayloadLength() - 1);
Request request = new Request();
if (isHeartBeat(wsStompFrame)) {
request.setMethod("");
request.setBody(new Body(bais));
} else {
if (wsStompFrame.getPayload()[(int) wsStompFrame.getPayloadLength() - 1] != 0)
throw new IOException("STOMP frame is not terminated by \\0.");
request.read(bais, true);
}
Exchange result = new Exchange(null);
result.setRequest(request);
if (wsStompFrame.getOriginalExchange() != null)
result.setProperty(Exchange.WS_ORIGINAL_EXCHANGE, wsStompFrame.getOriginalExchange());
return result;
}
use of com.predic8.membrane.core.http.xml.Request in project service-proxy by membrane.
the class LimitedMemoryExchangeStoreTest method getExchange.
private Exchange getExchange(String id) throws IOException {
Exchange exc = new Exchange(null);
exc.setProperty("id", id);
Request req = new Request();
req.create("GET", "http://test", "HTTP/", new Header(), null);
exc.setRequest(req);
exc.setResponse(Response.ok().body("<xml />").build());
return exc;
}
Aggregations