use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class NavajoStreamCollector method createHeader.
private void createHeader(NavajoHead head) {
Header h = NavajoFactory.getInstance().createHeader(assemble, head.name(), head.username().orElse(null), head.password().orElse(null), -1);
assemble.addHeader(h);
}
use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class AsyncClientImpl method callService.
private void callService(final String url, Navajo input, NavajoResponseHandler continuation, Integer timeout) throws IOException {
logger.info("Calling service: {} at {} ", input.getHeader().getRPCName(), url);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
input.write(baos);
final byte[] byteArray = baos.toByteArray();
httpClient.newRequest(url).method(HttpMethod.POST).header("Accept-Encoding", null).timeout(MAX_TIMEOUT, TimeUnit.SECONDS).idleTimeout(MAX_IDLE_TIMEOUT, TimeUnit.SECONDS).content(new BytesContentProvider(byteArray), "text/xml; charset=utf-8").onRequestFailure((request, throwable) -> {
logger.error("Request failed: HTTP call to: " + url + " failed: {}", throwable);
if (continuation != null) {
try {
continuation.onFail(throwable);
} catch (IOException exc) {
logger.error("Error: ", exc);
}
}
if (closeAfterUse) {
close();
}
}).onResponseFailure((response, throwable) -> {
logger.error("Response failed: HTTP call to: " + url + " failed: {}", throwable);
if (continuation != null) {
try {
continuation.onFail(throwable);
} catch (IOException exc) {
logger.error("Error: ", exc);
}
}
if (closeAfterUse) {
close();
}
}).send(new BufferingResponseListener(MAX_RESULT_SIZE) {
@Override
public void onComplete(Result result) {
try {
Navajo response = NavajoFactory.getInstance().createNavajo(getContentAsInputStream());
if (continuation != null) {
continuation.onResponse(response);
}
} catch (UnsupportedOperationException exc) {
logger.error("Error: ", exc);
} finally {
if (closeAfterUse) {
close();
}
setActualCalls(getActualCalls() - 1);
}
}
});
}
use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class ServerAsyncRunner method poll.
private void poll(Navajo temp) throws ClientException {
Header head = temp.getHeader();
if (head == null) {
logger.warn("Received no header. returning and killing thread");
throw new ClientException(-1, -1, "No async header!");
}
if (isFinished(temp)) {
// Really dont know what I should pass to getCallBackPointer
if (myListener != null) {
myListener.setProgress(head.getCallBackPointer(null), 100);
myListener.receiveServerAsync(temp, myMethod, head.getCallBackPointer(null), myClientId);
}
registry.deRegisterAsyncRunner(myClientId);
myNavajo.removeHeader();
this.iterate = false;
} else {
if (myListener != null) {
myListener.setProgress(head.getCallBackPointer(null), head.getCallBackProgress());
}
}
checkPollingInterval(head.getCallBackProgress());
sleep();
}
use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class ServerAsyncRunner method startAsync.
/**
* Start the ServerAsyncRunner
* @throws ClientException
* @return String
*/
public String startAsync() throws ClientException {
if (myNavajo.getHeader() != null) {
myNavajo.removeHeader();
}
myResult = doSimpleSend(myNavajo, myMethod);
Header resultHead = myResult.getHeader();
if (resultHead != null) {
if (myListener != null) {
myListener.serviceStarted(resultHead.getCallBackPointer(null));
start();
return resultHead.getCallBackPointer(null);
}
} else {
logger.info("Received no header. returning and killing thread");
throw new ClientException(-1, -1, "No async header!");
}
return null;
}
use of com.dexels.navajo.document.Header in project navajo by Dexels.
the class NavajoClient method doSimpleSend.
@Override
public final Navajo doSimpleSend(Navajo out, String method, Integer retries) throws ClientException {
if (bearerToken == null) {
if (username == null) {
throw new ClientException(1, 1, "No username set!");
}
if (password == null) {
throw new ClientException(1, 1, "No password set!");
}
}
if (getCurrentHost() == null) {
throw new ClientException(1, 1, "No host set!");
}
/**
* Make sure that same Navajo is not used simultaneously.
*/
synchronized (this) {
// ====================================================
Header header = out.getHeader();
String callingService = null;
if (header == null) {
header = NavajoFactory.getInstance().createHeader(out, method, username, password, -1);
out.addHeader(header);
} else {
callingService = header.getRPCName();
header.setRPCName(method);
header.setRPCUser(username);
header.setRPCPassword(password);
}
// ALWAY SET REQUEST ID AT THIS POINT.
if (header.getRequestId() != null && header.getRequestId().equals("42")) {
//
} else {
header.setRequestId(Guid.create());
}
String sessionToken = getSessionTokenProvider().getSessionToken();
header.setHeaderAttribute("clientToken", sessionToken);
header.setHeaderAttribute("clientInfo", getSystemInfoProvider().toString());
for (Entry<String, String> entry : navajoHeaders.entrySet()) {
header.setHeaderAttribute(entry.getKey(), entry.getValue());
}
long clientTime = 0;
try {
if (out.getHeader() != null) {
processPiggybackData(out.getHeader());
}
Navajo n = null;
long timeStamp = System.currentTimeMillis();
n = doTransaction(out, allowCompression, retries, 0);
if (markDescriptions) {
addParagraphToAllPropertyDescriptions(n, null);
}
if (n.getHeader() != null) {
n.getHeader().setHeaderAttribute("sourceScript", callingService);
clientTime = (System.currentTimeMillis() - timeStamp);
n.getHeader().setHeaderAttribute("clientTime", "" + clientTime);
String tot = n.getHeader().getHeaderAttribute("serverTime");
long totalTime = -1;
if (tot != null && !"".equals(tot)) {
totalTime = Long.parseLong(tot);
n.getHeader().setHeaderAttribute("transferTime", "" + (clientTime - totalTime));
}
Map<String, String> headerAttributes = n.getHeader().getHeaderAttributes();
Map<String, String> pbd = new HashMap<>(headerAttributes);
pbd.put("type", "performanceStats");
pbd.put("service", method);
synchronized (piggyBackData) {
piggyBackData.add(pbd);
}
} else {
logger.info("Null header in input message?");
}
return n;
} catch (ClientException e) {
throw e;
} catch (Exception e) {
throw new ClientException(-1, -1, e.getMessage(), e);
}
}
}
Aggregations