Example usage for javax.xml.datatype DatatypeFactory newXMLGregorianCalendar

List of usage examples for javax.xml.datatype DatatypeFactory newXMLGregorianCalendar

Introduction

In this page you can find the example usage for javax.xml.datatype DatatypeFactory newXMLGregorianCalendar.

Prototype

public abstract XMLGregorianCalendar newXMLGregorianCalendar(final GregorianCalendar cal);

Source Link

Document

Create an XMLGregorianCalendar from a GregorianCalendar .

Usage

From source file:org.tolven.app.bean.DataExtractBean.java

public void streamResultsXML(Writer out, DataQueryResults dq) {
    Long totalCount = null;/*w w w.  jav a  2s. c  o  m*/
    if (dq.isReturnTotalCount()) {
        getMDQueryResults(dq, true);
        totalCount = (Long) dq.getIterator().next();
    }

    if (dq.getLimit() != 0) {
        getMDQueryResults(dq, false);
    }
    try {
        XMLStreamWriter xmlStreamWriter = null;
        try {
            XMLOutputFactory factory = XMLOutputFactory.newInstance();
            xmlStreamWriter = factory.createXMLStreamWriter(out);
            xmlStreamWriter.writeStartDocument("UTF-8", "1.0");
            xmlStreamWriter.writeStartElement("results");
            xmlStreamWriter.writeAttribute("path", dq.getPath());
            xmlStreamWriter.writeAttribute("account", String.valueOf(dq.getAccount().getId()));
            xmlStreamWriter.writeAttribute("database",
                    getTolvenPropertiesBean().getProperty("tolven.repository.oid"));
            GregorianCalendar nowCal = new GregorianCalendar();
            nowCal.setTime(dq.getNow());
            DatatypeFactory xmlFactory = DatatypeFactory.newInstance();
            XMLGregorianCalendar ts = xmlFactory.newXMLGregorianCalendar(nowCal);
            xmlStreamWriter.writeAttribute("timestamp", ts.toXMLFormat());
            if (!dq.isItemQuery()) {
                xmlStreamWriter.writeAttribute("offset", Long.toString(dq.getOffset()));
                xmlStreamWriter.writeAttribute("limit", Long.toString(dq.getLimit()));
                xmlStreamWriter.writeAttribute("count", Long.toString(dq.getCount()));
            }
            if (!dq.isItemQuery() && totalCount != null) {
                xmlStreamWriter.writeAttribute("totalCount", totalCount.toString());
            }
            addExtendedFields(dq);
            //addPlaceholderIds(dq);
            if (MenuStructure.PLACEHOLDER.equals(dq.getMenuStructure().getRole())) {
                addParentFields(dq);
            }
            addSimpleXMLColumnHeadings(dq, xmlStreamWriter);
            if (dq.getLimit() != 0) {
                addXMLRows(dq, xmlStreamWriter);
            }
            xmlStreamWriter.writeEndElement();
            xmlStreamWriter.writeEndDocument();
        } finally {
            if (xmlStreamWriter != null) {
                xmlStreamWriter.close();
            }
        }
    } catch (Exception ex) {
        throw new RuntimeException("Could not obtain XML results for menupath: " + dq.getPath()
                + " in account: " + dq.getAccount().getId(), ex);
    }
}

From source file:test.integ.be.e_contract.mycarenet.genins.GenericInsurabilityClientTest.java

