@Test
  public void testMappedConfig_Override() throws Exception {

    MappedFilter mappedFilter =
        new MappedFilter(mockFilter, new HashSet<>(Arrays.asList("/a/*", "/b/*")), "f1", 0);

    app.start(
        binder -> {
          JettyModule.contributeMappedFilters(binder).addBinding().toInstance(mappedFilter);
        },
        "--config=classpath:io/bootique/jetty/MappedFilterIT1.yml");

    WebTarget base = ClientBuilder.newClient().target("http://localhost:8080");

    Response r1 = base.path("/a").request().get();
    assertEquals(Status.NOT_FOUND.getStatusCode(), r1.getStatus());

    Response r2 = base.path("/b").request().get();
    assertEquals(Status.NOT_FOUND.getStatusCode(), r2.getStatus());

    Response r3 = base.path("/c").request().get();
    assertEquals(Status.OK.getStatusCode(), r3.getStatus());

    verify(mockFilter, times(1)).doFilter(any(), any(), any());
  }
  @Test
  public void testMissingGetInstance() {
    Response response =
        instanceResource.getInstance(UUID.randomUUID().toString(), INSTANCE_URI_INFO);

    assertEquals(response.getStatus(), Status.NOT_FOUND.getStatusCode());
  }
Esempio n. 3
0
 @Test
 public void shouldGet404WhenDeletingNonExtistentIndex() {
   String indexName = "nosuchindex";
   String indexUri = functionalTestHelper.nodeIndexUri() + indexName;
   JaxRsResponse response = RestRequest.req().delete(indexUri);
   assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
 }
Esempio n. 4
0
 @Test
 public void shouldGet404WhenRequestingIndexUriWhichDoesntExist() {
   String key = "key3";
   String value = "value";
   String indexName = "nosuchindex";
   String indexUri = functionalTestHelper.nodeIndexUri() + indexName + "/" + key + "/" + value;
   JaxRsResponse response = RestRequest.req().get(indexUri);
   assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
 }
Esempio n. 5
0
 @Test(groups = "slow")
 public void testCreditDoesNotExist() throws Exception {
   final Response response =
       doGet(
           JaxrsResource.CREDITS_PATH + "/" + UUID.randomUUID().toString(),
           DEFAULT_EMPTY_QUERY,
           DEFAULT_HTTP_TIMEOUT_SEC);
   assertEquals(
       response.getStatusCode(), Status.NOT_FOUND.getStatusCode(), response.getResponseBody());
 }
Esempio n. 6
0
  public void testPie1() {
    try {

      String url = baseURL + "/rest/Pie/search;id=*/utensilCollection";

      WebClient client = WebClient.create(url);
      client.type("application/xml").accept("application/xml");
      Response response = client.get();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      File myFile = new File("Pie_Search" + "XML.xml");
      System.out.println("writing data to file " + myFile.getAbsolutePath());
      FileWriter myWriter = new FileWriter(myFile);

      BufferedReader br =
          new BufferedReader(new InputStreamReader(((InputStream) response.getEntity())));

      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
        myWriter.write(output);
        System.out.println(output);
      }

      myWriter.flush();
      myWriter.close();

    } catch (Exception e) {
      e.printStackTrace();
      ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR);
      builder.type("application/xml");
      StringBuffer buffer = new StringBuffer();
      buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      buffer.append("<response>");
      buffer.append("<type>ERROR</type>");
      buffer.append("<code>INTERNAL_ERROR_4</code>");
      buffer.append("<message>Failed to Query due to: " + e.getMessage() + "</message>");
      buffer.append("</response>");
      builder.entity(buffer.toString());
      throw new WebApplicationException(builder.build());
    }
  }
 @Test
 public void discardComponentUnknown() {
   try {
     deleteAt(aResourceURI("<exception>"), PersonalComponentEntity.class);
     fail("A user shouldn't discard an unknown component");
   } catch (final UniformInterfaceException ex) {
     final int receivedStatus = ex.getResponse().getStatus();
     final int unauthorized = Status.NOT_FOUND.getStatusCode();
     assertThat(receivedStatus, is(unauthorized));
   }
 }
