Example usage for org.apache.http.entity ContentType APPLICATION_ATOM_XML

List of usage examples for org.apache.http.entity ContentType APPLICATION_ATOM_XML

Introduction

In this page you can find the example usage for org.apache.http.entity ContentType APPLICATION_ATOM_XML.

Prototype

ContentType APPLICATION_ATOM_XML

To view the source code for org.apache.http.entity ContentType APPLICATION_ATOM_XML.

Click Source Link

Usage

From source file:tech.sirwellington.alchemy.http.HttpVerbImplTest.java

@Test
public void testExecuteWhenContentTypeInvalid() throws IOException {
    List<ContentType> invalidContentTypes = Arrays.asList(ContentType.APPLICATION_ATOM_XML,
            ContentType.TEXT_HTML, ContentType.TEXT_XML, ContentType.APPLICATION_XML,
            ContentType.APPLICATION_OCTET_STREAM, ContentType.create(one(alphabeticString())));

    ContentType invalidContentType = Lists.oneOf(invalidContentTypes);

    String string = one(alphanumericString());
    entity = new StringEntity(string, invalidContentType);

    when(apacheResponse.getEntity()).thenReturn(entity);

    HttpResponse result = instance.execute(apacheClient, request);
    assertThat(result.bodyAsString(), is(string));
    verify(apacheResponse).close();/*from   ww  w  .  ja  v a2s. c  o  m*/
}

From source file:org.apache.olingo.fit.v3.EntityCreateTestITCase.java

@Test
public void issue135() {
    final int id = 2;
    final ODataEntity original = getSampleCustomerProfile(id, "Sample customer for issue 135", false);

    final URIBuilder uriBuilder = client.newURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer");
    final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory()
            .getEntityCreateRequest(uriBuilder.build(), original);
    createReq.setFormat(ODataFormat.JSON_FULL_METADATA);
    createReq.setContentType(ContentType.APPLICATION_ATOM_XML.getMimeType());
    createReq.setPrefer(client.newPreferences().returnContent());

    try {/*ww w . jav  a2  s. c  o  m*/
        final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
        assertEquals(201, createRes.getStatusCode());
    } catch (Exception e) {
        fail(e.getMessage());
    } finally {
        final ODataDeleteResponse deleteRes = client.getCUDRequestFactory()
                .getDeleteRequest(client.newURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer")
                        .appendKeySegment(id).build())
                .execute();
        assertEquals(204, deleteRes.getStatusCode());
    }
}

From source file:com.msopentech.odatajclient.engine.it.EntityCreateTestITCase.java

@Test
@Ignore/*  w  w  w  .  j  a va 2 s  .c o  m*/
public void issue135() {
    final int id = 2;
    final ODataEntity original = getSampleCustomerProfile(id, "Sample customer for issue 135", false);

    final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer");
    final ODataEntityCreateRequest createReq = client.getCUDRequestFactory()
            .getEntityCreateRequest(uriBuilder.build(), original);
    createReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
    createReq.setContentType(ContentType.APPLICATION_ATOM_XML.getMimeType());
    createReq.setPrefer(ODataHeaderValues.preferReturnContent);

    try {
        final ODataEntityCreateResponse createRes = createReq.execute();
        assertEquals(201, createRes.getStatusCode());
    } catch (Exception e) {
        fail(e.getMessage());
    } finally {
        final ODataDeleteResponse deleteRes = client.getCUDRequestFactory()
                .getDeleteRequest(client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer")
                        .appendKeySegment(id).build())
                .execute();
        assertEquals(204, deleteRes.getStatusCode());
    }
}

From source file:org.apache.olingo.client.core.it.v3.EntityCreateTestITCase.java