@Test
public void testInvoke() throws Exception {
    EHealthSTSClient client = new EHealthSTSClient("https://wwwacc.ehealth.fgov.be/sts_1_1/SecureTokenService");

    Security.addProvider(new BeIDProvider());
    KeyStore keyStore = KeyStore.getInstance("BeID");
    keyStore.load(null);/*from w w w .ja v  a  2 s.  c  om*/
    PrivateKey authnPrivateKey = (PrivateKey) keyStore.getKey("Authentication", null);
    X509Certificate authnCertificate = (X509Certificate) keyStore.getCertificate("Authentication");

    KeyStore eHealthKeyStore = KeyStore.getInstance("PKCS12");
    FileInputStream fileInputStream = new FileInputStream(this.config.getEHealthPKCS12Path());
    eHealthKeyStore.load(fileInputStream, this.config.getEHealthPKCS12Password().toCharArray());
    Enumeration<String> aliasesEnum = eHealthKeyStore.aliases();
    String alias = aliasesEnum.nextElement();
    X509Certificate eHealthCertificate = (X509Certificate) eHealthKeyStore.getCertificate(alias);
    PrivateKey eHealthPrivateKey = (PrivateKey) eHealthKeyStore.getKey(alias,
            this.config.getEHealthPKCS12Password().toCharArray());

    List<Attribute> attributes = new LinkedList<Attribute>();
    attributes.add(new Attribute("urn:be:fgov:identification-namespace",
            "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin"));
    attributes.add(new Attribute("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin"));

    List<AttributeDesignator> attributeDesignators = new LinkedList<AttributeDesignator>();
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:identification-namespace",
            "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin"));
    attributeDesignators
            .add(new AttributeDesignator("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin"));
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:certified-namespace:ehealth",
            "urn:be:fgov:person:ssin:ehealth:1.0:doctor:nihii11"));
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:certified-namespace:ehealth",
            "urn:be:fgov:person:ssin:doctor:boolean"));

    Element assertion = client.requestAssertion(authnCertificate, authnPrivateKey, eHealthCertificate,
            eHealthPrivateKey, attributes, attributeDesignators);

    assertNotNull(assertion);

    String assertionString = client.toString(assertion);

    // String location =
    // "https://services-int.ehealth.fgov.be/GenericInsurability/v1";
    String location = "https://services-acpt.ehealth.fgov.be/GenericInsurability/v1";
    GenericInsurabilityClient genInsClient = new GenericInsurabilityClient(location);
    genInsClient.setCredentials(eHealthPrivateKey, assertionString);

    ObjectFactory objectFactory = new ObjectFactory();
    GetInsurabilityAsXmlOrFlatRequestType body = objectFactory.createGetInsurabilityAsXmlOrFlatRequestType();

    be.e_contract.mycarenet.genins.jaxb.core.ObjectFactory coreObjectFactory = new be.e_contract.mycarenet.genins.jaxb.core.ObjectFactory();
    CommonInputType commonInput = coreObjectFactory.createCommonInputType();
    body.setCommonInput(commonInput);

    RequestType request = coreObjectFactory.createRequestType();
    request.setIsTest(true);
    commonInput.setRequest(request);

    OriginType origin = coreObjectFactory.createOriginType();
    commonInput.setOrigin(origin);
    PackageType packageObject = coreObjectFactory.createPackageType();
    origin.setPackage(packageObject);
    LicenseType license = coreObjectFactory.createLicenseType();
    packageObject.setLicense(license);
    PackageLicenseKey packageLicenseKey = this.config.getPackageLicenseKey();
    license.setUsername(packageLicenseKey.getUsername());
    license.setPassword(packageLicenseKey.getPassword());

    Element namespaceElement = assertion.getOwnerDocument().createElement("ns");
    namespaceElement.setAttributeNS(Constants.NamespaceSpecNS, "xmlns:saml",
            "urn:oasis:names:tc:SAML:1.0:assertion");
    Node nihiiNode = XPathAPI.selectSingleNode(assertion,
            "saml:AttributeStatement/saml:Attribute[@AttributeName='urn:be:fgov:person:ssin:ehealth:1.0:doctor:nihii11']/saml:AttributeValue/text()",
            namespaceElement);
    String myNihii = nihiiNode.getTextContent();
    LOG.debug("NIHII: " + myNihii);
    Node ssinNode = XPathAPI.selectSingleNode(assertion,
            "saml:AttributeStatement/saml:Attribute[@AttributeName='urn:be:fgov:person:ssin']/saml:AttributeValue/text()",
            namespaceElement);
    String mySsin = ssinNode.getTextContent();

    CareProviderType careProvider = coreObjectFactory.createCareProviderType();
    origin.setCareProvider(careProvider);
    NihiiType nihii = coreObjectFactory.createNihiiType();
    careProvider.setNihii(nihii);
    nihii.setQuality("doctor");
    ValueRefString nihiiValue = coreObjectFactory.createValueRefString();
    nihii.setValue(nihiiValue);
    nihiiValue.setValue(myNihii);
    IdType physicalPerson = coreObjectFactory.createIdType();
    careProvider.setPhysicalPerson(physicalPerson);
    ValueRefString ssinValue = coreObjectFactory.createValueRefString();
    physicalPerson.setSsin(ssinValue);
    ssinValue.setValue(mySsin);

    commonInput.setInputReference("PRIG1234567890");
    RecordCommonInputType recordCommonInput = coreObjectFactory.createRecordCommonInputType();
    body.setRecordCommonInput(recordCommonInput);
    recordCommonInput.setInputReference(new BigDecimal("1234567890123"));

    SingleInsurabilityRequestType singleInsurabilityRequest = coreObjectFactory
            .createSingleInsurabilityRequestType();
    body.setRequest(singleInsurabilityRequest);
    CareReceiverIdType careReceiverId = coreObjectFactory.createCareReceiverIdType();
    singleInsurabilityRequest.setCareReceiverId(careReceiverId);
    careReceiverId.setInss(mySsin);
    InsurabilityRequestDetailType insurabilityRequestDetail = coreObjectFactory
            .createInsurabilityRequestDetailType();
    singleInsurabilityRequest.setInsurabilityRequestDetail(insurabilityRequestDetail);
    InsurabilityRequestTypeType insurabilityRequestType = InsurabilityRequestTypeType.INFORMATION;
    insurabilityRequestDetail.setInsurabilityRequestType(insurabilityRequestType);
    PeriodType period = coreObjectFactory.createPeriodType();
    insurabilityRequestDetail.setPeriod(period);
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    GregorianCalendar periodStartCal = new GregorianCalendar();
    DateTime periodStartDateTime = new DateTime();
    periodStartCal.setTime(periodStartDateTime.toDate());
    XMLGregorianCalendar periodStart = datatypeFactory.newXMLGregorianCalendar(periodStartCal);
    period.setPeriodStart(periodStart);
    DateTime periodEndDateTime = periodStartDateTime;
    GregorianCalendar periodEndCal = new GregorianCalendar();
    periodEndCal.setTime(periodEndDateTime.toDate());
    XMLGregorianCalendar periodEnd = datatypeFactory.newXMLGregorianCalendar(periodEndCal);
    period.setPeriodEnd(periodEnd);
    insurabilityRequestDetail.setInsurabilityContactType(InsurabilityContactTypeType.HOSPITALIZED_FOR_DAY);

    genInsClient.getInsurability(body);
}

