use of com.helger.json.IJsonObject in project phoss-directory by phax.
the class SMPBusinessCardProviderTest method testFetch.
@Test
public void testFetch() {
final SMPBusinessCardProvider aBI = SMPBusinessCardProvider.createWithSMLAutoDetect(PDServerConfiguration.getSMPMode(), PDServerConfiguration.getURLProvider(), SML_SUPPLIER);
final PDExtendedBusinessCard aExtBI = aBI.getBusinessCard(PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:test"));
assertNotNull(aExtBI);
assertEquals(1, aExtBI.getBusinessCard().businessEntities().size());
LOGGER.info(aExtBI.toString());
// Test to JSON and back
final IJsonObject aJson1 = aExtBI.getAsJson();
final PDExtendedBusinessCard aExtBC2 = PDExtendedBusinessCard.of(aJson1);
assertNotNull(aExtBC2);
assertEquals(aJson1, aExtBC2.getAsJson());
}
use of com.helger.json.IJsonObject in project ph-web by phax.
the class LoggingRequest method getAsJson.
@Nonnull
public IJsonObject getAsJson() {
final JsonObject ret = new JsonObject();
if (m_sSender != null)
ret.add("sender", m_sSender);
if (m_sMethod != null)
ret.add("method", m_sMethod);
if (m_sPath != null)
ret.add("path", m_sPath);
if (m_aParams != null)
ret.addJson("params", new JsonObject().addAll(m_aParams));
if (m_aHeaders != null) {
final IJsonObject aHeaders = new JsonObject();
m_aHeaders.forEachSingleHeader(aHeaders::add, true);
ret.addJson("headers", aHeaders);
}
if (m_sBody != null)
ret.add("body", m_sBody);
return ret;
}
use of com.helger.json.IJsonObject in project ph-web by phax.
the class LoggingResponse method getAsJson.
@Nonnull
public IJsonObject getAsJson() {
final JsonObject ret = new JsonObject();
if (m_nStatus != 0)
ret.add("status", m_nStatus);
if (m_aHeaders != null) {
final IJsonObject aHeaders = new JsonObject();
m_aHeaders.forEachSingleHeader(aHeaders::add, true);
ret.addJson("headers", aHeaders);
}
if (m_sBody != null)
ret.add("body", m_sBody);
return ret;
}
use of com.helger.json.IJsonObject in project peppol-commons by phax.
the class SMPJsonResponse method convert.
@Nonnull
public static IJsonObject convert(@Nonnull final IParticipantIdentifier aParticipantID, @Nonnull final IDocumentTypeIdentifier aDocTypeID, @Nonnull final com.helger.xsds.peppol.smp1.ServiceMetadataType aSM) {
ValueEnforcer.notNull(aParticipantID, "ParticipantID");
ValueEnforcer.notNull(aDocTypeID, "DocTypeID");
ValueEnforcer.notNull(aSM, "SM");
final IJsonObject ret = new JsonObject();
ret.add(JSON_SMPTYPE, ESMPAPIType.PEPPOL.getID());
ret.add(JSON_PARTICIPANT_ID, aParticipantID.getURIEncoded());
ret.add(JSON_DOCUMENT_TYPE_ID, aDocTypeID.getURIEncoded());
final com.helger.xsds.peppol.smp1.RedirectType aRedirect = aSM.getRedirect();
if (aRedirect != null) {
final IJsonObject aJsonRedirect = new JsonObject().add(JSON_HREF, aRedirect.getHref()).add(JSON_CERTIFICATE_UID, aRedirect.getCertificateUID()).add(JSON_EXTENSION, SMPExtensionConverter.convertToString(aRedirect.getExtension()));
ret.addJson(JSON_REDIRECT, aJsonRedirect);
} else {
final com.helger.xsds.peppol.smp1.ServiceInformationType aSI = aSM.getServiceInformation();
final IJsonObject aJsonSI = new JsonObject();
{
final IJsonArray aJsonProcs = new JsonArray();
// For all processes
if (aSI.getProcessList() != null)
for (final com.helger.xsds.peppol.smp1.ProcessType aProcess : aSI.getProcessList().getProcess()) if (aProcess.getProcessIdentifier() != null) {
final IJsonObject aJsonProc = new JsonObject().add(JSON_PROCESS_ID, CIdentifier.getURIEncoded(aProcess.getProcessIdentifier()));
final IJsonArray aJsonEPs = new JsonArray();
// For all endpoints
if (aProcess.getServiceEndpointList() != null)
for (final com.helger.xsds.peppol.smp1.EndpointType aEndpoint : aProcess.getServiceEndpointList().getEndpoint()) {
aJsonEPs.add(convertEndpoint(aEndpoint));
}
aJsonProc.addJson(JSON_ENDPOINTS, aJsonEPs).add(JSON_EXTENSION, SMPExtensionConverter.convertToString(aProcess.getExtension()));
aJsonProcs.add(aJsonProc);
}
aJsonSI.addJson(JSON_PROCESSES, aJsonProcs).add(JSON_EXTENSION, SMPExtensionConverter.convertToString(aSI.getExtension()));
}
ret.addJson(JSON_SERVICEINFO, aJsonSI);
}
return ret;
}
use of com.helger.json.IJsonObject in project peppol-commons by phax.
the class SMPJsonResponse method convertEndpoint.
@Nonnull
public static IJsonObject convertEndpoint(@Nonnull final com.helger.xsds.bdxr.smp1.EndpointType aEndpoint) {
final IJsonObject aJsonEP = new JsonObject().add(JSON_TRANSPORT_PROFILE, aEndpoint.getTransportProfile()).add(JSON_ENDPOINT_REFERENCE, aEndpoint.getEndpointURI()).add(JSON_REQUIRE_BUSINESS_LEVEL_SIGNATURE, aEndpoint.isRequireBusinessLevelSignature()).add(JSON_MINIMUM_AUTHENTICATION_LEVEL, aEndpoint.getMinimumAuthenticationLevel());
aJsonEP.addIfNotNull(JSON_SERVICE_ACTIVATION_DATE, getLDT(aEndpoint.getServiceActivationDate()));
aJsonEP.addIfNotNull(JSON_SERVICE_EXPIRATION_DATE, getLDT(aEndpoint.getServiceExpirationDate()));
convertCertificate(aJsonEP, Base64.encodeBytes(aEndpoint.getCertificate()));
aJsonEP.add(JSON_SERVICE_DESCRIPTION, aEndpoint.getServiceDescription()).add(JSON_TECHNICAL_CONTACT_URL, aEndpoint.getTechnicalContactUrl()).add(JSON_TECHNICAL_INFORMATION_URL, aEndpoint.getTechnicalInformationUrl()).addIfNotNull(JSON_EXTENSION, BDXR1ExtensionConverter.convertToJson(aEndpoint.getExtension()));
return aJsonEP;
}
Aggregations