@Test
@Ignore//from  www. j a  v  a 2  s  .c om
public void issue135() {
    final int id = 2;
    final ODataEntity original = getSampleCustomerProfile(id, "Sample customer for issue 135", false);

    final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot())
            .appendEntitySetSegment("Customer");
    final ODataEntityCreateRequest createReq = client.getCUDRequestFactory()
            .getEntityCreateRequest(uriBuilder.build(), original);
    createReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
    createReq.setContentType(ContentType.APPLICATION_ATOM_XML.getMimeType());
    createReq.setPrefer(ODataHeaderValues.preferReturnContent);

    try {
        final ODataEntityCreateResponse createRes = createReq.execute();
        assertEquals(201, createRes.getStatusCode());
    } catch (Exception e) {
        fail(e.getMessage());
    } finally {
        final ODataDeleteResponse deleteRes = client.getCUDRequestFactory()
                .getDeleteRequest(client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer")
                        .appendKeySegment(id).build())
                .execute();
        assertEquals(204, deleteRes.getStatusCode());
    }
}

From source file:com.salesmanager.core.business.modules.integration.shipping.impl.UPSShippingQuote.java

@Override
public List<ShippingOption> getShippingQuotes(ShippingQuote shippingQuote, List<PackageDetails> packages,
        BigDecimal orderTotal, Delivery delivery, ShippingOrigin origin, MerchantStore store,
        IntegrationConfiguration configuration, IntegrationModule module,
        ShippingConfiguration shippingConfiguration, Locale locale) throws IntegrationException {

    Validate.notNull(configuration, "IntegrationConfiguration must not be null for USPS shipping module");

    if (StringUtils.isBlank(delivery.getPostalCode())) {
        return null;
    }/* w w  w.  j ava 2  s.c om*/

    BigDecimal total = orderTotal;

    if (packages == null) {
        return null;
    }

    List<ShippingOption> options = null;

    // only applies to Canada and US
    Country country = delivery.getCountry();

    if (!(country.getIsoCode().equals("US") || country.getIsoCode().equals("CA"))) {
        return null;
        //throw new IntegrationException("UPS Not configured for shipping in country " + country.getIsoCode());
    }

    // supports en and fr
    String language = locale.getLanguage();
    if (!language.equals(Locale.FRENCH.getLanguage()) && !language.equals(Locale.ENGLISH.getLanguage())) {
        language = Locale.ENGLISH.getLanguage();
    }

    String pack = configuration.getIntegrationOptions().get("packages").get(0);
    Map<String, String> keys = configuration.getIntegrationKeys();

    String accessKey = keys.get("accessKey");
    String userId = keys.get("userId");
    String password = keys.get("password");

    String host = null;
    String protocol = null;
    String port = null;
    String url = null;

    StringBuilder xmlbuffer = new StringBuilder();
    HttpPost httppost = null;
    BufferedReader reader = null;

    try {
        String env = configuration.getEnvironment();

        Set<String> regions = module.getRegionsSet();
        if (!regions.contains(store.getCountry().getIsoCode())) {
            throw new IntegrationException("Can't use the service for store country code ");
        }

        Map<String, ModuleConfig> moduleConfigsMap = module.getModuleConfigs();
        for (String key : moduleConfigsMap.keySet()) {

            ModuleConfig moduleConfig = (ModuleConfig) moduleConfigsMap.get(key);
            if (moduleConfig.getEnv().equals(env)) {
                host = moduleConfig.getHost();
                protocol = moduleConfig.getScheme();
                port = moduleConfig.getPort();
                url = moduleConfig.getUri();
            }
        }

        StringBuilder xmlreqbuffer = new StringBuilder();
        xmlreqbuffer.append("<?xml version=\"1.0\"?>");
        xmlreqbuffer.append("<AccessRequest>");
        xmlreqbuffer.append("<AccessLicenseNumber>");
        xmlreqbuffer.append(accessKey);
        xmlreqbuffer.append("</AccessLicenseNumber>");
        xmlreqbuffer.append("<UserId>");
        xmlreqbuffer.append(userId);
        xmlreqbuffer.append("</UserId>");
        xmlreqbuffer.append("<Password>");
        xmlreqbuffer.append(password);
        xmlreqbuffer.append("</Password>");
        xmlreqbuffer.append("</AccessRequest>");

        String xmlhead = xmlreqbuffer.toString();

        String weightCode = store.getWeightunitcode();
        String measureCode = store.getSeizeunitcode();

        if (weightCode.equals("KG")) {
            weightCode = "KGS";
        } else {
            weightCode = "LBS";
        }

        String xml = "<?xml version=\"1.0\"?><RatingServiceSelectionRequest><Request><TransactionReference><CustomerContext>Shopizer</CustomerContext><XpciVersion>1.0001</XpciVersion></TransactionReference><RequestAction>Rate</RequestAction><RequestOption>Shop</RequestOption></Request>";
        StringBuffer xmldatabuffer = new StringBuffer();

        /**
         * <Shipment>
         * 
         * <Shipper> <Address> <City></City>
         * <StateProvinceCode>QC</StateProvinceCode>
         * <CountryCode>CA</CountryCode> <PostalCode></PostalCode>
         * </Address> </Shipper>
         * 
         * <ShipTo> <Address> <City>Redwood Shores</City>
         * <StateProvinceCode>CA</StateProvinceCode>
         * <CountryCode>US</CountryCode> <PostalCode></PostalCode>
         * <ResidentialAddressIndicator/> </Address> </ShipTo>
         * 
         * <Package> <PackagingType> <Code>21</Code> </PackagingType>
         * <PackageWeight> <UnitOfMeasurement> <Code>LBS</Code>
         * </UnitOfMeasurement> <Weight>1.1</Weight> </PackageWeight>
         * <PackageServiceOptions> <InsuredValue>
         * <CurrencyCode>CAD</CurrencyCode>
         * <MonetaryValue>100</MonetaryValue> </InsuredValue>
         * </PackageServiceOptions> </Package>
         * 
         * 
         * </Shipment>
         * 
         * <CustomerClassification> <Code>03</Code>
         * </CustomerClassification> </RatingServiceSelectionRequest>
         * **/

        /**Map countriesMap = (Map) RefCache.getAllcountriesmap(LanguageUtil
              .getLanguageNumberCode(locale.getLanguage()));
        Map zonesMap = (Map) RefCache.getAllZonesmap(LanguageUtil
              .getLanguageNumberCode(locale.getLanguage()));
                
        Country storeCountry = (Country) countriesMap.get(store
              .getCountry());
                
        Country customerCountry = (Country) countriesMap.get(customer
              .getCustomerCountryId());
                
        int sZone = -1;
        try {
           sZone = Integer.parseInt(store.getZone());
        } catch (Exception e) {
           // TODO: handle exception
        }
                
        Zone storeZone = (Zone) zonesMap.get(sZone);
        Zone customerZone = (Zone) zonesMap.get(customer
              .getCustomerZoneId());**/

        xmldatabuffer.append("<PickupType><Code>03</Code></PickupType>");
        // xmldatabuffer.append("<Description>Daily Pickup</Description>");
        xmldatabuffer.append("<Shipment><Shipper>");
        xmldatabuffer.append("<Address>");
        xmldatabuffer.append("<City>");
        xmldatabuffer.append(store.getStorecity());
        xmldatabuffer.append("</City>");
        // if(!StringUtils.isBlank(store.getStorestateprovince())) {
        if (store.getZone() != null) {
            xmldatabuffer.append("<StateProvinceCode>");
            xmldatabuffer.append(store.getZone().getCode());// zone code
            xmldatabuffer.append("</StateProvinceCode>");
        }
        xmldatabuffer.append("<CountryCode>");
        xmldatabuffer.append(store.getCountry().getIsoCode());
        xmldatabuffer.append("</CountryCode>");
        xmldatabuffer.append("<PostalCode>");
        xmldatabuffer.append(DataUtils.trimPostalCode(store.getStorepostalcode()));
        xmldatabuffer.append("</PostalCode></Address></Shipper>");

        // ship to
        xmldatabuffer.append("<ShipTo>");
        xmldatabuffer.append("<Address>");
        xmldatabuffer.append("<City>");
        xmldatabuffer.append(delivery.getCity());
        xmldatabuffer.append("</City>");
        // if(!StringUtils.isBlank(customer.getCustomerState())) {
        if (delivery.getZone() != null) {
            xmldatabuffer.append("<StateProvinceCode>");
            xmldatabuffer.append(delivery.getZone().getCode());// zone code
            xmldatabuffer.append("</StateProvinceCode>");
        }
        xmldatabuffer.append("<CountryCode>");
        xmldatabuffer.append(delivery.getCountry().getIsoCode());
        xmldatabuffer.append("</CountryCode>");
        xmldatabuffer.append("<PostalCode>");
        xmldatabuffer.append(DataUtils.trimPostalCode(delivery.getPostalCode()));
        xmldatabuffer.append("</PostalCode></Address></ShipTo>");
        // xmldatabuffer.append("<Service><Code>11</Code></Service>");//TODO service codes (next day ...)

        for (PackageDetails packageDetail : packages) {

            xmldatabuffer.append("<Package>");
            xmldatabuffer.append("<PackagingType>");
            xmldatabuffer.append("<Code>");
            xmldatabuffer.append(pack);
            xmldatabuffer.append("</Code>");
            xmldatabuffer.append("</PackagingType>");

            // weight
            xmldatabuffer.append("<PackageWeight>");
            xmldatabuffer.append("<UnitOfMeasurement>");
            xmldatabuffer.append("<Code>");
            xmldatabuffer.append(weightCode);
            xmldatabuffer.append("</Code>");
            xmldatabuffer.append("</UnitOfMeasurement>");
            xmldatabuffer.append("<Weight>");
            xmldatabuffer.append(
                    new BigDecimal(packageDetail.getShippingWeight()).setScale(1, BigDecimal.ROUND_HALF_UP));
            xmldatabuffer.append("</Weight>");
            xmldatabuffer.append("</PackageWeight>");

            // dimension
            xmldatabuffer.append("<Dimensions>");
            xmldatabuffer.append("<UnitOfMeasurement>");
            xmldatabuffer.append("<Code>");
            xmldatabuffer.append(measureCode);
            xmldatabuffer.append("</Code>");
            xmldatabuffer.append("</UnitOfMeasurement>");
            xmldatabuffer.append("<Length>");
            xmldatabuffer.append(
                    new BigDecimal(packageDetail.getShippingLength()).setScale(2, BigDecimal.ROUND_HALF_UP));
            xmldatabuffer.append("</Length>");
            xmldatabuffer.append("<Width>");
            xmldatabuffer.append(
                    new BigDecimal(packageDetail.getShippingWidth()).setScale(2, BigDecimal.ROUND_HALF_UP));
            xmldatabuffer.append("</Width>");
            xmldatabuffer.append("<Height>");
            xmldatabuffer.append(
                    new BigDecimal(packageDetail.getShippingHeight()).setScale(2, BigDecimal.ROUND_HALF_UP));
            xmldatabuffer.append("</Height>");
            xmldatabuffer.append("</Dimensions>");
            xmldatabuffer.append("</Package>");

        }

        xmldatabuffer.append("</Shipment>");
        xmldatabuffer.append("</RatingServiceSelectionRequest>");

        xmlbuffer.append(xmlhead).append(xml).append(xmldatabuffer.toString());

        LOGGER.debug("UPS QUOTE REQUEST " + xmlbuffer.toString());

        CloseableHttpClient httpclient = HttpClients.createDefault();
        //HttpClient client = new HttpClient();
        httppost = new HttpPost(protocol + "://" + host + ":" + port + url);

        StringEntity entity = new StringEntity(xmlbuffer.toString(), ContentType.APPLICATION_ATOM_XML);

        //RequestEntity entity = new StringRequestEntity(
        //      xmlbuffer.toString(), "text/plain", "UTF-8");
        httppost.setEntity(entity);

        // Create a custom response handler
        ResponseHandler<String> responseHandler = new ResponseHandler<String>() {

            @Override
            public String handleResponse(final HttpResponse response)
                    throws ClientProtocolException, IOException {
                int status = response.getStatusLine().getStatusCode();
                if (status >= 200 && status < 300) {
                    HttpEntity entity = response.getEntity();
                    return entity != null ? EntityUtils.toString(entity) : null;
                } else {
                    LOGGER.error("Communication Error with ups quote " + status);
                    throw new ClientProtocolException("UPS quote communication error " + status);
                }
            }

        };

        String data = httpclient.execute(httppost, responseHandler);

        //int result = response.getStatusLine().getStatusCode();
        //int result = client.executeMethod(httppost);
        /*         if (result != 200) {
                    LOGGER.error("Communication Error with ups quote " + result + " "
          + protocol + "://" + host + ":" + port + url);
                    throw new Exception("UPS quote communication error " + result);
                 }*/

        LOGGER.debug("ups quote response " + data);

        UPSParsedElements parsed = new UPSParsedElements();

        Digester digester = new Digester();
        digester.push(parsed);
        digester.addCallMethod("RatingServiceSelectionResponse/Response/Error", "setErrorCode", 0);
        digester.addCallMethod("RatingServiceSelectionResponse/Response/ErrorDescriprion", "setError", 0);
        digester.addCallMethod("RatingServiceSelectionResponse/Response/ResponseStatusCode", "setStatusCode",
                0);
        digester.addCallMethod("RatingServiceSelectionResponse/Response/ResponseStatusDescription",
                "setStatusMessage", 0);
        digester.addCallMethod("RatingServiceSelectionResponse/Response/Error/ErrorDescription", "setError", 0);

        digester.addObjectCreate("RatingServiceSelectionResponse/RatedShipment", ShippingOption.class);
        // digester.addSetProperties(
        // "RatingServiceSelectionResponse/RatedShipment", "sequence",
        // "optionId" );
        digester.addCallMethod("RatingServiceSelectionResponse/RatedShipment/Service/Code", "setOptionId", 0);
        digester.addCallMethod("RatingServiceSelectionResponse/RatedShipment/TotalCharges/MonetaryValue",
                "setOptionPriceText", 0);
        //digester
        //      .addCallMethod(
        //            "RatingServiceSelectionResponse/RatedShipment/TotalCharges/CurrencyCode",
        //            "setCurrency", 0);
        digester.addCallMethod("RatingServiceSelectionResponse/RatedShipment/Service/Code", "setOptionCode", 0);
        digester.addCallMethod("RatingServiceSelectionResponse/RatedShipment/GuaranteedDaysToDelivery",
                "setEstimatedNumberOfDays", 0);
        digester.addSetNext("RatingServiceSelectionResponse/RatedShipment", "addOption");

        // <?xml
        // version="1.0"?><AddressValidationResponse><Response><TransactionReference><CustomerContext>SalesManager
        // Data</CustomerContext><XpciVersion>1.0</XpciVersion></TransactionReference><ResponseStatusCode>0</ResponseStatusCode><ResponseStatusDescription>Failure</ResponseStatusDescription><Error><ErrorSeverity>Hard</ErrorSeverity><ErrorCode>10002</ErrorCode><ErrorDescription>The
        // XML document is well formed but the document is not
        // valid</ErrorDescription><ErrorLocation><ErrorLocationElementName>AddressValidationRequest</ErrorLocationElementName></ErrorLocation></Error></Response></AddressValidationResponse>

        Reader xmlreader = new StringReader(data);

        digester.parse(xmlreader);

        if (!StringUtils.isBlank(parsed.getErrorCode())) {

            LOGGER.error(
                    "Can't process UPS statusCode=" + parsed.getErrorCode() + " message= " + parsed.getError());
            throw new IntegrationException(parsed.getError());
        }
        if (!StringUtils.isBlank(parsed.getStatusCode()) && !parsed.getStatusCode().equals("1")) {

            throw new IntegrationException(parsed.getError());
        }

        if (parsed.getOptions() == null || parsed.getOptions().size() == 0) {

            throw new IntegrationException("No shipping options available for the configuration");
        }

        /*String carrier = getShippingMethodDescription(locale);
        // cost is in CAD, need to do conversion
                
                
        boolean requiresCurrencyConversion = false; String storeCurrency
         = store.getCurrency();
        if(!storeCurrency.equals(Constants.CURRENCY_CODE_CAD)) {
         requiresCurrencyConversion = true; }
                 
                
        LabelUtil labelUtil = LabelUtil.getInstance();
        Map serviceMap = com.salesmanager.core.util.ShippingUtil
              .buildServiceMap("upsxml", locale);
                
        *//** Details on whit RT quote information to display **//*
                                                                  MerchantConfiguration rtdetails = config
                                                                  .getMerchantConfiguration(ShippingConstants.MODULE_SHIPPING_DISPLAY_REALTIME_QUOTES);
                                                                  int displayQuoteDeliveryTime = ShippingConstants.NO_DISPLAY_RT_QUOTE_TIME;
                                                                          
                                                                          
                                                                  if (rtdetails != null) {
                                                                          
                                                                  if (!StringUtils.isBlank(rtdetails.getConfigurationValue1())) {// display
                                                                  // or
                                                                  // not
                                                                  // quotes
                                                                  try {
                                                                  displayQuoteDeliveryTime = Integer.parseInt(rtdetails
                                                                  .getConfigurationValue1());
                                                                          
                                                                  } catch (Exception e) {
                                                                  log.error("Display quote is not an integer value ["
                                                                  + rtdetails.getConfigurationValue1() + "]");
                                                                  }
                                                                  }
                                                                  }*/

        List<ShippingOption> shippingOptions = parsed.getOptions();

        if (shippingOptions != null) {

            Map<String, String> details = module.getDetails();

            for (ShippingOption option : shippingOptions) {

                String name = details.get(option.getOptionCode());
                option.setOptionName(name);
                if (option.getOptionPrice() == null) {
                    String priceText = option.getOptionPriceText();
                    if (StringUtils.isBlank(priceText)) {
                        throw new IntegrationException("Price text is null for option " + name);
                    }

                    try {
                        BigDecimal price = new BigDecimal(priceText);
                        option.setOptionPrice(price);
                    } catch (Exception e) {
                        throw new IntegrationException("Can't convert to numeric price " + priceText);
                    }

                }

            }

        }

        /*         if (options != null) {
                
                    Map selectedintlservices = (Map) config
          .getConfiguration("service-global-upsxml");
                
                    Iterator i = options.iterator();
                    while (i.hasNext()) {
                       ShippingOption option = (ShippingOption) i.next();
                       // option.setCurrency(store.getCurrency());
                       StringBuffer description = new StringBuffer();
                
                       String code = option.getOptionCode();
                       option.setOptionCode(code);
                       // get description
                       String label = (String) serviceMap.get(code);
                       if (label == null) {
          log
                .warn("UPSXML cannot find description for service code "
                      + code);
                       }
                
                       option.setOptionName(label);
                
                       description.append(option.getOptionName());
                       if (displayQuoteDeliveryTime == ShippingConstants.DISPLAY_RT_QUOTE_TIME) {
          if (!StringUtils.isBlank(option
                .getEstimatedNumberOfDays())) {
             description.append(" (").append(
                   option.getEstimatedNumberOfDays()).append(
                   " ").append(
                   labelUtil.getText(locale,
                         "label.generic.days.lowercase"))
                   .append(")");
          }
                       }
                       option.setDescription(description.toString());
                
                       // get currency
                       if (!option.getCurrency().equals(store.getCurrency())) {
          option.setOptionPrice(CurrencyUtil.convertToCurrency(
                option.getOptionPrice(), option.getCurrency(),
                store.getCurrency()));
                       }
                
                       if (!selectedintlservices.containsKey(option
             .getOptionCode())) {
          if (returnColl == null) {
             returnColl = new ArrayList();
          }
          returnColl.add(option);
          // options.remove(option);
                       }
                
                    }
                
                    if (options.size() == 0) {
                       LogMerchantUtil
             .log(
                   store.getMerchantId(),
                   " none of the service code returned by UPS ["
                         + selectedintlservices
                               .keySet()
                               .toArray(
                                     new String[selectedintlservices
                                           .size()])
                         + "] for this shipping is in your selection list");
                    }
                 }*/

        return shippingOptions;

    } catch (Exception e1) {
        LOGGER.error("UPS quote error", e1);
        throw new IntegrationException(e1);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception ignore) {
            }
        }

        if (httppost != null) {
            httppost.releaseConnection();
        }
    }
}

