Search in sources :

Example 66 with Error

use of com.google.privacy.dlp.v2.Error in project openflowplugin by opendaylight.

the class DeviceContextImplTest method testProcessReply.

@Test
public void testProcessReply() {
    final Error mockedError = mock(Error.class);
    deviceContext.processReply(mockedError);
    verify(messageSpy).spyMessage(Mockito.<Class>any(), eq(MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_FAILURE));
    final OfHeader mockedOfHeader = mock(OfHeader.class);
    deviceContext.processReply(mockedOfHeader);
    verify(messageSpy).spyMessage(Mockito.<Class>any(), eq(MessageSpy.StatisticsGroup.FROM_SWITCH_PUBLISHED_SUCCESS));
}
Also used : OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader) Error(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error) Test(org.junit.Test)

Example 67 with Error

use of com.google.privacy.dlp.v2.Error in project openflowplugin by opendaylight.

the class StackedSegment method completeEntry.

private static boolean completeEntry(final OutboundQueueEntry entry, final OfHeader response) {
    if (response instanceof Error) {
        final Error err = (Error) response;
        LOG.debug("Device-reported request XID {} failed {}:{}", response.getXid(), err.getTypeString(), err.getCodeString());
        entry.fail(new DeviceRequestFailedException("Device-side failure", err));
        return true;
    }
    return entry.complete(response);
}
Also used : Error(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error) DeviceRequestFailedException(org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException)

Example 68 with Error

use of com.google.privacy.dlp.v2.Error in project ovirt-engine-sdk-java by oVirt.

the class ConnectionBuilder42 method createConnectionSocketFactoryRegistry.

private SchemeRegistry createConnectionSocketFactoryRegistry() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    SSLSocketFactory sf;
    // Create SSL/TLS or plain connection:
    if (HTTP_PROTOCOL.equals(getProtocol())) {
        schemeRegistry.register(new Scheme(HTTP_PROTOCOL, getPort(), PlainSocketFactory.getSocketFactory()));
    } else if (HTTPS_PROTOCOL.equals(getProtocol())) {
        try {
            if (this.insecure) {
                SSLContext sslcontext = SSLContext.getInstance("TLS");
                sslcontext.init(null, new TrustManager[] { noCaTrustManager }, null);
                sf = new SSLSocketFactory(sslcontext, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
            } else {
                KeyStore truststore = null;
                InputStream in = null;
                if (this.trustStoreFile != null) {
                    truststore = KeyStore.getInstance(KeyStore.getDefaultType());
                    try {
                        in = new FileInputStream(this.trustStoreFile);
                        truststore.load(in, this.trustStorePassword != null ? this.trustStorePassword.toCharArray() : null);
                    } finally {
                        if (in != null) {
                            in.close();
                        }
                    }
                }
                sf = new SSLSocketFactory(SSLSocketFactory.TLS, null, null, truststore, null, null, SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
            }
            schemeRegistry.register(new Scheme(HTTPS_PROTOCOL, getPort(), sf));
        } catch (NoSuchAlgorithmException e) {
            throw new Error(NO_TLS_ERROR, e);
        } catch (KeyManagementException e) {
            throw new Error(BAD_KEY_ERROR, e);
        } catch (KeyStoreException e) {
            throw new Error(KEY_STORE_ERROR, e);
        } catch (FileNotFoundException e) {
            throw new Error(KEY_STORE_FILE_NOT_FOUND_ERROR, e);
        } catch (CertificateException e) {
            throw new Error(CERTIFICATE_ERROR, e);
        } catch (IOException e) {
            throw new Error(IO_ERROR, e);
        } catch (UnrecoverableKeyException e) {
            throw new Error(UNRECOVERABLE_KEY_ERROR, e);
        }
    }
    return schemeRegistry;
}
Also used : Scheme(org.apache.http.conn.scheme.Scheme) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) Error(org.ovirt.engine.sdk4.Error) CertificateException(java.security.cert.CertificateException) SSLContext(javax.net.ssl.SSLContext) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyStore(java.security.KeyStore) FileInputStream(java.io.FileInputStream) KeyManagementException(java.security.KeyManagementException) TrustManager(javax.net.ssl.TrustManager) UnrecoverableKeyException(java.security.UnrecoverableKeyException) SchemeRegistry(org.apache.http.conn.scheme.SchemeRegistry) AuthSchemeRegistry(org.apache.http.auth.AuthSchemeRegistry) SSLSocketFactory(org.apache.http.conn.ssl.SSLSocketFactory)

