public boolean removeUserCredentialsForPaaS(String userInstanceUriId, String paaSInstanceUriId)
      throws SOAException {
    String rsUri = getBASE_URI() + "removeUserCredentialsForPaaS";

    WebClient client = WebClient.create(rsUri);
    client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN);

    registerJsonProvider();

    List<Attachment> atts = new LinkedList<Attachment>();

    atts.add(new Attachment("userInstanceUriId", MediaType.TEXT_PLAIN, userInstanceUriId));

    atts.add(new Attachment("paaSInstanceUriId", MediaType.TEXT_PLAIN, paaSInstanceUriId));

    Response response = client.post(new MultipartBody(atts));

    if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.ACCEPTED) {
      try {
        String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity());
        logger.debug("Response Status ACCEPTED - " + responseString);
      } catch (IOException ex) {
        logger.error("Error reading the REST response: " + ex.getMessage());
      }
      return true;
    }
    return false;
  }
  public String storeTurtleUserProfile(String userProfile, String username, String password) {
    String rsUri = getBASE_URI() + "createNewUserAccount";

    WebClient client = WebClient.create(rsUri);
    client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN);

    registerJsonProvider();

    List<Attachment> atts = new LinkedList<Attachment>();

    atts.add(new Attachment("userProfile", MediaType.TEXT_PLAIN, userProfile));

    atts.add(new Attachment("username", MediaType.TEXT_PLAIN, username));

    atts.add(new Attachment("password", MediaType.TEXT_PLAIN, password));

    Response response = client.post(new MultipartBody(atts));
    String userInstanceUriId = null;
    if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.CREATED) {
      try {
        userInstanceUriId = IOUtils.readStringFromStream((InputStream) response.getEntity());
        logger.debug("Response Status CREATED - userInstanceUriId: " + userInstanceUriId);
      } catch (IOException ex) {
        logger.error("Error reading the REST response: " + ex.getMessage());
      }
    }
    return userInstanceUriId;
  }
  private void onException(Throwable e, Response r, boolean mapped) {
    if (request.isTracingEnabled()) {
      Response.Status s = Response.Status.fromStatusCode(r.getStatus());
      if (s != null) {
        request.trace(
            String.format(
                "mapped exception to response: %s -> %d (%s)",
                ReflectionHelper.objectToString(e), r.getStatus(), s.getReasonPhrase()));
      } else {
        request.trace(
            String.format(
                "mapped exception to response: %s -> %d",
                ReflectionHelper.objectToString(e), r.getStatus()));
      }
    }

    if (!mapped && r.getStatus() >= 500) {
      logException(e, r, Level.SEVERE);
    } else if (LOGGER.isLoggable(Level.FINE)) {
      logException(e, r, Level.FINE);
    }

    setResponse(r);

    this.mappedThrowable = e;

    if (getEntity() != null && getHttpHeaders().getFirst(HttpHeaders.CONTENT_TYPE) == null) {
      Object m = request.getProperties().get(HttpMethodRule.CONTENT_TYPE_PROPERTY);
      if (m != null) {
        request.getProperties().remove(HttpMethodRule.CONTENT_TYPE_PROPERTY);
        getHttpHeaders().putSingle(HttpHeaders.CONTENT_TYPE, m);
      }
    }
  }