Esempio n. 8
0
 /** {@inheritDoc} */
 public Property<?> readProperty(String name) {
   if (name == null || name.isEmpty()) {
     throw new IllegalArgumentException("Property name cannot be null nor empty");
   }
   Response cRes = getStore().path(name).request(MediaType.APPLICATION_JSON_TYPE).get();
   if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
     throw new PropertyNotFoundException(name);
   }
   String resEntity = (String) cRes.readEntity(String.class);
   return PropertyJsonParser.parseProperty(resEntity);
 }
 @Test
 public void gettingAnUnexistingResource() {
   try {
     getAt(anUnexistingResourceURI(), getWebEntityClass());
     fail("A user shouldn't get an unexisting resource");
   } catch (WebApplicationException ex) {
     int receivedStatus = ex.getResponse().getStatus();
     int notFound = Status.NOT_FOUND.getStatusCode();
     assertThat(receivedStatus, is(notFound));
   }
 }
Esempio n. 10
0
 /** {@inheritDoc} */
 public void deleteProperty(String name) {
   Util.assertHasLength(name);
   Response cRes = getStore().path(name).request().delete();
   if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
     throw new PropertyNotFoundException(name);
   }
   if (Status.NO_CONTENT.getStatusCode() != cRes.getStatus()) {
     throw new PropertyAccessException(
         "Cannot delete property, an HTTP error " + cRes.getStatus() + " occured.");
   }
 }
 @Test
 public void updateOfAnUnexistingResource() {
   try {
     putAt(anUnexistingResourceURI(), aResource());
     fail("A user shouldn't update an unexisting resource");
   } catch (UniformInterfaceException ex) {
     int receivedStatus = ex.getResponse().getStatus();
     int notFound = Status.NOT_FOUND.getStatusCode();
     assertThat(receivedStatus, is(notFound));
   }
 }
  @Test(expected = UniformInterfaceException.class)
  @Category(UnitTest.class)
  public void testGetMapDoesntExist() throws Exception {
    try {
      execGet(String.valueOf(mapId + 1), null, null);
    } catch (UniformInterfaceException e) {
      Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), e.getResponse().getStatus());
      Assert.assertTrue(e.getResponse().getEntity(String.class).contains("No record exists"));

      throw e;
    }
  }
  @Test
  public void findById_notFound() throws Exception {
    expect(service.findById(RING_NAME, CASSANDRA_ID)).andReturn(null);
    replayAll();

    try {
      resource.findById(CASSANDRA_ID);
      fail("Expected NotFoundException");
    } catch (NotFoundException e) {
      assertEquals(Status.NOT_FOUND.getStatusCode(), e.getResponse().getStatus());
      assertEquals("No instance found with id: " + CASSANDRA_ID, e.getResponse().getEntity());
    }
  }
 @Test(expected = UniformInterfaceException.class)
 @Category(UnitTest.class)
 public void testGetInvalidReviewScoreMinParam() throws Exception {
   try {
     execGet(String.valueOf(mapId), "abc", null);
   } catch (UniformInterfaceException e) {
     // the input parameters for a Jersey request are more strongly typed than for a WPS request
     // so this unparsable type throws a 404, rather than a 400, b/c Jersey doesn't recognize the
     // request destination with unparsable input params.
     Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), e.getResponse().getStatus());
     throw e;
   }
 }
  @Test
  public void should_delete_forgotten_email_token() {

    final String uri = String.format(URI, "rec", "123");

    invoke(uri).post(Entity.entity(new Form(), "application/vnd.resource+json; charset=utf-8"));

    invoke(uri).delete();

    Response response = invoke(uri).get();

    assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
  }
Esempio n. 16
0
 /** {@inheritDoc} */
 public boolean existProperty(String name) {
   Util.assertHasLength(name);
   Response cRes = getStore().path(name).request(MediaType.APPLICATION_JSON_TYPE).get();
   if (Status.OK.getStatusCode() == cRes.getStatus()) {
     return true;
   }
   if (Status.NOT_FOUND.getStatusCode() == cRes.getStatus()) {
     return false;
   }
   throw new PropertyAccessException(
       "Cannot check existence of property, an HTTP error "
           + cRes.getStatus()
           + " occured : "
           + cRes.getEntity());
 }
