use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class RetransmissionQueueImpl method doResend.
private void doResend(SoapMessage message) {
InputStream is = null;
try {
// initialize copied interceptor chain for message
PhaseInterceptorChain retransmitChain = manager.getRetransmitChain(message);
ProtocolVariation protocol = RMContextUtils.getProtocolVariation(message);
Endpoint endpoint = manager.getReliableEndpoint(message).getEndpoint(protocol);
PhaseChainCache cache = new PhaseChainCache();
boolean after = true;
if (retransmitChain == null) {
// no saved retransmit chain, so construct one from scratch (won't work for WS-Security on server, so
// need to fix)
retransmitChain = buildRetransmitChain(endpoint, cache);
after = false;
}
message.setInterceptorChain(retransmitChain);
// clear flag for SOAP out interceptor so envelope will be written
message.remove(SoapOutInterceptor.WROTE_ENVELOPE_START);
// discard all saved content
Set<Class<?>> formats = message.getContentFormats();
List<CachedOutputStreamCallback> callbacks = null;
for (Class<?> clas : formats) {
Object content = message.getContent(clas);
if (content != null) {
LOG.info("Removing " + clas.getName() + " content of actual type " + content.getClass().getName());
message.removeContent(clas);
if (clas == OutputStream.class && content instanceof WriteOnCloseOutputStream) {
callbacks = ((WriteOnCloseOutputStream) content).getCallbacks();
}
}
}
// read SOAP headers from saved input stream
CachedOutputStream cos = (CachedOutputStream) message.get(RMMessageConstants.SAVED_CONTENT);
// CachedOutputStream is hold until delivering was successful
cos.holdTempFile();
// instance is needed to close input stream later on
is = cos.getInputStream();
XMLStreamReader reader = StaxUtils.createXMLStreamReader(is, StandardCharsets.UTF_8.name());
message.getHeaders().clear();
if (reader.getEventType() != XMLStreamConstants.START_ELEMENT && reader.nextTag() != XMLStreamConstants.START_ELEMENT) {
throw new IllegalStateException("No document found");
}
readHeaders(reader, message);
int event;
while ((event = reader.nextTag()) != XMLStreamConstants.START_ELEMENT) {
if (event == XMLStreamConstants.END_ELEMENT) {
throw new IllegalStateException("No body content present");
}
}
// set message addressing properties
AddressingProperties maps = MAPCodec.getInstance(message.getExchange().getBus()).unmarshalMAPs(message);
RMContextUtils.storeMAPs(maps, message, true, MessageUtils.isRequestor(message));
AttributedURIType to = null;
if (null != maps) {
to = maps.getTo();
}
if (null == to) {
LOG.log(Level.SEVERE, "NO_ADDRESS_FOR_RESEND_MSG");
return;
}
if (RMUtils.getAddressingConstants().getAnonymousURI().equals(to.getValue())) {
LOG.log(Level.FINE, "Cannot resend to anonymous target");
return;
}
// initialize conduit for new message
Conduit c = message.getExchange().getConduit(message);
if (c == null) {
c = buildConduit(message, endpoint, to);
}
c.prepare(message);
// replace standard message marshaling with copy from saved stream
ListIterator<Interceptor<? extends Message>> iterator = retransmitChain.getIterator();
while (iterator.hasNext()) {
Interceptor<? extends Message> incept = iterator.next();
// remove JAX-WS interceptors which handle message modes and such
if (incept.getClass().getName().startsWith("org.apache.cxf.jaxws.interceptors")) {
retransmitChain.remove(incept);
} else if (incept instanceof PhaseInterceptor && (((PhaseInterceptor<?>) incept).getPhase() == Phase.MARSHAL)) {
// remove any interceptors from the marshal phase
retransmitChain.remove(incept);
}
}
retransmitChain.add(new CopyOutInterceptor(reader));
// restore callbacks on output stream
if (callbacks != null) {
OutputStream os = message.getContent(OutputStream.class);
if (os != null) {
WriteOnCloseOutputStream woc;
if (os instanceof WriteOnCloseOutputStream) {
woc = (WriteOnCloseOutputStream) os;
} else {
woc = new WriteOnCloseOutputStream(os);
message.setContent(OutputStream.class, woc);
}
for (CachedOutputStreamCallback cb : callbacks) {
woc.registerCallback(cb);
}
}
}
// send the message
message.put(RMMessageConstants.RM_RETRANSMISSION, Boolean.TRUE);
if (after) {
retransmitChain.doInterceptStartingAfter(message, RMCaptureOutInterceptor.class.getName());
} else {
retransmitChain.doIntercept(message);
}
if (LOG.isLoggable(Level.INFO)) {
RMProperties rmps = RMContextUtils.retrieveRMProperties(message, true);
SequenceType seq = rmps.getSequence();
LOG.log(Level.INFO, "Retransmitted message " + seq.getMessageNumber() + " in sequence " + seq.getIdentifier().getValue());
rmps = new RMProperties();
}
} catch (Exception ex) {
LOG.log(Level.SEVERE, "RESEND_FAILED_MSG", ex);
} finally {
// make sure to always close InputStreams of the CachedOutputStream to avoid leaving temp files undeleted
if (null != is) {
try {
is.close();
} catch (IOException e) {
// Ignore
}
}
}
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class ProxyTest method testInvoke.
@Test
public void testInvoke() throws Exception {
Method m = Proxy.class.getDeclaredMethod("createClient", new Class[] { Bus.class, Endpoint.class, ProtocolVariation.class, Conduit.class, org.apache.cxf.ws.addressing.EndpointReferenceType.class });
Proxy proxy = EasyMock.createMockBuilder(Proxy.class).addMockedMethod(m).createMock(control);
proxy.setReliableEndpoint(rme);
RMManager manager = control.createMock(RMManager.class);
EasyMock.expect(rme.getManager()).andReturn(manager).anyTimes();
Bus bus = control.createMock(Bus.class);
EasyMock.expect(manager.getBus()).andReturn(bus).anyTimes();
Endpoint endpoint = control.createMock(Endpoint.class);
EasyMock.expect(rme.getEndpoint(ProtocolVariation.RM10WSA200408)).andReturn(endpoint).anyTimes();
BindingInfo bi = control.createMock(BindingInfo.class);
EasyMock.expect(rme.getBindingInfo(ProtocolVariation.RM10WSA200408)).andReturn(bi).anyTimes();
Conduit conduit = control.createMock(Conduit.class);
EasyMock.expect(rme.getConduit()).andReturn(conduit).anyTimes();
org.apache.cxf.ws.addressing.EndpointReferenceType replyTo = control.createMock(org.apache.cxf.ws.addressing.EndpointReferenceType.class);
EasyMock.expect(rme.getReplyTo()).andReturn(replyTo).anyTimes();
OperationInfo oi = control.createMock(OperationInfo.class);
BindingOperationInfo boi = control.createMock(BindingOperationInfo.class);
EasyMock.expect(bi.getOperation(oi)).andReturn(boi).anyTimes();
Client client = control.createMock(Client.class);
EasyMock.expect(client.getRequestContext()).andReturn(new HashMap<String, Object>()).anyTimes();
EasyMock.expect(proxy.createClient(bus, endpoint, ProtocolVariation.RM10WSA200408, conduit, replyTo)).andReturn(client).anyTimes();
Object[] args = new Object[] {};
Map<String, Object> context = new HashMap<>();
Object[] results = new Object[] { "a", "b", "c" };
Exchange exchange = control.createMock(Exchange.class);
EasyMock.expect(client.invoke(boi, args, context, exchange)).andReturn(results).anyTimes();
control.replay();
assertEquals("a", proxy.invoke(oi, ProtocolVariation.RM10WSA200408, args, context, exchange));
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class ProxyTest method testRMClientGetConduit.
@Test
public void testRMClientGetConduit() throws Exception {
Proxy proxy = new Proxy(rme);
Bus bus = control.createMock(Bus.class);
Endpoint endpoint = control.createMock(Endpoint.class);
Conduit conduit = control.createMock(Conduit.class);
ConduitSelector cs = control.createMock(ConduitSelector.class);
EasyMock.expect(cs.selectConduit(EasyMock.isA(Message.class))).andReturn(conduit).anyTimes();
control.replay();
Proxy.RMClient client = proxy.new RMClient(bus, endpoint, cs);
assertSame(conduit, client.getConduit());
client.close();
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class RMEndpointTest method testInitialise.
@Test
public void testInitialise() throws NoSuchMethodException {
Message m = new MessageImpl();
Method m1 = RMEndpoint.class.getDeclaredMethod("createServices", new Class[] {});
Method m2 = RMEndpoint.class.getDeclaredMethod("createEndpoints", new Class[] { org.apache.cxf.transport.Destination.class });
Method m3 = RMEndpoint.class.getDeclaredMethod("setPolicies", new Class[] { Message.class });
rme = EasyMock.createMockBuilder(RMEndpoint.class).addMockedMethods(m1, m2, m3).createMock(control);
rme.createServices();
EasyMock.expectLastCall();
rme.createEndpoints(null);
EasyMock.expectLastCall();
rme.setPolicies(m);
EasyMock.expectLastCall();
Conduit c = control.createMock(Conduit.class);
EndpointReferenceType epr = control.createMock(EndpointReferenceType.class);
control.replay();
rme.initialise(new RMConfiguration(), c, epr, null, m);
assertSame(c, rme.getConduit());
assertSame(epr, rme.getReplyTo());
}
use of org.apache.cxf.transport.Conduit in project cxf by apache.
the class RMManagerTest method testGetNewSequence.
@Test
public void testGetNewSequence() throws NoSuchMethodException, SequenceFault, RMException {
Method m = RMManager.class.getDeclaredMethod("getSource", new Class[] { Message.class });
manager = control.createMock(RMManager.class, new Method[] { m });
Message message = control.createMock(Message.class);
Exchange exchange = control.createMock(Exchange.class);
EasyMock.expect(message.getContextualPropertyKeys()).andReturn(new HashSet<>()).anyTimes();
EasyMock.expect(message.getExchange()).andReturn(exchange).anyTimes();
EasyMock.expect(exchange.getOutMessage()).andReturn(message).anyTimes();
EasyMock.expect(exchange.getInMessage()).andReturn(null).anyTimes();
EasyMock.expect(exchange.getOutFaultMessage()).andReturn(null).anyTimes();
Conduit conduit = control.createMock(Conduit.class);
EasyMock.expect(exchange.getConduit(message)).andReturn(conduit).anyTimes();
Identifier inSid = control.createMock(Identifier.class);
AddressingProperties maps = control.createMock(AddressingProperties.class);
Source source = control.createMock(Source.class);
EasyMock.expect(manager.getSource(message)).andReturn(source);
EasyMock.expect(source.getCurrent(inSid)).andReturn(null);
AttributedURIType uri = control.createMock(AttributedURIType.class);
EasyMock.expect(maps.getTo()).andReturn(uri);
EasyMock.expect(uri.getValue()).andReturn("http://localhost:9001/TestPort");
EndpointReferenceType epr = RMUtils.createNoneReference();
EasyMock.expect(maps.getReplyTo()).andReturn(epr);
RMEndpoint rme = control.createMock(RMEndpoint.class);
EasyMock.expect(source.getReliableEndpoint()).andReturn(rme).times(2);
Proxy proxy = control.createMock(Proxy.class);
EasyMock.expect(rme.getProxy()).andReturn(proxy);
CreateSequenceResponseType createResponse = control.createMock(CreateSequenceResponseType.class);
proxy.createSequence(EasyMock.isA(EndpointReferenceType.class), (RelatesToType) EasyMock.isNull(), EasyMock.eq(false), EasyMock.isA(ProtocolVariation.class), EasyMock.isA(Exchange.class), CastUtils.cast(EasyMock.isA(HashMap.class), String.class, Object.class));
EasyMock.expectLastCall().andReturn(createResponse);
Servant servant = control.createMock(Servant.class);
EasyMock.expect(rme.getServant()).andReturn(servant);
servant.createSequenceResponse(createResponse, ProtocolVariation.RM10WSA200408);
EasyMock.expectLastCall();
SourceSequence sseq = control.createMock(SourceSequence.class);
EasyMock.expect(source.awaitCurrent(inSid)).andReturn(sseq);
sseq.setTarget(EasyMock.isA(EndpointReferenceType.class));
EasyMock.expectLastCall();
control.replay();
assertSame(sseq, manager.getSequence(inSid, message, maps));
control.verify();
}
Aggregations