Search in sources :

Example 1 with JSONException

use of org.codehaus.jettison.json.JSONException in project hadoop by apache.

the class TestAHSWebServices method setupClass.

@BeforeClass
public static void setupClass() throws Exception {
    conf = new YarnConfiguration();
    TimelineStore store = TestApplicationHistoryManagerOnTimelineStore.createStore(MAX_APPS);
    TimelineACLsManager aclsManager = new TimelineACLsManager(conf);
    aclsManager.setTimelineStore(store);
    TimelineDataManager dataManager = new TimelineDataManager(store, aclsManager);
    conf.setBoolean(YarnConfiguration.YARN_ACL_ENABLE, true);
    conf.set(YarnConfiguration.YARN_ADMIN_ACL, "foo");
    conf.setBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED, true);
    conf.set(YarnConfiguration.NM_REMOTE_APP_LOG_DIR, remoteLogRootDir);
    dataManager.init(conf);
    ApplicationACLsManager appAclsManager = new ApplicationACLsManager(conf);
    ApplicationHistoryManagerOnTimelineStore historyManager = new ApplicationHistoryManagerOnTimelineStore(dataManager, appAclsManager);
    historyManager.init(conf);
    historyClientService = new ApplicationHistoryClientService(historyManager) {

        @Override
        protected void serviceStart() throws Exception {
        // Do Nothing
        }
    };
    historyClientService.init(conf);
    historyClientService.start();
    ahsWebservice = new AHSWebServices(historyClientService, conf) {

        @Override
        public String getNMWebAddressFromRM(Configuration configuration, String nodeId) throws ClientHandlerException, UniformInterfaceException, JSONException {
            if (nodeId.equals(NM_ID)) {
                return NM_WEBADDRESS;
            }
            return null;
        }
    };
    fs = FileSystem.get(conf);
    GuiceServletConfig.setInjector(Guice.createInjector(new WebServletModule()));
}
Also used : ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) Configuration(org.apache.hadoop.conf.Configuration) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ApplicationHistoryClientService(org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryClientService) JSONException(org.codehaus.jettison.json.JSONException) TimelineACLsManager(org.apache.hadoop.yarn.server.timeline.security.TimelineACLsManager) ServletException(javax.servlet.ServletException) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) JSONException(org.codehaus.jettison.json.JSONException) ClientHandlerException(com.sun.jersey.api.client.ClientHandlerException) TimelineDataManager(org.apache.hadoop.yarn.server.timeline.TimelineDataManager) ApplicationACLsManager(org.apache.hadoop.yarn.server.security.ApplicationACLsManager) UniformInterfaceException(com.sun.jersey.api.client.UniformInterfaceException) YarnConfiguration(org.apache.hadoop.yarn.conf.YarnConfiguration) ApplicationHistoryManagerOnTimelineStore(org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryManagerOnTimelineStore) TestApplicationHistoryManagerOnTimelineStore(org.apache.hadoop.yarn.server.applicationhistoryservice.TestApplicationHistoryManagerOnTimelineStore) ApplicationHistoryManagerOnTimelineStore(org.apache.hadoop.yarn.server.applicationhistoryservice.ApplicationHistoryManagerOnTimelineStore) TestApplicationHistoryManagerOnTimelineStore(org.apache.hadoop.yarn.server.applicationhistoryservice.TestApplicationHistoryManagerOnTimelineStore) TimelineStore(org.apache.hadoop.yarn.server.timeline.TimelineStore) BeforeClass(org.junit.BeforeClass)

Example 2 with JSONException

use of org.codehaus.jettison.json.JSONException in project hadoop by apache.

the class TestRMWebServicesReservation method getReservationIdTestHelper.

/**
   * This method is used when a ReservationId is required. Attempt to use REST
   * API. If authentication is not enabled, ensure that the response status is
   * unauthorized and generate a ReservationId because downstream components
   * require a ReservationId for testing.
   * @param fallbackReservationId the ReservationId to use if authentication
   *                              is not enabled, causing the getNewReservation
   *                              API to fail.
   * @return the object representing the reservation ID.
   */
