use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.
the class EndpointsApiServiceImpl method endpointsEndpointIdPut.
/**
* Updates an existing endpoint
*
* @param endpointId ID of the endpoint
* @param body Updated endpoint details
* @param ifMatch If-Match header value
* @param ifUnmodifiedSince If-Unmodified-Since header value
* @param request msf4j request object
* @return updated endpoint
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response endpointsEndpointIdPut(String endpointId, EndPointDTO body, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
Endpoint endpoint = MappingUtil.toEndpoint(body);
Endpoint retrievedEndpoint = apiPublisher.getEndpoint(endpointId);
if (retrievedEndpoint == null) {
String msg = "Endpoint not found " + endpointId;
log.error(msg);
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(ExceptionCodes.ENDPOINT_NOT_FOUND);
return Response.status(ExceptionCodes.ENDPOINT_NOT_FOUND.getHttpStatusCode()).entity(errorDTO).build();
}
String existingFingerprint = endpointsEndpointIdGetFingerprint(endpointId, null, null, request);
if (!StringUtils.isEmpty(ifMatch) && !StringUtils.isEmpty(existingFingerprint) && !ifMatch.contains(existingFingerprint)) {
return Response.status(Response.Status.PRECONDITION_FAILED).build();
}
Endpoint updatedEndpint = new Endpoint.Builder(endpoint).id(endpointId).build();
apiPublisher.updateEndpoint(updatedEndpint);
Endpoint updatedEndpoint = apiPublisher.getEndpoint(endpointId);
String newFingerprint = endpointsEndpointIdGetFingerprint(endpointId, null, null, request);
return Response.ok().header(HttpHeaders.ETAG, "\"" + newFingerprint + "\"").entity(MappingUtil.toEndPointDTO(updatedEndpoint)).build();
} catch (APIManagementException e) {
String errorMessage = "Error while getting the endpoint :" + endpointId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (JsonProcessingException e) {
String errorMessage = "Error while Converting Endpoint Security Details in Endpoint :" + endpointId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
} catch (IOException e) {
String errorMessage = "Error while Converting Endpoint Security Details in Endpoint :" + endpointId;
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.
the class MappingUtil method toEndpointListDto.
/**
* Converts {@link Endpoint} list to {@link EndPointDTO} list
*
* @param endpointList {@link Endpoint} list
* @return EndPointDTO list
*/
public static List<EndPointDTO> toEndpointListDto(List<Endpoint> endpointList) {
List<EndPointDTO> endPointDTOList = new ArrayList<>();
endpointList.forEach(endpoint -> endPointDTOList.add(new EndPointDTO().endpointConfig(endpoint.getEndpointConfig()).id(endpoint.getId()).type(endpoint.getType()).name(endpoint.getName()).security(endpoint.getSecurity())));
return endPointDTOList;
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.
the class MappingUtilTestCase method toEndpointListDtoTest.
@Test
public void toEndpointListDtoTest() {
List<Endpoint> endpointList = new ArrayList<>();
endpointList.add(SampleTestObjectCreator.createUniqueEndpoint());
endpointList.add(SampleTestObjectCreator.createUniqueEndpoint());
endpointList.add(SampleTestObjectCreator.createUniqueEndpoint());
List<EndPointDTO> endPointDTOList = MappingUtil.toEndpointListDto(endpointList);
Assert.assertEquals(endPointDTOList.size(), endpointList.size());
for (int i = 0; i < endpointList.size(); i++) {
Assert.assertEquals(endpointList.get(i).getEndpointConfig(), endPointDTOList.get(i).getEndpointConfig());
Assert.assertEquals(endpointList.get(i).getId(), endPointDTOList.get(i).getId());
Assert.assertEquals(endpointList.get(i).getType(), endPointDTOList.get(i).getType());
Assert.assertEquals(endpointList.get(i).getName(), endPointDTOList.get(i).getName());
Assert.assertEquals(endpointList.get(i).getSecurity(), endPointDTOList.get(i).getSecurity());
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.
the class EndpointsApiServiceImpl method endpointsPost.
/**
* Adds a new Endpoint
*
* @param body Endpoint details to be added
* @param ifNoneMatch If-None-Match header value
* @param ifModifiedSince If-Modified-Since header
* @param request msf4j request object
* @return Newly created endpoint details as the payload
* @throws NotFoundException When the particular resource does not exist in the system
*/
@Override
public Response endpointsPost(EndPointDTO body, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
String username = RestApiUtil.getLoggedInUsername(request);
try {
APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
Endpoint endpoint = MappingUtil.toEndpoint(body);
String endpointId = apiPublisher.addEndpoint(endpoint);
Endpoint retrievedEndpoint = apiPublisher.getEndpoint(endpointId);
return Response.status(Response.Status.CREATED).entity(MappingUtil.toEndPointDTO(retrievedEndpoint)).build();
} catch (APIManagementException e) {
String errorMessage = "Error while get All Endpoint";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
} catch (JsonProcessingException e) {
String errorMessage = "Error while Converting Endpoint Security Details in Endpoint";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
} catch (IOException e) {
String errorMessage = "Error while Converting Endpoint Security Details in Endpoint ";
ErrorDTO errorDTO = RestApiUtil.getErrorDTO(errorMessage, 900313L, errorMessage);
log.error(errorMessage, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.publisher.dto.EndPointDTO in project carbon-apimgt by wso2.
the class APIStoreImpl method setGatewayDefinitionSource.
private void setGatewayDefinitionSource(CompositeAPI.Builder apiBuilder) throws APIManagementException {
List<UriTemplate> list = new ArrayList<>(apiBuilder.getUriTemplates().values());
List<TemplateBuilderDTO> resourceList = new ArrayList<>();
String appId = null;
List<CompositeAPIEndpointDTO> endpointDTOs = new ArrayList<CompositeAPIEndpointDTO>();
try {
appId = apiBuilder.getApplicationId();
List<Subscription> subscriptions = getApiSubscriptionDAO().getAPISubscriptionsByApplication(apiBuilder.getApplicationId(), ApiType.STANDARD);
for (Subscription subscription : subscriptions) {
CompositeAPIEndpointDTO endpointDTO = new CompositeAPIEndpointDTO();
API api = subscription.getApi();
endpointDTO.setEndpointName(api.getName());
// TODO: currently only HTTPS endpoint considered. Websocket APIs and http transport should considered
endpointDTO.setTransportType(APIMgtConstants.HTTPS);
// TODO: replace host with gateway domain host
String endpointUrl = APIMgtConstants.HTTPS + APIMgtConstants.WEB_PROTOCOL_SUFFIX + config.getHostname() + "/" + api.getContext() + "/" + api.getVersion();
endpointDTO.setEndpointUrl(endpointUrl);
endpointDTOs.add(endpointDTO);
}
} catch (APIMgtDAOException e) {
String errorMsg = "Error while getting subscriptions of the application " + appId;
log.error(errorMsg, e);
throw new APIManagementException(errorMsg, e, e.getErrorHandler());
}
for (UriTemplate uriTemplate : list) {
TemplateBuilderDTO dto = new TemplateBuilderDTO();
dto.setTemplateId(uriTemplate.getTemplateId());
dto.setUriTemplate(uriTemplate.getUriTemplate());
dto.setHttpVerb(uriTemplate.getHttpVerb());
resourceList.add(dto);
}
GatewaySourceGenerator gatewaySourceGenerator = getGatewaySourceGenerator();
APIConfigContext apiConfigContext = new APIConfigContext(apiBuilder.build(), config.getGatewayPackageName());
gatewaySourceGenerator.setApiConfigContext(apiConfigContext);
String gatewayConfig = gatewaySourceGenerator.getCompositeAPIConfigStringFromTemplate(resourceList, endpointDTOs);
if (log.isDebugEnabled()) {
log.debug("API " + apiBuilder.getName() + "gateway config: " + gatewayConfig);
}
apiBuilder.gatewayConfig(gatewayConfig);
}
Aggregations