Search in sources :

Example 1 with Partnership

use of com.helger.as2lib.partner.Partnership in project as2-server by phax.

the class ViewPartnershipCommand method execute.

@Override
protected CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
    if (params.length < 1) {
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    }
    final String name = params[0].toString();
    final Partnership part = partFx.getPartnershipByName(name);
    if (part != null)
        return new CommandResult(ECommandResultType.TYPE_OK, part.toString());
    return new CommandResult(ECommandResultType.TYPE_ERROR, "Unknown partnership name");
}
Also used : Partnership(com.helger.as2lib.partner.Partnership) CommandResult(com.helger.as2.cmd.CommandResult)

Example 2 with Partnership

use of com.helger.as2lib.partner.Partnership in project as2-server by phax.

the class MainTestClient method checkRequired.

protected static void checkRequired(final IMessage aMsg) {
    final Partnership aPartnership = aMsg.partnership();
    try {
        InvalidParameterException.checkValue(aMsg, "ContentType", aMsg.getContentType());
        InvalidParameterException.checkValue(aMsg, "Attribute: " + CPartnershipIDs.PA_AS2_URL, aPartnership.getAS2URL());
        InvalidParameterException.checkValue(aMsg, "Receiver: " + CPartnershipIDs.PID_AS2, aPartnership.getReceiverAS2ID());
        InvalidParameterException.checkValue(aMsg, "Sender: " + CPartnershipIDs.PID_AS2, aPartnership.getSenderAS2ID());
        InvalidParameterException.checkValue(aMsg, "Subject", aMsg.getSubject());
        InvalidParameterException.checkValue(aMsg, "Sender: " + CPartnershipIDs.PID_EMAIL, aPartnership.getSenderEmail());
        InvalidParameterException.checkValue(aMsg, "Message Data", aMsg.getData());
    } catch (final InvalidParameterException rpe) {
        rpe.addSource(OpenAS2Exception.SOURCE_MESSAGE, aMsg);
    }
}
Also used : InvalidParameterException(com.helger.as2lib.params.InvalidParameterException) Partnership(com.helger.as2lib.partner.Partnership)

Example 3 with Partnership

use of com.helger.as2lib.partner.Partnership in project as2-server by phax.

the class MainTestClient method updateHttpHeaders.

protected void updateHttpHeaders(@Nonnull final HttpURLConnection aConn, @Nonnull final IMessage aMsg) {
    final Partnership aPartnership = aMsg.partnership();
    final AS2HttpHeaderWrapperHttpURLConnection aHeaderWrapper = new AS2HttpHeaderWrapperHttpURLConnection(aConn);
    aHeaderWrapper.setHttpHeader(CHttpHeader.CONNECTION, CAS2Header.DEFAULT_CONNECTION);
    aHeaderWrapper.setHttpHeader(CHttpHeader.USER_AGENT, CAS2Header.DEFAULT_USER_AGENT);
    aHeaderWrapper.setHttpHeader(CHttpHeader.DATE, AS2DateHelper.getFormattedDateNow(CAS2Header.DEFAULT_DATE_FORMAT));
    aHeaderWrapper.setHttpHeader(CHttpHeader.MESSAGE_ID, aMsg.getMessageID());
    // make sure this is the encoding used in the msg, run TBF1
    aHeaderWrapper.setHttpHeader(CHttpHeader.MIME_VERSION, CAS2Header.DEFAULT_MIME_VERSION);
    aHeaderWrapper.setHttpHeader(CHttpHeader.CONTENT_TYPE, aMsg.getContentType());
    aHeaderWrapper.setHttpHeader(CHttpHeader.AS2_VERSION, CAS2Header.DEFAULT_AS2_VERSION);
    aHeaderWrapper.setHttpHeader(CHttpHeader.RECIPIENT_ADDRESS, aPartnership.getAS2URL());
    aHeaderWrapper.setHttpHeader(CHttpHeader.AS2_TO, aPartnership.getReceiverAS2ID());
    aHeaderWrapper.setHttpHeader(CHttpHeader.AS2_FROM, aPartnership.getSenderAS2ID());
    aHeaderWrapper.setHttpHeader(CHttpHeader.SUBJECT, aMsg.getSubject());
    aHeaderWrapper.setHttpHeader(CHttpHeader.FROM, aPartnership.getSenderEmail());
    final String sDispTo = aPartnership.getAS2MDNTo();
    if (sDispTo != null)
        aHeaderWrapper.setHttpHeader(CHttpHeader.DISPOSITION_NOTIFICATION_TO, sDispTo);
    final String sDispOptions = aPartnership.getAS2MDNOptions();
    if (sDispOptions != null)
        aHeaderWrapper.setHttpHeader(CHttpHeader.DISPOSITION_NOTIFICATION_OPTIONS, sDispOptions);
    // Async MDN 2007-03-12
    final String sReceiptOption = aPartnership.getAS2ReceiptDeliveryOption();
    if (sReceiptOption != null)
        aHeaderWrapper.setHttpHeader(CHttpHeader.RECEIPT_DELIVERY_OPTION, sReceiptOption);
    // As of 2007-06-01
    final String sContentDisp = aMsg.getContentDisposition();
    if (sContentDisp != null)
        aHeaderWrapper.setHttpHeader(CHttpHeader.CONTENT_DISPOSITION, sContentDisp);
}
Also used : Partnership(com.helger.as2lib.partner.Partnership) AS2HttpHeaderWrapperHttpURLConnection(com.helger.as2lib.util.http.AS2HttpHeaderWrapperHttpURLConnection)

