public MultiPartUtility formField(String name, String value) { buffer.appendString("--" + BOUNDARY).appendString(LINE_FEED); buffer .appendString("Content-Disposition: form-data; name=\"" + name + "\"") .appendString(LINE_FEED); buffer.appendString("Content-Type: text/plain; charset=" + charset).appendString(LINE_FEED); buffer.appendString(LINE_FEED); buffer.appendString(value).appendString(LINE_FEED); return this; }
@Override public void handle(SockJSSocket sockJSSocket) { final String sessionId = sockJSSocket.webSession().id(); final MessageConsumer<String> sessionConsumer = consumers.get(sessionId); if (sessionConsumer == null) { final MessageConsumer<String> consumer = eventStore.consumer( UpdateOrdrEvent.class, message -> { final String id = sockJSSocket.webSession().get("id").toString(); JsonObject dashboardJson = new JsonObject(message.body()); if (dashboardJson.getString("id").equals(id)) { sockJSSocket.write(Buffer.buffer(message.body())); } }); log.info("bound WS handler to sessionId {}", sessionId); consumers.put(sessionId, consumer); log.info("registered consumers {}", consumers.size()); } sockJSSocket.endHandler( aVoid -> { final MessageConsumer<String> consumer = consumers.get(sessionId); consumer.unregister(); consumers.remove(sessionId); log.info("unregistered consumer for sessionId {}", sessionId); }); }
public MultiPartUtility attachmentHead(String fileName) { buffer.appendString("--" + BOUNDARY).appendString(LINE_FEED); buffer .appendString( "Content-Disposition: form-data; name=\"" + attachmentName + "\"; filename=\"" + fileName + "\"") .appendString(LINE_FEED); buffer .appendString("Content-Type: " + URLConnection.guessContentTypeFromName(fileName)) .appendString(LINE_FEED); buffer.appendString("Content-Transfer-Encoding: binary").appendString(LINE_FEED); buffer.appendString(LINE_FEED); return this; }
@Override public void handle(HttpClientResponse httpClientResponse) { if (httpClientResponse.statusCode() == HttpStatus.SC_OK) { httpClientResponse.bodyHandler(buffer -> totalBuffer.appendBuffer(buffer)); httpClientResponse.endHandler( aVoid -> { try { MailgunSendResponse response = jsonMapper.readValue(totalBuffer.toString(), MailgunSendResponse.class); if (response == null || response.getId() == null || response.getId().isEmpty()) { failure(sendRequest, new Exception("Invalid Response to Send Request")); return; } EmailEntity emailEntity = sendRequest.getEmailEntity(); emailEntity.setMessageId(response.getId()); updateRecords(emailEntity); publishEvent(emailEntity, true); success(sendRequest, emailEntity); } catch (Throwable throwable) { updateRecords(sendRequest.getEmailEntity()); publishEvent(sendRequest.getEmailEntity(), false); failure(sendRequest, throwable); } }); } else { if (sendRequest.getAttempts() < ALLOWED_ATTEMPTS) { sendEmail(sendRequest); } else { updateRecords(sendRequest.getEmailEntity()); publishEvent(sendRequest.getEmailEntity(), false); failure( sendRequest, new Exception( "Failed to Send Email Using " + ALLOWED_ATTEMPTS + " Attempts with Response Code: " + httpClientResponse.statusCode())); } } }
/** * Set the body. Used by the {@link io.vertx.ext.web.handler.BodyHandler}. You will not normally * call this method. * * @param body the body */ public void setBody(Buffer body) { this.delegate.setBody((io.vertx.core.buffer.Buffer) body.getDelegate()); }
/** * @return Get the entire HTTP request body as a . The context must have first been routed to a * {@link io.vertx.ext.web.handler.BodyHandler} for this to be populated. * @return */ public Buffer getBody() { Buffer ret = Buffer.newInstance(this.delegate.getBody()); return ret; }
public void end(Buffer t) { delegate.end((io.vertx.core.buffer.Buffer) t.getDelegate()); }
public SockJSSocket write(Buffer data) { ((io.vertx.ext.web.handler.sockjs.SockJSSocket) delegate) .write((io.vertx.core.buffer.Buffer) data.getDelegate()); return this; }
public HttpResponseHandler(MailgunSendRequest sendRequest) { this.sendRequest = sendRequest; this.totalBuffer = Buffer.buffer(); }
public MultiPartUtility() { this.buffer = Buffer.buffer(); }