Search in sources :

Example 11 with Header

use of com.predic8.membrane.core.http.Header in project service-proxy by membrane.

the class REST2SOAPInterceptor method modifyRequest.

private void modifyRequest(AbstractExchange exc, Mapping mapping) {
    exc.getRequest().setMethod("POST");
    exc.getRequest().getHeader().setSOAPAction(mapping.soapAction);
    Header header = exc.getRequest().getHeader();
    header.removeFields(Header.CONTENT_TYPE);
    header.setContentType(isSOAP12(exc) ? MimeType.APPLICATION_SOAP : MimeType.TEXT_XML_UTF8);
    exc.setProperty("mapping", mapping);
    setServiceEndpoint(exc, mapping);
}
Also used : Header(com.predic8.membrane.core.http.Header)

Example 12 with Header

use of com.predic8.membrane.core.http.Header in project service-proxy by membrane.

the class DynamicRegistration method registerWithCallbackAt.

public Client registerWithCallbackAt(String callbackUri, String registrationEndpoint) throws Exception {
    Exchange exc = new Request.Builder().post(registrationEndpoint).header(Header.CONTENT_TYPE, MimeType.APPLICATION_JSON_UTF8).body(getRegistrationBody(callbackUri)).buildExchange();
    Response response = doRequest(exc);
    HashMap<String, String> json = Util.parseSimpleJSONResponse(response);
    if (!json.containsKey("client_id") || !json.containsKey("client_secret"))
        throw new RuntimeException("Registration endpoint didn't return clientId/clientSecret");
    return new Client(json.get("client_id"), json.get("client_secret"), "");
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Response(com.predic8.membrane.core.http.Response) Client(com.predic8.membrane.core.interceptor.oauth2.Client) HttpClient(com.predic8.membrane.core.transport.http.HttpClient)

Example 13 with Header

use of com.predic8.membrane.core.http.Header 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 Header

use of com.predic8.membrane.core.http.Header in project service-proxy by membrane.

the class RegExReplaceInterceptorTest method testReplaceBinary.

@Test
public void testReplaceBinary() throws Exception {
    String example = "Hello";
    RegExReplaceInterceptor regexp = new RegExReplaceInterceptor();
    regexp.setRegex(Pattern.quote(example));
    regexp.setReplace("Membrane");
    Exchange exc = new Request.Builder().body(example).header("Content-Type", "text/plain").buildExchange();
    regexp.handleRequest(exc);
    assertTrue(exc.getRequest().getBodyAsStringDecoded().equals("Membrane"));
    exc = new Request.Builder().body(example).header("Content-Type", "application/octet-stream").buildExchange();
    regexp.handleRequest(exc);
    assertTrue(exc.getRequest().getBodyAsStringDecoded().equals(example));
}
Also used : Exchange(com.predic8.membrane.core.exchange.Exchange) Request(com.predic8.membrane.core.http.Request) Test(org.junit.Test)

Example 15 with Header

use of com.predic8.membrane.core.http.Header 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

Exchange (com.predic8.membrane.core.exchange.Exchange)26 Header (com.predic8.membrane.core.http.Header)16 Request (com.predic8.membrane.core.http.Request)13 IOException (java.io.IOException)13 Response (com.predic8.membrane.core.http.Response)12 CacheBuilder (com.google.common.cache.CacheBuilder)8 Test (org.junit.Test)8 AbstractExchange (com.predic8.membrane.core.exchange.AbstractExchange)7 HttpClient (com.predic8.membrane.core.transport.http.HttpClient)6 UnknownHostException (java.net.UnknownHostException)6 MCElement (com.predic8.membrane.annot.MCElement)5 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)4 AbstractExchangeSnapshot (com.predic8.membrane.core.exchange.snapshots.AbstractExchangeSnapshot)4 DynamicAbstractExchangeSnapshot (com.predic8.membrane.core.exchange.snapshots.DynamicAbstractExchangeSnapshot)4 HeaderField (com.predic8.membrane.core.http.HeaderField)4 JsonFactory (com.fasterxml.jackson.core.JsonFactory)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Cache (com.google.common.cache.Cache)2