Esempio n. 4
0
 @Override
 public String getStatusMessage(int status) {
   Status s = javax.ws.rs.core.Response.Status.fromStatusCode(status);
   if (s != null) {
     return s.getReasonPhrase();
   }
   return null;
 }
 private void logException(Throwable e, Response r, Level l) {
   Response.Status s = Response.Status.fromStatusCode(r.getStatus());
   if (s != null) {
     LOGGER.log(
         l,
         "Mapped exception to response: " + r.getStatus() + " (" + s.getReasonPhrase() + ")",
         e);
   } else {
     LOGGER.log(l, "Mapped exception to response: " + r.getStatus(), e);
   }
 }
  @Test
  public void testPublishDsw() throws Exception {
    DatasourceResource service = new DatasourceResource();
    Mockery mockery = new Mockery();
    final IPlatformImporter mockImporter = mockery.mock(IPlatformImporter.class);
    mp.defineInstance(IPlatformImporter.class, mockImporter);
    mockery.checking(
        new Expectations() {
          {
            oneOf(mockImporter)
                .importFile(
                    with(
                        match(
                            new TypeSafeMatcher<IPlatformImportBundle>() {
                              public boolean matchesSafely(IPlatformImportBundle bundle) {
                                return bundle.isPreserveDsw()
                                    && bundle.getProperty("domain-id").equals("AModel.xmi")
                                    && bundle.getMimeType().equals("text/xmi+xml");
                              }

                              public void describeTo(Description description) {
                                description.appendText("bundle with xmi");
                              }
                            })));
            oneOf(mockImporter)
                .importFile(
                    with(
                        match(
                            new TypeSafeMatcher<IPlatformImportBundle>() {
                              public boolean matchesSafely(IPlatformImportBundle bundle) {
                                return bundle.getProperty("domain-id").equals("AModel")
                                    && bundle
                                        .getMimeType()
                                        .equals("application/vnd.pentaho.mondrian+xml");
                              }

                              public void describeTo(Description description) {
                                description.appendText("bundle with mondrian schema");
                              }
                            })));
          }
        });
    FileInputStream in = new FileInputStream(new File(new File("test-res"), "SampleDataOlap.xmi"));
    try {
      Response resp = service.publishDsw("AModel.xmi", in, true, false);
      Assert.assertEquals(
          Response.Status.Family.SUCCESSFUL,
          Response.Status.fromStatusCode(resp.getStatus()).getFamily());
      mockery.assertIsSatisfied();
    } finally {
      IOUtils.closeQuietly(in);
    }
  }
  public UserPaaSCredentials readUserCredentialsForPaaS(
      String userInstanceUriId, String paaSInstanceUriId) throws SOAException {
    String rsUri = getBASE_URI() + "readUserCredentialsForPaaS";

    WebClient client = WebClient.create(rsUri);
    client.type("multipart/mixed").accept(MediaType.APPLICATION_JSON);

    registerJsonProvider();

    List<Attachment> atts = new LinkedList<Attachment>();

    atts.add(new Attachment("userInstanceUriId", MediaType.TEXT_PLAIN, userInstanceUriId));

    atts.add(new Attachment("paaSInstanceUriId", MediaType.TEXT_PLAIN, paaSInstanceUriId));
    UserPaaSCredentials userPaaSCredentials;
    try {
      userPaaSCredentials = client.post(new MultipartBody(atts), UserPaaSCredentials.class);
    } catch (ServerWebApplicationException cwe) {
      throw new SOAException(Response.Status.fromStatusCode(cwe.getStatus()), cwe.getMessage());
    }

    return userPaaSCredentials;
  }
  @DELETE
  @Path("/{streamRuleId}")
  @Timed
  @ApiOperation(value = "Delete a stream rule")
  @ApiResponses(
      value = {
        @ApiResponse(code = 404, message = "Stream rule not found."),
        @ApiResponse(code = 400, message = "Invalid ObjectId.")
      })
  public Response delete(
      @ApiParam(
              title = "streamid",
              description = "The stream id this new rule belongs to.",
              required = true)
          @PathParam("streamid")
          String streamid,
      @ApiParam(title = "streamRuleId", required = true) @PathParam("streamRuleId")
          String streamRuleId) {
    if (streamRuleId == null || streamRuleId.isEmpty()) {
      LOG.error("Missing streamRuleId. Returning HTTP 400.");
      throw new WebApplicationException(400);
    }
    checkPermission(RestPermissions.STREAMS_EDIT, streamid);

    try {
      StreamRule streamRule = streamRuleService.load(loadObjectId(streamRuleId));
      if (streamRule.getStreamId().equals(streamid)) {
        streamRuleService.destroy(streamRule);
      } else {
        throw new NotFoundException();
      }
    } catch (org.graylog2.database.NotFoundException e) {
      throw new WebApplicationException(404);
    }

    return Response.status(Response.Status.fromStatusCode(204)).build();
  }
 private void assertResponseStatus(Response response, Response.Status status) {
   assertThat(response, is(notNullValue()));
   assertThat(Response.Status.fromStatusCode(response.getStatus()), is(status));
 }