Search in sources :

Example 26 with Holder

use of javax.xml.ws.Holder in project java-chassis by ServiceComb.

the class ServiceRegistryClientImpl method findServiceInstance.

@Override
public List<MicroserviceInstance> findServiceInstance(String selfMicroserviceId, String appId, String serviceName, String versionRule) {
    Holder<FindInstancesResponse> holder = new Holder<>();
    IpPort ipPort = IpPortManager.INSTANCE.get();
    StringBuilder url = new StringBuilder(Const.MS_API_PATH);
    url.append(Const.INSTANCES_PATH);
    CountDownLatch countDownLatch = new CountDownLatch(1);
    RestUtils.get(ipPort, url.toString(), new RequestParam().addQueryParam("appId", appId).addQueryParam("serviceName", serviceName).addQueryParam("version", versionRule).addHeader("X-ConsumerId", selfMicroserviceId), syncHandler(countDownLatch, FindInstancesResponse.class, holder));
    try {
        countDownLatch.await();
        if (holder.value == null) {
            // error
            return null;
        }
        List<MicroserviceInstance> list = holder.value.getInstances();
        if (list == null) {
            return new ArrayList<>();
        }
        return list;
    } catch (Exception e) {
        LOGGER.error("find microservice instance {}/{}/{} failed", appId, serviceName, versionRule, e);
    }
    return null;
}
Also used : Holder(javax.xml.ws.Holder) ArrayList(java.util.ArrayList) MicroserviceInstance(io.servicecomb.serviceregistry.api.registry.MicroserviceInstance) IpPort(io.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) FindInstancesResponse(io.servicecomb.serviceregistry.api.response.FindInstancesResponse) ClientException(io.servicecomb.serviceregistry.client.ClientException)

Example 27 with Holder

use of javax.xml.ws.Holder in project java-chassis by ServiceComb.

the class ServiceRegistryClientImpl method getAllMicroservices.

@Override
public List<Microservice> getAllMicroservices() {
    Holder<GetAllServicesResponse> holder = new Holder<>();
    IpPort ipPort = IpPortManager.INSTANCE.get();
    CountDownLatch countDownLatch = new CountDownLatch(1);
    RestUtils.get(ipPort, Const.MS_API_PATH + Const.MICROSERVICE_PATH, new RequestParam(), syncHandler(countDownLatch, GetAllServicesResponse.class, holder));
    try {
        countDownLatch.await();
        if (holder.value != null) {
            return holder.value.getServices();
        }
    } catch (Exception e) {
        LOGGER.error("query all microservices failed", e);
    }
    return null;
}
Also used : GetAllServicesResponse(io.servicecomb.serviceregistry.api.response.GetAllServicesResponse) Holder(javax.xml.ws.Holder) IpPort(io.servicecomb.foundation.common.net.IpPort) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(io.servicecomb.serviceregistry.client.ClientException)

Example 28 with Holder

use of javax.xml.ws.Holder in project java-chassis by ServiceComb.

the class ServiceRegistryClientImpl method updateInstanceProperties.

@Override
public boolean updateInstanceProperties(String microserviceId, String microserviceInstanceId, Map<String, String> instanceProperties) {
    Holder<HttpClientResponse> holder = new Holder<>();
    IpPort ipPort = IpPortManager.INSTANCE.get();
    StringBuilder url = new StringBuilder(Const.MS_API_PATH);
    url.append(Const.MICROSERVICE_PATH).append("/").append(microserviceId).append(Const.INSTANCES_PATH).append("/").append(microserviceInstanceId).append(Const.PROPERTIES_PATH);
    try {
        UpdatePropertiesRequest request = new UpdatePropertiesRequest();
        request.setProperties(instanceProperties);
        byte[] body = JsonUtils.writeValueAsBytes(request);
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("update properties of microservice instance: {}", new String(body, Charset.defaultCharset()));
        }
        CountDownLatch countDownLatch = new CountDownLatch(1);
        RestUtils.put(ipPort, url.toString(), new RequestParam().setBody(body), syncHandler(countDownLatch, HttpClientResponse.class, holder));
        countDownLatch.await();
        if (holder.value != null) {
            if (holder.value.statusCode() == Status.OK.getStatusCode()) {
                return true;
            }
            LOGGER.warn(holder.value.statusMessage());
        }
    } catch (Exception e) {
        LOGGER.error("update properties of microservice instance {}/{} failed", microserviceId, microserviceInstanceId, e);
    }
    return false;
}
Also used : Holder(javax.xml.ws.Holder) HttpClientResponse(io.vertx.core.http.HttpClientResponse) IpPort(io.servicecomb.foundation.common.net.IpPort) UpdatePropertiesRequest(io.servicecomb.serviceregistry.api.request.UpdatePropertiesRequest) CountDownLatch(java.util.concurrent.CountDownLatch) ClientException(io.servicecomb.serviceregistry.client.ClientException)

