Search in sources :

Example 46 with IJsonObject

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());
}
Also used : IJsonObject(com.helger.json.IJsonObject) Test(org.junit.Test)

Example 47 with IJsonObject

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;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 48 with IJsonObject

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;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Example 49 with IJsonObject

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;
}
Also used : JsonArray(com.helger.json.JsonArray) IJsonArray(com.helger.json.IJsonArray) IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) IJsonArray(com.helger.json.IJsonArray) Nonnull(javax.annotation.Nonnull)

Example 50 with IJsonObject

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;
}
Also used : IJsonObject(com.helger.json.IJsonObject) IJsonObject(com.helger.json.IJsonObject) JsonObject(com.helger.json.JsonObject) Nonnull(javax.annotation.Nonnull)

Aggregations

IJsonObject (com.helger.json.IJsonObject)79 JsonObject (com.helger.json.JsonObject)44 Nonnull (javax.annotation.Nonnull)41 IJsonArray (com.helger.json.IJsonArray)22 JsonArray (com.helger.json.JsonArray)19 Test (org.junit.Test)15 JsonWriter (com.helger.json.serialize.JsonWriter)12 IJson (com.helger.json.IJson)10 Map (java.util.Map)10 StopWatch (com.helger.commons.timing.StopWatch)9 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)9 ZonedDateTime (java.time.ZonedDateTime)9 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)7 IError (com.helger.commons.error.IError)7 PDBusinessCard (com.helger.pd.businesscard.generic.PDBusinessCard)5 IDocumentTypeIdentifier (com.helger.peppolid.IDocumentTypeIdentifier)5 Nullable (javax.annotation.Nullable)5 Nonempty (com.helger.commons.annotation.Nonempty)4 ReturnsMutableCopy (com.helger.commons.annotation.ReturnsMutableCopy)3 CommonsLinkedHashMap (com.helger.commons.collection.impl.CommonsLinkedHashMap)3