Search in sources :

Example 11 with WSMarshaller

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

the class AndroidMarshallerTest method testConversionOfStartPAOSResponse.

@Test
public void testConversionOfStartPAOSResponse() throws Exception {
    WSMarshaller m = new AndroidMarshaller();
    Object o = m.unmarshal(m.str2doc(START_PAOS_RESPONSE));
    if (!(o instanceof StartPAOSResponse)) {
        throw new Exception("Object should be an instace of StartPAOSResponse");
    }
    StartPAOSResponse stPaosResponse = (StartPAOSResponse) o;
    assertEquals(stPaosResponse.getResult().getResultMajor(), "http://www.bsi.bund.de/ecard/api/1.1/resultmajor#error");
    assertEquals(stPaosResponse.getResult().getResultMinor(), "http://www.bsi.bund.de/ecard/api/1.1/resultminor/dp#timeout");
    assertEquals(stPaosResponse.getResult().getResultMessage().getValue(), "WaitStartPAOS timeout");
    assertEquals(stPaosResponse.getResult().getResultMessage().getLang(), "en");
}
Also used : WSMarshaller(org.openecard.ws.marshal.WSMarshaller) StartPAOSResponse(iso.std.iso_iec._24727.tech.schema.StartPAOSResponse) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 12 with WSMarshaller

use of org.openecard.ws.marshal.WSMarshaller 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 13 with WSMarshaller

use of org.openecard.ws.marshal.WSMarshaller 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 14 with WSMarshaller

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

the class Body method loadEmptyMarshaller.

private static WSMarshaller loadEmptyMarshaller() throws WSMarshallerException {
    WSMarshaller m = WSMarshallerFactory.createInstance();
    m.removeAllTypeClasses();
    return m;
}
Also used : WSMarshaller(org.openecard.ws.marshal.WSMarshaller)

Example 15 with WSMarshaller

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

the class TCTokenHandler method handleNoCardActivate.

/**
 * Activates the client according to the received TCToken.
 *
 * @param token The activation TCToken.
 * @return The response containing the result of the activation process.
 */
public BindingResult handleNoCardActivate(TCToken token) {
    if (LOG.isDebugEnabled()) {
        try {
            WSMarshaller m = WSMarshallerFactory.createInstance();
            LOG.debug("TCToken:\n{}", m.doc2str(m.marshal(token)));
        } catch (TransformerException | WSMarshallerException ex) {
        // it's no use
        }
    }
    try {
        // process binding and follow redirect addresses afterwards
        ChipGatewayResponse response = processBinding(token);
        // fill in values, so it is usuable by the transport module
        response.finishResponse();
        return response;
    } catch (RedirectionBaseError ex) {
        LOG.error(ex.getMessage(), ex);
        return ex.getBindingResult();
    } catch (FatalActivationError ex) {
        LOG.error(ex.getMessage(), ex);
        return ex.getBindingResult();
    }
}
Also used : FatalActivationError(org.openecard.addons.cg.ex.FatalActivationError) WSMarshallerException(org.openecard.ws.marshal.WSMarshallerException) ChipGatewayResponse(org.openecard.addons.cg.impl.ChipGatewayResponse) WSMarshaller(org.openecard.ws.marshal.WSMarshaller) TransformerException(javax.xml.transform.TransformerException) RedirectionBaseError(org.openecard.addons.cg.ex.RedirectionBaseError)

Aggregations

WSMarshaller (org.openecard.ws.marshal.WSMarshaller)36 Test (org.testng.annotations.Test)28 Document (org.w3c.dom.Document)21 IOException (java.io.IOException)12 InternationalStringType (oasis.names.tc.dss._1_0.core.schema.InternationalStringType)6 WSMarshallerException (org.openecard.ws.marshal.WSMarshallerException)6 Element (org.w3c.dom.Element)6 BigInteger (java.math.BigInteger)5 Result (oasis.names.tc.dss._1_0.core.schema.Result)5 EstablishChannel (iso.std.iso_iec._24727.tech.schema.EstablishChannel)4 StringReader (java.io.StringReader)4 Connect (iso.std.iso_iec._24727.tech.schema.Connect)3 ConnectionHandleType (iso.std.iso_iec._24727.tech.schema.ConnectionHandleType)3 DIDAuthenticateResponse (iso.std.iso_iec._24727.tech.schema.DIDAuthenticateResponse)3 EstablishChannelResponse (iso.std.iso_iec._24727.tech.schema.EstablishChannelResponse)3 EstablishContext (iso.std.iso_iec._24727.tech.schema.EstablishContext)3 DocumentBuilder (javax.xml.parsers.DocumentBuilder)3 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)3 ChannelHandleType (iso.std.iso_iec._24727.tech.schema.ChannelHandleType)2 ControlIFD (iso.std.iso_iec._24727.tech.schema.ControlIFD)2