Search in sources :

Example 81 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class FiqlSearchConditionBuilderTest method testLessOrEqualToDuration.

@Test
public void testLessOrEqualToDuration() throws DatatypeConfigurationException {
    Duration d = DatatypeFactory.newInstance().newDuration(false, 0, 0, 1, 12, 0, 0);
    String ret = b.is("foo").notAfter(d).query();
    assertEquals("foo=le=-P0Y0M1DT12H0M0S", ret);
}
Also used : Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 82 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class Proxy method createSequence.

public CreateSequenceResponseType createSequence(EndpointReferenceType defaultAcksTo, RelatesToType relatesTo, boolean isServer, final ProtocolVariation protocol, final Exchange exchange, Map<String, Object> context) throws RMException {
    this.sequenceContext = context;
    SourcePolicyType sp = reliableEndpoint.getManager().getSourcePolicy();
    CreateSequenceType create = new CreateSequenceType();
    String address = sp.getAcksTo();
    final EndpointReferenceType acksTo;
    if (null != address) {
        acksTo = RMUtils.createReference(address);
    } else {
        acksTo = defaultAcksTo;
    }
    create.setAcksTo(acksTo);
    Duration d = sp.getSequenceExpiration();
    if (null != d) {
        Expires expires = new Expires();
        expires.setValue(d);
        create.setExpires(expires);
    }
    if (sp.isIncludeOffer()) {
        OfferType offer = new OfferType();
        d = sp.getOfferedSequenceExpiration();
        if (null != d) {
            Expires expires = new Expires();
            expires.setValue(d);
            offer.setExpires(expires);
        }
        offer.setIdentifier(reliableEndpoint.getSource().generateSequenceIdentifier());
        offer.setEndpoint(acksTo);
        create.setOffer(offer);
        setOfferedIdentifier(offer);
    }
    InterfaceInfo ii = reliableEndpoint.getEndpoint(protocol).getEndpointInfo().getService().getInterface();
    EncoderDecoder codec = protocol.getCodec();
    RMConstants constants = codec.getConstants();
    final OperationInfo oi = isServer ? ii.getOperation(constants.getCreateSequenceOnewayOperationName()) : ii.getOperation(constants.getCreateSequenceOperationName());
    final Object send = codec.convertToSend(create);
    if (isServer) {
        LOG.fine("sending CreateSequenceRequest from server side");
        Runnable r = new Runnable() {

            public void run() {
                try {
                    invoke(oi, protocol, new Object[] { send }, null, exchange);
                } catch (RMException ex) {
                // already logged
                }
            }
        };
        Executor ex = reliableEndpoint.getApplicationEndpoint().getExecutor();
        if (ex == null) {
            ex = SynchronousExecutor.getInstance();
        }
        ex.execute(r);
        return null;
    }
    Object resp = invoke(oi, protocol, new Object[] { send }, context, exchange);
    return codec.convertReceivedCreateSequenceResponse(resp);
}
Also used : BindingOperationInfo(org.apache.cxf.service.model.BindingOperationInfo) OperationInfo(org.apache.cxf.service.model.OperationInfo) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) Duration(javax.xml.datatype.Duration) OfferType(org.apache.cxf.ws.rm.v200702.OfferType) Executor(java.util.concurrent.Executor) SynchronousExecutor(org.apache.cxf.workqueue.SynchronousExecutor) CreateSequenceType(org.apache.cxf.ws.rm.v200702.CreateSequenceType) SourcePolicyType(org.apache.cxf.ws.rm.manager.SourcePolicyType) Expires(org.apache.cxf.ws.rm.v200702.Expires) InterfaceInfo(org.apache.cxf.service.model.InterfaceInfo)

Example 83 with Duration

use of javax.xml.datatype.Duration in project cxf by apache.

the class AbstractTypeTestClient method testDuration.

