Android: Xades URI error
<p>I am working on a xades-bes type signature with Android Studio. The library that I use is not xades4j. My country's government provided another library jor java and I am using it. I am trying to sign a XML file.</p>

<p>I have a XML file for my xades signature in <em>/raw</em> directory (<strong>not test file</strong>):</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xmlsignature_config xmlns="http://uekae.tubitak.gov.tr/xml/signature#"&gt;
    &lt;locale language="tr" country="TR"/&gt;

    &lt;http&gt;
        &lt;proxy-host&gt;&lt;/proxy-host&gt;
        &lt;proxy-port&gt;&lt;/proxy-port&gt;
        &lt;proxy-username&gt;&lt;/proxy-username&gt;
        &lt;proxy-password&gt;&lt;/proxy-password&gt;
        &lt;basic-authentication-username&gt;&lt;/basic-authentication-username&gt;
        &lt;basic-authentication-password&gt;&lt;/basic-authentication-password&gt;
        &lt;connection-timeout-in-milliseconds&gt;2000&lt;/connection-timeout-in-milliseconds&gt;
    &lt;/http&gt;

    &lt;!--
    IdResolver, DOMResolver, HttpResolver, XPointerResolver, FileResolver;
    --&gt;
    &lt;resolvers&gt;
        &lt;resolver class="tr.gov.tubitak.uekae.esya.api.xmlsignature.resolver.IdResolver"/&gt;
        &lt;resolver class="tr.gov.tubitak.uekae.esya.api.xmlsignature.resolver.DOMResolver"/&gt;
        &lt;resolver class="tr.gov.tubitak.uekae.esya.api.xmlsignature.resolver.HttpResolver"/&gt;
        &lt;resolver class="tr.gov.tubitak.uekae.esya.api.xmlsignature.resolver.XPointerResolver"/&gt;
        &lt;resolver class="tr.gov.tubitak.uekae.esya.api.xmlsignature.resolver.FileResolver"/&gt;
    &lt;/resolvers&gt;

    &lt;timestamp-server&gt;
        &lt;host&gt;http://tzd.kamusm.gov.tr&lt;/host&gt;
        &lt;digest-alg&gt;SHA-256&lt;/digest-alg&gt;
        &lt;!-- leave below settings blank, if not ESYA Timestamp Server! --&gt;
        &lt;!-- for test timestamp account mail to bilgi@kamusm.gov.tr  --&gt;
        &lt;userid&gt;user_id&lt;/userid&gt;
        &lt;password&gt;password&lt;/password&gt;
    &lt;/timestamp-server&gt;

    &lt;algorithms&gt;
        &lt;digest-method&gt;http://www.w3.org/2001/04/xmlenc#sha256&lt;/digest-method&gt;
    &lt;/algorithms&gt;

    &lt;validation&gt;

        &lt;grace-period-in-seconds&gt;0&lt;/grace-period-in-seconds&gt;
        &lt;!-- how old revocation data should be accepted? --&gt;
        &lt;last-revocation-period-in-seconds&gt;17280000&lt;/last-revocation-period-in-seconds&gt;
        &lt;!-- compare resolved policy with the one at policy uri, if indicated --&gt;
        &lt;check-policy-uri&gt;false&lt;/check-policy-uri&gt;

        &lt;!-- loosening below 2 settings will cause warnings instead of validation failure --&gt;
        &lt;!-- referenced validation data must be used for cert validation is set true --&gt;
        &lt;force-strict-reference-use&gt;true&lt;/force-strict-reference-use&gt;
        &lt;!-- validation data must be published after creation ifs set true, requires grace period for signers --&gt;
        &lt;use-validation-data-published-after-creation&gt;false&lt;/use-validation-data-published-after-creation&gt;

        &lt;validate-certificate-before-signing&gt;false&lt;/validate-certificate-before-signing&gt;

        &lt;!-- if there is a signing time in the signature, decide if you want to trust --&gt;
        &lt;trust-signing-time&gt;false&lt;/trust-signing-time&gt;

        &lt;validators&gt;
            &lt;!--
            valid profile types are XMLDSig, XAdES_BES, XAdES_EPES,  XAdES_T,
            XAdES_C, XAdES_X, XAdES_X_L and XAdES_A
            --&gt;
            &lt;profile type="XMLDSig"&gt;
            &lt;/profile&gt;
            &lt;profile type="XAdES_BES" inherit-validators-from="XMLDSig"&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.AllDataObjectsTimeStampValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.DataObjectFormatValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.IndividualDataObjectsTimeStampValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.SigningCertificateValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.SigningTimeValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.TurkishESigProfileAttributeValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.TurkishESigProfileValidator"/&gt;
            &lt;/profile&gt;
            &lt;profile type="XAdES_EPES" inherit-validators-from="XAdES_BES" &gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.SignaturePolicyValidator"/&gt;
            &lt;/profile&gt;
            &lt;profile type="XAdES_T" inherit-validators-from="XAdES_EPES"&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.SignatureTimeStampValidator"/&gt;
            &lt;/profile&gt;
            &lt;profile type="XAdES_C" inherit-validators-from="XAdES_T"&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.CompleteCertificateRefsValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.CompleteRevocationRefsValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.AttributeCertificateRefsValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.AttributeRevocationRefsValidator"/&gt;
            &lt;/profile&gt;
            &lt;profile type="XAdES_X" inherit-validators-from="XAdES_C"&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.SigAndRefsTimestampValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.RefsOnlyTimestampValidator"/&gt;
            &lt;/profile&gt;
            &lt;profile type="XAdES_X_L" inherit-validators-from="XAdES_X"&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.CertificateValuesValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.RevocationValuesValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.AttrAuthoritiesCertValuesValidator"/&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.AttributeRevocationValuesValidator"/&gt;
            &lt;/profile&gt;
            &lt;profile type="XAdES_A" inherit-validators-from="XAdES_X_L"&gt;
                &lt;validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator.ArchiveTimestampValidator"/&gt;
                &lt;!--validator class="tr.gov.tubitak.uekae.esya.api.xmlsignature.validator."/--&gt;
            &lt;/profile&gt;
        &lt;/validators&gt;
    &lt;/validation&gt;

    &lt;parameters&gt;
        &lt;!-- should referenced validation data be written to signature dir, or
        certvalidation is configured to write that data to somewhere
        eg local cert store? --&gt;
        &lt;write-referencedvalidationdata-to-file-on-upgrade value="false"/&gt;

    &lt;/parameters&gt;
