use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class MtomServerTest method testURLBasedAttachment.
@Test
public void testURLBasedAttachment() throws Exception {
JaxWsServerFactoryBean sf = new JaxWsServerFactoryBean();
sf.setServiceBean(new EchoService());
sf.setBus(getStaticBus());
String address = "http://localhost:" + PORT2 + "/EchoService";
sf.setAddress(address);
Map<String, Object> props = new HashMap<>();
props.put(Message.MTOM_ENABLED, "true");
sf.setProperties(props);
Server server = sf.create();
server.getEndpoint().getService().getDataBinding().setMtomThreshold(0);
servStatic(getClass().getResource("mtom-policy.xml"), "http://localhost:" + PORT2 + "/policy.xsd");
EndpointInfo ei = new EndpointInfo(null, HTTP_ID);
ei.setAddress(address);
ConduitInitiatorManager conduitMgr = getStaticBus().getExtension(ConduitInitiatorManager.class);
ConduitInitiator conduitInit = conduitMgr.getConduitInitiator("http://schemas.xmlsoap.org/soap/http");
Conduit conduit = conduitInit.getConduit(ei, getStaticBus());
TestUtilities.TestMessageObserver obs = new TestUtilities.TestMessageObserver();
conduit.setMessageObserver(obs);
Message m = new MessageImpl();
String ct = "multipart/related; type=\"application/xop+xml\"; " + "start=\"<soap.xml@xfire.codehaus.org>\"; " + "start-info=\"text/xml; charset=utf-8\"; " + "boundary=\"----=_Part_4_701508.1145579811786\"";
m.put(Message.CONTENT_TYPE, ct);
conduit.prepare(m);
OutputStream os = m.getContent(OutputStream.class);
InputStream is = testUtilities.getResourceAsStream("request-url-attachment");
if (is == null) {
throw new RuntimeException("Could not find resource " + "request");
}
try (ByteArrayOutputStream bout = new ByteArrayOutputStream()) {
IOUtils.copy(is, bout);
String s = bout.toString(StandardCharsets.UTF_8.name());
s = s.replaceAll(":9036/", ":" + PORT2 + "/");
os.write(s.getBytes(StandardCharsets.UTF_8));
}
os.flush();
is.close();
os.close();
byte[] res = obs.getResponseStream().toByteArray();
MessageImpl resMsg = new MessageImpl();
resMsg.setContent(InputStream.class, new ByteArrayInputStream(res));
resMsg.put(Message.CONTENT_TYPE, obs.getResponseContentType());
resMsg.setExchange(new ExchangeImpl());
AttachmentDeserializer deserializer = new AttachmentDeserializer(resMsg);
deserializer.initializeAttachments();
Collection<Attachment> attachments = resMsg.getAttachments();
assertNotNull(attachments);
assertEquals(1, attachments.size());
Attachment inAtt = attachments.iterator().next();
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
IOUtils.copy(inAtt.getDataHandler().getInputStream(), out);
assertTrue("Wrong size: " + out.size() + "\n" + out.toString(), out.size() > 970 && out.size() < 1020);
}
unregisterServStatic("http://localhost:" + PORT2 + "/policy.xsd");
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class ClientConfiguration method getConduit.
/**
* Gets the conduit responsible for a transport-level
* communication with the remote service.
* @return the conduit
*/
public Conduit getConduit() {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
message.setExchange(exchange);
exchange.put(MessageObserver.class, new ClientMessageObserver(this));
if (conduitSelector != null) {
exchange.put(Endpoint.class, conduitSelector.getEndpoint());
}
exchange.put(Bus.class, bus);
prepareConduitSelector(message);
return getConduitSelector().selectConduit(message);
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class MAPCodecTest method getMAPs.
private AddressingProperties getMAPs(boolean requestor, boolean outbound, String uri) {
AddressingProperties maps = new AddressingProperties();
boolean exposeAsNative = Names.WSA_NAMESPACE_NAME.equals(uri);
boolean exposeAs200408 = Names200408.WSA_NAMESPACE_NAME.equals(uri);
boolean exposeAs200403 = Names200403.WSA_NAMESPACE_NAME.equals(uri);
AttributedURIType id = ContextUtils.getAttributedURI("urn:uuid:12345");
maps.setMessageID(id);
AttributedURIType to = ContextUtils.getAttributedURI("foobar");
EndpointReferenceType toEpr = EndpointReferenceUtils.getEndpointReference(to);
maps.setTo(toEpr);
EndpointReferenceType replyTo = new EndpointReferenceType();
String anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS : exposeAs200408 ? Names200408.WSA_ANONYMOUS_ADDRESS : Names200403.WSA_ANONYMOUS_ADDRESS;
replyTo.setAddress(ContextUtils.getAttributedURI(anonymous));
maps.setReplyTo(replyTo);
EndpointReferenceType from = EndpointReferenceUtils.getEndpointReference("snafu");
maps.setFrom(from);
EndpointReferenceType faultTo = new EndpointReferenceType();
anonymous = exposeAsNative ? Names.WSA_ANONYMOUS_ADDRESS : exposeAs200408 ? Names200408.WSA_ANONYMOUS_ADDRESS : Names200403.WSA_ANONYMOUS_ADDRESS;
faultTo.setAddress(ContextUtils.getAttributedURI(anonymous));
maps.setFaultTo(faultTo);
RelatesToType relatesTo = null;
if (expectRelatesTo) {
String correlationID = "urn:uuid:67890";
relatesTo = new RelatesToType();
relatesTo.setValue(correlationID);
maps.setRelatesTo(relatesTo);
if (nonReplyRelationship == null) {
correlatedExchange = new ExchangeImpl();
codec.uncorrelatedExchanges.put(correlationID, correlatedExchange);
} else {
relatesTo.setRelationshipType(nonReplyRelationship);
}
}
AttributedURIType action = ContextUtils.getAttributedURI("http://foo/bar/SEI/opRequest");
maps.setAction(action);
maps.exposeAs(uri);
expectedNamespaceURI = uri;
expectedNames = new QName[] { new QName(uri, Names.WSA_ACTION_NAME), new QName(uri, Names.WSA_MESSAGEID_NAME), new QName(uri, Names.WSA_TO_NAME), new QName(uri, Names.WSA_REPLYTO_NAME), new QName(uri, Names.WSA_RELATESTO_NAME), new QName(uri, Names.WSA_FROM_NAME), new QName(uri, Names.WSA_FAULTTO_NAME) };
if (exposeAsNative) {
expectedValues = new Object[] { action, id, to, replyTo, relatesTo, from, faultTo };
} else if (exposeAs200408) {
expectedValues = new Object[] { org.apache.cxf.ws.addressing.VersionTransformer.convert(action), org.apache.cxf.ws.addressing.VersionTransformer.convert(id), org.apache.cxf.ws.addressing.VersionTransformer.convert(to), org.apache.cxf.ws.addressing.VersionTransformer.convert(replyTo), org.apache.cxf.ws.addressing.VersionTransformer.convert(relatesTo), org.apache.cxf.ws.addressing.VersionTransformer.convert(from), org.apache.cxf.ws.addressing.VersionTransformer.convert(faultTo) };
if (!outbound) {
// conversion from 2004/08 to 2005/08 anonymous address
// occurs transparently in VersionTransformer
Names200408.EPR_TYPE.cast(expectedValues[3]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
Names200408.EPR_TYPE.cast(expectedValues[5]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
}
} else if (exposeAs200403) {
expectedValues = new Object[] { org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(action), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(id), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(to), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(replyTo), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(relatesTo), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(from), org.apache.cxf.ws.addressing.VersionTransformer.convertTo200403(faultTo) };
if (!outbound) {
// conversion from 2004/03 to 2005/08 anonymous address
// occurs transparently in VersionTransformer
Names200403.EPR_TYPE.cast(expectedValues[3]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
Names200403.EPR_TYPE.cast(expectedValues[5]).getAddress().setValue(Names.WSA_ANONYMOUS_ADDRESS);
}
} else {
fail("unexpected namespace URI: " + uri);
}
return maps;
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class MAPCodecTest method setUpOutbound.
private void setUpOutbound(Message message, boolean outbound) {
Exchange exchange = new ExchangeImpl();
exchange.setOutMessage(outbound ? message : new MessageImpl());
message.setExchange(exchange);
}
use of org.apache.cxf.message.ExchangeImpl in project cxf by apache.
the class ServantTest method createTestCloseSequenceMessage.
private static Message createTestCloseSequenceMessage(String sidstr) {
Message message = new MessageImpl();
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(message);
message.put(Message.REQUESTOR_ROLE, Boolean.FALSE);
AddressingProperties maps = new AddressingProperties();
String msgId = "urn:uuid:12345-" + Math.random();
AttributedURIType id = ContextUtils.getAttributedURI(msgId);
maps.setMessageID(id);
maps.setAction(ContextUtils.getAttributedURI(RM10Constants.INSTANCE.getTerminateSequenceAction()));
maps.setTo(ContextUtils.getAttributedURI(SERVICE_URL));
maps.setReplyTo(RMUtils.createReference(DECOUPLED_URL));
message.put(JAXWSAConstants.ADDRESSING_PROPERTIES_INBOUND, maps);
CloseSequenceType cs = new CloseSequenceType();
org.apache.cxf.ws.rm.v200702.Identifier sid = new org.apache.cxf.ws.rm.v200702.Identifier();
sid.setValue(sidstr);
cs.setIdentifier(sid);
MessageContentsList contents = new MessageContentsList();
contents.add(cs);
message.setContent(List.class, contents);
RMContextUtils.setProtocolVariation(message, ProtocolVariation.RM11WSA200508);
return message;
}
Aggregations