From source file:test.integ.be.e_contract.mycarenet.tarification.TarificationClientTest.java

@Test
public void testTarificationConsultation() throws Exception {
    // STS/*from   ww w .java  2s . c o m*/
    EHealthSTSClient client = new EHealthSTSClient(
            "https://services-acpt.ehealth.fgov.be/IAM/Saml11TokenService/Legacy/v1");

    Security.addProvider(new BeIDProvider());
    KeyStore keyStore = KeyStore.getInstance("BeID");
    BeIDKeyStoreParameter beIDKeyStoreParameter = new BeIDKeyStoreParameter();
    beIDKeyStoreParameter.addPPDUName("digipass 870");
    beIDKeyStoreParameter.addPPDUName("digipass 875");
    beIDKeyStoreParameter.addPPDUName("digipass 920");
    keyStore.load(beIDKeyStoreParameter);
    PrivateKey authnPrivateKey = (PrivateKey) keyStore.getKey("Authentication", null);
    X509Certificate authnCertificate = (X509Certificate) keyStore.getCertificate("Authentication");

    KeyStore eHealthKeyStore = KeyStore.getInstance("PKCS12");
    FileInputStream fileInputStream = new FileInputStream(this.config.getEHealthPKCS12Path());
    eHealthKeyStore.load(fileInputStream, this.config.getEHealthPKCS12Password().toCharArray());
    Enumeration<String> aliasesEnum = eHealthKeyStore.aliases();
    String alias = aliasesEnum.nextElement();
    X509Certificate eHealthCertificate = (X509Certificate) eHealthKeyStore.getCertificate(alias);
    PrivateKey eHealthPrivateKey = (PrivateKey) eHealthKeyStore.getKey(alias,
            this.config.getEHealthPKCS12Password().toCharArray());

    List<Attribute> attributes = new LinkedList<>();
    attributes.add(new Attribute("urn:be:fgov:identification-namespace",
            "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin"));
    attributes.add(new Attribute("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin"));

    List<AttributeDesignator> attributeDesignators = new LinkedList<>();
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:identification-namespace",
            "urn:be:fgov:ehealth:1.0:certificateholder:person:ssin"));
    attributeDesignators
            .add(new AttributeDesignator("urn:be:fgov:identification-namespace", "urn:be:fgov:person:ssin"));
    attributeDesignators.add(new AttributeDesignator("urn:be:fgov:certified-namespace:ehealth",
            "urn:be:fgov:person:ssin:nurse:boolean"));

    Element assertion = client.requestAssertion(authnCertificate, authnPrivateKey, eHealthCertificate,
            eHealthPrivateKey, attributes, attributeDesignators);

    assertNotNull(assertion);

    String assertionString = client.toString(assertion);

    // Tarification
    TarificationClient tarificationClient = new TarificationClient(
            "https://services-acpt.ehealth.fgov.be/MyCareNet/Tarification/v1");
    tarificationClient.setCredentials(eHealthPrivateKey, assertionString);

    ObjectFactory objectFactory = new ObjectFactory();
    SendRequestType sendRequest = objectFactory.createSendRequestType();

    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    GregorianCalendar issueInstantCal = new GregorianCalendar();
    DateTime issueInstantDateTime = new DateTime();
    issueInstantCal.setTime(issueInstantDateTime.toDate());
    XMLGregorianCalendar issueInstant = datatypeFactory.newXMLGregorianCalendar(issueInstantCal);
    sendRequest.setIssueInstant(issueInstant);

    // TODO...

    tarificationClient.tarificationConsultation(sendRequest);

}

