Search in sources :

Example 1 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException in project open-ecard by ecsec.

the class LocalCifRepo method getCardInfoOrACD.

@Override
public GetCardInfoOrACDResponse getCardInfoOrACD(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACD parameters) {
    List<String> cardTypes = parameters.getCardTypeIdentifier();
    ArrayList<CardInfoType> cifsResult = new ArrayList<>(cardTypes.size());
    Result result = WSHelper.makeResultOK();
    try {
        if (ECardConstants.CIF.GET_SPECIFIED.equals(parameters.getAction())) {
            ArrayList<String> missingTypes = new ArrayList<>();
            for (String cardType : cardTypes) {
                Document cif = cifs.get(cardType);
                if (cif == null) {
                    missingTypes.add(cardType);
                } else {
                    // marshal here to receive a copy of the CIF
                    cifsResult.add((CardInfoType) m.unmarshal(cif));
                }
            }
            if (!missingTypes.isEmpty()) {
                StringBuilder error = new StringBuilder("The following card types could not be found:");
                for (String type : missingTypes) {
                    error.append("\n  ").append(type);
                }
                result = WSHelper.makeResultError(ECardConstants.Minor.SAL.UNKNOWN_CARDTYPE, error.toString());
            }
        } else if (ECardConstants.CIF.GET_OTHER.equals(parameters.getAction())) {
            HashMap<String, Document> cifsTmp = new HashMap<>();
            cifsTmp.putAll(cifs);
            for (String cardType : cardTypes) {
                cifsTmp.remove(cardType);
            }
            for (Map.Entry<String, Document> e : cifsTmp.entrySet()) {
                Document next = e.getValue();
                cifsResult.add((CardInfoType) m.unmarshal(next));
            }
        } else {
            result = WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, "Given action is unsupported.");
        }
        GetCardInfoOrACDResponse res = WSHelper.makeResponse(GetCardInfoOrACDResponse.class, result);
        res.getCardInfoOrCapabilityInfo().addAll(cifsResult);
        return res;
    } catch (WSMarshallerException ex) {
        String msg = "Failed to unmarshal a CIF document.";
        logger.error(msg, ex);
        result = WSHelper.makeResultError(ECardConstants.Minor.App.INT_ERROR, msg);
        GetCardInfoOrACDResponse res = WSHelper.makeResponse(GetCardInfoOrACDResponse.class, result);
        return res;
    }
}
Also used : WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) Result(oasis.names.tc.dss._1_0.core.schema.Result) CardInfoType(iso.std.iso_iec._24727.tech.schema.CardInfoType) GetCardInfoOrACDResponse(iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)

Example 2 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException in project open-ecard by ecsec.

the class AndroidMarshaller method unmarshal.

