programmatically add parameters to URL java - java

i have a java application in which i want to programmatically add URL parameters to a given base url, instead of string manipulation to form a url. i have heard that URIBuilder is the way to go, though I have not been able to get that class or the maven repository to that class anywhere? is that the way to go or is there any other method to get that done?
EDIT: i have heard of using apache http client utils URIBuilder and not the javax.ws URIBuilder class

Drop this dependency in your pom to get UriBuilder:
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>jsr311-api</artifactId>
<version>1.1.1</version><!-- Select the version you want here -->
</dependency>
More info: http://mvnrepository.com/artifact/javax.ws.rs/jsr311-api
The Apache version is part of the httpcomponents:
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.1</version>
</dependency>
More info: http://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient/

You can use java.net.URL to create a URL. The set() method allows you to set query parameters.

Related

How to change the Swagger UI path for a Spring Boot app using Sprinfgox?

I need to remove the "/swagger-ui" part from the Swagger UI URL. So far I have seen examples of how to add a prefix prior to the "/swagger-ui" such as "/prefix/swagger-ui" but I want to remove it completely and just have the prefix.
localhost:8080/swagger-ui -> localhost:8080/test
I have tried adding the following two to the .properties file but had no luck:
springdoc.swagger-ui.path=/test
springfox.documentation.swagger-ui.base-url=test
-spring-boot version: 2.5.6
I am using the below dependency for Springfox:
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>3.0.0</version>
</dependency>
I am wondering if there is any other way.

How to setup java for dynamo db for first time?

I am new to use Dynamo DB,
I want to know how to setup pom.xml like if I use maven what is dependency use for dynamodb
<dependencies>
<dependency>
<groupId>??</groupId>
<artifactId>??</artifactId>
<version>??</version>
<scope>test</scope>
</dependency>
<dependency>
or any example source code which I can research how to use it?
For dynamodb and how to setup like list of table and create column one by one in dynamodb any source can i read ?
if you want to use aws dynamo DB so you can use following code:
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-dynamodb</artifactId>
<version>1.11.784</version>
</dependency>
you can use following example for setup by using below link
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/CodeSamples.Java.html
Dependency in pom is:
<dependency>
<groupId>com.github.derjust</groupId>
<artifactId>spring-data-dynamodb</artifactId>
<version>5.1.0</version>
</dependency>
Next if You want to use it in code You need to read about #DynamoDBTable .
Best lecture about it have of course Baeldung

Twitter4j: Cannot use StatusListener cannot be resolved

I'm struggling with Twitter4j. I am using a Maven project with the following Twitter4j dependency:
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>[4.0,)</version>
</dependency>
However every time I try and declare a StatusListener, I get Cannot resolve symbol 'StatusListener' even though I'm importing import twitter4j.*;.
Anyone know why this might happen when I can use pretty much all other features of Twitter4j?
I needed to add
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-stream</artifactId>
<version>[4.0,)</version>
</dependency>
As a dependency to my pom.xml. Turns out the Streaming API and all related classes are in a different part of the Twitter4J ecosystem.
As twitter4j lib contains the core, async, example, and a stream part. You should try to include all these but mainly the stream dependency contains the status listener method. I hope it solves your problem.

Customization of GraphiQL interface in Spring-Boot project

According to the GraphiQL README I can customize the interface by adding React children like this:
<GraphiQL.Logo>
My Custom Logo
</GraphiQL.Logo>
That is great, but how do I actually set these children? I'm not a web developer and I've never used React before! I'm developing a Spring-Boot project with the following dependencies:
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphql-spring-boot-starter</artifactId>
<version>5.0.6</version>
</dependency>
<dependency>
<groupId>com.graphql-java-kickstart</groupId>
<artifactId>graphiql-spring-boot-starter</artifactId>
<version>5.0.6</version>
</dependency>
I don't see any way to set the children via application.properties/yml, although I can set other things there like the pageTitle, defaultQuery and editorTheme.
I can override the graphiql.html page provided by the starter. I naively tried to set the children like this at the end of the page:
// Render <GraphiQL /> into the body.
ReactDOM.render(
React.createElement(GraphiQL, props, [React.createElement('GraphiQL.Logo', {}, 'Custom LOGO')]),
document.body
);
That didn't have any effect.
How should I approach this?

Problems in migrating from swagger_jaxrs_2.10 to latest swagger_jaxrs

I had swagger_jaxrs_2.10 (1.3.6) working for a long time, I want to benefit from the new 2.0 swagger specification.
Hence I've changed in my pom from
<dependency>
<groupId>com.wordnik</groupId>
<artifactId>swagger-jaxrs_2.10</artifactId>
<version>1.3.6</version>
</dependency>
to
<groupId>io.swagger</groupId>
<artifactId>swagger-jaxrs</artifactId>
<version>1.5.3</version>
</dependency>
When I run, I get the following error trying to access myApp/swagger.json
SEVERE: Conflicting URI templates. The URI template / for root resource class io.swagger.jaxrs.listing.ApiListingResource and the URI template / transform to the same regular expression (/.*)?
Any ideas?
In the case of swagger from the 1.5.x libraries, the swagger description will live at /swagger.json. It depends on where your app is mounted though.
The error message your describing tells me that you're mounting a root resource (/*) which is indeed going to conflict with the /swagger.json. Consider mounting your API on a path like /users or something else to avoid that conflict.

Categories