Search in sources :

Example 16 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException 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);
        // Request for highest hierarchy view. The rest hierarchy will be Detailed->FreeBusy->MergedOnly->None
        availabilityOpts.getRequestedView().add("DetailedMerged");
        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>();
        TimeZoneDefinitionType tzdt = new TimeZoneDefinitionType();
        tzdt.setId("Greenwich Standard Time");
        TimeZoneContextType tzct = new TimeZoneContextType();
        tzct.setTimeZoneDefinition(tzdt);
        service.getUserAvailability(availabilityRequest, tzct, serverVersion, 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) {
        int i = 0;
        long startTime = req.get(0).start;
        long endTime = req.get(0).end;
        for (FreeBusyResponseType attendeeAvailability : results) {
            if (attendeeAvailability.getFreeBusyView() != null) {
                String fbResponseViewType = attendeeAvailability.getFreeBusyView().getFreeBusyViewType().get(0);
                String emailAddress = attendees.getMailboxData().get(i).getEmail().getAddress();
                ZimbraLog.fb.debug("For user :%s free busy response type received is : %s", emailAddress, fbResponseViewType);
                if (re.email == emailAddress) {
                    if (ResponseClassType.ERROR == attendeeAvailability.getResponseMessage().getResponseClass()) {
                        ZimbraLog.fb.debug("Unable to fetch free busy for %s  error code %s :: %s", emailAddress, attendeeAvailability.getResponseMessage().getResponseCode(), attendeeAvailability.getResponseMessage().getMessageText());
                        FreeBusy npFreeBusy = FreeBusy.nodataFreeBusy(emailAddress, startTime, endTime);
                        ret.add(npFreeBusy);
                        if (attendeeAvailability.getResponseMessage().getResponseCode().equals(ResponseCodeType.ERROR_NO_FREE_BUSY_ACCESS)) {
                            npFreeBusy.mList.getHead().hasPermission = false;
                        }
                        ZimbraLog.fb.info("Error in response. continuing to next one sending nodata as response");
                        i++;
                        continue;
                    }
                    String fb = attendeeAvailability.getFreeBusyView().getMergedFreeBusy();
                    ZimbraLog.fb.info("Merged view Free Busy info received for user:%s is %s: ", emailAddress, fb);
                    ArrayList<FreeBusy> userIntervals = new ArrayList<FreeBusy>();
                    if (fb == null) {
                        ZimbraLog.fb.warn("Merged view Free Busy info not avaiable for the user");
                        // Avoid NPE.
                        fb = "";
                    } else {
                        userIntervals.add(new ExchangeFreeBusyProvider.ExchangeUserFreeBusy(fb, re.email, fb_interval, startTime, endTime));
                        ret.addAll(userIntervals);
                    }
                    // Parsing Detailed fb view response
                    if ("DetailedMerged".equals(fbResponseViewType) || "FreeBusyMerged".equals(fbResponseViewType)) {
                        parseDetailedFreeBusyResponse(emailAddress, startTime, endTime, attendeeAvailability, userIntervals);
                        ret.addAll(userIntervals);
                    } else {
                        // No FreeBusy view information available. returning nodata freebusy in response
                        ZimbraLog.fb.debug("No Free Busy view info avaiable for [%s], free busy view type from response : %s", emailAddress, fbResponseViewType);
                        ret.add(FreeBusy.nodataFreeBusy(emailAddress, startTime, endTime));
                    }
                }
                i++;
            }
        }
    }
    return ret;
}
Also used : ServerInfo(com.zimbra.cs.fb.ExchangeFreeBusyProvider.ServerInfo) TimeZoneContextType(com.microsoft.schemas.exchange.services._2006.types.TimeZoneContextType) ArrayList(java.util.ArrayList) RequestServerVersion(com.microsoft.schemas.exchange.services._2006.types.RequestServerVersion) TimeZoneDefinitionType(com.microsoft.schemas.exchange.services._2006.types.TimeZoneDefinitionType) 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 17 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project openolat by klemens.

the class ManifestMetadataBuilder method setOpenOLATMetadataCopiedAt.

