use of org.apache.cxf.jaxrs.impl.HttpHeadersImpl in project tomee by apache.
the class JAASAuthenticationFilter method handleAuthenticationException.
protected Response handleAuthenticationException(SecurityException ex, Message m) {
HttpHeaders headers = new HttpHeadersImpl(m);
if (redirectURI != null && isRedirectPossible(headers)) {
final URI finalRedirectURI;
if (!redirectURI.isAbsolute()) {
String endpointAddress = HttpUtils.getEndpointAddress(m);
Object basePathProperty = m.get(Message.BASE_PATH);
if (ignoreBasePath && basePathProperty != null && !"/".equals(basePathProperty)) {
int index = endpointAddress.lastIndexOf(basePathProperty.toString());
if (index != -1) {
endpointAddress = endpointAddress.substring(0, index);
}
}
finalRedirectURI = UriBuilder.fromUri(endpointAddress).path(redirectURI.toString()).build();
} else {
finalRedirectURI = redirectURI;
}
return Response.status(getRedirectStatus()).header(HttpHeaders.LOCATION, finalRedirectURI).build();
}
ResponseBuilder builder = Response.status(Response.Status.UNAUTHORIZED);
StringBuilder sb = new StringBuilder();
List<String> authHeader = headers.getRequestHeader(HttpHeaders.AUTHORIZATION);
if (authHeader != null && !authHeader.isEmpty()) {
// should HttpHeadersImpl do it ?
String[] authValues = authHeader.get(0).split(" ");
if (authValues.length > 0) {
sb.append(authValues[0]);
}
} else {
sb.append("Basic");
}
if (realmName != null) {
sb.append(" realm=\"").append(realmName).append('"');
}
builder.header(HttpHeaders.WWW_AUTHENTICATE, sb.toString());
return builder.build();
}
use of org.apache.cxf.jaxrs.impl.HttpHeadersImpl in project cxf by apache.
the class WadlGenerator method doFilter.
protected void doFilter(ContainerRequestContext context, Message m) {
if (!"GET".equals(m.get(Message.HTTP_REQUEST_METHOD))) {
return;
}
UriInfo ui = context.getUriInfo();
if (!ui.getQueryParameters().containsKey(WADL_QUERY)) {
if (stylesheetReference != null || !docLocationMap.isEmpty()) {
String path = ui.getPath(false);
if (path.startsWith("/") && !path.isEmpty()) {
path = path.substring(1);
}
if (stylesheetReference != null && path.endsWith(".xsl") || docLocationMap.containsKey(path)) {
context.abortWith(getExistingResource(m, ui, path));
}
}
return;
}
if (ignoreRequests) {
context.abortWith(Response.status(404).build());
return;
}
if (allowList != null && !allowList.isEmpty()) {
ServletRequest servletRequest = (ServletRequest) m.getContextualProperty("HTTP.REQUEST");
final String remoteAddress;
if (servletRequest != null) {
remoteAddress = servletRequest.getRemoteAddr();
} else {
remoteAddress = "";
}
boolean foundMatch = false;
for (String addr : allowList) {
if (addr.equals(remoteAddress)) {
foundMatch = true;
break;
}
}
if (!foundMatch) {
context.abortWith(Response.status(404).build());
return;
}
}
HttpHeaders headers = new HttpHeadersImpl(m);
List<MediaType> accepts = headers.getAcceptableMediaTypes();
MediaType type = accepts.contains(WADL_TYPE) ? WADL_TYPE : accepts.contains(MediaType.APPLICATION_JSON_TYPE) ? MediaType.APPLICATION_JSON_TYPE : defaultWadlResponseMediaType;
Response response = getExistingWadl(m, ui, type);
if (response != null) {
context.abortWith(response);
return;
}
boolean isJson = isJson(type);
StringBuilder sbMain = generateWADL(getBaseURI(m, ui), getResourcesList(m, ui), isJson, m, ui);
m.getExchange().put(JAXRSUtils.IGNORE_MESSAGE_WRITERS, !isJson && ignoreMessageWriters);
Response r = Response.ok().type(type).entity(createResponseEntity(m, ui, sbMain.toString(), isJson)).build();
context.abortWith(r);
}
use of org.apache.cxf.jaxrs.impl.HttpHeadersImpl in project cxf by apache.
the class BinaryDataProvider method copyInputToOutput.
protected void copyInputToOutput(InputStream is, OutputStream os, Annotation[] anns, MultivaluedMap<String, Object> outHeaders) throws IOException {
if (isRangeSupported()) {
Message inMessage = PhaseInterceptorChain.getCurrentMessage().getExchange().getInMessage();
handleRangeRequest(is, os, new HttpHeadersImpl(inMessage), outHeaders);
} else {
boolean nioWrite = AnnotationUtils.getAnnotation(anns, UseNio.class) != null;
if (nioWrite) {
ContinuationProvider provider = getContinuationProvider();
if (provider != null) {
copyUsingNio(is, os, provider.getContinuation());
}
return;
}
if (closeResponseInputStream) {
IOUtils.copyAndCloseInput(is, os, bufferSize);
} else {
IOUtils.copy(is, os, bufferSize);
}
}
}
use of org.apache.cxf.jaxrs.impl.HttpHeadersImpl in project camel by apache.
the class CxfRsInvoker method prepareExchange.
private org.apache.camel.Exchange prepareExchange(Exchange cxfExchange, Method method, Object[] paramArray, Object response) {
ExchangePattern ep = ExchangePattern.InOut;
if (method.getReturnType() == Void.class) {
ep = ExchangePattern.InOnly;
}
final org.apache.camel.Exchange camelExchange = endpoint.createExchange(ep);
if (response != null) {
camelExchange.getOut().setBody(response);
}
CxfRsBinding binding = endpoint.getBinding();
binding.populateExchangeFromCxfRsRequest(cxfExchange, camelExchange, method, paramArray);
// the CXF in message property. Question: where should this property name be set up ?
if (endpoint.isPropagateContexts()) {
camelExchange.setProperty(UriInfo.class.getName(), new UriInfoImpl(cxfExchange.getInMessage()));
camelExchange.setProperty(Request.class.getName(), new RequestImpl(cxfExchange.getInMessage()));
camelExchange.setProperty(HttpHeaders.class.getName(), new HttpHeadersImpl(cxfExchange.getInMessage()));
camelExchange.setProperty(SecurityContext.class.getName(), new SecurityContextImpl(cxfExchange.getInMessage()));
}
return camelExchange;
}
use of org.apache.cxf.jaxrs.impl.HttpHeadersImpl in project tomee by apache.
the class JAXRSUtils method readFromMessageBodyReader.
@SuppressWarnings("unchecked")
public static Object readFromMessageBodyReader(List<ReaderInterceptor> readers, Class<?> targetTypeClass, Type parameterType, Annotation[] parameterAnnotations, InputStream is, MediaType mediaType, Message m) throws IOException, WebApplicationException {
// Verbose but avoids an extra context instantiation for the typical path
if (readers.size() > 1) {
ReaderInterceptor first = readers.remove(0);
ReaderInterceptorContext context = new ReaderInterceptorContextImpl(targetTypeClass, parameterType, parameterAnnotations, is, m, readers);
return first.aroundReadFrom(context);
}
MessageBodyReader<?> provider = ((ReaderInterceptorMBR) readers.get(0)).getMBR();
@SuppressWarnings("rawtypes") Class cls = targetTypeClass;
return provider.readFrom(cls, parameterType, parameterAnnotations, mediaType, new HttpHeadersImpl(m).getRequestHeaders(), is);
}
Aggregations