Esempio n. 17
0
  public void testDelete() throws Exception {

    try {

      Pie searchObject = new Pie();
      Collection results =
          getApplicationService()
              .search(
                  "gov.nih.nci.cacoresdk.domain.other.differentpackage.associations.Pie",
                  searchObject);
      String id = "";

      if (results != null && results.size() > 0) {
        Pie obj = (Pie) ((List) results).get(0);

        Integer idVal = obj.getId();

        id = new Integer(idVal).toString();

      } else return;

      if (id.equals("")) return;

      String url = baseURL + "/rest/Pie/" + id;
      WebClient client = WebClient.create(url);

      Response response = client.delete();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }
  @Test
  public void testDeleteInstance() {
    String createdInstance =
        inMemoryInstanceConnector.createInstance("m1.tiny", "mattstep", "in-memory");

    Response getResponse1 = instanceResource.getInstance(createdInstance, INSTANCE_URI_INFO);

    assertEquals(getResponse1.getStatus(), Status.OK.getStatusCode());

    Response deleteResponse = instanceResource.deleteInstance(createdInstance);

    assertEquals(deleteResponse.getStatus(), Status.NO_CONTENT.getStatusCode());

    Response getResponse2 = instanceResource.getInstance(createdInstance, INSTANCE_URI_INFO);

    assertEquals(getResponse2.getStatus(), Status.NOT_FOUND.getStatusCode());
  }
Esempio n. 19
0
  public void testSearch() throws Exception {

    try {

      String url = baseURL + "/rest/Pupil/search;id=*";
      WebClient client = WebClient.create(url);
      client.type("application/xml").accept("application/xml");
      Response response = client.get();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      File myFile = new File("Pupil_Search" + "XML.xml");
      System.out.println("writing data to file " + myFile.getAbsolutePath());
      FileWriter myWriter = new FileWriter(myFile);

      BufferedReader br =
          new BufferedReader(new InputStreamReader(((InputStream) response.getEntity())));

      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
        myWriter.write(output);
        System.out.println(output);
      }

      myWriter.flush();
      myWriter.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  @Test
  @SuppressWarnings("unchecked")
  public void testDeleteResource() {
    WebResource wr = resource().path(getResourcePath());
    T r = createTestResource();

    T res =
        (T)
            wr.type(MediaType.APPLICATION_XML)
                .accept(MediaType.APPLICATION_XML)
                .post(r.getClass(), r);
    Assert.assertNotNull("Resource not created", res);

    wr = resource().path(getResourcePath() + "/" + getResourceId(res));
    ClientResponse response = wr.delete(ClientResponse.class);
    Assert.assertEquals(Status.NO_CONTENT.getStatusCode(), response.getStatus());
    response = wr.accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
    Assert.assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());
  }
Esempio n. 21
0
  @Test(groups = "slow")
  public void testAccountDoesNotExist() throws Exception {
    final LocalDate effectiveDate = clock.getUTCToday();
    final CreditJson input =
        new CreditJson(
            BigDecimal.TEN,
            UUID.randomUUID().toString(),
            UUID.randomUUID().toString(),
            effectiveDate,
            UUID.randomUUID().toString(),
            null);
    final String jsonInput = mapper.writeValueAsString(input);

    // Try to create the credit
    final Response response =
        doPost(
            JaxrsResource.CREDITS_PATH, jsonInput, DEFAULT_EMPTY_QUERY, DEFAULT_HTTP_TIMEOUT_SEC);
    assertEquals(
        response.getStatusCode(), Status.NOT_FOUND.getStatusCode(), response.getResponseBody());
  }
  @Test
  public void should_return_notFound_if_attempt_doesnt_exist() {

    final String uri = String.format(URI, "type", "key");

    Response response = invoke(uri).get();
    assertEquals(Status.NOT_FOUND.getStatusCode(), response.getStatus());

    JsonObject token1 = response.readEntity(JsonObject.class);
    JsonArray jsonArray = token1.getJsonObject("errors").getJsonArray("messages");

    for (int i = 0; jsonArray.size() > i; i++) {
      JsonObject item = jsonArray.getJsonObject(i);

      assertEquals(
          NotFoundEnum.ATTEMPT.getCode().longValue(), item.getJsonNumber("code").longValue());
      assertNull(item.getJsonString("field"));
      assertEquals("attempt_not_found", item.getJsonString("message").getString());
    }
  }
  /**
   * This method is supposed to be used as exception mapper from <code>WebApplicationException
   * </code>, sent in REST response, to <code>AuxiliaryStorageException</code>.
   *
   * @param exception Exception to convert from.
   */
  private void handleWebException(WebApplicationException exception) {

    Response response = exception.getResponse();
    if (response == null) {
      throw new AuxiliaryStorageException("Mapping exception error: response is null");
    }

    int responseStatus = response.getStatus();

    if (Status.BAD_REQUEST.getStatusCode() == responseStatus) {
      throw new IllegalParameterException("Bad request server error");
    } else if (Status.NOT_FOUND.getStatusCode() == responseStatus) {
      throw new ObjectNotFoundException("Object not found in auxiliary storage");
    } else if (Status.CONFLICT.getStatusCode() == responseStatus) {
      throw new ObjectAlreadyExistsException("Object already exists in auxiliary storage");
    } else if (Status.INTERNAL_SERVER_ERROR.getStatusCode() == responseStatus) {
      throw new AuxiliaryStorageException("Internal server error");
    } else {
      throw new AuxiliaryStorageException("Unknown server error");
    }
  }
 @Test
 @Graph(
     value = {
       "a to c", "a to d", "c to b", "d to e", "b to f", "c to f", "f to g", "d to g", "e to g",
       "c to g"
     })
 public void shouldReturn404WhenFailingToFindASinglePath() throws JsonParseException {
   long a = nodeId(data.get(), "a");
   long g = nodeId(data.get(), "g");
   String noHitsJson =
       "{\"to\":\""
           + nodeUri(g)
           + "\", \"max_depth\":1, \"relationships\":{\"type\":\"dummy\", \"direction\":\"in\"}, \"algorithm\":\"shortestPath\"}";
   String entity =
       gen()
           .expectedStatus(Status.NOT_FOUND.getStatusCode())
           .payload(noHitsJson)
           .post("http://localhost:7474/db/data/node/" + a + "/path")
           .entity();
   System.out.println(entity);
 }
  @Test
  public void testPostGetDeleteMessage() {

    // test POST [app/messages]
    Response response =
        webTarget
            .request()
            .post(Entity.entity("Hello World !!!", MediaType.TEXT_PLAIN), Response.class);
    assertEquals(Status.CREATED.getStatusCode(), response.getStatus());

    // test GET [app/messages/{number}]
    URI location = response.getLocation();
    String resourceNum = location.getPath().substring(location.getPath().lastIndexOf("/") + 1);
    Message message =
        webTarget.path(resourceNum).request(MediaType.APPLICATION_XML).get(Message.class);
    assertEquals("Hello World !!!", message.getMessage());

    // test DELETE [app/messages/{number}]
    response = webTarget.path(resourceNum).request().delete();
    assertNotSame(Status.NOT_FOUND.getStatusCode(), response.getStatus());
  }
Esempio n. 26
0
  @Test
  public void testRun() throws InterruptedException, ExecutionException, TimeoutException {

    app.newRuntime().startServer("--config=src/test/resources/com/nhl/bootique/bom/jetty/test.yml");

    // wait for Jetty to start and run some web requests...
    Thread.sleep(1000);
    WebTarget base = ClientBuilder.newClient().target("http://localhost:11234/");

    Response r1 = base.path("/testc").request().get();
    assertEquals(Status.OK.getStatusCode(), r1.getStatus());
    String expected1 =
        String.format("bom_filter_before%nbom_servlet_query_string: null%nbom_filter_after%n");
    assertEquals(expected1, r1.readEntity(String.class));

    Response r2 = base.path("/testb").request().get();
    assertEquals(Status.NOT_FOUND.getStatusCode(), r2.getStatus());

    Response r3 = base.path("/testc").queryParam("p", "v").request().get();
    assertEquals(Status.OK.getStatusCode(), r3.getStatus());
    String expected3 =
        String.format("bom_filter_before%nbom_servlet_query_string: p=v%nbom_filter_after%n");
    assertEquals(expected3, r3.readEntity(String.class));
  }
Esempio n. 27
0
 @Test
 public void shouldNotFindVdb() throws Exception {
   this.response =
       request(UriBuilder.fromUri(_uriBuilder.generateVdbsUri()).path("blah").build()).get();
   assertThat(this.response.getStatus(), is(Status.NOT_FOUND.getStatusCode()));
 }
  @Test
  public void testDeleteMissingInstance() {
    Response deleteResponse = instanceResource.deleteInstance(UUID.randomUUID().toString());

    assertEquals(deleteResponse.getStatus(), Status.NOT_FOUND.getStatusCode());
  }
Esempio n. 29
0
  /**
   * Uses Nested Search Criteria for search Verifies that the results are returned Verifies size of
   * the result set Verifies that none of the attributes are null
   *
   * @throws Exception
   */
  public void testGet() throws Exception {

    try {

      Pupil searchObject = new Pupil();
      Collection results =
          getApplicationService()
              .search("gov.nih.nci.cacoresdk.domain.inheritance.abstrakt.Pupil", searchObject);
      String id = "";

      if (results != null && results.size() > 0) {
        Pupil obj = (Pupil) ((List) results).get(0);

        id = obj.getId().getExtension();

      } else return;

      if (id.equals("")) return;

      String url = baseURL + "/rest/Pupil/" + id;

      WebClient client = WebClient.create(url);
      client.type("application/xml").accept("application/xml");
      Response response = client.get();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      File myFile = new File("Pupil" + "XML.xml");

      System.out.println("writing data to file " + myFile.getAbsolutePath());
      FileWriter myWriter = new FileWriter(myFile);

      BufferedReader br =
          new BufferedReader(new InputStreamReader(((InputStream) response.getEntity())));

      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
        myWriter.write(output);
        System.out.println(output);
      }

      myWriter.flush();
      myWriter.close();
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
  }
Esempio n. 30
0
  public void testgetUtensilCollection() {
    try {
      Pie searchObject = new Pie();
      Collection results4 =
          getApplicationService()
              .search(
                  "gov.nih.nci.cacoresdk.domain.other.differentpackage.associations.Pie",
                  searchObject);
      String id = "";

      if (results4 != null && results4.size() > 0) {
        Pie obj = (Pie) ((List) results4).get(0);

        Integer idVal = obj.getId();

        id = new Integer(idVal).toString();

      } else return;

      if (id.equals("")) return;

      String url = baseURL + "/rest/Pie/" + id + "/utensilCollection";

      WebClient client = WebClient.create(url);
      client.type("application/xml").accept("application/xml");
      Response response = client.get();

      if (response.getStatus() == Status.NOT_ACCEPTABLE.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() == Status.NOT_FOUND.getStatusCode()) {
        InputStream is = (InputStream) response.getEntity();
        org.jdom.input.SAXBuilder builder = new org.jdom.input.SAXBuilder(false);
        org.jdom.Document jDoc = builder.build(is);
        assertEquals(jDoc.getRootElement().getName(), "response");
      } else if (response.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
      }

      File myFile = new File("Pie_Search" + "XML.xml");
      System.out.println("writing data to file " + myFile.getAbsolutePath());
      FileWriter myWriter = new FileWriter(myFile);

      BufferedReader br =
          new BufferedReader(new InputStreamReader(((InputStream) response.getEntity())));

      String output;
      System.out.println("Output from Server .... \n");
      while ((output = br.readLine()) != null) {
        myWriter.write(output);
        System.out.println(output);
      }

      myWriter.flush();
      myWriter.close();
    } catch (Exception e) {
      e.printStackTrace();
      ResponseBuilder builder = Response.status(Status.INTERNAL_SERVER_ERROR);
      builder.type("application/xml");
      StringBuffer buffer = new StringBuffer();
      buffer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      buffer.append("<response>");
      buffer.append("<type>ERROR</type>");
      buffer.append("<code>INTERNAL_ERROR_4</code>");
      buffer.append("<message>Failed to Query due to: " + e.getMessage() + "</message>");
      buffer.append("</response>");
      builder.entity(buffer.toString());
      throw new WebApplicationException(builder.build());
    }
  }