public void setOpenOLATMetadataCopiedAt(Date date) {
    try {
        GregorianCalendar cal = new GregorianCalendar();
        cal.setTime(date);
        getOpenOLATMetadata(true).setCopiedAt(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
    } catch (DatatypeConfigurationException e) {
        log.error("", e);
    }
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) GregorianCalendar(java.util.GregorianCalendar)

Example 18 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project ddf by codice.

the class DateTimeAdapter method marshalFrom.

public static DateTimeElement marshalFrom(Attribute attribute) {
    DateTimeElement element = new DateTimeElement();
    element.setName(attribute.getName());
    if (attribute.getValue() != null) {
        for (Serializable value : attribute.getValues()) {
            if (!(value instanceof Date)) {
                continue;
            }
            Date date = (Date) value;
            GregorianCalendar cal = new GregorianCalendar();
            cal.setTime(date);
            try {
                ((DateTimeElement) element).getValue().add(DatatypeFactory.newInstance().newXMLGregorianCalendar(cal));
            } catch (DatatypeConfigurationException e) {
                LOGGER.debug("Could not parse Metacard Attribute. XML Date could not be generated.", e);
            }
        }
    }
    return element;
}
Also used : DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Serializable(java.io.Serializable) DateTimeElement(ddf.catalog.transformer.xml.binding.DateTimeElement) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Date(java.util.Date)

Example 19 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project ddf by codice.

the class CswQueryResponseTransformer method writeAcknowledgement.

private ByteArrayOutputStream writeAcknowledgement(GetRecordsType request) throws CatalogTransformerException {
    try {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        JAXBContext jaxBContext = JAXBContext.newInstance("net.opengis.cat.csw.v_2_0_2:" + "net.opengis.filter.v_1_1_0:net.opengis.gml.v_3_1_1:net.opengis.ows.v_1_0_0");
        Marshaller marshaller = jaxBContext.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        AcknowledgementType ack = new AcknowledgementType();
        EchoedRequestType echoedRequest = new EchoedRequestType();
        JAXBElement<GetRecordsType> jaxBRequest = new ObjectFactory().createGetRecords(request);
        echoedRequest.setAny(jaxBRequest);
        ack.setEchoedRequest(echoedRequest);
        try {
            ack.setTimeStamp(DatatypeFactory.newInstance().newXMLGregorianCalendar(new GregorianCalendar()));
        } catch (DatatypeConfigurationException e) {
            LOGGER.debug("Failed to set timestamp on Acknowledgement", e);
        }
        JAXBElement<AcknowledgementType> jaxBAck = new ObjectFactory().createAcknowledgement(ack);
        marshaller.marshal(jaxBAck, byteArrayOutputStream);
        return byteArrayOutputStream;
    } catch (JAXBException e) {
        throw new CatalogTransformerException(e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) JAXBException(javax.xml.bind.JAXBException) GregorianCalendar(java.util.GregorianCalendar) EchoedRequestType(net.opengis.cat.csw.v_2_0_2.EchoedRequestType) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) JAXBContext(javax.xml.bind.JAXBContext) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ObjectFactory(net.opengis.cat.csw.v_2_0_2.ObjectFactory) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType)

Example 20 with DatatypeConfigurationException

use of javax.xml.datatype.DatatypeConfigurationException in project metron by apache.

the class TaxiiHandler method run.

/**
 * The action to be performed by this timer task.
 */
@Override
public void run() {
    if (inProgress) {
        return;
    }
    Date ts = new Date();
    LOG.info("Polling...{}", new SimpleDateFormat().format(ts));
    try {
        inProgress = true;
        // Prepare the message to send.
        String sessionID = MessageHelper.generateMessageId();
        PollRequest request = messageFactory.get().createPollRequest().withMessageId(sessionID).withCollectionName(collection);
        if (subscriptionId != null) {
            request = request.withSubscriptionID(subscriptionId);
        } else {
            request = request.withPollParameters(messageFactory.get().createPollParametersType());
        }
        if (beginTime != null) {
            Calendar gc = GregorianCalendar.getInstance();
            gc.setTime(beginTime);
            XMLGregorianCalendar gTime = null;
            try {
                gTime = DatatypeFactory.newInstance().newXMLGregorianCalendar((GregorianCalendar) gc).normalize();
            } catch (DatatypeConfigurationException e) {
                RuntimeErrors.ILLEGAL_STATE.throwRuntime("Unable to set the begin time due to", e);
            }
            gTime.setFractionalSecond(null);
            LOG.info("Begin Time: {}", gTime);
            request.setExclusiveBeginTimestamp(gTime);
        }
        try {
            PollResponse response = call(request, PollResponse.class);
            LOG.info("Got Poll Response with {} blocks", response.getContentBlocks().size());
            int numProcessed = 0;
            long avgTimeMS = 0;
            long timeStartedBlock = System.currentTimeMillis();
            for (ContentBlock block : response.getContentBlocks()) {
                AnyMixedContentType content = block.getContent();
                for (Object o : content.getContent()) {
                    numProcessed++;
                    long timeS = System.currentTimeMillis();
                    String xml = null;
                    if (o instanceof Element) {
                        Element element = (Element) o;
                        xml = getStringFromDocument(element.getOwnerDocument());
                        if (LOG.isDebugEnabled() && Math.random() < 0.01) {
                            LOG.debug("Random Stix doc: {}", xml);
                        }
                        for (LookupKV<EnrichmentKey, EnrichmentValue> kv : extractor.extract(xml)) {
                            if (allowedIndicatorTypes.isEmpty() || allowedIndicatorTypes.contains(kv.getKey().type)) {
                                kv.getValue().getMetadata().put("source_type", "taxii");
                                kv.getValue().getMetadata().put("taxii_url", endpoint.toString());
                                kv.getValue().getMetadata().put("taxii_collection", collection);
                                Put p = converter.toPut(columnFamily, kv.getKey(), kv.getValue());
                                Table table = getTable(hbaseTable);
                                table.put(p);
                                LOG.info("Found Threat Intel: {} => ", kv.getKey(), kv.getValue());
                            }
                        }
                    }
                    avgTimeMS += System.currentTimeMillis() - timeS;
                }
                if ((numProcessed + 1) % 100 == 0) {
                    LOG.info("Processed {}  in {} ms, avg time: {}", numProcessed, System.currentTimeMillis() - timeStartedBlock, avgTimeMS / content.getContent().size());
                    timeStartedBlock = System.currentTimeMillis();
                    avgTimeMS = 0;
                    numProcessed = 0;
                }
            }
        } catch (Exception e) {
            LOG.error(e.getMessage(), e);
            throw new RuntimeException("Unable to make request", e);
        }
    } finally {
        inProgress = false;
        beginTime = ts;
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) PollRequest(org.mitre.taxii.messages.xml11.PollRequest) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Element(org.w3c.dom.Element) Date(java.util.Date) EnrichmentKey(org.apache.metron.enrichment.converter.EnrichmentKey) Put(org.apache.hadoop.hbase.client.Put) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) JAXBException(javax.xml.bind.JAXBException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) ContentBlock(org.mitre.taxii.messages.xml11.ContentBlock) PollResponse(org.mitre.taxii.messages.xml11.PollResponse) AnyMixedContentType(org.mitre.taxii.messages.xml11.AnyMixedContentType) SimpleDateFormat(java.text.SimpleDateFormat) EnrichmentValue(org.apache.metron.enrichment.converter.EnrichmentValue)

Aggregations

DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)56 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)35 GregorianCalendar (java.util.GregorianCalendar)33 DatatypeFactory (javax.xml.datatype.DatatypeFactory)20 Date (java.util.Date)18 BigInteger (java.math.BigInteger)6 ParseException (java.text.ParseException)6 JAXBException (javax.xml.bind.JAXBException)5 QName (javax.xml.namespace.QName)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 ConverterException (ch.ehi.ili2db.converter.ConverterException)2 BlackboxType (ch.interlis.ili2c.metamodel.BlackboxType)2 EnumerationType (ch.interlis.ili2c.metamodel.EnumerationType)2 NumericType (ch.interlis.ili2c.metamodel.NumericType)2 PrecisionDecimal (ch.interlis.ili2c.metamodel.PrecisionDecimal)2 IomObject (ch.interlis.iom.IomObject)2 ArrayOfString (com.marketo.mktows.ArrayOfString)2 LastUpdateAtSelector (com.marketo.mktows.LastUpdateAtSelector)2 File (java.io.File)2