Search in sources :

Example 11 with Request

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;
}
Also used : User(com.predic8.membrane.core.interceptor.registration.entity.User) Request(com.predic8.membrane.core.http.Request) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 12 with Request

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;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange)

Example 13 with Request

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;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Header(com.predic8.membrane.core.http.Header) Request(com.predic8.membrane.core.http.Request)

Example 14 with Request

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;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) ByteArrayInputStream(java.io.ByteArrayInputStream) Request(com.predic8.membrane.core.http.Request) IOException(java.io.IOException) Body(com.predic8.membrane.core.http.Body)

Example 15 with Request

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;
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Header(com.predic8.membrane.core.http.Header) Request(com.predic8.membrane.core.http.Request)

Aggregations

Request (com.predic8.membrane.core.http.Request)39 Exchange (com.predic8.membrane.core.exchange.Exchange)20 Test (org.junit.Test)12 IOException (java.io.IOException)11 Header (com.predic8.membrane.core.http.Header)8 Response (com.predic8.membrane.core.http.Response)8 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)5 Message (com.predic8.membrane.core.http.Message)5 Outcome (com.predic8.membrane.core.interceptor.Outcome)5 Body (com.predic8.membrane.core.http.Body)3 Request (com.predic8.membrane.core.http.xml.Request)3 EndOfStreamException (com.predic8.membrane.core.util.EndOfStreamException)3 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)2 CacheBuilder (com.google.common.cache.CacheBuilder)2 HeaderField (com.predic8.membrane.core.http.HeaderField)2 ResponseBuilder (com.predic8.membrane.core.http.Response.ResponseBuilder)2 ResolverMap (com.predic8.membrane.core.resolver.ResolverMap)2 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)2 StringReader (java.io.StringReader)2 SocketException (java.net.SocketException)2