Example 29 with Holder

use of javax.xml.ws.Holder in project zm-mailbox by Zimbra.

the class ExchangeEWSFreeBusyProvider method getFreeBusyForHost.

public List<FreeBusy> getFreeBusyForHost(String host, ArrayList<Request> req) throws IOException {
    int fb_interval = LC.exchange_free_busy_interval_min.intValueWithinRange(5, 1444);
    List<FreeBusyResponseType> results = null;
    ArrayList<FreeBusy> ret = new ArrayList<FreeBusy>();
    Request r = req.get(0);
    long start = Request.offsetInterval(req.get(0).start, fb_interval);
    ServerInfo serverInfo = (ServerInfo) r.data;
    if (serverInfo == null) {
        ZimbraLog.fb.warn("no exchange server info for user " + r.email);
        return ret;
    }
    if (!serverInfo.enabled)
        return ret;
    ArrayOfMailboxData attendees = new ArrayOfMailboxData();
    for (Request request : req) {
        EmailAddress email = new EmailAddress();
        email.setAddress(request.email);
        MailboxData mailbox = new MailboxData();
        mailbox.setEmail(email);
        mailbox.setAttendeeType(MeetingAttendeeType.REQUIRED);
        attendees.getMailboxData().add(mailbox);
    }
    try {
        Duration duration = new Duration();
        DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
        GregorianCalendar gregorianCalStart = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gregorianCalStart.setTimeInMillis(start);
        duration.setStartTime(datatypeFactory.newXMLGregorianCalendar(gregorianCalStart));
        GregorianCalendar gregorianCalEnd = new GregorianCalendar(TimeZone.getTimeZone("GMT"));
        gregorianCalEnd.setTimeInMillis(req.get(0).end);
        duration.setEndTime(datatypeFactory.newXMLGregorianCalendar(gregorianCalEnd));
        FreeBusyViewOptionsType availabilityOpts = new FreeBusyViewOptionsType();
        availabilityOpts.setMergedFreeBusyIntervalInMinutes(fb_interval);
        availabilityOpts.getRequestedView().add("MergedOnly");
        availabilityOpts.setTimeWindow(duration);
        GetUserAvailabilityRequestType availabilityRequest = new GetUserAvailabilityRequestType();
        // TODO: check if we need to set request timezone
        SerializableTimeZone timezone = new SerializableTimeZone();
        timezone.setBias(0);
        SerializableTimeZoneTime standardTime = new SerializableTimeZoneTime();
        standardTime.setTime("00:00:00");
        standardTime.setDayOrder((short) 1);
        standardTime.setDayOfWeek(DayOfWeekType.SUNDAY);
        timezone.setStandardTime(standardTime);
        timezone.setDaylightTime(standardTime);
        availabilityRequest.setTimeZone(timezone);
        availabilityRequest.setFreeBusyViewOptions(availabilityOpts);
        availabilityRequest.setMailboxDataArray(attendees);
        RequestServerVersion serverVersion = new RequestServerVersion();
        serverVersion.setVersion(ExchangeVersionType.EXCHANGE_2010_SP_1);
        Holder<GetUserAvailabilityResponseType> availabilityResponse = new Holder<GetUserAvailabilityResponseType>();
        Holder<ServerVersionInfo> gfversionInfo = new Holder<ServerVersionInfo>();
        service.getUserAvailability(availabilityRequest, availabilityResponse, gfversionInfo);
        results = availabilityResponse.value.getFreeBusyResponseArray().getFreeBusyResponse();
    } catch (DatatypeConfigurationException dce) {
        ZimbraLog.fb.warn("getFreeBusyForHost DatatypeConfiguration failure", dce);
        return getEmptyList(req);
    } catch (Exception e) {
        ZimbraLog.fb.warn("getFreeBusyForHost failure", e);
        return getEmptyList(req);
    }
    for (Request re : req) {
        String fb = "";
        int i = 0;
        for (FreeBusyResponseType attendeeAvailability : results) {
            if (re.email == attendees.getMailboxData().get(i).getEmail().getAddress()) {
                if (ResponseClassType.SUCCESS != attendeeAvailability.getResponseMessage().getResponseClass()) {
                    ZimbraLog.fb.warn(attendeeAvailability.getResponseMessage().getMessageText());
                    ZimbraLog.fb.warn("Error in response. continuing to next one");
                    i++;
                    continue;
                }
                ZimbraLog.fb.debug("Availability for " + attendees.getMailboxData().get(i).getEmail().getAddress() + " [" + attendeeAvailability.getFreeBusyView().getMergedFreeBusy() + "]");
                fb = attendeeAvailability.getFreeBusyView().getMergedFreeBusy();
                if (fb == null) {
                    ZimbraLog.fb.warn("Merged view Free Busy info not avaiable");
                    //Avoid NPE.
                    fb = "";
                }
                break;
            }
            i++;
        }
        ret.add(new ExchangeFreeBusyProvider.ExchangeUserFreeBusy(fb, re.email, fb_interval, req.get(0).start, req.get(0).end));
    }
    return ret;
}
Also used : ServerInfo(com.zimbra.cs.fb.ExchangeFreeBusyProvider.ServerInfo) ArrayList(java.util.ArrayList) RequestServerVersion(com.microsoft.schemas.exchange.services._2006.types.RequestServerVersion) GetUserAvailabilityResponseType(com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityResponseType) ServerVersionInfo(com.microsoft.schemas.exchange.services._2006.types.ServerVersionInfo) FreeBusyResponseType(com.microsoft.schemas.exchange.services._2006.messages.FreeBusyResponseType) FreeBusyViewOptionsType(com.microsoft.schemas.exchange.services._2006.types.FreeBusyViewOptionsType) SerializableTimeZoneTime(com.microsoft.schemas.exchange.services._2006.types.SerializableTimeZoneTime) DatatypeFactory(javax.xml.datatype.DatatypeFactory) ArrayOfMailboxData(com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData) Holder(javax.xml.ws.Holder) MailboxData(com.microsoft.schemas.exchange.services._2006.types.MailboxData) ArrayOfMailboxData(com.microsoft.schemas.exchange.services._2006.types.ArrayOfMailboxData) GregorianCalendar(java.util.GregorianCalendar) Duration(com.microsoft.schemas.exchange.services._2006.types.Duration) SerializableTimeZone(com.microsoft.schemas.exchange.services._2006.types.SerializableTimeZone) EmailAddress(com.microsoft.schemas.exchange.services._2006.types.EmailAddress) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ServiceException(com.zimbra.common.service.ServiceException) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) CertificateException(java.security.cert.CertificateException) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) GetUserAvailabilityRequestType(com.microsoft.schemas.exchange.services._2006.messages.GetUserAvailabilityRequestType)

