Search in sources :

Example 61 with JsonMapObject

use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.

the class SwaggerToOpenApiConversionUtilsTest method verifyPetFindByStatusOrTags.

private void verifyPetFindByStatusOrTags(JsonMapObject pet, String opId) {
    JsonMapObject petGet = pet.getJsonMapProperty("get");
    boolean findByStatus = "findPetsByStatus".equals(opId);
    assertEquals(findByStatus ? 7 : 8, petGet.size());
    testCommonVerbProps(petGet, opId);
    assertNull(petGet.getJsonMapProperty("requestBody"));
    List<Map<String, Object>> parameters = petGet.getListMapProperty("parameters");
    assertEquals(1, parameters.size());
    JsonMapObject param = new JsonMapObject(parameters.get(0));
    assertEquals(findByStatus ? "status" : "tags", param.getProperty("name"));
    assertEquals("query", param.getProperty("in"));
    assertNull(param.getProperty("type"));
    assertNull(param.getProperty("items"));
    assertNull(param.getProperty("collectionFormat"));
    assertTrue(param.getBooleanProperty("explode"));
    assertTrue(param.getBooleanProperty("required"));
    JsonMapObject schema = param.getJsonMapProperty("schema");
    assertEquals(2, schema.size());
    assertEquals("array", schema.getStringProperty("type"));
    assertNotNull(schema.getProperty("items"));
    assertNull(schema.getProperty("requestBody"));
    JsonMapObject responses = petGet.getJsonMapProperty("responses");
    assertEquals(2, responses.size());
    assertNotNull(responses.getProperty("400"));
    JsonMapObject okResp = responses.getJsonMapProperty("200");
    assertEquals(2, okResp.size());
    assertNotNull(okResp.getProperty("description"));
    JsonMapObject content = okResp.getJsonMapProperty("content");
    assertEquals(2, content.size());
    verifyArrayContent(content, "application/json", "Pet");
    verifyArrayContent(content, "application/xml", "Pet");
    if (findByStatus) {
        assertNull(petGet.getProperty("deprecated"));
    } else {
        assertTrue(petGet.getBooleanProperty("deprecated"));
    }
}
Also used : Map(java.util.Map) JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject)

Example 62 with JsonMapObject

use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.

the class JsonMapObjectProvider method readFrom.

@Override
public JsonMapObject readFrom(Class<JsonMapObject> cls, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, String> headers, InputStream is) throws IOException, WebApplicationException {
    String s = IOUtils.readStringFromStream(is);
    try {
        JsonMapObject obj = cls == JsonMapObject.class ? new JsonMapObject() : (JsonMapObject) cls.newInstance();
        handler.fromJson(obj, s);
        return obj;
    } catch (Exception ex) {
        throw new IOException(ex);
    }
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject)

Example 63 with JsonMapObject

use of org.apache.cxf.jaxrs.json.basic.JsonMapObject in project cxf by apache.

the class JwsJsonConsumer method prepare.

private void prepare(String detachedPayload) {
    JsonMapObject jsonObject = new JsonMapObject();
    new JsonMapObjectReaderWriter().fromJson(jsonObject, jwsSignedDocument);
    Map<String, Object> jsonObjectMap = jsonObject.asMap();
    jwsPayload = (String) jsonObjectMap.get("payload");
    if (jwsPayload == null) {
        jwsPayload = detachedPayload;
    } else if (detachedPayload != null) {
        LOG.warning("JSON JWS includes a payload expected to be detached");
        throw new JwsException(JwsException.Error.INVALID_JSON_JWS);
    }
    if (jwsPayload == null) {
        LOG.warning("JSON JWS has no payload");
        throw new JwsException(JwsException.Error.INVALID_JSON_JWS);
    }
    List<Map<String, Object>> signatureArray = CastUtils.cast((List<?>) jsonObjectMap.get("signatures"));
    if (signatureArray != null) {
        if (jsonObjectMap.containsKey("signature")) {
            LOG.warning("JSON JWS has a flattened 'signature' element and a 'signatures' object");
            throw new JwsException(JwsException.Error.INVALID_JSON_JWS);
        }
        for (Map<String, Object> signatureEntry : signatureArray) {
            this.signatures.add(getSignatureObject(signatureEntry));
        }
    } else {
        this.signatures.add(getSignatureObject(jsonObjectMap));
    }
    if (signatures.isEmpty()) {
        LOG.warning("JSON JWS has no signatures");
        throw new JwsException(JwsException.Error.INVALID_JSON_JWS);
    }
    validateB64Status();
}
Also used : JsonMapObjectReaderWriter(org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter) JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject) Map(java.util.Map) JsonMapObject(org.apache.cxf.jaxrs.json.basic.JsonMapObject)

Aggregations

JsonMapObject (org.apache.cxf.jaxrs.json.basic.JsonMapObject)63 Map (java.util.Map)23 LinkedHashMap (java.util.LinkedHashMap)5 JsonMapObjectReaderWriter (org.apache.cxf.jaxrs.json.basic.JsonMapObjectReaderWriter)5 Test (org.junit.Test)3 LinkedList (java.util.LinkedList)2 IOException (java.io.IOException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 WebClient (org.apache.cxf.jaxrs.client.WebClient)1