Search in sources :

Example 31 with Error

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

the class AbstractRequestCallback method onFailure.

@Override
public final void onFailure(final Throwable throwable) {
    final RpcResultBuilder<T> builder;
    if (null != eventIdentifier) {
        EventsTimeCounter.markEnd(eventIdentifier);
    }
    if (throwable instanceof DeviceRequestFailedException) {
        final Error err = ((DeviceRequestFailedException) throwable).getError();
        final String errorString = String.format("Device reported error type %s code %s", err.getTypeString(), err.getCodeString());
        builder = RpcResultBuilder.<T>failed().withError(ErrorType.APPLICATION, errorString, throwable);
        spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_FAILURE);
    } else {
        if (throwable != null) {
            builder = RpcResultBuilder.<T>failed().withError(ErrorType.APPLICATION, throwable.getMessage(), throwable);
        } else {
            Throwable deviceReadFailedThrowable = new Throwable("Failed to read from device.");
            builder = RpcResultBuilder.<T>failed().withError(ErrorType.APPLICATION, deviceReadFailedThrowable.getMessage(), deviceReadFailedThrowable);
        }
        spyMessage(StatisticsGroup.TO_SWITCH_SUBMIT_ERROR);
    }
    context.setResult(builder.build());
    RequestContextUtil.closeRequestContext(context);
}
Also used : DeviceRequestFailedException(org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException) Error(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error)

Example 32 with Error

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

the class HttpConnection method getAccessToken.

private String getAccessToken() {
    if (ssoToken == null) {
        // Build SSO URL if necessary:
        URI ssoURI = ssoUrl != null ? SsoUtils.buildUrl(ssoUrl) : kerberos ? SsoUtils.buildSsoUrlKerberos(url) : SsoUtils.buildSsoUrlBasic(url);
        // Construct POST body:
        List<NameValuePair> params = new ArrayList<>(4);
        params.add(new BasicNameValuePair("scope", "ovirt-app-api"));
        if (kerberos) {
            params.add(new BasicNameValuePair("grant_type", "urn:ovirt:params:oauth:grant-type:http"));
        } else {
            params.add(new BasicNameValuePair("username", user));
            params.add(new BasicNameValuePair("password", password));
            params.add(new BasicNameValuePair("grant_type", "password"));
        }
        // Send request to obtain SSO token:
        JsonNode node = getSsoResponse(ssoURI, params);
        if (node.isArray()) {
            node = node.get(0);
        }
        if (node.get("error") != null) {
            throw new Error(String.format("Error during SSO authentication %1$s : %2$s", node.get("error_code"), node.get("error")));
        }
        ssoToken = node.get(ssoTokenName).textValue();
    }
    return ssoToken;
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) Error(org.ovirt.engine.sdk4.Error) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI)

Example 33 with Error

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

the class HttpConnection method revokeAccessToken.

private void revokeAccessToken() {
    // Build SSO revoke URL:
    URI ssoRevokeURI = ssoRevokeUrl != null ? SsoUtils.buildUrl(ssoRevokeUrl) : ssoToken != null ? SsoUtils.buildSsoRevokeUrl(url) : null;
    // Construct POST body:
    List<NameValuePair> params = new ArrayList<>(2);
    params.add(new BasicNameValuePair("scope", "ovirt-app-api"));
    params.add(new BasicNameValuePair("token", ssoToken));
    // Send request to revoke SSO token:
    if (ssoRevokeURI != null) {
        JsonNode node = getSsoResponse(ssoRevokeURI, params);
        if (node.isArray()) {
            node = node.get(0);
        }
        if (node.get("error") != null) {
            throw new Error(String.format("Error during SSO token revoke %1$s : %2$s", node.get("error_code"), node.get("error")));
        }
    }
}
Also used : BasicNameValuePair(org.apache.http.message.BasicNameValuePair) NameValuePair(org.apache.http.NameValuePair) BasicNameValuePair(org.apache.http.message.BasicNameValuePair) ArrayList(java.util.ArrayList) Error(org.ovirt.engine.sdk4.Error) JsonNode(com.fasterxml.jackson.databind.JsonNode) URI(java.net.URI)

Example 34 with Error

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

the class HttpConnection method followLink.

@Override
public <TYPE> TYPE followLink(TYPE object) {
    if (!isLink(object)) {
        throw new Error("Can't follow link because object don't have any");
    }
    String href = getHref(object);
    if (href == null) {
        throw new Error("Can't follow link because the 'href' attribute does't have a value");
    }
    try {
        URL url = new URL(getUrl());
        String prefix = url.getPath();
        if (!prefix.endsWith("/")) {
            prefix += "/";
        }
        if (!href.startsWith(prefix)) {
            throw new Error("The URL '" + href + "' isn't compatible with the base URL of the connection");
        }
        // Get service based on path
        String path = href.substring(prefix.length());
        Service service = systemService().service(path);
        // Obtain method which provides result object and invoke it:
        Method get;
        if (object instanceof ListWithHref) {
            get = service.getClass().getMethod("list");
        } else {
            get = service.getClass().getMethod("get");
        }
        Object getRequest = get.invoke(service);
        Method send = getRequest.getClass().getMethod("send");
        send.setAccessible(true);
        Object getResponse = send.invoke(getRequest);
        for (Method obtainObject : getResponse.getClass().getDeclaredMethods()) {
            if (obtainObject.getParameterCount() == 0) {
                obtainObject.setAccessible(true);
                return (TYPE) obtainObject.invoke(getResponse);
            }
        }
        throw new NoSuchMethodException("No obtain method found");
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException ex) {
        throw new Error(String.format("Unexpected error while following link \"%1$s\"", href), ex);
    } catch (MalformedURLException ex) {
        throw new Error(String.format("Error while creating URL \"%1$s\"", getUrl()), ex);
    }
}
Also used : ListWithHref(org.ovirt.api.metamodel.runtime.util.ListWithHref) MalformedURLException(java.net.MalformedURLException) Error(org.ovirt.engine.sdk4.Error) SystemService(org.ovirt.engine.sdk4.services.SystemService) Service(org.ovirt.engine.sdk4.Service) Method(java.lang.reflect.Method) URL(java.net.URL) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 35 with Error

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

the class SsoUtils method buildSsoUrlBasic.

/**
 * Construct SSO URL to obtain token from username and password.
 *
 * @param url oVirt engine URL
 * @return URI to be used to obtain token
 */
public static URI buildSsoUrlBasic(String url) {
    try {
        URI uri = new URI(url);
        URIBuilder uriBuilder = new URIBuilder(String.format("%1$s://%2$s/ovirt-engine/sso/oauth/%3$s", uri.getScheme(), uri.getAuthority(), ENTRY_POINT_TOKEN));
        return uriBuilder.build();
    } catch (URISyntaxException ex) {
        throw new Error("Failed to build SSO authentication URL", ex);
    }
}
Also used : Error(org.ovirt.engine.sdk4.Error) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URIBuilder(org.apache.http.client.utils.URIBuilder)

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