use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class Proxy method invoke.
Object invoke(OperationInfo oi, ProtocolVariation protocol, Object[] params, Map<String, Object> context, Exchange exchange, Level exceptionLevel) throws RMException {
if (LOG.isLoggable(Level.INFO)) {
LOG.log(Level.INFO, "Sending out-of-band RM protocol message {0}.", oi == null ? null : oi.getName());
}
RMManager manager = reliableEndpoint.getManager();
Bus bus = manager.getBus();
Endpoint endpoint = reliableEndpoint.getEndpoint(protocol);
BindingInfo bi = reliableEndpoint.getBindingInfo(protocol);
Conduit c = reliableEndpoint.getConduit();
Client client = null;
if (params.length > 0 && params[0] instanceof DestinationSequence) {
EndpointReferenceType acksTo = ((DestinationSequence) params[0]).getAcksTo();
String acksAddress = acksTo.getAddress().getValue();
AttributedURIType attrURIType = new AttributedURIType();
attrURIType.setValue(acksAddress);
EndpointReferenceType acks = new EndpointReferenceType();
acks.setAddress(attrURIType);
client = createClient(bus, endpoint, protocol, c, acks);
params = new Object[] {};
} else {
EndpointReferenceType replyTo = reliableEndpoint.getReplyTo();
client = createClient(bus, endpoint, protocol, c, replyTo);
}
BindingOperationInfo boi = bi.getOperation(oi);
try {
if (context != null) {
client.getRequestContext().putAll(context);
}
Object[] result = client.invoke(boi, params, context, exchange);
if (result != null && result.length > 0) {
return result[0];
}
} catch (Exception ex) {
org.apache.cxf.common.i18n.Message msg = new org.apache.cxf.common.i18n.Message("SEND_PROTOCOL_MSG_FAILED_EXC", LOG, oi == null ? null : oi.getName());
LOG.log(exceptionLevel, msg.toString(), ex);
throw new RMException(msg, ex);
}
return null;
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class LocalDestinationTest method testStatusCodeSetAfterClose.
/**
* Tests if the status code is available after closing the destination so that it can be logged.
* Note that this test verifies the current approach of setting the status code if it is not set earlier.
*
* @throws Exception
*/
@Test
public void testStatusCodeSetAfterClose() throws Exception {
Bus bus = BusFactory.getDefaultBus();
LocalTransportFactory factory = new LocalTransportFactory();
EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
ei.setAddress("http://localhost/test");
LocalDestination d = (LocalDestination) factory.getDestination(ei, bus);
MessageImpl m = new MessageImpl();
Conduit conduit = factory.getConduit(ei, bus);
m.put(LocalConduit.IN_CONDUIT, conduit);
Exchange ex = new ExchangeImpl();
ex.put(Bus.class, bus);
m.setExchange(ex);
Integer code = (Integer) m.get(Message.RESPONSE_CODE);
assertNull(code);
Conduit backChannel = d.getBackChannel(m);
backChannel.close(m);
code = (Integer) m.get(Message.RESPONSE_CODE);
assertNotNull(code);
assertEquals(200, code.intValue());
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class LocalTransportFactoryTest method testInvocation.
private void testInvocation(boolean isDirectDispatch) throws Exception {
// Need to create a DefaultBus
Bus bus = BusFactory.getDefaultBus();
LocalTransportFactory factory = new LocalTransportFactory();
EndpointInfo ei = new EndpointInfo(null, "http://schemas.xmlsoap.org/soap/http");
ei.setAddress("http://localhost/test");
LocalDestination d = (LocalDestination) factory.getDestination(ei, bus);
d.setMessageObserver(new EchoObserver());
// Set up a listener for the response
Conduit conduit = factory.getConduit(ei, bus);
TestMessageObserver obs = new TestMessageObserver();
conduit.setMessageObserver(obs);
MessageImpl m = new MessageImpl();
if (isDirectDispatch) {
m.put(LocalConduit.DIRECT_DISPATCH, Boolean.TRUE);
}
m.setDestination(d);
Exchange ex = new ExchangeImpl();
ex.put(Bus.class, bus);
m.setExchange(ex);
conduit.prepare(m);
OutputStream out = m.getContent(OutputStream.class);
StringBuilder builder = new StringBuilder();
for (int x = 0; x < 1000; x++) {
builder.append("hello");
}
out.write(builder.toString().getBytes());
out.close();
conduit.close(m);
assertEquals(builder.toString(), obs.getResponseStream().toString());
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class MAPAggregatorImpl method addRoleSpecific.
/**
* Add MAPs which are specific to the requestor or responder role.
*
* @param maps the MAPs being assembled
* @param message the current message
* @param isRequestor true iff the current messaging role is that of
* requestor
* @param isFault true if a fault is being mediated
*/
private void addRoleSpecific(AddressingProperties maps, Message message, boolean isRequestor, boolean isFault) {
if (isRequestor) {
Exchange exchange = message.getExchange();
// add request-specific MAPs
boolean isOneway = exchange.isOneWay();
boolean isOutbound = ContextUtils.isOutbound(message);
// To
if (maps.getTo() == null) {
Conduit conduit = null;
if (isOutbound) {
conduit = ContextUtils.getConduit(null, message);
}
String s = (String) message.get(Message.ENDPOINT_ADDRESS);
EndpointReferenceType reference = conduit != null ? conduit.getTarget() : ContextUtils.getNoneEndpointReference();
if (conduit != null && !StringUtils.isEmpty(s) && !reference.getAddress().getValue().equals(s)) {
EndpointReferenceType ref = new EndpointReferenceType();
AttributedURIType tp = new AttributedURIType();
tp.setValue(s);
ref.setAddress(tp);
ref.setMetadata(reference.getMetadata());
ref.setReferenceParameters(reference.getReferenceParameters());
ref.getOtherAttributes().putAll(reference.getOtherAttributes());
reference = ref;
}
maps.setTo(reference);
}
// ReplyTo, set if null in MAPs or if set to a generic address
// (anonymous or none) that may not be appropriate for the
// current invocation
EndpointReferenceType replyTo = maps.getReplyTo();
if (ContextUtils.isGenericAddress(replyTo)) {
replyTo = getReplyTo(message, replyTo);
if (replyTo == null || (isOneway && (replyTo == null || replyTo.getAddress() == null || !Names.WSA_NONE_ADDRESS.equals(replyTo.getAddress().getValue())))) {
AttributedURIType address = ContextUtils.getAttributedURI(isOneway ? Names.WSA_NONE_ADDRESS : Names.WSA_ANONYMOUS_ADDRESS);
replyTo = ContextUtils.WSA_OBJECT_FACTORY.createEndpointReferenceType();
replyTo.setAddress(address);
}
maps.setReplyTo(replyTo);
}
// FaultTo
if (maps.getFaultTo() == null) {
maps.setFaultTo(maps.getReplyTo());
} else if (maps.getFaultTo().getAddress() == null) {
maps.setFaultTo(null);
}
} else {
// add response-specific MAPs
AddressingProperties inMAPs = getMAPs(message, false, false);
maps.exposeAs(inMAPs.getNamespaceURI());
// on the fault status of the response)
if (isFault && inMAPs.getFaultTo() != null) {
maps.setTo(inMAPs.getFaultTo());
} else if (maps.getTo() == null && inMAPs.getReplyTo() != null) {
maps.setTo(inMAPs.getReplyTo());
}
// RelatesTo taken from MessageID in incoming MAPs
if (inMAPs.getMessageID() != null && !Boolean.TRUE.equals(message.get(Message.PARTIAL_RESPONSE_MESSAGE))) {
String inMessageID = inMAPs.getMessageID().getValue();
maps.setRelatesTo(ContextUtils.getRelatesTo(inMessageID));
} else {
maps.setRelatesTo(ContextUtils.getRelatesTo(Names.WSA_UNSPECIFIED_RELATIONSHIP));
}
// fallback fault action
if (isFault && maps.getAction() == null) {
maps.setAction(ContextUtils.getAttributedURI(Names.WSA_DEFAULT_FAULT_ACTION));
}
if (isFault && !ContextUtils.isGenericAddress(inMAPs.getFaultTo())) {
Message m = message.getExchange().getInFaultMessage();
if (m == null) {
m = message;
}
InternalContextUtils.rebaseResponse(inMAPs.getFaultTo(), inMAPs, m);
Destination destination = InternalContextUtils.createDecoupledDestination(m.getExchange(), inMAPs.getFaultTo());
m.getExchange().setDestination(destination);
}
}
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class MAPAggregatorTest method setUpRebase.
private void setUpRebase(Message message, Exchange exchange, Endpoint endpoint) throws Exception {
setUpMessageProperty(message, "org.apache.cxf.ws.addressing.partial.response.sent", Boolean.FALSE);
Binding binding = control.createMock(Binding.class);
endpoint.getBinding();
EasyMock.expectLastCall().andReturn(binding).anyTimes();
Message partialResponse = getMessage();
binding.createMessage(EasyMock.isA(Message.class));
EasyMock.expectLastCall().andReturn(partialResponse);
Destination target = control.createMock(Destination.class);
setUpMessageDestination(message, target);
Conduit backChannel = control.createMock(Conduit.class);
target.getBackChannel(EasyMock.eq(message));
EasyMock.expectLastCall().andReturn(backChannel);
// REVISIT test interceptor chain setup & send
}
Aggregations