@Override
public synchronized Object unmarshal(Node n) throws MarshallingTypeException, WSMarshallerException {
    Document newDoc = createDoc(n);
    try {
        XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
        factory.setNamespaceAware(true);
        XmlPullParser parser = factory.newPullParser();
        parser.setInput(new ByteArrayInputStream(this.doc2str(newDoc).getBytes("UTF-8")), "UTF-8");
        int eventType = parser.getEventType();
        while (eventType != XmlPullParser.END_DOCUMENT) {
            if (eventType == XmlPullParser.START_TAG) {
                Object obj = parse(parser);
                return obj;
            }
            eventType = parser.next();
        }
        return null;
    } catch (Exception e) {
        LOG.error("Unable to unmarshal Node element.", e);
        throw new MarshallingTypeException(e);
    }
}
Also used : MarshallingTypeException(org.openecard.ws.marshal.MarshallingTypeException) XmlPullParserFactory(org.xmlpull.v1.XmlPullParserFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) XmlPullParser(org.xmlpull.v1.XmlPullParser) Document(org.w3c.dom.Document) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) MarshallingTypeException(org.openecard.ws.marshal.MarshallingTypeException) TransformerException(javax.xml.transform.TransformerException) IOException(java.io.IOException) RuntimeCryptoException(org.openecard.bouncycastle.crypto.RuntimeCryptoException) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) SAXException(org.xml.sax.SAXException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SOAPException(org.openecard.ws.soap.SOAPException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 3 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException in project open-ecard by ecsec.

the class LogSettingsGroup method loadProperties.

private static Properties loadProperties() {
    try {
        File confFile = LogbackConfig.getConfFile();
        if (!confFile.exists()) {
            // no file yet
            return new Properties();
        } else {
            // load file into a Document
            WSMarshaller m = WSMarshallerFactory.createInstance();
            m.removeAllTypeClasses();
            FileInputStream fin = new FileInputStream(confFile);
            Document conf = m.str2doc(fin);
            // fill the properties
            Properties p = new Properties();
            p.setProperty(ROOT_KEY, getRootlevel(conf));
            p.setProperty(PAOS_KEY, getLoglevel(conf, PAOS_KEY));
            p.setProperty(EAC_KEY, getLoglevel(conf, EAC_KEY));
            p.setProperty(PACE_KEY, getLoglevel(conf, PACE_KEY));
            p.setProperty(TRCHECKS_KEY, getLoglevel(conf, TRCHECKS_KEY));
            p.setProperty(TCTOKEN_KEY, getLoglevel(conf, TCTOKEN_KEY));
            p.setProperty(EVENT_KEY, getLoglevel(conf, EVENT_KEY));
            p.setProperty(HTTPBIND_KEY, getLoglevel(conf, HTTPBIND_KEY));
            p.setProperty(ADDON_KEY, getLoglevel(conf, ADDON_KEY));
            p.setProperty(SALSTATE_KEY, getLoglevel(conf, SALSTATE_KEY));
            p.setProperty(MDLW_KEY, getLoglevel(conf, MDLW_KEY));
            p.setProperty(MDLW_EVENT_KEY, getLoglevel(conf, MDLW_EVENT_KEY));
            p.setProperty(CG_KEY, getLoglevel(conf, CG_KEY));
            return p;
        }
    } catch (IOException | SAXException | WSMarshallerException | AddonPropertiesException ex) {
        // something else went wrong
        return new Properties();
    }
}
Also used : WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) AddonPropertiesException(org.openecard.addon.AddonPropertiesException) IOException(java.io.IOException) Properties(java.util.Properties) Document(org.w3c.dom.Document) HTMLDocument(javax.swing.text.html.HTMLDocument) File(java.io.File) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException)

Example 4 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException in project open-ecard by ecsec.

the class LogSettingsGroup method saveProperties.

