Search in sources :

Example 41 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project pentaho-kettle by pentaho.

the class JobEntrySSH2PUTDialog method connect.

private boolean connect() {
    boolean retval = false;
    try {
        if (conn == null) {
            // Create a connection instance
            conn = new Connection(jobMeta.environmentSubstitute(wServerName.getText()), Const.toInt(jobMeta.environmentSubstitute(wServerPort.getText()), 22));
            /* We want to connect through a HTTP proxy */
            if (wuseHTTPProxy.getSelection()) {
                // if the proxy requires basic authentication:
                if (wuseBasicAuthentication.getSelection()) {
                    conn.setProxyData(new HTTPProxyData(jobMeta.environmentSubstitute(wHTTPProxyHost.getText()), Const.toInt(wHTTPProxyPort.getText(), 22), jobMeta.environmentSubstitute(wHTTPProxyUsername.getText()), jobMeta.environmentSubstitute(wHTTPProxyPassword.getText())));
                } else {
                    conn.setProxyData(new HTTPProxyData(jobMeta.environmentSubstitute(wHTTPProxyHost.getText()), Const.toInt(wHTTPProxyPort.getText(), 22)));
                }
            }
            conn.connect();
            // Authenticate
            if (wusePublicKey.getSelection()) {
                retval = conn.authenticateWithPublicKey(jobMeta.environmentSubstitute(wUserName.getText()), new java.io.File(jobMeta.environmentSubstitute(wKeyFilename.getText())), jobMeta.environmentSubstitute(wkeyfilePass.getText()));
            } else {
                retval = conn.authenticateWithPassword(jobMeta.environmentSubstitute(wUserName.getText()), jobMeta.environmentSubstitute(wPassword.getText()));
            }
        }
        retval = true;
    } catch (Exception e) {
        MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
        mb.setMessage(BaseMessages.getString(PKG, "JobSSH2PUT.ErrorConnect.NOK", e.getMessage()) + Const.CR);
        mb.setText(BaseMessages.getString(PKG, "JobSSH2PUT.ErrorConnect.Title.Bad"));
        mb.open();
    }
    return retval;
}
Also used : Connection(com.trilead.ssh2.Connection) HTTPProxyData(com.trilead.ssh2.HTTPProxyData) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 42 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project brave by openzipkin.

the class TracingInterceptor method parseRouteAddress.

