After upgrading to springboot 3 and java 17 from 1.8 I am facing an issue with spring hateoas link been created by the WebMvcLinkBuilder.linkTo The expected link was
https://test.com/dutyofcare/v1/bookings/8fcc2cc9-fc63-4bb4-acdf-2f3a11efd9f1
enter code here
but the actual link created after upgrade was below,
https://api.beta.eks.us-west-2.lab.egencia.cloud/doc-service/v1/bookings/8fcc2cc9-fc63-4bb4-acdf-2f3a11efd9f1
some how dutyofcare is been overriden by doc-service and the response for this get endpoint was 404 not found (even when i manually change it to dutyofcare also it is throwing error 404)
I have recently updated the hateos dependency to this for the upgrade.
<dependency>
<groupId>org.springframework.hateoas</groupId>
<artifactId>spring-hateoas</artifactId>
<exclusions>
<exclusion>
<artifactId>log4j-to-slf4j</artifactId>
<groupId>org.apache.logging.log4j</groupId>
</exclusion>
</exclusions>
</dependency>
Please see the assembler created for building links
import DutyOfCareDataRetrieveController;
import DutyOfCareDataResponseBean;
import MetadataBean;
import ErrorCode;
import DutyOfCareTechnicalException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.hateoas.Link;
import org.springframework.hateoas.EntityModel;
import org.springframework.stereotype.Component;
import static ErrorCode.INTERNAL_SERVER_ERROR;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.linkTo;
import static org.springframework.hateoas.server.mvc.WebMvcLinkBuilder.methodOn;
@Component
public class DocDataResourceAssembler extends SimpleResourceAssembler<DutyOfCareDataResponseBean> {
private static final Logger LOGGER = LoggerFactory.getLogger(DocDataResourceAssembler.class);
@Override
protected void addLinks(EntityModel<DutyOfCareDataResponseBean> resource) {
try {
DutyOfCareDataResponseBean dutyOfCareDataResponseBean = resource.getContent();
MetadataBean metadata = dutyOfCareDataResponseBean.getMetadata();
final String resourceId = dutyOfCareDataResponseBean.getResourceId();
int currentPage = metadata.getCurrentPage();
int totalPages = metadata.getTotalPages();
if ((currentPage < totalPages)) {
String url = linkTo(methodOn(DutyOfCareDataRetrieveController.class).
getBookings(resourceId, currentPage)).withRel("next").getHref().split("\\?")[0];
Link link = Link.of(url).withRel("next");
LOGGER.info("Generated URL for testing: " + url); // Add this line to log the generated URL
resource.add(link);
}
} catch (Exception ex) {
LOGGER.error("Exception occurred while adding Hateoas links.");
throw new DutyOfCareTechnicalException(ErrorCode.INTERNAL_SERVER_ERROR, INTERNAL_SERVER_ERROR.getMessage());
}
}
}
Can some one help me to figure out?