use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class JAXRSInvoker method handleFault.
private Object handleFault(Fault ex, Message inMessage, ClassResourceInfo cri, Method methodToInvoke) {
String errorMessage = ex.getMessage();
if (errorMessage != null && cri != null && errorMessage.contains(PROXY_INVOCATION_ERROR_FRAGMENT)) {
org.apache.cxf.common.i18n.Message errorM = new org.apache.cxf.common.i18n.Message("PROXY_INVOCATION_FAILURE", BUNDLE, methodToInvoke, cri.getServiceClass().getName());
LOG.severe(errorM.toString());
}
Response excResponse = JAXRSUtils.convertFaultToResponse(ex.getCause() == null ? ex : ex.getCause(), inMessage);
if (excResponse == null) {
inMessage.getExchange().put(Message.PROPOGATE_EXCEPTION, ExceptionUtils.propogateException(inMessage));
throw ex;
}
return new MessageContentsList(excResponse);
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class ClientRequestContextImpl method doSetEntity.
private void doSetEntity(Object entity) {
Object actualEntity = InjectionUtils.getEntity(entity);
m.setContent(List.class, actualEntity == null ? new MessageContentsList() : new MessageContentsList(actualEntity));
if (entity != null) {
final Type type;
if (GenericEntity.class.isAssignableFrom(entity.getClass())) {
type = ((GenericEntity<?>) entity).getType();
} else {
type = entity.getClass();
}
m.put(Type.class, type);
m.remove("org.apache.cxf.empty.request");
}
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class SoapOutInterceptor method handleHeaderPart.
private boolean handleHeaderPart(boolean preexistingHeaders, SoapMessage message, String soapPrefix) {
// add MessagePart to soapHeader if necessary
boolean endedHeader = false;
Exchange exchange = message.getExchange();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
if (bop == null) {
return endedHeader;
}
XMLStreamWriter xtw = message.getContent(XMLStreamWriter.class);
boolean startedHeader = false;
BindingOperationInfo unwrappedOp = bop;
if (bop.isUnwrapped()) {
unwrappedOp = bop.getWrappedOperation();
}
boolean client = isRequestor(message);
BindingMessageInfo bmi = client ? unwrappedOp.getInput() : unwrappedOp.getOutput();
BindingMessageInfo wrappedBmi = client ? bop.getInput() : bop.getOutput();
if (bmi == null) {
return endedHeader;
}
if (wrappedBmi.getMessageInfo().getMessagePartsNumber() > 0) {
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs == null) {
return endedHeader;
}
SoapVersion soapVersion = message.getVersion();
List<SoapHeaderInfo> headers = bmi.getExtensors(SoapHeaderInfo.class);
if (headers == null) {
return endedHeader;
}
for (SoapHeaderInfo header : headers) {
MessagePartInfo part = header.getPart();
if (wrappedBmi != bmi) {
part = wrappedBmi.getMessageInfo().addMessagePart(part.getName());
}
if (part.getIndex() >= objs.size()) {
// The optional out of band header is not a part of parameters of the method
continue;
}
Object arg = objs.get(part);
if (arg == null) {
continue;
}
objs.remove(part);
if (!(startedHeader || preexistingHeaders)) {
try {
xtw.writeStartElement(soapPrefix, soapVersion.getHeader().getLocalPart(), soapVersion.getNamespace());
} catch (XMLStreamException e) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
}
startedHeader = true;
}
DataWriter<XMLStreamWriter> dataWriter = getDataWriter(message);
dataWriter.write(arg, header.getPart(), xtw);
}
if (startedHeader || preexistingHeaders) {
try {
xtw.writeEndElement();
endedHeader = true;
} catch (XMLStreamException e) {
throw new SoapFault(new org.apache.cxf.common.i18n.Message("XML_WRITE_EXC", BUNDLE), e, soapVersion.getSender());
}
}
}
return endedHeader;
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class STSInvoker method invoke.
public Object invoke(Exchange exchange, Object o) {
AddressingProperties inProps = (AddressingProperties) exchange.getInMessage().getContextualProperty(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND);
if (inProps != null) {
AddressingProperties props = inProps.createCompatibleResponseProperties();
AttributedURIType action = new AttributedURIType();
action.setValue(inProps.getAction().getValue().replace("/RST/", "/RSTR/"));
props.setAction(action);
exchange.getOutMessage().put(JAXWSAConstants.ADDRESSING_PROPERTIES_OUTBOUND, props);
}
MessageContentsList lst = (MessageContentsList) o;
DOMSource src = (DOMSource) lst.get(0);
Node nd = src.getNode();
final Element requestEl;
if (nd instanceof Document) {
requestEl = ((Document) nd).getDocumentElement();
} else {
requestEl = (Element) nd;
}
String namespace = requestEl.getNamespaceURI();
String prefix = requestEl.getPrefix();
SecurityToken cancelOrRenewToken = null;
if ("RequestSecurityToken".equals(requestEl.getLocalName())) {
try {
String requestType = null;
Element binaryExchange = null;
String tokenType = null;
Element el = DOMUtils.getFirstElement(requestEl);
while (el != null) {
String localName = el.getLocalName();
if (namespace.equals(el.getNamespaceURI())) {
if ("RequestType".equals(localName)) {
requestType = el.getTextContent();
} else if ("CancelTarget".equals(localName) || "RenewTarget".equals(localName)) {
cancelOrRenewToken = findCancelOrRenewToken(exchange, el);
} else if ("BinaryExchange".equals(localName)) {
binaryExchange = el;
} else if ("TokenType".equals(localName)) {
tokenType = DOMUtils.getContent(el);
}
}
el = DOMUtils.getNextElement(el);
}
if (requestType == null) {
requestType = "/Issue";
}
if (requestType.endsWith("/Issue") && !STSUtils.getTokenTypeSCT(namespace).equals(tokenType)) {
throw new Exception("Unknown token type: " + tokenType);
}
W3CDOMStreamWriter writer = new W3CDOMStreamWriter();
writer.setNsRepairing(true);
if (requestType.endsWith("/Issue")) {
doIssue(requestEl, exchange, binaryExchange, writer, prefix, namespace);
} else if (requestType.endsWith("/Cancel")) {
doCancel(exchange, cancelOrRenewToken, writer, prefix, namespace);
} else if (requestType.endsWith("/Renew")) {
doRenew(requestEl, exchange, cancelOrRenewToken, binaryExchange, writer, prefix, namespace);
}
return new MessageContentsList(new DOMSource(writer.getDocument()));
} catch (RuntimeException ex) {
throw ex;
} catch (Exception ex) {
throw new Fault(ex);
}
}
throw new Fault("Unknown SecureConversation element: " + requestEl.getLocalName(), LOG);
}
use of org.apache.cxf.message.MessageContentsList in project cxf by apache.
the class JAXRSBeanValidationInvoker method invoke.
@Override
public Object invoke(Exchange exchange, final Object serviceObject, Method m, List<Object> params) {
Message message = JAXRSUtils.getCurrentMessage();
BeanValidationProvider theProvider = getProvider(message);
try {
if (isValidateServiceObject()) {
theProvider.validateBean(serviceObject);
}
theProvider.validateParameters(serviceObject, m, params.toArray());
Object response = super.invoke(exchange, serviceObject, m, params);
if (response instanceof MessageContentsList) {
MessageContentsList list = (MessageContentsList) response;
if (list.size() == 1) {
Object entity = list.get(0);
if (entity instanceof Response) {
theProvider.validateReturnValue(serviceObject, m, ((Response) entity).getEntity());
} else {
theProvider.validateReturnValue(serviceObject, m, entity);
}
}
}
return response;
} catch (Fault ex) {
throw ex;
} catch (Throwable ex) {
throw new Fault(ex);
}
}
Aggregations