Search in sources :

Example 21 with Header

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);
}
Also used : Header(com.dexels.navajo.document.Header)

Example 22 with Header

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);
            }
        }
    });
}
Also used : Result(org.eclipse.jetty.client.api.Result) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) LoggerFactory(org.slf4j.LoggerFactory) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) HashSet(java.util.HashSet) HttpClient(org.eclipse.jetty.client.HttpClient) NavajoResponseCallback(com.dexels.navajo.script.api.NavajoResponseCallback) Map(java.util.Map) HttpProxy(org.eclipse.jetty.client.HttpProxy) ProxyConfiguration(org.eclipse.jetty.client.ProxyConfiguration) Navajo(com.dexels.navajo.document.Navajo) SchedulerRegistry(com.dexels.navajo.script.api.SchedulerRegistry) NavajoResponseHandler(com.dexels.navajo.client.NavajoResponseHandler) Logger(org.slf4j.Logger) BufferingResponseListener(org.eclipse.jetty.client.util.BufferingResponseListener) Access(com.dexels.navajo.script.api.Access) Set(java.util.Set) IOException(java.io.IOException) TimeUnit(java.util.concurrent.TimeUnit) NavajoFactory(com.dexels.navajo.document.NavajoFactory) HttpMethod(org.eclipse.jetty.http.HttpMethod) ManualAsyncClient(com.dexels.navajo.client.async.ManualAsyncClient) AsyncClientFactory(com.dexels.navajo.client.async.AsyncClientFactory) TmlRunnable(com.dexels.navajo.script.api.TmlRunnable) Header(com.dexels.navajo.document.Header) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Navajo(com.dexels.navajo.document.Navajo) BytesContentProvider(org.eclipse.jetty.client.util.BytesContentProvider) BufferingResponseListener(org.eclipse.jetty.client.util.BufferingResponseListener) Result(org.eclipse.jetty.client.api.Result)

Example 23 with Header

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();
}
Also used : Header(com.dexels.navajo.document.Header) ClientException(com.dexels.navajo.client.ClientException)

Example 24 with Header

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;
}
Also used : Header(com.dexels.navajo.document.Header) ClientException(com.dexels.navajo.client.ClientException)

Example 25 with Header

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);
        }
    }
}
Also used : Header(com.dexels.navajo.document.Header) HashMap(java.util.HashMap) Navajo(com.dexels.navajo.document.Navajo) NavajoException(com.dexels.navajo.document.NavajoException)

Aggregations

Header (com.dexels.navajo.document.Header)29 Navajo (com.dexels.navajo.document.Navajo)19 NavajoException (com.dexels.navajo.document.NavajoException)9 IOException (java.io.IOException)9 FatalException (com.dexels.navajo.script.api.FatalException)7 UserException (com.dexels.navajo.script.api.UserException)7 Message (com.dexels.navajo.document.Message)6 SystemException (com.dexels.navajo.script.api.SystemException)6 AuthorizationException (com.dexels.navajo.script.api.AuthorizationException)5 Property (com.dexels.navajo.document.Property)4 TriggerException (com.dexels.navajo.server.enterprise.scheduler.TriggerException)4 ClientException (com.dexels.navajo.client.ClientException)3 Access (com.dexels.navajo.script.api.Access)3 NavajoResponseHandler (com.dexels.navajo.client.NavajoResponseHandler)2 MappableException (com.dexels.navajo.script.api.MappableException)2 BufferedReader (java.io.BufferedReader)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2