@Test
public void testDuration() throws Exception {
    if (!shouldRunTest("Duration")) {
        return;
    }
    javax.xml.datatype.DatatypeFactory datatypeFactory = javax.xml.datatype.DatatypeFactory.newInstance();
    Duration x = datatypeFactory.newDuration("P1Y35DT60M60.500S");
    Duration yOrig = datatypeFactory.newDuration("-P2MT24H60S");
    Holder<Duration> y = new Holder<>(yOrig);
    Holder<Duration> z = new Holder<>();
    Duration ret;
    if (testDocLiteral) {
        ret = docClient.testDuration(x, y, z);
    } else if (testXMLBinding) {
        ret = xmlClient.testDuration(x, y, z);
    } else {
        ret = rpcClient.testDuration(x, y, z);
    }
    assertEquals("testDuration(): Incorrect value for inout param", x, y.value);
    assertEquals("testDuration(): Incorrect value for out param", yOrig, z.value);
    assertEquals("testDuration(): Incorrect return value", x, ret);
}
Also used : Holder(javax.xml.ws.Holder) Duration(javax.xml.datatype.Duration) Test(org.junit.Test)

Example 84 with Duration

use of javax.xml.datatype.Duration in project iaf by ibissource.

the class IdinSender method sendMessage.

@Override
public Message sendMessage(Message message, PipeLineSession session) throws SenderException, TimeoutException {
    Element queryElement = null;
    try {
        if (XmlUtils.isWellFormed(message.asString(), "idin")) {
            queryElement = XmlUtils.buildElement(message.asString());
        } else {
            queryElement = XmlUtils.buildElement("<idin/>");
        }
    } catch (DomBuilderException | IOException e) {
        throw new SenderException(e);
    }
    XmlBuilder result = new XmlBuilder("result");
    ErrorResponse error = null;
    if (getAction().equals("DIRECTORY")) {
        DirectoryResponse response = getCommunicator().getDirectory();
        if (response.getIsError()) {
            error = response.getErrorResponse();
        } else {
            XmlBuilder issuers = new XmlBuilder("issuers");
            if (XmlUtils.getChildTagAsBoolean(queryElement, "issuersByCountry")) {
                for (Entry<String, List<Issuer>> entry : response.getIssuersByCountry().entrySet()) {
                    XmlBuilder countryXml = new XmlBuilder("country");
                    String country = entry.getKey();
                    countryXml.addAttribute("name", country);
                    for (Issuer issuer : entry.getValue()) {
                        XmlBuilder issuerXml = new XmlBuilder("issuer");
                        issuerXml.setValue(issuer.getIssuerName());
                        issuerXml.addAttribute("id", issuer.getIssuerID());
                        countryXml.addSubElement(issuerXml);
                    }
                    issuers.addSubElement(countryXml);
                }
            } else {
                for (Issuer issuer : response.getIssuers()) {
                    XmlBuilder issuerXml = new XmlBuilder("issuer");
                    issuerXml.setValue(issuer.getIssuerName());
                    issuerXml.addAttribute("id", issuer.getIssuerID());
                    issuerXml.addAttribute("country", issuer.getIssuerCountry());
                    issuers.addSubElement(issuerXml);
                }
            }
            result.addSubElement(issuers);
            XmlBuilder timestamp = new XmlBuilder("timestamp");
            Date txDate = response.getDirectoryDateTimestamp().toGregorianCalendar().getTime();
            timestamp.setValue(DateUtils.format(txDate, "yyyy-MM-dd HH:mm:ss.SSS"), false);
            result.addSubElement(timestamp);
        }
        if (StringUtils.isNotEmpty(response.getRawMessage())) {
            log.debug(response.getRawMessage());
        }
    } else if (getAction().equals("RESPONSE")) {
        String transactionID = XmlUtils.getChildTagAsString(queryElement, "transactionID");
        if (StringUtils.isEmpty(transactionID))
            throw new SenderException("no transactionID was supplied");
        StatusRequest statusRequest = new StatusRequest();
        statusRequest.setTransactionID(transactionID);
        StatusResponse response = getCommunicator().getResponse(statusRequest);
        if (response.getIsError()) {
            error = response.getErrorResponse();
        } else {
            XmlBuilder status = new XmlBuilder("status");
            status.setValue(response.getStatus(), false);
            result.addSubElement(status);
            if (response.getStatus() == StatusResponse.Success) {
                SamlResponse saml = response.getSamlResponse();
                XmlBuilder samlXml = new XmlBuilder("saml");
                XmlBuilder acquirerId = new XmlBuilder("acquirerId");
                acquirerId.setValue(saml.getAcquirerID());
                samlXml.addSubElement(acquirerId);
                XmlBuilder attributes = new XmlBuilder("attributes");
                for (Entry<String, String> entry : saml.getAttributes().entrySet()) {
                    XmlBuilder attribute = new XmlBuilder("attribute");
                    attribute.addAttribute("name", entry.getKey());
                    attribute.setValue(entry.getValue());
                    attributes.addSubElement(attribute);
                }
                samlXml.addSubElement(attributes);
                XmlBuilder merchantReference = new XmlBuilder("merchantReference");
                merchantReference.setValue(saml.getMerchantReference());
                samlXml.addSubElement(merchantReference);
                XmlBuilder version = new XmlBuilder("version");
                version.setValue(saml.getAcquirerID());
                samlXml.addSubElement(version);
                result.addSubElement(samlXml);
            }
            XmlBuilder transactionIdXml = new XmlBuilder("transactionID");
            transactionIdXml.setValue(response.getTransactionID(), false);
            result.addSubElement(transactionIdXml);
            XmlBuilder timestamp = new XmlBuilder("timestamp");
            Date txDate = response.getStatusDateTimestamp().toGregorianCalendar().getTime();
            timestamp.setValue(DateUtils.format(txDate, "yyyy-MM-dd HH:mm:ss.SSS"), false);
            result.addSubElement(timestamp);
        }
        if (StringUtils.isNotEmpty(response.getRawMessage())) {
            log.debug(response.getRawMessage());
        }
    } else if (getAction().equals("AUTHENTICATE")) {
        AuthenticationRequest authRequest = new AuthenticationRequest();
        String issuerId = XmlUtils.getChildTagAsString(queryElement, "issuerId");
        if (StringUtils.isEmpty(issuerId))
            throw new SenderException("no issuerId was supplied");
        authRequest.setIssuerID(issuerId);
        String language = XmlUtils.getChildTagAsString(queryElement, "language");
        if (StringUtils.isNotEmpty(language))
            authRequest.setLanguage(language);
        String expirationPeriod = XmlUtils.getChildTagAsString(queryElement, "expirationPeriod");
        if (StringUtils.isNotEmpty(expirationPeriod)) {
            try {
                Duration duration = DatatypeFactory.newInstance().newDuration(expirationPeriod);
                authRequest.setExpirationPeriod(duration);
            } catch (DatatypeConfigurationException e) {
                throw new SenderException(e);
            }
        }
        String requestedServiceId = XmlUtils.getChildTagAsString(queryElement, "requestedServiceId");
        if (StringUtils.isNotEmpty(requestedServiceId)) {
            authRequest.setRequestedServiceID(new ServiceId(requestedServiceId));
        }
        String merchantReference = XmlUtils.getChildTagAsString(queryElement, "merchantReference");
        if (StringUtils.isNotEmpty(requestedServiceId))
            authRequest.setMerchantReference(merchantReference);
        AssuranceLevel assuranceLevel = AssuranceLevel.Loa3;
        String assurance = XmlUtils.getChildTagAsString(queryElement, "assuranceLevel");
        if (StringUtils.isNotEmpty(assurance))
            assuranceLevel = AssuranceLevel.valueOf(assurance);
        authRequest.setAssuranceLevel(assuranceLevel);
        String entranceCode = XmlUtils.getChildTagAsString(queryElement, "entranceCode");
        if (StringUtils.isNotEmpty(entranceCode))
            authRequest.setEntranceCode(entranceCode);
        AuthenticationResponse response = getCommunicator().newAuthenticationRequest(authRequest);
        if (response.getIsError()) {
            error = response.getErrorResponse();
        } else {
            XmlBuilder authenticationURL = new XmlBuilder("authenticationURL");
            authenticationURL.setValue(response.getIssuerAuthenticationURL(), false);
            result.addSubElement(authenticationURL);
            XmlBuilder transactionIdXml = new XmlBuilder("transactionID");
            transactionIdXml.setValue(response.getTransactionID(), false);
            result.addSubElement(transactionIdXml);
            XmlBuilder creationTime = new XmlBuilder("creationTime");
            Date txDate = response.getTransactionCreateDateTimestamp().toGregorianCalendar().getTime();
            creationTime.setValue(DateUtils.format(txDate, "yyyy-MM-dd HH:mm:ss.SSS"), false);
            result.addSubElement(creationTime);
        }
        if (StringUtils.isNotEmpty(response.getRawMessage())) {
            log.debug(response.getRawMessage());
        }
    }
    if (error != null) {
        XmlBuilder errorXml = new XmlBuilder("error");
        XmlBuilder statusCodeXml = new XmlBuilder("statusCode");
        statusCodeXml.setValue(error.getErrorCode());
        errorXml.addSubElement(statusCodeXml);
        XmlBuilder detailsXml = new XmlBuilder("details");
        detailsXml.setValue(error.getErrorDetails());
        errorXml.addSubElement(detailsXml);
        XmlBuilder messageXml = new XmlBuilder("message");
        messageXml.setValue(error.getErrorMessage());
        errorXml.addSubElement(messageXml);
        result.addSubElement(errorXml);
    }
    return new Message(result.toXML());
}
Also used : StatusRequest(net.bankid.merchant.library.StatusRequest) Message(nl.nn.adapterframework.stream.Message) Issuer(net.bankid.merchant.library.internal.DirectoryResponseBase.Issuer) Element(org.w3c.dom.Element) Duration(javax.xml.datatype.Duration) IOException(java.io.IOException) StatusResponse(net.bankid.merchant.library.StatusResponse) AuthenticationResponse(net.bankid.merchant.library.AuthenticationResponse) Date(java.util.Date) ErrorResponse(net.bankid.merchant.library.ErrorResponse) ServiceId(net.bankid.merchant.library.ServiceId) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) Entry(java.util.Map.Entry) AssuranceLevel(net.bankid.merchant.library.AssuranceLevel) DirectoryResponse(net.bankid.merchant.library.DirectoryResponse) XmlBuilder(nl.nn.adapterframework.util.XmlBuilder) List(java.util.List) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) SamlResponse(net.bankid.merchant.library.SamlResponse) SenderException(nl.nn.adapterframework.core.SenderException) AuthenticationRequest(net.bankid.merchant.library.AuthenticationRequest)