&lt;/xmlsignature_config&gt;
</code></pre>

<p>And in my mainActivity class related part of my code is:</p>

<pre><code> String sourceFilePath = filePathView.getText().toString();
                if (sourceFilePath.isEmpty()) {
                    exc = new Exception("No File Selected.");
                    return null;
                }
                mAPDUSmartCard.login(pwdText);
                Pair&lt;CardTerminal, ECertificate&gt; selection = certListAdapter.getSelection();
                ECertificate signCert = selection.second;
                BaseSigner signer = mAPDUSmartCard.getSigner(signCert.asX509Certificate(), Algorithms.SIGNATURE_RSA_SHA256);    

                Resources res1 = getResources();
                Config conf = new Config ( res1.openRawResource(R.raw.xmlsignature_config));
                Context context = new Context();
                context.setConfig(conf);

                XMLSignature signature = new XMLSignature(context);

                signature.addDocument( sourceFilePath, "application/xml", false);  // This part's first parameter can be the reason of error. 
                        signature.getSignedInfo().setSignatureMethod(SignatureMethod.RSA_SHA256);
                signature.addKeyInfo(signCert);
                signature.sign(signer);
                signature.write(new FileOutputStream(sourceFilePath + ".xsig"));
</code></pre>

<p>The program is working. However, when I choose the file and click the Sign button:</p>

<p><strong>1-</strong> I am taking a reference error, in log it says that uri could not  found the path of <strong>sourceFilePath</strong> variable which is the path of file to sign.
It also gives a Reference id with the error.
When I give an empty string ("") instead of sourceFilePath variable, the program says the file has been signed ( I don't understand how can it be signed without giving parameter in  <strong>addDocument</strong> method. Anyway, the validation program for signed files does not validate the file because of reference not found error.</p>

<p><strong>2-</strong> Also in my xml file <strong>xmlns="http://uekae.tubitak.gov.tr/xml/signature#</strong> line gives error of "Uri is not registered". I have done what I have found here but the problem was not solved. Can this situation be the reason for error that I face?</p>

<p>I have been working on this issue for days but still could not find any solution.</p>