use of org.apache.cxf.message.Exchange in project cxf by apache.
the class JAXRSOutInterceptor method processResponse.
// Response shouldn't be closed here
@SuppressWarnings("resource")
private void processResponse(ServerProviderFactory providerFactory, Message message) {
if (isResponseAlreadyHandled(message)) {
return;
}
MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs == null || objs.isEmpty()) {
return;
}
Object responseObj = objs.get(0);
Response response = null;
if (responseObj instanceof Response) {
response = (Response) responseObj;
if (response.getStatus() == 500 && message.getExchange().get(JAXRSUtils.EXCEPTION_FROM_MAPPER) != null) {
message.put(Message.RESPONSE_CODE, 500);
return;
}
} else {
int status = getStatus(message, responseObj != null ? 200 : 204);
response = JAXRSUtils.toResponseBuilder(status).entity(responseObj).build();
}
Exchange exchange = message.getExchange();
OperationResourceInfo ori = (OperationResourceInfo) exchange.get(OperationResourceInfo.class.getName());
serializeMessage(providerFactory, message, response, ori, true);
}
use of org.apache.cxf.message.Exchange in project cxf by apache.
the class XmlSecOutInterceptor method getEncoding.
private String getEncoding(Message message) {
Exchange ex = message.getExchange();
String encoding = (String) message.get(Message.ENCODING);
if (encoding == null && ex.getInMessage() != null) {
encoding = (String) ex.getInMessage().get(Message.ENCODING);
message.put(Message.ENCODING, encoding);
}
if (encoding == null) {
encoding = StandardCharsets.UTF_8.name();
message.put(Message.ENCODING, encoding);
}
return encoding;
}
use of org.apache.cxf.message.Exchange in project cxf by apache.
the class DocLiteralInInterceptorTest method testUnmarshalSourceData.
@Test
public void testUnmarshalSourceData() throws Exception {
XMLStreamReader reader = StaxUtils.createXMLStreamReader(getClass().getResourceAsStream("resources/multiPartDocLitBareReq.xml"));
assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
XMLStreamReader filteredReader = new PartialXMLStreamReader(reader, new QName("http://schemas.xmlsoap.org/soap/envelope/", "Body"));
// advance the xml reader to the message parts
StaxUtils.read(filteredReader);
assertEquals(XMLStreamConstants.START_ELEMENT, reader.nextTag());
Message m = new MessageImpl();
Exchange exchange = new ExchangeImpl();
Service service = control.createMock(Service.class);
exchange.put(Service.class, service);
EasyMock.expect(service.getDataBinding()).andReturn(new SourceDataBinding());
EasyMock.expect(service.size()).andReturn(0).anyTimes();
EasyMock.expect(service.isEmpty()).andReturn(true).anyTimes();
Endpoint endpoint = control.createMock(Endpoint.class);
exchange.put(Endpoint.class, endpoint);
OperationInfo operationInfo = new OperationInfo();
operationInfo.setProperty("operation.is.synthetic", Boolean.TRUE);
MessageInfo messageInfo = new MessageInfo(operationInfo, Type.INPUT, new QName("http://foo.com", "bar"));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo1"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo2"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo3"), null));
messageInfo.addMessagePart(new MessagePartInfo(new QName("http://foo.com", "partInfo4"), null));
for (MessagePartInfo mpi : messageInfo.getMessageParts()) {
mpi.setMessageContainer(messageInfo);
}
operationInfo.setInput("inputName", messageInfo);
BindingOperationInfo boi = new BindingOperationInfo(null, operationInfo);
exchange.put(BindingOperationInfo.class, boi);
EndpointInfo endpointInfo = control.createMock(EndpointInfo.class);
BindingInfo binding = control.createMock(BindingInfo.class);
EasyMock.expect(endpoint.getEndpointInfo()).andReturn(endpointInfo).anyTimes();
EasyMock.expect(endpointInfo.getBinding()).andReturn(binding).anyTimes();
EasyMock.expect(binding.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(endpointInfo.getProperties()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(endpoint.size()).andReturn(0).anyTimes();
EasyMock.expect(endpoint.isEmpty()).andReturn(true).anyTimes();
ServiceInfo serviceInfo = control.createMock(ServiceInfo.class);
EasyMock.expect(endpointInfo.getService()).andReturn(serviceInfo).anyTimes();
EasyMock.expect(serviceInfo.getName()).andReturn(new QName("http://foo.com", "service")).anyTimes();
InterfaceInfo interfaceInfo = control.createMock(InterfaceInfo.class);
EasyMock.expect(serviceInfo.getInterface()).andReturn(interfaceInfo).anyTimes();
EasyMock.expect(interfaceInfo.getName()).andReturn(new QName("http://foo.com", "interface")).anyTimes();
EasyMock.expect(endpointInfo.getName()).andReturn(new QName("http://foo.com", "endpoint")).anyTimes();
EasyMock.expect(endpointInfo.getProperty("URI", URI.class)).andReturn(new URI("dummy")).anyTimes();
List<OperationInfo> operations = new ArrayList<>();
EasyMock.expect(interfaceInfo.getOperations()).andReturn(operations).anyTimes();
m.setExchange(exchange);
m.put(Message.SCHEMA_VALIDATION_ENABLED, false);
m.setContent(XMLStreamReader.class, reader);
control.replay();
new DocLiteralInInterceptor().handleMessage(m);
MessageContentsList params = (MessageContentsList) m.getContent(List.class);
assertEquals(4, params.size());
assertEquals("StringDefaultInputElem", ((DOMSource) params.get(0)).getNode().getFirstChild().getNodeName());
assertEquals("IntParamInElem", ((DOMSource) params.get(1)).getNode().getFirstChild().getNodeName());
}
use of org.apache.cxf.message.Exchange in project cxf by apache.
the class AbstractEndpointSelectionInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Exchange ex = message.getExchange();
Set<Endpoint> endpoints = CastUtils.cast((Set<?>) ex.get(MultipleEndpointObserver.ENDPOINTS));
Endpoint ep = selectEndpoint(message, endpoints);
if (ep == null) {
return;
}
ex.put(Endpoint.class, ep);
ex.put(Binding.class, ep.getBinding());
ex.put(Service.class, ep.getService());
InterceptorChain chain = message.getInterceptorChain();
chain.add(ep.getInInterceptors());
chain.add(ep.getBinding().getInInterceptors());
chain.add(ep.getService().getInInterceptors());
chain.setFaultObserver(ep.getOutFaultObserver());
}
use of org.apache.cxf.message.Exchange in project cxf by apache.
the class BareInInterceptor method handleMessage.
public void handleMessage(Message message) {
if (isGET(message) && message.getContent(List.class) != null) {
LOG.fine("BareInInterceptor skipped in HTTP GET method");
return;
}
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
Exchange exchange = message.getExchange();
DataReader<XMLStreamReader> dr = getDataReader(message);
MessageContentsList parameters = new MessageContentsList();
Endpoint ep = exchange.getEndpoint();
BindingOperationInfo bop = exchange.getBindingOperationInfo();
ServiceInfo si = ep.getEndpointInfo().getService();
BindingMessageInfo msgInfo = null;
boolean client = isRequestor(message);
Collection<OperationInfo> ops = null;
if (bop == null) {
ops = new ArrayList<>();
ops.addAll(si.getInterface().getOperations());
if (xmlReader.getEventType() == XMLStreamConstants.END_ELEMENT && !client) {
// TO DO : check duplicate operation with no input
for (OperationInfo op : ops) {
MessageInfo bmsg = op.getInput();
if (bmsg.getMessagePartsNumber() == 0) {
BindingOperationInfo boi = ep.getEndpointInfo().getBinding().getOperation(op);
exchange.put(BindingOperationInfo.class, boi);
exchange.setOneWay(op.isOneWay());
}
}
}
} else {
getMessageInfo(message, bop);
if (client) {
msgInfo = bop.getOutput();
} else {
msgInfo = bop.getInput();
}
}
int paramNum = 0;
while (StaxUtils.toNextElement(xmlReader)) {
QName elName = xmlReader.getName();
Object o = null;
MessagePartInfo p;
if (msgInfo != null && msgInfo.getMessageParts() != null) {
assert msgInfo.getMessageParts().size() > paramNum;
p = msgInfo.getMessageParts().get(paramNum);
} else {
p = findMessagePart(exchange, ops, elName, client, paramNum, message);
}
if (p == null) {
throw new Fault(new org.apache.cxf.common.i18n.Message("NO_PART_FOUND", LOG, elName), Fault.FAULT_CODE_CLIENT);
}
try {
o = dr.read(p, xmlReader);
} catch (Fault fault) {
if (!isRequestor(message)) {
fault.setFaultCode(Fault.FAULT_CODE_CLIENT);
}
throw fault;
}
if (o != null) {
parameters.put(p, o);
}
paramNum++;
}
if (!parameters.isEmpty()) {
message.setContent(List.class, parameters);
}
}
Aggregations