Example 85 with Duration

use of javax.xml.datatype.Duration in project midpoint by Evolveum.

the class JobExecutor method getRescheduleTime.

private RescheduleTime getRescheduleTime(TaskExecutionConstraintsType executionConstraints, int defaultInterval, Long nextTaskRunTime) {
    long retryAt;
    Duration retryAfter = executionConstraints != null ? executionConstraints.getRetryAfter() : null;
    if (retryAfter != null) {
        retryAt = XmlTypeConverter.toMillis(XmlTypeConverter.addDuration(XmlTypeConverter.createXMLGregorianCalendar(new Date()), retryAfter));
    } else {
        retryAt = System.currentTimeMillis() + defaultInterval * 1000L;
    }
    if (nextTaskRunTime != null && nextTaskRunTime < retryAt) {
        return new RescheduleTime(nextTaskRunTime, true);
    } else {
        return new RescheduleTime(retryAt, false);
    }
}
Also used : Duration(javax.xml.datatype.Duration) Date(java.util.Date)

Aggregations

Duration (javax.xml.datatype.Duration)137 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)57 Test (org.junit.Test)16 ArrayList (java.util.ArrayList)14 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)12 Date (java.util.Date)12 BigDecimal (java.math.BigDecimal)9 Calendar (java.util.Calendar)9 GregorianCalendar (java.util.GregorianCalendar)9 ObjectDeltaType (com.evolveum.prism.xml.ns._public.types_3.ObjectDeltaType)8 ItemPath (com.evolveum.midpoint.prism.path.ItemPath)7 CleanupPolicyType (com.evolveum.midpoint.xml.ns._public.common.common_3.CleanupPolicyType)6 ItemDelta (com.evolveum.midpoint.prism.delta.ItemDelta)5 IOException (java.io.IOException)5 XSDayTimeDuration (org.eclipse.wst.xml.xpath2.processor.internal.types.XSDayTimeDuration)5 FileNotFoundException (java.io.FileNotFoundException)4 Collection (java.util.Collection)4 DatatypeFactory (javax.xml.datatype.DatatypeFactory)4 NotNull (org.jetbrains.annotations.NotNull)4 PrismObject (com.evolveum.midpoint.prism.PrismObject)3