HTTPS from a console application?

Create and install a root authority and HTTPS certificate Open command prompt as Administrator: Create folder C:\Certs and navigate to it. #Root Authority makecert.exe -r -pe -n “CN=My Root Authority” -ss CA -sr LocalMachine -a sha1 -sky signature -cy authority -sv CA.pvk CA.cer #Certificate makecert.exe -pe -n “CN=localhost” -a sha1 -sky exchange -eku 1.3.6.1.5.5.7.3.1 -ic … Read more

How to download a file using a Java REST service and a data stream

“How can I directly (without saving the file on 2nd server) download the file from 1st server to client’s machine?” Just use the Client API and get the InputStream from the response Client client = ClientBuilder.newClient(); String url = “…”; final InputStream responseStream = client.target(url).request().get(InputStream.class); There are two flavors to get the InputStream. You can … Read more

Django REST Serializer Method Writable Field

Here is a read/write serializer method field: class ReadWriteSerializerMethodField(serializers.SerializerMethodField): def __init__(self, method_name=None, **kwargs): self.method_name = method_name kwargs[‘source’] = ‘*’ super(serializers.SerializerMethodField, self).__init__(**kwargs) def to_internal_value(self, data): return {self.field_name: data}

How to generate java client code for swagger REST API documentation

Instead of using the JAR, you can also use https://generator.swagger.io to generate the SDKs (Java, Ruby, PHP, etc) online without installing anything. Here is an example: curl -X POST -H “content-type:application/json” -d ‘{“swaggerUrl”:”http://petstore.swagger.io/v2/swagger.json”}’ https://generator.swagger.io/api/gen/clients/java and here is a sample response: {“code”:”1445940806041″,”link”:”https://generator.swagger.io/api/gen/download/1445940806041″} You can then download the zipped SDK from the link. For more options on … Read more

@POST in RESTful web service

Please find example below, it might help you package jersey.rest.test; import javax.ws.rs.DELETE; import javax.ws.rs.GET; import javax.ws.rs.HEAD; import javax.ws.rs.POST; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.core.Response; @Path(“/hello”) public class SimpleService { @GET @Path(“/{param}”) public Response getMsg(@PathParam(“param”) String msg) { String output = “Get:Jersey say : ” + msg; return Response.status(200).entity(output).build(); } @POST @Path(“/{param}”) public Response … Read more

Swagger UI passing authentication token to API call in header

@ApiImplicitParams and @ApiImplicitParam should do the trick: @GET @Produces(“application/json”) @ApiImplicitParams({ @ApiImplicitParam(name = “Authorization”, value = “Authorization token”, required = true, dataType = “string”, paramType = “header”) }) public String getUser(@PathParam(“username”) String userName) { … } From the documentation: You may wish you describe operation parameters manually. This can be for various reasons, for example: Using … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)