static void parseRouteAddress(Chain chain, Span span) {
    if (span.isNoop())
        return;
    Connection connection = chain.connection();
    if (connection == null)
        return;
    InetSocketAddress socketAddress = connection.route().socketAddress();
    span.remoteIpAndPort(socketAddress.getHostString(), socketAddress.getPort());
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Connection(okhttp3.Connection)

Example 43 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project pancm_project by xuwujing.

the class SshUtil method main.

public static void main(String[] args) {
    // 此处根据实际情况,换成自己需要访问的主机IP
    String ip = "192.168.8.12";
    String userName = "root";
    String password = "admin123";
    Connection conn = SshUtil.login(ip, userName, password);
    String cmd = "dis mac-address";
    String result = SshUtil.execute(conn, cmd);
    System.out.println(splitStr + "\n执行的结果如下: \n" + result + splitStr);
}
Also used : Connection(ch.ethz.ssh2.Connection)

Example 44 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project ttdj by soonphe.

the class HttpLoggingInterceptor method intercept.

@Override
public Response intercept(Chain chain) throws IOException {
    Level level = this.level;
    Request request = chain.request();
    if (level == Level.NONE) {
        return chain.proceed(request);
    }
    boolean logBody = level == Level.BODY;
    boolean logHeaders = logBody || level == Level.HEADERS;
    RequestBody requestBody = request.body();
    boolean hasRequestBody = requestBody != null;
    Connection connection = chain.connection();
    Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
    String requestStartMessage = "--> " + request.method() + ' ' + request.url() + ' ' + protocol(protocol);
    if (!logHeaders && hasRequestBody) {
        requestStartMessage += " (" + requestBody.contentLength() + "-byte body)";
    }
    logger.log(requestStartMessage);
    if (logHeaders) {
        if (hasRequestBody) {
            // them to be included (when available) so there values are known.
            if (requestBody.contentType() != null) {
                logger.log("Content-Type: " + requestBody.contentType());
            }
            if (requestBody.contentLength() != -1) {
                logger.log("Content-Length: " + requestBody.contentLength());
            }
        }
        Headers headers = request.headers();
        for (int i = 0, count = headers.size(); i < count; i++) {
            String name = headers.name(i);
            // Skip headers from the request body as they are explicitly logged above.
            if (!"Content-Type".equalsIgnoreCase(name) && !"Content-Length".equalsIgnoreCase(name)) {
                logger.log(name + ": " + headers.value(i));
            }
        }
        if (!logBody || !hasRequestBody) {
            logger.log("--> END " + request.method());
        } else if (bodyEncoded(request.headers())) {
            logger.log("--> END " + request.method() + " (encoded body omitted)");
        } else {
            Buffer buffer = new Buffer();
            requestBody.writeTo(buffer);
            Charset charset = UTF8;
            MediaType contentType = requestBody.contentType();
            if (contentType != null) {
                charset = contentType.charset(UTF8);
            }
            logger.log("");
            logger.log(buffer.readString(charset));
            logger.log("--> END " + request.method() + " (" + requestBody.contentLength() + "-byte body)");
        }
    }
    long startNs = System.nanoTime();
    Response response = chain.proceed(request);
    long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
    ResponseBody responseBody = response.body();
    long contentLength = responseBody.contentLength();
    String bodySize = contentLength != -1 ? contentLength + "-byte" : "unknown-length";
    logger.log("<-- " + response.code() + ' ' + response.message() + ' ' + response.request().url() + " (" + tookMs + "ms" + (!logHeaders ? ", " + bodySize + " body" : "") + ')');
    if (logHeaders) {
        Headers headers = response.headers();
        for (int i = 0, count = headers.size(); i < count; i++) {
            logger.log(headers.name(i) + ": " + headers.value(i));
        }
        if (!logBody || !HttpHeaders.hasBody(response)) {
            logger.log("<-- END HTTP");
        } else if (bodyEncoded(response.headers())) {
            logger.log("<-- END HTTP (encoded body omitted)");
        } else {
            BufferedSource source = responseBody.source();
            // Buffer the entire body.
            source.request(Long.MAX_VALUE);
            Buffer buffer = source.buffer();
            Charset charset = UTF8;
            MediaType contentType = responseBody.contentType();
            if (contentType != null) {
                charset = contentType.charset(UTF8);
            }
            if (contentLength != 0) {
                logger.log("");
                logger.log(buffer.clone().readString(charset));
            }
            logger.log("<-- END HTTP (" + buffer.size() + "-byte body)");
        }
    }
    return response;
}
Also used : Buffer(okio.Buffer) HttpHeaders(okhttp3.internal.http.HttpHeaders) Headers(okhttp3.Headers) Request(okhttp3.Request) Connection(okhttp3.Connection) Charset(java.nio.charset.Charset) ResponseBody(okhttp3.ResponseBody) Response(okhttp3.Response) MediaType(okhttp3.MediaType) Protocol(okhttp3.Protocol) RequestBody(okhttp3.RequestBody) BufferedSource(okio.BufferedSource)

Example 45 with Connection

use of org.geotoolkit.sml.xml.v100.Connection in project ovirt-engine-sdk-java by oVirt.

the class IscsiDiscover method main.

public static void main(String[] args) throws Exception {
    // Create the connection to the server:
    Connection connection = connection().url("https://engine40.example.com/ovirt-engine/api").user("admin@internal").password("redhat123").trustStoreFile("truststore.jks").build();
    // Get the reference to the hosts service:
    HostsService hostsService = connection.systemService().hostsService();
    // Find the host:
    Host host = hostsService.list().search("name=myhost").send().hosts().get(0);
    // Locate the service that manages the host, as that is where the action methods are defined:
    HostService hostService = hostsService.hostService(host.id());
    // Call the "iscsiDiscover" method of the service to start it:
    HostService.IscsiDiscoverResponse response = hostService.iscsiDiscover().iscsi(iscsiDetails().address("myaddress")).send();
    // Print only targets:
    for (String target : response.iscsiTargets()) {
        System.out.println(target);
    }
    // Print only address corresponding to target:
    for (IscsiDetails detail : response.discoveredTargets()) {
        System.out.println(detail.address() + ":" + detail.target());
    }
    // Close the connection to the server:
    connection.close();
}
Also used : HostService(org.ovirt.engine.sdk4.services.HostService) IscsiDetails(org.ovirt.engine.sdk4.types.IscsiDetails) Connection(org.ovirt.engine.sdk4.Connection) HostsService(org.ovirt.engine.sdk4.services.HostsService) Host(org.ovirt.engine.sdk4.types.Host)

Aggregations

IOException (java.io.IOException)68 Connection (org.ovirt.engine.sdk4.Connection)64 Connection (com.trilead.ssh2.Connection)61 Connection (org.osate.aadl2.Connection)57 Session (com.trilead.ssh2.Session)33 Connection (org.jboss.remoting3.Connection)33 Connection (com.google.cloud.bigquery.connection.v1.Connection)31 Test (org.junit.Test)30 VmsService (org.ovirt.engine.sdk4.services.VmsService)30 Vm (org.ovirt.engine.sdk4.types.Vm)30 InputStream (java.io.InputStream)29 Connection (okhttp3.Connection)28 Connection (ch.ethz.ssh2.Connection)24 Request (okhttp3.Request)20 Subcomponent (org.osate.aadl2.Subcomponent)19 FeatureGroupConnection (org.osate.aadl2.FeatureGroupConnection)18 PortConnection (org.osate.aadl2.PortConnection)18 VmService (org.ovirt.engine.sdk4.services.VmService)18 ArrayList (java.util.ArrayList)17 Response (okhttp3.Response)17