From source file:com.rackspacecloud.blueflood.inputs.handlers.HttpHandlerIntegrationTest.java

@Test
public void testSearchMetricsWithAcceptNonJsonShouldReturn415() throws Exception {

    // test the GET /v2.0/%s/metrics/search
    URIBuilder query_builder = getMetricDataQueryURIBuilder().setPath(String.format(getSearchPath, TENANT_ID));
    query_builder.setParameter("query", "foo.bar.none");
    HttpGet searchRequest = new HttpGet(query_builder.build());
    searchRequest.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_ATOM_XML.toString());
    HttpResponse response = client.execute(searchRequest);
    assertEquals("accept non Json should get 415", 415, response.getStatusLine().getStatusCode());
}

From source file:com.rackspacecloud.blueflood.inputs.handlers.HttpHandlerIntegrationTest.java

@Test
public void testGetViewWithAcceptNonJsonShouldReturn415() throws Exception {
    // test the GET /v2.0/%s/views/%s
    parameterMap = new HashMap<String, String>();
    parameterMap.put(Event.fromParameterName, String.valueOf(baseMillis - 86400000));
    parameterMap.put(Event.untilParameterName, String.valueOf(baseMillis + (86400000 * 3)));
    HttpGet get = new HttpGet(getQueryMetricViewsURI(TENANT_ID, "bogus.name"));
    get.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_ATOM_XML.toString());
    HttpResponse response = client.execute(get);
    Assert.assertEquals(415, response.getStatusLine().getStatusCode());
}

