Search in sources :

Example 6 with Version

use of org.codehaus.jackson.Version in project apex-core by apache.

the class StramWebServices method init.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void init() {
    // clear content type
    httpResponse.setContentType(null);
    if (!initialized) {
        Map<Class<?>, Class<? extends StringCodec<?>>> codecs = dagManager.getApplicationAttributes().get(DAGContext.STRING_CODECS);
        StringCodecs.loadConverters(codecs);
        if (codecs != null) {
            SimpleModule sm = new SimpleModule("DTSerializationModule", new Version(1, 0, 0, null));
            for (Map.Entry<Class<?>, Class<? extends StringCodec<?>>> entry : codecs.entrySet()) {
                try {
                    final StringCodec<Object> codec = (StringCodec<Object>) entry.getValue().newInstance();
                    sm.addSerializer(new SerializerBase(entry.getKey()) {

                        @Override
                        public void serialize(Object value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
                            jgen.writeString(codec.toString(value));
                        }
                    });
                } catch (Exception ex) {
                    LOG.error("Caught exception when instantiating codec for class {}", entry.getKey().getName(), ex);
                }
            }
            objectMapper.registerModule(sm);
        }
        initialized = true;
    }
}
Also used : SerializerBase(org.codehaus.jackson.map.ser.std.SerializerBase) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) NotFoundException(org.apache.hadoop.yarn.webapp.NotFoundException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) JSONException(org.codehaus.jettison.json.JSONException) StringCodec(com.datatorrent.api.StringCodec) Version(org.codehaus.jackson.Version) JsonGenerator(org.codehaus.jackson.JsonGenerator) JSONObject(org.codehaus.jettison.json.JSONObject) SerializerProvider(org.codehaus.jackson.map.SerializerProvider) Map(java.util.Map) BeanMap(org.apache.commons.beanutils.BeanMap) HashMap(java.util.HashMap) JsonProcessingException(org.codehaus.jackson.JsonProcessingException) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 7 with Version

use of org.codehaus.jackson.Version in project oxTrust by GluuFederation.

the class GroupWebService method searchGroups.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchGroups(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        if (count > getMaxCount()) {
            String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
            return getErrorResponse(detail, Response.Status.BAD_REQUEST.getStatusCode());
        } else {
            log.info(" Searching groups from LDAP ");
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuGroup> gluuGroups = search(groupService.getDnForGroup(null), GluuGroup.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            // List<GluuGroup> groupList = groupService.getAllGroupsList();
            GluuGroupList groupsList = new GluuGroupList();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
            log.info(" setting schema");
            groupsList.setSchemas(schema);
            // Set total
            groupsList.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && gluuGroups != null && !gluuGroups.isEmpty()) {
                for (GluuGroup gluuGroup : gluuGroups) {
                    ScimGroup group = copyUtils.copy(gluuGroup, null);
                    log.info(" group to be added displayName : " + group.getDisplayName());
                    groupsList.getResources().add(group);
                    log.info(" group added? : " + groupsList.getResources().contains(group));
                }
                // Set the rest of results info
                groupsList.setItemsPerPage(vlvResponse.getItemsPerPage());
                groupsList.setStartIndex(vlvResponse.getStartIndex());
            }
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Groups");
            // Serialize to JSON
            ObjectMapper mapper = new ObjectMapper();
            mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
            SimpleModule customScimFilterModule = new SimpleModule("CustomScim1GroupFilterModule", new Version(1, 0, 0, ""));
            GluuGroupListSerializer serializer = new GluuGroupListSerializer();
            serializer.setAttributesArray(attributesArray);
            customScimFilterModule.addSerializer(ScimGroup.class, serializer);
            mapper.registerModule(customScimFilterModule);
            String json = mapper.writeValueAsString(groupsList);
            return Response.ok(json).location(location).build();
        }
    } catch (Exception ex) {
        log.error("Error in searchGroups", ex);
        ex.printStackTrace();
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) GluuGroup(org.gluu.oxtrust.model.GluuGroup) URI(java.net.URI) GluuGroupListSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.GluuGroupListSerializer) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) GluuGroupList(org.gluu.oxtrust.model.GluuGroupList) Version(org.codehaus.jackson.Version) ScimGroup(org.gluu.oxtrust.model.scim.ScimGroup) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with Version