From source file:test.integ.be.fedict.hsm.ws.WSSecurityTestSOAPHandler.java

private Element addTimestamp(Element wsSecurityHeaderElement)
        throws SOAPException, DatatypeConfigurationException {
    if (false == this.addTimestamp) {
        return null;
    }// ww  w .  j  a v  a 2  s .  c o  m
    Document document = wsSecurityHeaderElement.getOwnerDocument();
    Element timestampElement = document.createElementNS(WSU_NAMESPACE, "wsu:Timestamp");
    timestampElement.setAttributeNS(WSU_NAMESPACE, "wsu:Id", "TS");
    Attr idAttr = timestampElement.getAttributeNodeNS(WSU_NAMESPACE, "Id");
    timestampElement.setIdAttributeNode(idAttr, true);

    Element createdElement = document.createElementNS(WSU_NAMESPACE, "wsu:Created");
    DatatypeFactory datatypeFactory = DatatypeFactory.newInstance();
    GregorianCalendar gregorianCalendar = new GregorianCalendar();
    Date now = new Date();
    gregorianCalendar.setTime(now);
    gregorianCalendar.setTimeZone(TimeZone.getTimeZone("UTC"));
    XMLGregorianCalendar xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(gregorianCalendar);
    createdElement.setTextContent(xmlGregorianCalendar.toXMLFormat());
    timestampElement.appendChild(createdElement);

    Element expiresElement = document.createElementNS(WSU_NAMESPACE, "wsu:Expires");
    Date expiresDate = new Date(now.getTime() + 1000 * 60 * 5);
    gregorianCalendar.setTime(expiresDate);
    xmlGregorianCalendar = datatypeFactory.newXMLGregorianCalendar(gregorianCalendar);
    expiresElement.setTextContent(xmlGregorianCalendar.toXMLFormat());
    timestampElement.appendChild(expiresElement);
    wsSecurityHeaderElement.appendChild(timestampElement);
    return timestampElement;
}