From source file:com.rackspacecloud.blueflood.inputs.handlers.HttpHandlerIntegrationTest.java

@Test
public void testGetAnnotationWithAcceptNonJsonShouldReturn415() throws Exception {
    // test the GET /v2.0/%s/events
    parameterMap = new HashMap<String, String>();
    parameterMap.put(Event.fromParameterName, String.valueOf(baseMillis - 86400000));
    parameterMap.put(Event.untilParameterName, String.valueOf(baseMillis + (86400000 * 3)));
    HttpGet get = new HttpGet(getQueryEventsURI(TENANT_ID));
    get.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_ATOM_XML.toString());
    HttpResponse response = client.execute(get);
    Assert.assertEquals(415, response.getStatusLine().getStatusCode());
}

From source file:com.rackspacecloud.blueflood.inputs.handlers.HttpHandlerIntegrationTest.java

@Test
public void testGetMetricNameSearchWithAcceptNonJsonShouldReturn415() throws Exception {
    // test the GET /v2.0/%s/metrics_name/search
    parameterMap = new HashMap<String, String>();
    parameterMap.put(Event.fromParameterName, String.valueOf(baseMillis - 86400000));
    parameterMap.put(Event.untilParameterName, String.valueOf(baseMillis + (86400000 * 3)));
    HttpGet get = new HttpGet(getMetricNameSearchURI(TENANT_ID));
    get.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_ATOM_XML.toString());
    HttpResponse response = client.execute(get);
    Assert.assertEquals(415, response.getStatusLine().getStatusCode());
}