use of org.apache.cxf.jaxrs.ext.MessageContext in project tomee by apache.
the class XSLTJaxbProvider method createTemplates.
protected Templates createTemplates(Templates templates, Map<String, Object> configuredParams, Map<String, String> outProps) {
if (templates == null) {
if (supportJaxbOnly) {
return null;
}
LOG.severe("No template is available");
throw ExceptionUtils.toInternalServerErrorException(null, null);
}
TemplatesImpl templ = new TemplatesImpl(templates, uriResolver);
MessageContext mc = getContext();
if (mc != null) {
UriInfo ui = mc.getUriInfo();
MultivaluedMap<String, String> params = ui.getPathParameters();
for (Map.Entry<String, List<String>> entry : params.entrySet()) {
String value = entry.getValue().get(0);
int ind = value.indexOf(';');
if (ind > 0) {
value = value.substring(0, ind);
}
templ.setTransformerParameter(entry.getKey(), value);
}
List<PathSegment> segments = ui.getPathSegments();
if (!segments.isEmpty()) {
setTransformParameters(templ, segments.get(segments.size() - 1).getMatrixParameters());
}
setTransformParameters(templ, ui.getQueryParameters());
templ.setTransformerParameter(ABSOLUTE_PATH_PARAMETER, ui.getAbsolutePath().toString());
templ.setTransformerParameter(RELATIVE_PATH_PARAMETER, ui.getPath());
templ.setTransformerParameter(BASE_PATH_PARAMETER, ui.getBaseUri().toString());
if (configuredParams != null) {
for (Map.Entry<String, Object> entry : configuredParams.entrySet()) {
templ.setTransformerParameter(entry.getKey(), entry.getValue());
}
}
}
if (outProps != null) {
templ.setOutProperties(outProps);
}
return templ;
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project tomee by apache.
the class SourceProvider method getPreferredSource.
protected String getPreferredSource() {
MessageContext mc = getContext();
String source = null;
if (mc != null) {
source = (String) mc.getContextualProperty(PREFERRED_FORMAT);
}
return source != null ? source : "sax";
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project tomee by apache.
the class JAXBElementProvider method marshal.
// CHECKSTYLE:OFF
protected final void marshal(Object obj, Class<?> cls, Type genericType, String enc, OutputStream os, Annotation[] anns, MediaType mt, Marshaller ms) throws Exception {
// CHECKSTYLE:ON
for (Map.Entry<String, Object> entry : mProperties.entrySet()) {
ms.setProperty(entry.getKey(), entry.getValue());
}
MessageContext mc = getContext();
if (mc != null) {
// they'll overwrite statically configured ones
for (String key : MARSHALLER_PROPERTIES) {
Object value = mc.get(key);
if (value != null) {
ms.setProperty(key, value);
}
}
}
XMLStreamWriter writer = getStreamWriter(obj, os, mt);
if (writer != null) {
if (os == null) {
ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
} else if (mc != null) {
if (mc.getContent(XMLStreamWriter.class) != null) {
ms.setProperty(Marshaller.JAXB_FRAGMENT, true);
}
mc.put(XMLStreamWriter.class.getName(), writer);
}
marshalToWriter(ms, obj, writer, anns, mt);
if (mc != null) {
writer.writeEndDocument();
}
} else {
marshalToOutputStream(ms, obj, os, anns, mt);
}
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project carbon-apimgt by wso2.
the class RetrieveApiArtifactsApiServiceImpl method retrieveApiArtifactsPost.
public Response retrieveApiArtifactsPost(String xWSO2Tenant, String gatewayLabel, String type, UUIDListDTO uuidList, MessageContext messageContext) throws APIManagementException {
xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
RuntimeArtifactDto runtimeArtifactDto = APIArtifactGeneratorUtil.generateAPIArtifact(uuidList.getUuids(), "", "", gatewayLabel, type, xWSO2Tenant);
if (runtimeArtifactDto != null) {
if (runtimeArtifactDto.isFile()) {
File artifact = (File) runtimeArtifactDto.getArtifact();
StreamingOutput streamingOutput = (outputStream) -> {
try {
Files.copy(artifact.toPath(), outputStream);
} finally {
Files.delete(artifact.toPath());
}
};
return Response.ok(streamingOutput).header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=apis.zip").header(RestApiConstants.HEADER_CONTENT_TYPE, APIConstants.APPLICATION_ZIP).build();
} else {
SynapseArtifactListDTO synapseArtifactListDTO = new SynapseArtifactListDTO();
if (runtimeArtifactDto.getArtifact() instanceof List) {
synapseArtifactListDTO.setList((List<String>) runtimeArtifactDto.getArtifact());
synapseArtifactListDTO.setCount(((List<String>) runtimeArtifactDto.getArtifact()).size());
}
return Response.ok().entity(synapseArtifactListDTO).header(RestApiConstants.HEADER_CONTENT_TYPE, RestApiConstants.APPLICATION_JSON).build();
}
} else {
return Response.status(Response.Status.NOT_FOUND).entity(RestApiUtil.getErrorDTO(ExceptionCodes.NO_API_ARTIFACT_FOUND)).build();
}
}
use of org.apache.cxf.jaxrs.ext.MessageContext in project carbon-apimgt by wso2.
the class RuntimeMetadataApiServiceImpl method runtimeMetadataGet.
public Response runtimeMetadataGet(String xWSO2Tenant, String apiId, String gatewayLabel, MessageContext messageContext) throws APIManagementException {
xWSO2Tenant = SubscriptionValidationDataUtil.validateTenantDomain(xWSO2Tenant, messageContext);
RuntimeArtifactDto runtimeArtifactDto = RuntimeArtifactGeneratorUtil.generateMetadataArtifact(xWSO2Tenant, apiId, gatewayLabel);
if (runtimeArtifactDto != null) {
File artifact = (File) runtimeArtifactDto.getArtifact();
StreamingOutput streamingOutput = (outputStream) -> {
try {
Files.copy(artifact.toPath(), outputStream);
} finally {
Files.delete(artifact.toPath());
}
};
return Response.ok(streamingOutput).header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=deployment.json").header(RestApiConstants.HEADER_CONTENT_TYPE, APIConstants.APPLICATION_JSON_MEDIA_TYPE).build();
} else {
return Response.status(Response.Status.NOT_FOUND).entity(RestApiUtil.getErrorDTO(ExceptionCodes.NO_API_ARTIFACT_FOUND)).build();
}
}
Aggregations