use of org.codehaus.jackson.Version in project oxTrust by GluuFederation.

the class UserWebService method searchPersons.

@GET
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@HeaderParam("Accept")
@DefaultValue(MediaType.APPLICATION_JSON)
public Response searchPersons(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_FILTER) final String filterString, @QueryParam(OxTrustConstants.QUERY_PARAMETER_START_INDEX) final int startIndex, @QueryParam(OxTrustConstants.QUERY_PARAMETER_COUNT) final int count, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_BY) final String sortBy, @QueryParam(OxTrustConstants.QUERY_PARAMETER_SORT_ORDER) final String sortOrder, @QueryParam(OxTrustConstants.QUERY_PARAMETER_ATTRIBUTES) final String attributesArray) throws Exception {
    Response authorizationResponse = processAuthorization(authorization);
    if (authorizationResponse != null) {
        return authorizationResponse;
    }
    try {
        if (count > getMaxCount()) {
            String detail = "Too many results (=" + count + ") would be returned; max is " + getMaxCount() + " only.";
            return getErrorResponse(detail, Response.Status.BAD_REQUEST.getStatusCode());
        } else {
            log.info(" Searching persons from LDAP ");
            VirtualListViewResponse vlvResponse = new VirtualListViewResponse();
            List<GluuCustomPerson> gluuCustomPersons = search(personService.getDnForPerson(null), GluuCustomPerson.class, filterString, startIndex, count, sortBy, sortOrder, vlvResponse, attributesArray);
            // List<GluuCustomPerson> personList = personService.findAllPersons(null);
            GluuCustomPersonList personsList = new GluuCustomPersonList();
            List<String> schema = new ArrayList<String>();
            schema.add(Constants.SCIM1_CORE_SCHEMA_ID);
            log.info(" setting schema");
            personsList.setSchemas(schema);
            // Set total
            personsList.setTotalResults(vlvResponse.getTotalResults());
            if (count > 0 && gluuCustomPersons != null && !gluuCustomPersons.isEmpty()) {
                for (GluuCustomPerson gluuPerson : gluuCustomPersons) {
                    ScimPerson person = copyUtils.copy(gluuPerson, null);
                    log.info(" person to be added id : " + person.getUserName());
                    personsList.getResources().add(person);
                    log.info(" person added? : " + personsList.getResources().contains(person));
                }
                // Set the rest of results info
                personsList.setItemsPerPage(vlvResponse.getItemsPerPage());
                personsList.setStartIndex(vlvResponse.getStartIndex());
            }
            URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v1/Users");
            // Serialize to JSON
            ObjectMapper mapper = new ObjectMapper();
            mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
            SimpleModule customScimFilterModule = new SimpleModule("CustomScim1PersonFilterModule", new Version(1, 0, 0, ""));
            GluuCustomPersonListSerializer serializer = new GluuCustomPersonListSerializer();
            serializer.setAttributesArray(attributesArray);
            customScimFilterModule.addSerializer(ScimPerson.class, serializer);
            mapper.registerModule(customScimFilterModule);
            String json = mapper.writeValueAsString(personsList);
            return Response.ok(json).location(location).build();
        }
    } catch (Exception ex) {
        log.error("Error in searchPersons", ex);
        ex.printStackTrace();
        return getErrorResponse(INTERNAL_SERVER_ERROR_MESSAGE, Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ArrayList(java.util.ArrayList) GluuCustomPersonListSerializer(org.gluu.oxtrust.service.antlr.scimFilter.util.GluuCustomPersonListSerializer) URI(java.net.URI) PersonRequiredFieldsException(org.gluu.oxtrust.exception.PersonRequiredFieldsException) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) Response(javax.ws.rs.core.Response) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) Version(org.codehaus.jackson.Version) ScimPerson(org.gluu.oxtrust.model.scim.ScimPerson) GluuCustomPersonList(org.gluu.oxtrust.model.GluuCustomPersonList) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with Version

use of org.codehaus.jackson.Version in project oxTrust by GluuFederation.

the class GroupCoreLoadingStrategy method load.

@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
    log.info(" load() ");
    Meta meta = new Meta();
    meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
    meta.setResourceType("Schema");
    schemaType.setMeta(meta);
    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule groupCoreLoadingStrategyModule = new SimpleModule("GroupCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeGroupSerializer serializer = new SchemaTypeGroupSerializer();
    serializer.setSchemaType(schemaType);
    groupCoreLoadingStrategyModule.addSerializer(Group.class, serializer);
    mapper.registerModule(groupCoreLoadingStrategyModule);
    mapper.writeValueAsString(createDummyGroup());
    return serializer.getSchemaType();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaTypeGroupSerializer(org.gluu.oxtrust.service.scim2.schema.strategy.serializers.SchemaTypeGroupSerializer) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Example 10 with Version

use of org.codehaus.jackson.Version in project oxTrust by GluuFederation.

the class UserCoreLoadingStrategy method load.

@Override
public SchemaType load(AppConfiguration appConfiguration, SchemaType schemaType) throws Exception {
    log.info(" load() ");
    Meta meta = new Meta();
    meta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/Schemas/" + schemaType.getId());
    meta.setResourceType("Schema");
    schemaType.setMeta(meta);
    // Use serializer to walk the class structure
    ObjectMapper mapper = new ObjectMapper();
    mapper.disable(SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS);
    SimpleModule userCoreLoadingStrategyModule = new SimpleModule("UserCoreLoadingStrategyModule", new Version(1, 0, 0, ""));
    SchemaTypeUserSerializer serializer = new SchemaTypeUserSerializer();
    serializer.setSchemaType(schemaType);
    userCoreLoadingStrategyModule.addSerializer(User.class, serializer);
    mapper.registerModule(userCoreLoadingStrategyModule);
    mapper.writeValueAsString(createDummyUser());
    return serializer.getSchemaType();
}
Also used : SchemaTypeUserSerializer(org.gluu.oxtrust.service.scim2.schema.strategy.serializers.SchemaTypeUserSerializer) Meta(org.gluu.oxtrust.model.scim2.Meta) Version(org.codehaus.jackson.Version) ObjectMapper(org.codehaus.jackson.map.ObjectMapper) SimpleModule(org.codehaus.jackson.map.module.SimpleModule)

Aggregations

Version (org.codehaus.jackson.Version)15 SimpleModule (org.codehaus.jackson.map.module.SimpleModule)15 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)13 URI (java.net.URI)3 DefaultValue (javax.ws.rs.DefaultValue)3 HeaderParam (javax.ws.rs.HeaderParam)3 Produces (javax.ws.rs.Produces)3 Response (javax.ws.rs.core.Response)3 Meta (org.gluu.oxtrust.model.scim2.Meta)3 DuplicateEntryException (org.gluu.site.ldap.exception.DuplicateEntryException)3 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 PersonRequiredFieldsException (org.gluu.oxtrust.exception.PersonRequiredFieldsException)2 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)2 Extension (org.gluu.oxtrust.model.scim2.Extension)2 User (org.gluu.oxtrust.model.scim2.User)2 ListResponseGroupSerializer (org.gluu.oxtrust.service.antlr.scimFilter.util.ListResponseGroupSerializer)2 ListResponseUserSerializer (org.gluu.oxtrust.service.antlr.scimFilter.util.ListResponseUserSerializer)2