@Override
protected void saveProperties() throws IOException, SecurityException, AddonPropertiesException {
    try {
        File confFile = LogbackConfig.getConfFile();
        // create file if needed
        // if (! confFile.exists()) {
        {
            // overwrite with default settings
            InputStream is = FileUtils.resolveResourceAsStream(LogSettingsGroup.class, "/logback.xml");
            try (FileOutputStream os = new FileOutputStream(confFile)) {
                byte[] buffer = new byte[4096];
                int n;
                while ((n = is.read(buffer)) > 0) {
                    os.write(buffer, 0, n);
                }
            }
        }
        // load file into a Document
        WSMarshaller m = WSMarshallerFactory.createInstance();
        m.removeAllTypeClasses();
        FileInputStream fin = new FileInputStream(confFile);
        Document conf = m.str2doc(fin);
        // process root value
        String val = properties.getProperty(ROOT_KEY);
        val = (val != null) ? val : "ERROR";
        setRootlevel(conf, val);
        // process every value
        val = properties.getProperty(PAOS_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, PAOS_KEY, val);
        val = properties.getProperty(EAC_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, EAC_KEY, val);
        val = properties.getProperty(PACE_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, PACE_KEY, val);
        val = properties.getProperty(TRCHECKS_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, TRCHECKS_KEY, val);
        val = properties.getProperty(TCTOKEN_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, TCTOKEN_KEY, val);
        val = properties.getProperty(EVENT_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, EVENT_KEY, val);
        val = properties.getProperty(HTTPBIND_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, HTTPBIND_KEY, val);
        val = properties.getProperty(ADDON_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, ADDON_KEY, val);
        val = properties.getProperty(SALSTATE_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, SALSTATE_KEY, val);
        val = properties.getProperty(MDLW_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, MDLW_KEY, val);
        val = properties.getProperty(MDLW_EVENT_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, MDLW_EVENT_KEY, val);
        val = properties.getProperty(CG_KEY);
        val = (val != null) ? val : "";
        setLoglevel(conf, CG_KEY, val);
        try (// write log to file
        FileWriter w = new FileWriter(confFile)) {
            String confStr = m.doc2str(conf);
            w.write(confStr);
        }
        // reload log config
        LogbackConfig.load();
    } catch (JoranException ex) {
        throw new AddonPropertiesException(ex.getMessage(), ex);
    } catch (WSMarshallerException | SAXException | TransformerException ex) {
        throw new IOException(ex.getMessage(), ex);
    }
}
Also used : WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileWriter(java.io.FileWriter) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) AddonPropertiesException(org.openecard.addon.AddonPropertiesException) IOException(java.io.IOException) Document(org.w3c.dom.Document) HTMLDocument(javax.swing.text.html.HTMLDocument) FileInputStream(java.io.FileInputStream) SAXException(org.xml.sax.SAXException) JoranException(ch.qos.logback.core.joran.spi.JoranException) FileOutputStream(java.io.FileOutputStream) File(java.io.File) TransformerException(javax.xml.transform.TransformerException)

Example 5 with WSMarshallerException

use of org.openecard.ws.marshal.WSMarshallerException in project open-ecard by ecsec.

the class ClasspathRegistry method loadManifest.

private void loadManifest(ArrayList<AddonSpecification> addons, WSMarshaller m, String addonName, String fileName) {
    try {
        InputStream manifestStream = FileUtils.resolveResourceAsStream(ClasspathRegistry.class, fileName);
        if (manifestStream == null) {
            LOG.warn("Skipped loading internal add-on {}, because it is not available.", addonName);
            return;
        }
        Document manifestDoc = m.str2doc(manifestStream);
        registerInt(addons, (AddonSpecification) m.unmarshal(manifestDoc));
        LOG.info("Loaded internal {} add-on.", addonName);
    } catch (IOException ex) {
        LOG.warn(String.format("Failed to load internal %s add-on.", addonName), ex);
    } catch (SAXException ex) {
        LOG.warn(String.format("Failed to load internal %s add-on.", addonName), ex);
    } catch (WSMarshallerException ex) {
        LOG.warn(String.format("Failed to load internal %s add-on.", addonName), ex);
    }
}
Also used : WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) InputStream(java.io.InputStream) IOException(java.io.IOException) Document(org.w3c.dom.Document) SAXException(org.xml.sax.SAXException)

Aggregations

WSMarshallerException (org.openecard.ws.marshal.WSMarshallerException)12 Document (org.w3c.dom.Document)8 SAXException (org.xml.sax.SAXException)7 IOException (java.io.IOException)6 WSMarshaller (org.openecard.ws.marshal.WSMarshaller)6 TransformerException (javax.xml.transform.TransformerException)5 CardInfoType (iso.std.iso_iec._24727.tech.schema.CardInfoType)3 InputStream (java.io.InputStream)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 HTMLDocument (javax.swing.text.html.HTMLDocument)2 AddonPropertiesException (org.openecard.addon.AddonPropertiesException)2 MarshallingTypeException (org.openecard.ws.marshal.MarshallingTypeException)2 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 Connect (iso.std.iso_iec._24727.tech.schema.Connect)1 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)1 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)1 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)1 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)1 GetCardInfoOrACDResponse (iso.std.iso_iec._24727.tech.schema.GetCardInfoOrACDResponse)1