Example 4 with Partnership

use of com.helger.as2lib.partner.Partnership in project as2-server by phax.

the class AddPartnershipCommand method execute.

@Override
public CommandResult execute(final IPartnershipFactoryWithPartners partFx, final Object[] params) throws OpenAS2Exception {
    if (params.length < 3)
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    final IMicroDocument doc = new MicroDocument();
    final IMicroElement root = doc.appendElement("partnership");
    for (int nIndex = 0; nIndex < params.length; nIndex++) {
        final String param = (String) params[nIndex];
        final int pos = param.indexOf('=');
        if (nIndex == 0) {
            root.setAttribute("name", param);
        } else if (nIndex == 1) {
            final IMicroElement elem = root.appendElement("sender");
            elem.setAttribute("name", param);
        } else if (nIndex == 2) {
            final IMicroElement elem = root.appendElement("receiver");
            elem.setAttribute("name", param);
        } else if (pos == 0) {
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing name");
        } else if (pos > 0) {
            final IMicroElement elem = root.appendElement("attribute");
            elem.setAttribute("name", param.substring(0, pos));
            elem.setAttribute("value", param.substring(pos + 1));
        } else
            return new CommandResult(ECommandResultType.TYPE_ERROR, "incoming parameter missing value");
    }
    final XMLPartnershipFactory aXMLPartnershipFactory = (XMLPartnershipFactory) partFx;
    final Partnership aPartnership = aXMLPartnershipFactory.loadPartnership(root, aXMLPartnershipFactory.getPartnerMap());
    if (aXMLPartnershipFactory.getPartnershipByName(aPartnership.getName()) != null)
        return new CommandResult(ECommandResultType.TYPE_ERROR, "A partnership with name '" + aPartnership.getName() + "' is already present!");
    // add the partnership to the list of available partnerships
    partFx.addPartnership(aPartnership);
    return new CommandResult(ECommandResultType.TYPE_OK);
}
Also used : IMicroDocument(com.helger.xml.microdom.IMicroDocument) MicroDocument(com.helger.xml.microdom.MicroDocument) Partnership(com.helger.as2lib.partner.Partnership) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument) XMLPartnershipFactory(com.helger.as2lib.partner.xml.XMLPartnershipFactory) CommandResult(com.helger.as2.cmd.CommandResult)

Example 5 with Partnership

use of com.helger.as2lib.partner.Partnership in project as2-server by phax.

the class DeletePartnerCommand method execute.

@Override
public CommandResult execute(@Nonnull final IPartnershipFactoryWithPartners partFx, final Object[] aParams) throws OpenAS2Exception {
    if (aParams.length < 1)
        return new CommandResult(ECommandResultType.TYPE_INVALID_PARAM_COUNT, getUsage());
    final String sName = aParams[0].toString();
    if (!partFx.getAllPartnerNames().contains(sName))
        return new CommandResult(ECommandResultType.TYPE_ERROR, "Unknown partner name '" + sName + "'");
    for (final Partnership aPartnership : partFx.getAllPartnerships()) if (aPartnership.containsReceiverID(sName) || aPartnership.containsSenderID(sName)) {
        return new CommandResult(ECommandResultType.TYPE_ERROR, "Can not delete partner '" + sName + "'; it is tied to some partnerships");
    }
    partFx.removePartner(sName);
    return new CommandResult(ECommandResultType.TYPE_OK);
}
Also used : Partnership(com.helger.as2lib.partner.Partnership) CommandResult(com.helger.as2.cmd.CommandResult)

Aggregations

Partnership (com.helger.as2lib.partner.Partnership)7 CommandResult (com.helger.as2.cmd.CommandResult)4 CertificateFactory (com.helger.as2lib.cert.CertificateFactory)1 DispositionOptions (com.helger.as2lib.disposition.DispositionOptions)1 AS2Message (com.helger.as2lib.message.AS2Message)1 IMessage (com.helger.as2lib.message.IMessage)1 IMessageMDN (com.helger.as2lib.message.IMessageMDN)1 InvalidParameterException (com.helger.as2lib.params.InvalidParameterException)1 SelfFillingPartnershipFactory (com.helger.as2lib.partner.SelfFillingPartnershipFactory)1 XMLPartnershipFactory (com.helger.as2lib.partner.xml.XMLPartnershipFactory)1 AS2SenderModule (com.helger.as2lib.processor.sender.AS2SenderModule)1 AS2Session (com.helger.as2lib.session.AS2Session)1 CAS2Header (com.helger.as2lib.util.CAS2Header)1 AS2HttpHeaderWrapperHttpURLConnection (com.helger.as2lib.util.http.AS2HttpHeaderWrapperHttpURLConnection)1 StringMap (com.helger.commons.collection.attr.StringMap)1 CHttpHeader (com.helger.commons.http.CHttpHeader)1 IMicroDocument (com.helger.xml.microdom.IMicroDocument)1 IMicroElement (com.helger.xml.microdom.IMicroElement)1 MicroDocument (com.helger.xml.microdom.MicroDocument)1 Header (javax.mail.Header)1