Example usage for com.itextpdf.text.pdf.codec Base64 DONT_BREAK_LINES

List of usage examples for com.itextpdf.text.pdf.codec Base64 DONT_BREAK_LINES

Introduction

In this page you can find the example usage for com.itextpdf.text.pdf.codec Base64 DONT_BREAK_LINES.

Prototype

int DONT_BREAK_LINES

To view the source code for com.itextpdf.text.pdf.codec Base64 DONT_BREAK_LINES.

Click Source Link

Document

Don't break lines when encoding (violates strict Base64 specification)

Usage

From source file:com.swisscom.ais.itext.Soap.java

License:Open Source License

/**
 * Create SOAP message object for server request. Will print debug information if debug is set to true
 *
 * @param reqType                  Type of request message e.g. singing or pending request
 * @param digestMethodAlgorithmURL Uri of hash algorithm
 * @param mobileIDStepUp           certificate request profile. Only necessary when on demand certificate is needed
 * @param hashList                 Hashes from documents which should be signed
 * @param additionalProfiles       Urn of additional profiles e.g. ondemand certificate, timestamp signature, batch process etc.
 * @param claimedIdentity          Signers identity / profile
 * @param signatureType            Urn of signature type e.g. signature type cms or timestamp
 * @param distinguishedName        Information about signer e.g. name, country etc.
 * @param mobileIdType             Urn of mobile id type
 * @param phoneNumber              Mobile id for on demand certificates with mobile id request
 * @param certReqMsg               Message which will be send to phone number if set
 * @param certReqMsgLang           Language from message which will be send to mobile id
 * @param responseId               Only necessary when asking the signing status on server
 * @param requestId                Request id to identify signature in response
 * @return SOAP response from server. Depending on request profile it can be a signarure, signing status information or an error
 * @throws SOAPException If there is an error creating SOAP message
 * @throws IOException   If there is an error writing debug information
 *///  w  ww .jav  a 2s. c om