Example 30 with Holder

use of javax.xml.ws.Holder in project zm-mailbox by Zimbra.

the class ExchangeEWSFreeBusyProvider method bindFolder.

BaseFolderType bindFolder(DistinguishedFolderIdNameType distinguishedFolderId, DefaultShapeNamesType shapeType) {
    final DistinguishedFolderIdType distinguishedFolderIdType = new DistinguishedFolderIdType();
    distinguishedFolderIdType.setId(distinguishedFolderId);
    final NonEmptyArrayOfBaseFolderIdsType nonEmptyArrayOfBaseFolderIdsType = new NonEmptyArrayOfBaseFolderIdsType();
    nonEmptyArrayOfBaseFolderIdsType.getFolderIdOrDistinguishedFolderId().add(distinguishedFolderIdType);
    GetFolderType getFolderRequest = new GetFolderType();
    getFolderRequest.setFolderIds(nonEmptyArrayOfBaseFolderIdsType);
    FolderResponseShapeType stResp = new FolderResponseShapeType();
    stResp.setBaseShape(shapeType);
    getFolderRequest.setFolderShape(stResp);
    RequestServerVersion serverVersion = new RequestServerVersion();
    serverVersion.setVersion(ExchangeVersionType.EXCHANGE_2010_SP_1);
    Holder<ServerVersionInfo> gfversionInfo = new Holder<ServerVersionInfo>();
    Holder<GetFolderResponseType> gfresponseHolder = new Holder<GetFolderResponseType>();
    MailboxCultureType mct = new MailboxCultureType();
    mct.setValue("EN");
    TimeZoneDefinitionType tzdt = new TimeZoneDefinitionType();
    tzdt.setId("Greenwich Standard Time");
    TimeZoneContextType tzct = new TimeZoneContextType();
    tzct.setTimeZoneDefinition(tzdt);
    service.getFolder(getFolderRequest, mct, serverVersion, tzct, gfresponseHolder, gfversionInfo);
    FolderInfoResponseMessageType firmtResp = (FolderInfoResponseMessageType) gfresponseHolder.value.getResponseMessages().getCreateItemResponseMessageOrDeleteItemResponseMessageOrGetItemResponseMessage().get(0).getValue();
    if (firmtResp.getFolders().getFolderOrCalendarFolderOrContactsFolder().size() > 0) {
        return firmtResp.getFolders().getFolderOrCalendarFolderOrContactsFolder().get(0);
    } else {
        ZimbraLog.fb.error("Could not find the folder in Exchange : " + distinguishedFolderId.toString());
    }
    return null;
}
Also used : NonEmptyArrayOfBaseFolderIdsType(com.microsoft.schemas.exchange.services._2006.types.NonEmptyArrayOfBaseFolderIdsType) Holder(javax.xml.ws.Holder) TimeZoneContextType(com.microsoft.schemas.exchange.services._2006.types.TimeZoneContextType) FolderInfoResponseMessageType(com.microsoft.schemas.exchange.services._2006.messages.FolderInfoResponseMessageType) FolderResponseShapeType(com.microsoft.schemas.exchange.services._2006.types.FolderResponseShapeType) DistinguishedFolderIdType(com.microsoft.schemas.exchange.services._2006.types.DistinguishedFolderIdType) GetFolderResponseType(com.microsoft.schemas.exchange.services._2006.messages.GetFolderResponseType) RequestServerVersion(com.microsoft.schemas.exchange.services._2006.types.RequestServerVersion) TimeZoneDefinitionType(com.microsoft.schemas.exchange.services._2006.types.TimeZoneDefinitionType) ServerVersionInfo(com.microsoft.schemas.exchange.services._2006.types.ServerVersionInfo) GetFolderType(com.microsoft.schemas.exchange.services._2006.messages.GetFolderType) MailboxCultureType(com.microsoft.schemas.exchange.services._2006.types.MailboxCultureType)

Aggregations

Holder (javax.xml.ws.Holder)129 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)77 Test (org.testng.annotations.Test)53 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)48 SelectorQualifiedGetOptionsType (com.evolveum.midpoint.xml.ns._public.common.common_3.SelectorQualifiedGetOptionsType)33 AbstractModelIntegrationTest (com.evolveum.midpoint.model.test.AbstractModelIntegrationTest)29 UserType (com.evolveum.midpoint.xml.ns._public.common.common_3.UserType)29 PrismAsserts.assertEqualsPolyString (com.evolveum.midpoint.prism.util.PrismAsserts.assertEqualsPolyString)24 ObjectListType (com.evolveum.midpoint.xml.ns._public.common.api_types_3.ObjectListType)23 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)23 Test (org.junit.Test)23 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)21 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)21 ShadowType (com.evolveum.midpoint.xml.ns._public.common.common_3.ShadowType)19 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)18 ObjectReferenceType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType)16 GenericObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.GenericObjectType)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 IpPort (io.servicecomb.foundation.common.net.IpPort)14 ClientException (io.servicecomb.serviceregistry.client.ClientException)14