To list the docker running containers use the following command:

docker ps

To show all running containers use the -a (--all) option:

docker ps -a

If you want to filter, by name for example you can use the --filter option with the name=containing_text value

$ docker ps --filter "name=codever"
8a01ae8ef526   jboss/keycloak:6.0.1   "/opt/jboss/tools/do…"   3 days ago      Exited (255) 10 hours ago   0.0.0.0:8480->8080/tcp     codever-keycloak
f7c51c81dc4f   mongo:3.4              "docker-entrypoint.s…"   3 days ago      Exited (255) 10 hours ago   0.0.0.0:27017->27017/tcp   codever-mongo
5b2f88b9fe57   postgres               "docker-entrypoint.s…"   3 days ago      Exited (255) 10 hours ago   5432/tcp                   codever-postgres

You could also obtain similar results if piping the docker ps command to grep - docker ps -a | grep codever

Reference - https://docs.docker.com/engine/reference/commandline/ps/


Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Project: Codever

Enclose the response in setTimeout

router.get('/', async (request, response) => {

  const {page, limit} = PaginationQueryParamsHelper.getPageAndLimit(request);
  const bookmarks = await PublicBookmarksService.getLatestPublicBookmarks(page, limit);

  setTimeout((() => {
    return response.send(bookmarks);
  }), 2000)
});

Reference - https://developer.mozilla.org/en-US/docs/Web/API/setTimeout


Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Project: Codever - File: user.router.js The values are present in the request.body which contains key-value pairs of data submitted in the request body. In our case we access the userDisplayName with the following expression request.body.userDisplayName as in the example below:

usersRouter.post('/:userId/bookmarks/upload', keycloak.protect(),
  uploadBookmarks.single("bookmarks" /* name attribute of <file> element in your form */),
  async (request, response) => {
    userIdTokenValidator.validateUserId(request);

    const userDisplayName = request.body.userDisplayName;
    const importResponse = await browserBookmarksImportService.imporBrowserBookmarks(request.params.userId, request.file.buffer, userDisplayName);

    const str = JSON.stringify(importResponse, null, 2); // spacing level = 2
    console.log(str);

    return response.status(HttpStatus.OK).send(importResponse);
  }
);

In angular the userDisplayName value has been appended to the FormData and submitted to a post request via the Angular Http Client:

  uploadBookmarks(userId: String, bookmarks: File, userDisplayName: string): Observable<any> {
    const formData = new FormData();
    formData.append('bookmarks', bookmarks);
    formData.append('userDisplayName', userDisplayName);

    return this.httpClient.post(`${this.usersApiBaseUrl}/${userId}/bookmarks/upload`, formData);
  }

Reference - https://expressjs.com/en/api.html#req.body


Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

TLDR; - include also the imported xsd file in the schema sources in xml unit validator

When trying to validate an xml document against an xsd schema with xmlunit I get the following exception

org.xmlunit.XMLUnitException: The schema is invalid

	at org.xmlunit.validation.JAXPValidator.validateInstance(JAXPValidator.java:81)
	at ch.mobi.siefs.connector.helper.XmlUnitComparisonTest.givenXml_whenValidatesAgainstXsd_thenCorrect(XmlUnitComparisonTest.java:48)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
.....
Caused by: org.xml.sax.SAXParseException; lineNumber: 89; columnNumber: 98; src-resolve: Cannot resolve the name 'mobits:HistoryTimestamp' to a(n) 'type definition' component.
	at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:204)
	at java.xml/com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:135)
....

The unit test looked like the following:

@Test
public void givenXml_whenValidatesAgainstXsd_thenCorrect() {
  Validator v = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI);
  v.setSchemaSource(Input.fromStream(
          XmlUnitComparisonTest.class.getResourceAsStream("xsd/bookmark.xsd")).build());
  ValidationResult r = v.validateInstance(Input.fromStream(
          XmlUnitComparisonTest.class.getResourceAsStream("message/bookmark-example.xml")).build());
  Iterator<ValidationProblem> probs = r.getProblems().iterator();
  while (probs.hasNext()) {
    probs.next().toString();
  }
  Assertions.assertThat(r.isValid()).isTrue();
}

The problem element mentioned in the stack trace comes from the imported xsd, which xml wise everything seems ok:

<?xml version="1.0" encoding="utf-8" ?>
<xsd:schema
            xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:common="http://xml.bookmarks.dev/datatype/common/Commons/v3">
    <xsd:import namespace=""http://xml.bookmarks.dev/datatype/common/Commons/v3" schemaLocation="common-Commons-3.0.xsd"/>

The solution was to add also the imported xsd schema when building the validator in xmlunit

  @Test
  public void givenXml_whenValidatesAgainstXsd_thenCorrect() {
    Validator v = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI);
    v.setSchemaSources( // order of xsd sources is important
        Input.fromStream(
                getClass().getClassLoader().getResourceAsStream("xsd/bookmarks.xsd"))
            .build(),
        Input.fromStream(
                getClass().getClassLoader().getResourceAsStream("xsd/common-Commons-3.0.xsd"))
            .build());
    ValidationResult r =
        v.validateInstance(
            Input.fromStream(
                    getClass()
                        .getClassLoader()
                        .getResourceAsStream("message/bookmark-example.xml"))
                .build());
    Iterator<ValidationProblem> probs = r.getProblems().iterator();
    while (probs.hasNext()) {
      probs.next().toString();
    }
    assertThat(r.isValid()).isTrue();
  }

Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.

Use MediaType.TEXT_PLAIN in the @Consumes annotation and then you have access to the text content as string

    @POST
    @Path("organisation")
    @Consumes(MediaType.TEXT_PLAIN)
    @ApiOperation(value = "Create bookmark from text")
    @ApiResponses({
            @ApiResponse(code = 201, message = "Bookmark successfully created.", response = Bookmark.class),
            @ApiResponse(code = 403, message = "Forbidden")
    })
    public Response createBookmark(@ApiParam("Bookmark") String boookmark, @Context UriInfo uriInfo) throws JAXBException {
        Bookmark created = bookmarkService.createBookmarkFromString(bookmark);
        UriBuilder builder = uriInfo.getAbsolutePathBuilder();
        builder.path(created.getUuid().toString());
        return Response.created(builder.build()).build();
    }

Shared with from Codever.land. 👉 Use the Copy to mine functionality to copy this snippet to your own personal collection and easy manage your code snippets.