use of com.predic8.membrane.core.http.Message in project service-proxy by membrane.
the class HeaderFilterInterceptor method handleMessage.
private void handleMessage(Message msg) {
if (msg == null)
return;
Header h = msg.getHeader();
if (h == null)
return;
for (HeaderField hf : h.getAllHeaderFields()) for (Rule r : rules) if (r.matches(hf.getHeaderName().toString())) {
switch(r.getAction()) {
case REMOVE:
log.debug("Removing HTTP header " + hf.getHeaderName().toString());
h.remove(hf);
break;
case KEEP:
break;
}
break;
}
}
use of com.predic8.membrane.core.http.Message in project service-proxy by membrane.
the class LimitInterceptor method handleMessage.
private Outcome handleMessage(Exchange exc, Message msg) throws IOException {
if (maxBodyLength == -1)
return Outcome.CONTINUE;
long len = msg.getHeader().getContentLength();
if (len != -1 && len > maxBodyLength) {
log.info("Message length (" + len + ") exceeded limit (" + maxBodyLength + ")");
exc.setResponse(createFailureResponse());
return Outcome.ABORT;
}
msg.setBody(new Body(new LengthLimitingStream(msg.getBodyAsStream())));
return Outcome.CONTINUE;
}
use of com.predic8.membrane.core.http.Message in project service-proxy by membrane.
the class LimitedMemoryExchangeStore method addObservers.
private void addObservers(AbstractExchange exc, AbstractExchange excCopy, Flow flow) throws Exception {
Message msg = null;
if (flow == Flow.REQUEST) {
msg = exc.getRequest();
} else
msg = exc.getResponse();
msg.addObserver(new MessageObserver() {
@Override
public void bodyRequested(AbstractBody body) {
}
@Override
public void bodyComplete(AbstractBody body) {
try {
cleanSnapshot(Exchange.updateCopy(exc, excCopy));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
});
exc.addExchangeViewerListener(new AbstractExchangeViewerListener() {
@Override
public void setExchangeFinished() {
try {
cleanSnapshot(Exchange.updateCopy(exc, excCopy));
} catch (Exception e) {
e.printStackTrace();
}
}
});
cleanSnapshot(Exchange.updateCopy(exc, excCopy));
}
use of com.predic8.membrane.core.http.Message in project service-proxy by membrane.
the class HttpUtil method setHTMLErrorResponse.
public static Response setHTMLErrorResponse(ResponseBuilder responseBuilder, String message, String comment) {
Response response = responseBuilder.build();
response.setHeader(createHeaders(MimeType.TEXT_HTML_UTF8));
response.setBodyContent(getHTMLErrorBody(message, comment).getBytes(Constants.UTF_8_CHARSET));
return response;
}
use of com.predic8.membrane.core.http.Message in project service-proxy by membrane.
the class TelekomSMSTokenProvider method sendSMS.
@Override
protected void sendSMS(String text, String recipientNumber) {
recipientNumber = recipientNumber.replaceAll("^00", "\\+");
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
JsonFactory jsonFactory = new JsonFactory();
JsonGenerator jg = jsonFactory.createGenerator(baos, JsonEncoding.UTF8);
jg.writeStartObject();
jg.writeObjectFieldStart("outboundSMSMessageRequest");
jg.writeArrayFieldStart("address");
jg.writeString("tel:" + recipientNumber);
jg.writeEndArray();
jg.writeStringField("senderAddress", senderAddress);
jg.writeObjectFieldStart("outboundSMSTextMessage");
jg.writeStringField("message", text);
jg.writeEndObject();
jg.writeStringField("outboundEncoding", "7bitGSM");
jg.writeStringField("clientCorrelator", "" + ((long) (Math.random() * Long.MAX_VALUE)));
if (senderName != null)
jg.writeStringField("senderName", senderName);
jg.writeEndObject();
jg.writeEndObject();
jg.close();
Exchange exc = new Request.Builder().post("https://gateway.developer.telekom.com/plone/sms/rest/" + environment.name().toLowerCase() + "/smsmessaging/v1/outbound/" + URLEncoder.encode(senderAddress, "UTF-8") + "/requests").header("Host", "gateway.developer.telekom.com").header("Authorization", "OAuth realm=\"developergarden.com\",oauth_token=\"" + getAccessToken() + "\"").header("Accept", "application/json").header("Content-Type", "application/json").body(baos.toByteArray()).buildExchange();
hc.call(exc, false, true);
if (exc.getResponse().getStatusCode() != 201)
throw new RuntimeException("Could not send SMS: " + exc.getResponse());
log.debug("sent SMS to " + recipientNumber);
} catch (Exception e2) {
throw new RuntimeException(e2);
}
}
Aggregations