Example 69 with Error

use of com.google.privacy.dlp.v2.Error in project ovirt-engine-sdk-java by oVirt.

the class HttpConnection method checkContentType.

/**
 * Checks the given content type and raises an exception if it isn't the
 * expected one.
 *
 * @param pattern The regular expression used to check the expected content type.
 * @param expectedName The name of the expected content type.
 * @param actual The actual value of the `Content-Type` header.
 * @throws MalformedURLException When URL isn't correct.
 */
private void checkContentType(Pattern pattern, String expectedName, String actual) throws MalformedURLException {
    if (!pattern.matcher(actual).matches()) {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("The response content type '%1$s' isn't the expected %2$s", actual, expectedName));
        URL url = new URL(getUrl());
        if (!url.getPath().equals(TYPICAL_PATH)) {
            sb.append(String.format(". Is the path '%1$s' included in the 'url' parameter correct?", url.getPath()));
            sb.append(String.format(" The typical one is '%1$s'", TYPICAL_PATH));
        }
        throw new Error(sb.toString());
    }
}
Also used : Error(org.ovirt.engine.sdk4.Error) URL(java.net.URL)

Example 70 with Error

use of com.google.privacy.dlp.v2.Error in project ovirt-engine-sdk-java by oVirt.

the class HttpConnection method send.

private HttpResponse send(HttpUriRequest request, boolean failedAuth) {
    try {
        injectHeaders(request);
        HttpResponse response = client.execute(request);
        /**
         * If the request failed because of authentication, and it
         * wasn't a request to the SSO service, then the most likely
         * cause is an expired SSO token. In this case we need to
         * request a new token, and try the original request again, but
         * only once. It if fails again, we just return the failed
         * response.
         */
        if (response.getStatusLine().getStatusCode() == 401 && !failedAuth) {
            ssoToken = null;
            authenticate();
            response = send(request, true);
        }
        if (response.getFirstHeader("content-type") != null) {
            checkContentType(XML_CONTENT_TYPE_RE, "XML", response.getFirstHeader("content-type").getValue());
        }
        return response;
    } catch (Exception e) {
        throw new Error("Failed to send request", e);
    }
}
Also used : HttpResponse(org.apache.http.HttpResponse) Error(org.ovirt.engine.sdk4.Error) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

ArrayList (java.util.ArrayList)28 DlpServiceClient (com.google.cloud.dlp.v2.DlpServiceClient)23 Test (org.junit.Test)23 ParseException (org.apache.commons.cli.ParseException)18 AbstractMessage (com.google.protobuf.AbstractMessage)16 DlpJob (com.google.privacy.dlp.v2.DlpJob)15 InfoType (com.google.privacy.dlp.v2.InfoType)13 CreateDlpJobRequest (com.google.privacy.dlp.v2.CreateDlpJobRequest)12 ByteString (com.google.protobuf.ByteString)12 Error (dev.hawala.xns.level2.Error)12 Error (org.ovirt.engine.sdk4.Error)12 InspectConfig (com.google.privacy.dlp.v2.InspectConfig)11 Error (org.eclipse.bpmn2.Error)11 ContentItem (com.google.privacy.dlp.v2.ContentItem)10 ProjectName (com.google.privacy.dlp.v2.ProjectName)9 Iterator (java.util.Iterator)9 JobTrigger (com.google.privacy.dlp.v2.JobTrigger)8 RootElement (org.eclipse.bpmn2.RootElement)8 Error (com.google.privacy.dlp.v2.Error)7 ServiceOptions (com.google.cloud.ServiceOptions)6