use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.
the class PDStoredBusinessEntity method getAsBusinessCard.
/**
* @return This {@link PDStoredBusinessEntity} as a {@link PDBusinessCard}.
*/
@Nonnull
@ReturnsMutableCopy
public PDBusinessCard getAsBusinessCard() {
final PDBusinessCard ret = new PDBusinessCard();
ret.setParticipantIdentifier(new PDIdentifier(m_aParticipantID.getScheme(), m_aParticipantID.getValue()));
// We have a single entity
ret.businessEntities().add(getAsBusinessEntity());
return ret;
}
use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.
the class PDSMPHttpResponseHandlerBusinessCard method handleEntity.
@Override
@Nullable
public PDBusinessCard handleEntity(@Nonnull final HttpEntity aEntity) throws IOException {
// Read the payload and remember it!
final ContentType aContentType = ContentType.getOrDefault(aEntity);
final Charset aCharset = aContentType.getCharset();
final byte[] aData = StreamHelper.getAllBytes(aEntity.getContent());
if (aData == null)
return null;
final PDBusinessCard aBC = PDBusinessCardHelper.parseBusinessCard(aData, aCharset);
if (aBC != null)
return aBC;
// Unsupported
throw new ClientProtocolException("Malformed XML document returned from SMP server:\n" + new String(aData, StandardCharsets.UTF_8));
}
use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.
the class SMPBusinessCardProvider method getBusinessCardPeppolSMP.
@Nullable
@VisibleForTesting
PDExtendedBusinessCard getBusinessCardPeppolSMP(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final SMPClientReadOnly aSMPClient, @Nonnull final HttpClientSettings aHCS) {
LOGGER.info("Querying BusinessCard for '" + aParticipantID.getURIEncoded() + "' from Peppol SMP '" + aSMPClient.getSMPHostURI() + "'");
// First query the service group
com.helger.xsds.peppol.smp1.ServiceGroupType aServiceGroup;
try {
aServiceGroup = aSMPClient.getServiceGroupOrNull(aParticipantID);
} catch (final SMPClientException ex) {
LOGGER.error("Error querying SMP for ServiceGroup of '" + aParticipantID.getURIEncoded() + "'", ex);
return null;
}
// If the service group is present, try querying the business card
final PDBusinessCard aBusinessCard;
try (final HttpClientManager aHCM = HttpClientManager.create(aHCS)) {
// Use the optional business card API
final HttpGet aRequest = new HttpGet(aSMPClient.getSMPHostURI() + "businesscard/" + aParticipantID.getURIPercentEncoded());
aBusinessCard = aHCM.execute(aRequest, new PDSMPHttpResponseHandlerBusinessCard());
} catch (final IOException ex) {
if ((ex instanceof HttpResponseException && ((HttpResponseException) ex).getStatusCode() == CHttp.HTTP_NOT_FOUND) || ex instanceof UnknownHostException) {
LOGGER.warn("No BusinessCard available for '" + aParticipantID.getURIEncoded() + "' - not in configured SMK/SML? - " + ex.getMessage());
} else
LOGGER.error("Error querying SMP for BusinessCard of '" + aParticipantID.getURIEncoded() + "'", ex);
return null;
}
if (aBusinessCard == null) {
// No extension present - no need to try again
LOGGER.warn("Failed to get SMP BusinessCard of " + aParticipantID.getURIEncoded());
return null;
}
// Query all document types
final IIdentifierFactory aIdentifierFactory = PDMetaManager.getIdentifierFactory();
final ICommonsList<IDocumentTypeIdentifier> aDocumentTypeIDs = SMPClientReadOnly.getAllDocumentTypes(aServiceGroup, aIdentifierFactory, UNHANDLED_HREF_HANDLER);
return new PDExtendedBusinessCard(aBusinessCard, aDocumentTypeIDs);
}
use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.
the class PD2APIHelper method createBusinessCard.
@Nonnull
public static PDBusinessCard createBusinessCard(@Nonnull final PD2BusinessCardType aBC) {
ValueEnforcer.notNull(aBC, "BusinessCard");
final PDBusinessCard ret = new PDBusinessCard();
ret.setParticipantIdentifier(createIdentifier(aBC.getParticipantIdentifier()));
ret.businessEntities().setAllMapped(aBC.getBusinessEntity(), PD2APIHelper::createBusinessEntity);
return ret;
}
use of com.helger.pd.businesscard.generic.PDBusinessCard in project phoss-directory by phax.
the class PD3APIHelper method createBusinessCard.
@Nonnull
public static PDBusinessCard createBusinessCard(@Nonnull final PD3BusinessCardType aBC) {
ValueEnforcer.notNull(aBC, "BusinessCard");
final PDBusinessCard ret = new PDBusinessCard();
ret.setParticipantIdentifier(createIdentifier(aBC.getParticipantIdentifier()));
ret.businessEntities().setAllMapped(aBC.getBusinessEntity(), PD3APIHelper::createBusinessEntity);
return ret;
}
Aggregations