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");
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations