Search in sources :

Example 46 with Service

use of com.google.cloud.servicedirectory.v1.Service in project axis-axis2-java-core by apache.

the class WSDL20ToAxisServiceBuilder method processService.

private void processService() throws AxisFault {
    Service[] services = description.getServices();
    if (services.length == 0) {
        throw new AxisFault("No wsdlService found in the WSDL");
    }
    if (serviceName != null) {
        for (int i = 0; i < services.length; i++) {
            if (serviceName.equals(services[i].getName())) {
                wsdlService = services[i];
                // found it. Stop looking.
                break;
            }
        }
        if (wsdlService == null) {
            throw new AxisFault("Service with the specified name not found in the WSDL : " + serviceName.getLocalPart());
        }
    } else {
        wsdlService = services[0];
    }
    axisService.setName(wsdlService.getName().getLocalPart());
    Interface serviceInterface = wsdlService.getInterface();
    axisService.addParameter(new Parameter(WSDL2Constants.INTERFACE_LOCAL_NAME, serviceInterface.getName().getLocalPart()));
    processInterface(serviceInterface);
    if (isCodegen) {
        axisService.setOperationsNameList(operationNames);
    }
    processEndpoints(serviceInterface);
}
Also used : AxisFault(org.apache.axis2.AxisFault) Service(org.apache.woden.wsdl20.Service) Endpoint(org.apache.woden.wsdl20.Endpoint) Interface(org.apache.woden.wsdl20.Interface)

Example 47 with Service

use of com.google.cloud.servicedirectory.v1.Service 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 48 with Service

use of com.google.cloud.servicedirectory.v1.Service in project java-servicedirectory by googleapis.

the class ServicesCreate method createService.

// Create a new service.
public static void createService(String projectId, String locationId, String namespaceId, String serviceId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (RegistrationServiceClient client = RegistrationServiceClient.create()) {
        // The namespace to create the service in.
        NamespaceName parent = NamespaceName.of(projectId, locationId, namespaceId);
        // The service object to create.
        // Optionally add some annotations for the service.
        Service service = Service.newBuilder().putAnnotations("protocol", "tcp").build();
        // Send the request to create the namespace.
        Service createdService = client.createService(parent, service, serviceId);
        // Process the response.
        System.out.println("Created Service: " + createdService.getName());
        System.out.println("Annotations: " + createdService.getAnnotations());
    }
}
Also used : NamespaceName(com.google.cloud.servicedirectory.v1.NamespaceName) Service(com.google.cloud.servicedirectory.v1.Service) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient)

Example 49 with Service

use of com.google.cloud.servicedirectory.v1.Service in project java-servicedirectory by googleapis.

the class EndpointsCreate method createEndpoint.

// Create a new endpoint.
public static void createEndpoint(String projectId, String locationId, String namespaceId, String serviceId, String endpointId) throws IOException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (RegistrationServiceClient client = RegistrationServiceClient.create()) {
        // The service to create the endpoint in.
        ServiceName parent = ServiceName.of(projectId, locationId, namespaceId, serviceId);
        // The endpoint to create, with fields filled in.
        // Optionally set an IP address and port for the endpoint.
        Endpoint endpoint = Endpoint.newBuilder().setAddress("10.0.0.1").setPort(443).build();
        // Send the request to create the endpoint.
        Endpoint createdEndpoint = client.createEndpoint(parent, endpoint, endpointId);
        // Process the response.
        System.out.println("Created Endpoint: " + createdEndpoint.getName());
        System.out.println("IP Address: " + createdEndpoint.getAddress());
        System.out.println("Port: " + createdEndpoint.getPort());
    }
}
Also used : Endpoint(com.google.cloud.servicedirectory.v1.Endpoint) ServiceName(com.google.cloud.servicedirectory.v1.ServiceName) RegistrationServiceClient(com.google.cloud.servicedirectory.v1.RegistrationServiceClient)

Example 50 with Service

use of com.google.cloud.servicedirectory.v1.Service in project java-servicedirectory by googleapis.

the class RegistrationServiceClientTest method listEndpointsTest.

@Test
public void listEndpointsTest() throws Exception {
    Endpoint responsesElement = Endpoint.newBuilder().build();
    ListEndpointsResponse expectedResponse = ListEndpointsResponse.newBuilder().setNextPageToken("").addAllEndpoints(Arrays.asList(responsesElement)).build();
    mockRegistrationService.addResponse(expectedResponse);
    ServiceName parent = ServiceName.of("[PROJECT]", "[LOCATION]", "[NAMESPACE]", "[SERVICE]");
    ListEndpointsPagedResponse pagedListResponse = client.listEndpoints(parent);
    List<Endpoint> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getEndpointsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockRegistrationService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListEndpointsRequest actualRequest = ((ListEndpointsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ListEndpointsPagedResponse(com.google.cloud.servicedirectory.v1.RegistrationServiceClient.ListEndpointsPagedResponse) Test(org.junit.Test)

Aggregations

Test (org.junit.jupiter.api.Test)33 Service (io.fabric8.knative.serving.v1.Service)28 Connector (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Connector)22 Service (org.eclipse.jst.server.tomcat.core.internal.xml.server40.Service)22 Test (org.junit.Test)19 MockGrpcService (com.google.api.gax.grpc.testing.MockGrpcService)18 CoreException (org.eclipse.core.runtime.CoreException)18 Service (com.google.monitoring.v3.Service)16 IOException (java.io.IOException)15 AbstractMessage (com.google.protobuf.AbstractMessage)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)13 HasMetadata (io.fabric8.kubernetes.api.model.HasMetadata)11 ProdBuildResults (io.quarkus.test.ProdBuildResults)11 ProdModeTestResults (io.quarkus.test.ProdModeTestResults)11 QuarkusProdModeTest (io.quarkus.test.QuarkusProdModeTest)11 Path (java.nio.file.Path)11 ArrayList (java.util.ArrayList)11 RegisterExtension (org.junit.jupiter.api.extension.RegisterExtension)11 List (java.util.List)10 DisplayName (org.junit.jupiter.api.DisplayName)10