private ReservationId getReservationIdTestHelper(int fallbackReservationId) throws Exception {
    Thread.sleep(1000);
    ClientResponse response = constructWebResource(GET_NEW_RESERVATION_PATH).type(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(ClientResponse.class);
    if (!this.isAuthenticationEnabled()) {
        assertResponseStatusCode(Status.UNAUTHORIZED, response.getStatusInfo());
        return ReservationId.newInstance(clock.getTime(), fallbackReservationId);
    }
    System.out.println("RESPONSE:" + response);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    ReservationId rid = null;
    try {
        rid = ReservationId.parseReservationId(json.getString("reservation-id"));
    } catch (JSONException j) {
    // failure is possible and is checked outside
    }
    return rid;
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) ReservationId(org.apache.hadoop.yarn.api.records.ReservationId) JSONException(org.codehaus.jettison.json.JSONException)

Example 3 with JSONException

use of org.codehaus.jettison.json.JSONException in project ORCID-Source by ORCID.

the class SalesForceAdapter method createContactsWithRolesFromJson.

public List<Contact> createContactsWithRolesFromJson(JSONObject object) {
    try {
        JSONObject firstRecord = extractFirstRecord(object);
        JSONObject contactRoles = firstRecord.getJSONObject("Membership_Contact_Roles__r");
        List<JSONObject> objectsList = extractObjectListFromRecords(contactRoles);
        return objectsList.stream().map(e -> mapperFacade.map(e, Contact.class)).collect(Collectors.toList());
    } catch (JSONException e) {
        throw new RuntimeException("Error getting contacts with roles list from SalesForce JSON", e);
    }
}
Also used : JsonUtils.extractString(org.orcid.core.utils.JsonUtils.extractString) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) URL(java.net.URL) Resource(javax.annotation.Resource) Member(org.orcid.core.salesforce.model.Member) LoggerFactory(org.slf4j.LoggerFactory) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) JsonUtils.extractObject(org.orcid.core.utils.JsonUtils.extractObject) Opportunity(org.orcid.core.salesforce.model.Opportunity) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) ArrayList(java.util.ArrayList) List(java.util.List) JsonUtils(org.orcid.core.utils.JsonUtils) JSONException(org.codehaus.jettison.json.JSONException) MapperFacade(ma.glasnost.orika.MapperFacade) Consortium(org.orcid.core.salesforce.model.Consortium) Contact(org.orcid.core.salesforce.model.Contact) Integration(org.orcid.core.salesforce.model.Integration) ContactRole(org.orcid.core.salesforce.model.ContactRole) JSONObject(org.codehaus.jettison.json.JSONObject) JSONException(org.codehaus.jettison.json.JSONException)

Example 4 with JSONException

use of org.codehaus.jettison.json.JSONException in project ORCID-Source by ORCID.

the class SalesForceAdapter method createConsortiumFromJson.

public Consortium createConsortiumFromJson(JSONObject results) {
    try {
        int numFound = JsonUtils.extractInt(results, "totalSize");
        if (numFound == 0) {
            return null;
        }
        Consortium consortium = new Consortium();
        List<Opportunity> opportunityList = new ArrayList<>();
        consortium.setOpportunities(opportunityList);
        JSONArray records = results.getJSONArray("records");
        JSONObject firstRecord = records.getJSONObject(0);
        JSONObject opportunities = extractObject(firstRecord, "ConsortiaOpportunities__r");
        if (opportunities != null) {
            JSONArray opportunityRecords = opportunities.getJSONArray("records");
            for (int i = 0; i < opportunityRecords.length(); i++) {
                Opportunity salesForceOpportunity = new Opportunity();
                JSONObject opportunity = opportunityRecords.getJSONObject(i);
                salesForceOpportunity.setId(extractOpportunityId(opportunity));
                JSONObject account = extractObject(opportunity, "Account");
                salesForceOpportunity.setTargetAccountId(extractAccountId(account));
                // salesForceOpportunity.setAccountName(JsonUtils.extractString(account,
                // "Name"));
                salesForceOpportunity.setAccountName(JsonUtils.extractString(account, "Public_Display_Name__c"));
                opportunityList.add(salesForceOpportunity);
            }
            return consortium;
        }
    } catch (JSONException e) {
        throw new RuntimeException("Error getting consortium record from SalesForce JSON", e);
    }
    return null;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) Opportunity(org.orcid.core.salesforce.model.Opportunity) Consortium(org.orcid.core.salesforce.model.Consortium) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException)

Example 5 with JSONException

use of org.codehaus.jettison.json.JSONException in project mirrorgate-jira-stories-collector by BBVA.

the class JiraIssueUtils method getPriorSprint.

public SprintDTO getPriorSprint(Object o) {
    if (o == null) {
        return null;
    }
    List<String> sprints = null;
    if (o instanceof JSONArray) {
        JSONArray array = (JSONArray) o;
        sprints = new ArrayList<>(array.length());
        for (int i = 0; i < array.length(); i++) {
            try {
                sprints.add((String) array.get(i));
            } catch (JSONException e) {
                LOGGER.error("Error parsing sprint field", e);
            }
        }
    } else if (o instanceof List) {
        sprints = (List<String>) o;
    }
    return getPriorSprint(sprints);
}
Also used : JSONArray(org.codehaus.jettison.json.JSONArray) JSONException(org.codehaus.jettison.json.JSONException)

Aggregations

JSONException (org.codehaus.jettison.json.JSONException)281 JSONObject (org.codehaus.jettison.json.JSONObject)256 Response (javax.ws.rs.core.Response)183 Builder (javax.ws.rs.client.Invocation.Builder)179 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)179 Test (org.testng.annotations.Test)174 BaseTest (org.xdi.oxauth.BaseTest)174 Parameters (org.testng.annotations.Parameters)171 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)78 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)68 JSONArray (org.codehaus.jettison.json.JSONArray)44 RegisterResponse (org.xdi.oxauth.client.RegisterResponse)43 URISyntaxException (java.net.URISyntaxException)35 TokenRequest (org.xdi.oxauth.client.TokenRequest)35 ResponseType (org.xdi.oxauth.model.common.ResponseType)35 WebApplicationException (javax.ws.rs.WebApplicationException)18 IOException (java.io.IOException)17 OxAuthCryptoProvider (org.xdi.oxauth.model.crypto.OxAuthCryptoProvider)17 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14