private SOAPMessage createRequestMessage(@Nonnull Include.RequestType reqType,
        @Nonnull String digestMethodAlgorithmURL, boolean mobileIDStepUp, @Nonnull byte[][] hashList,
        String[] additionalProfiles, String claimedIdentity, @Nonnull String signatureType,
        String distinguishedName, String mobileIdType, String phoneNumber, String certReqMsg,
        String certReqMsgLang, String certReqSerialNumber, String responseId, String requestId)
        throws SOAPException, IOException {

    MessageFactory messageFactory = MessageFactory.newInstance();
    SOAPMessage soapMessage = messageFactory.createMessage();
    SOAPPart soapPart = soapMessage.getSOAPPart();

    // SOAP Envelope
    SOAPEnvelope envelope = soapPart.getEnvelope();
    envelope.removeNamespaceDeclaration("SOAP-ENV");
    envelope.setPrefix("soap");
    envelope.addAttribute(new QName("xmlns"), "urn:oasis:names:tc:dss:1.0:core:schema");
    envelope.addNamespaceDeclaration("dsig", "http://www.w3.org/2000/09/xmldsig#");
    envelope.addNamespaceDeclaration("sc", "http://ais.swisscom.ch/1.0/schema");
    envelope.addNamespaceDeclaration("ais", "http://service.ais.swisscom.com/");

    //SOAP Header
    SOAPHeader soapHeader = envelope.getHeader();
    soapHeader.removeNamespaceDeclaration("SOAP-ENV");
    soapHeader.setPrefix("soap");

    // SOAP Body
    SOAPBody soapBody = envelope.getBody();
    soapBody.removeNamespaceDeclaration("SOAP-ENV");
    soapBody.setPrefix("soap");

    SOAPElement signElement = soapBody.addChildElement("sign", "ais");

    SOAPElement requestElement = signElement.addChildElement(reqType.getRequestType());
    requestElement.addAttribute(new QName("Profile"), reqType.getUrn());
    requestElement.addAttribute(new QName("RequestID"), requestId);
    SOAPElement inputDocumentsElement = requestElement.addChildElement("InputDocuments");

    SOAPElement digestValueElement;
    SOAPElement documentHashElement;
    SOAPElement digestMethodElement;

    for (int i = 0; i < hashList.length; i++) {
        documentHashElement = inputDocumentsElement.addChildElement("DocumentHash");
        if (hashList.length > 1)
            documentHashElement.addAttribute(new QName("ID"), String.valueOf(i));
        digestMethodElement = documentHashElement.addChildElement("DigestMethod", "dsig");
        digestMethodElement.addAttribute(new QName("Algorithm"), digestMethodAlgorithmURL);
        digestValueElement = documentHashElement.addChildElement("DigestValue", "dsig");

        String s = com.itextpdf.text.pdf.codec.Base64.encodeBytes(hashList[i], Base64.DONT_BREAK_LINES);
        digestValueElement.addTextNode(s);
    }

    if (additionalProfiles != null || claimedIdentity != null || signatureType != null) {
        SOAPElement optionalInputsElement = requestElement.addChildElement("OptionalInputs");

        SOAPElement additionalProfileelement;
        if (additionalProfiles != null) {
            for (String additionalProfile : additionalProfiles) {
                additionalProfileelement = optionalInputsElement.addChildElement("AdditionalProfile");
                additionalProfileelement.addTextNode(additionalProfile);
            }
        }

        if (claimedIdentity != null) {
            SOAPElement claimedIdentityElement = optionalInputsElement
                    .addChildElement(new QName("ClaimedIdentity"));
            SOAPElement claimedIdNameElement = claimedIdentityElement.addChildElement("Name");
            claimedIdNameElement.addTextNode(claimedIdentity);
        }

        if (mobileIDStepUp) {
            SOAPElement certificateRequestElement = optionalInputsElement.addChildElement("CertificateRequest",
                    "sc");
            if (distinguishedName != null) {
                SOAPElement distinguishedNameElement = certificateRequestElement
                        .addChildElement("DistinguishedName", "sc");
                distinguishedNameElement.addTextNode(distinguishedName);
                if (phoneNumber != null) {
                    SOAPElement stepUpAuthorisationElement = certificateRequestElement
                            .addChildElement("StepUpAuthorisation", "sc");
                    if (mobileIdType != null) {
                        SOAPElement mobileIdElement = stepUpAuthorisationElement.addChildElement("MobileID",
                                "sc");
                        mobileIdElement.addAttribute(new QName("Type"), _MOBILE_ID_TYPE);
                        SOAPElement msisdnElement = mobileIdElement.addChildElement("MSISDN", "sc");
                        msisdnElement.addTextNode(phoneNumber);
                        SOAPElement certReqMsgElement = mobileIdElement.addChildElement("Message", "sc");
                        certReqMsgElement.addTextNode(certReqMsg);
                        SOAPElement certReqMsgLangElement = mobileIdElement.addChildElement("Language", "sc");
                        certReqMsgLangElement.addTextNode(certReqMsgLang);
                        if (certReqSerialNumber != null) {
                            SOAPElement certReqMsgSerialNumberElement = mobileIdElement
                                    .addChildElement("SerialNumber", "sc");
                            certReqMsgSerialNumberElement.addTextNode(certReqSerialNumber);
                        }
                    }
                }
            }
        }

        if (signatureType != null) {
            SOAPElement signatureTypeElement = optionalInputsElement.addChildElement("SignatureType");
            signatureTypeElement.addTextNode(signatureType);
        }

        if (!signatureType.equals(_TIMESTAMP_URN)) {
            SOAPElement addTimeStampelement = optionalInputsElement.addChildElement("AddTimestamp");
            addTimeStampelement.addAttribute(new QName("Type"), _TIMESTAMP_URN);
        }

        // Always add revocation information
        // Type="BOTH" means PADES+CADES
        // PADES = signed attribute according to PAdES
        // CADES = unsigned attribute according to CAdES
        // PADES-attributes are signed and cannot be post-added to an already signed RFC3161-TimeStampToken
        // So the RevocationInformation (RI) of a trusted timestamp will be delivered via OptionalOutputs
        // and they shall be added to the Adobe DSS in order to enable LTV for a Timestamp
        SOAPElement addRevocationElement = optionalInputsElement.addChildElement("AddRevocationInformation",
                "sc");
        addRevocationElement.addAttribute(new QName("Type"), "BOTH"); // CADES + PADES attributes

        if (responseId != null) {
            SOAPElement responseIdElement = optionalInputsElement.addChildElement("ResponseID");
            responseIdElement.addTextNode(responseId);
        }
    }

    soapMessage.saveChanges();

    if (_debugMode) {
        System.out.print("\nRequest SOAP Message:\n");
        ByteArrayOutputStream ba = new ByteArrayOutputStream();
        soapMessage.writeTo(ba);
        String msg = new String(ba.toByteArray());
        System.out.println(getPrettyFormatedXml(msg, 2));
    }

    return soapMessage;
}