本文整理汇总了Java中org.apache.cxf.message.Message.setContent方法的典型用法代码示例。如果您正苦于以下问题:Java Message.setContent方法的具体用法?Java Message.setContent怎么用?Java Message.setContent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cxf.message.Message
的用法示例。
在下文中一共展示了Message.setContent方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
@Override
public void handleMessage(Message message) throws Fault
{
final OutputStream os = message.getContent(OutputStream.class);
if (os == null)
{
return;
}
Logger logger = getMessageLogger(message);
if (logger.isLoggable(Level.INFO) || writer != null)
{
// Write the output while caching it for the log message
boolean hasLogged = message.containsKey(LOG_SETUP);
if (!hasLogged)
{
message.put(LOG_SETUP, Boolean.TRUE);
final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(
os);
message.setContent(OutputStream.class, newOut);
newOut.registerCallback(new LoggingCallback(logger, message, os));
}
}
}
示例2: decryptContent
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
public static void decryptContent( SecurityManager securityManager, Message message, String hostIdSource,
String hostIdTarget )
{
InputStream is = message.getContent( InputStream.class );
CachedOutputStream os = new CachedOutputStream();
LOG.debug( String.format( "Decrypting IDs: %s -> %s", hostIdSource, hostIdTarget ) );
try
{
int copied = IOUtils.copyAndCloseInput( is, os );
os.flush();
byte[] data = copied > 0 ? decryptData( securityManager, hostIdSource, os.getBytes() ) : null;
org.apache.commons.io.IOUtils.closeQuietly( os );
if ( !ArrayUtils.isEmpty( data ) )
{
LOG.debug( String.format( "Decrypted payload: \"%s\"", new String( data ) ) );
message.setContent( InputStream.class, new ByteArrayInputStream( data ) );
}
else
{
LOG.debug( "Decrypted data is NULL!!!" );
}
}
catch ( Exception e )
{
LOG.error( "Error decrypting content", e );
}
}
示例3: handleMessage
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
@Override
public void handleMessage(Message message) throws Fault
{
String messageId = (String) message.getExchange().get(
LoggingMessage.ID_KEY);
LogBean bean = new LogBean();
bean.setResponseTime(new Date());
OutputStream stream = message.getContent(OutputStream.class);
final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(
stream);
message.setContent(OutputStream.class, newOut);
newOut.registerCallback(new LoggingCallback(messageId, bean));
}
示例4: doInterfaceLog
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
private void doInterfaceLog(Message message)
{
String messageId = (String)message.getExchange().get(LoggingMessage.ID_KEY);
String currentEnvelopeMessage = "";
/*****/
OutputStream os = message.getContent(OutputStream.class);
CachedStream cs = new CachedStream();
message.setContent(OutputStream.class, cs);
message.getInterceptorChain().doIntercept(message);
try
{
cs.flush();
IOUtils.closeQuietly(cs);
CachedOutputStream csnew = (CachedOutputStream)message.getContent(OutputStream.class);
currentEnvelopeMessage = IOUtils.toString(csnew.getInputStream(), "UTF-8");
csnew.flush();
IOUtils.closeQuietly(csnew);
InputStream replaceInStream = IOUtils.toInputStream(currentEnvelopeMessage, "UTF-8");
IOUtils.copy(replaceInStream, os);
replaceInStream.close();
IOUtils.closeQuietly(replaceInStream);
os.flush();
message.setContent(OutputStream.class, os);
IOUtils.closeQuietly(os);
}
catch (IOException ioe)
{
throw new RuntimeException(ioe);
}
/*****/
InterfaceLogBean bean = new InterfaceLogBean();
bean.setTransactionId(messageId);
bean.setReq(false);
bean.setRespTime(new Date());
bean.setResultCode(getResultCode(currentEnvelopeMessage));
IInterfaceLog logger = ApplicationContextUtil.getBean("interfaceLogger");
logger.info(bean);
}
示例5: handleMessage
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
@Override
public void handleMessage(Message message) throws Fault
{
String messageId = (String) message.getExchange().get(
LoggingMessage.ID_KEY);
LogBean bean = new LogBean();
bean.setResponseTime(new Date());
OutputStream stream = message.getContent(OutputStream.class);
final CacheAndWriteOutputStream newOut = new CacheAndWriteOutputStream(
stream);
message.setContent(OutputStream.class, newOut);
newOut.registerCallback(new LoggingCallback(messageId,bean));
}
示例6: handleMessage
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
public void handleMessage(Message message) throws Fault {
DepthXMLStreamReader xmlReader = getXMLStreamReader(message);
try {
// put the payload source as a document
Document doc = StaxUtils.read(xmlReader);
message.setContent(Source.class, new DOMSource(doc));
} catch (XMLStreamException e) {
throw new Fault(new org.apache.cxf.common.i18n.Message("XMLSTREAM_EXCEPTION", JUL_LOG), e);
}
}
示例7: prepare
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
public void prepare(Message message) throws IOException {
LOG.trace("CamelConduit send message");
CamelOutputStream os = new CamelOutputStream(this.targetCamelEndpointUri,
this.producer,
this.headerFilterStrategy,
this.getMessageObserver(),
message);
message.setContent(OutputStream.class, os);
}
示例8: encryptContent
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
public static void encryptContent( SecurityManager securityManager, String hostIdSource, String hostIdTarget,
Message message )
{
OutputStream os = message.getContent( OutputStream.class );
CachedStream cs = new CachedStream();
message.setContent( OutputStream.class, cs );
message.getInterceptorChain().doIntercept( message );
LOG.debug( String.format( "Encrypting IDs: %s -> %s", hostIdSource, hostIdTarget ) );
try
{
cs.flush();
CachedOutputStream csnew = ( CachedOutputStream ) message.getContent( OutputStream.class );
byte[] originalMessage = org.apache.commons.io.IOUtils.toByteArray( csnew.getInputStream() );
LOG.debug( String.format( "Original payload: \"%s\"", new String( originalMessage ) ) );
csnew.flush();
org.apache.commons.io.IOUtils.closeQuietly( cs );
org.apache.commons.io.IOUtils.closeQuietly( csnew );
//do something with original message to produce finalMessage
byte[] finalMessage =
originalMessage.length > 0 ? encryptData( securityManager, hostIdTarget, originalMessage ) : null;
if ( !ArrayUtils.isEmpty( finalMessage ) )
{
InputStream replaceInStream = new ByteArrayInputStream( finalMessage );
org.apache.commons.io.IOUtils.copy( replaceInStream, os );
replaceInStream.close();
org.apache.commons.io.IOUtils.closeQuietly( replaceInStream );
os.flush();
message.setContent( OutputStream.class, os );
}
org.apache.commons.io.IOUtils.closeQuietly( os );
}
catch ( Exception ioe )
{
throw new ActionFailedException( "Error encrypting content", ioe );
}
}
示例9: setParameters
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
protected void setParameters(Object[] params, Message message) {
Object attachments = message.get(CxfConstants.CAMEL_CXF_ATTACHMENTS);
if (attachments != null) {
message.setAttachments((Collection<Attachment>) attachments);
message.remove(CxfConstants.CAMEL_CXF_ATTACHMENTS);
}
// Don't try to reset the parameters if the parameter is not CxfPayload instance
// as the setParameter will be called more than once when using the fail over feature
if (DataFormat.PAYLOAD == message.get(DataFormat.class) && params[0] instanceof CxfPayload) {
CxfPayload<?> payload = (CxfPayload<?>) params[0];
List<Source> elements = payload.getBodySources();
BindingOperationInfo boi = message.get(BindingOperationInfo.class);
MessageContentsList content = new MessageContentsList();
int i = 0;
for (MessagePartInfo partInfo : boi.getInput().getMessageParts()) {
if (elements.size() > i) {
if (isSkipPayloadMessagePartCheck()) {
content.put(partInfo, elements.get(i++));
} else {
String name = findName(elements, i);
if (partInfo.getConcreteName().getLocalPart().equals(name)) {
content.put(partInfo, elements.get(i++));
}
}
}
}
if (elements != null && content.size() < elements.size()) {
throw new IllegalArgumentException("The PayLoad elements cannot fit with the message parts of the BindingOperation. Please check the BindingOperation and PayLoadMessage.");
}
message.setContent(List.class, content);
// merge header list from request context with header list from CXF payload
List<Object> headerListOfRequestContxt = (List<Object>)message.get(Header.HEADER_LIST);
List<Object> headerListOfPayload = CastUtils.cast(payload.getHeaders());
if (headerListOfRequestContxt == headerListOfPayload) {
// == is correct, we want to compare the object instances
// nothing to do, this can happen when the CXF payload is already created in the from-cxf-endpoint and then forwarded to a to-cxf-endpoint
} else {
if (headerListOfRequestContxt == null) {
message.put(Header.HEADER_LIST, payload.getHeaders());
} else {
headerListOfRequestContxt.addAll(headerListOfPayload);
}
}
} else {
super.setParameters(params, message);
}
message.remove(DataFormat.class);
}
示例10: testRoundTripDestinationWithFault
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
@Test
public void testRoundTripDestinationWithFault() throws Exception {
inMessage = null;
EndpointInfo conduitEpInfo = new EndpointInfo();
conduitEpInfo.setAddress("camel://direct:Producer");
// set up the conduit send to be true
CamelConduit conduit = setupCamelConduit(conduitEpInfo, true, false);
final Message outMessage = new MessageImpl();
endpointInfo.setAddress("camel://direct:EndpointA");
final CamelDestination destination = setupCamelDestination(endpointInfo, true);
destination.setCheckException(true);
// set up MessageObserver for handling the conduit message
MessageObserver observer = new MessageObserver() {
public void onMessage(Message m) {
try {
Exchange exchange = new ExchangeImpl();
exchange.setInMessage(m);
m.setExchange(exchange);
verifyReceivedMessage(m, "HelloWorld");
//verifyHeaders(m, outMessage);
// setup the message for
Conduit backConduit;
backConduit = getBackChannel(destination, m);
// wait for the message to be got from the conduit
Message replyMessage = new MessageImpl();
replyMessage.setContent(Exception.class, new RuntimeCamelException());
sendoutMessage(backConduit, replyMessage, true, "HelloWorld Fault");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
};
MockEndpoint error = context.getEndpoint("mock:error", MockEndpoint.class);
error.expectedMessageCount(1);
//this call will active the camelDestination
destination.setMessageObserver(observer);
// set is one way false for get response from destination
// need to use another thread to send the request message
sendoutMessage(conduit, outMessage, false, "HelloWorld");
// wait for the message to be got from the destination,
// create the thread to handler the Destination incoming message
verifyReceivedMessage(inMessage, "HelloWorld Fault");
error.assertIsSatisfied();
destination.shutdown();
}
示例11: prepare
import org.apache.cxf.message.Message; //导入方法依赖的package包/类
/**
* Send an outbound message, assumed to contain all the name-value
* mappings of the corresponding input message (if any).
*
* @param message the message to be sent.
*/
public void prepare(Message message) throws IOException {
message.put(CamelTransportConstants.CAMEL_EXCHANGE, inMessage.get(CamelTransportConstants.CAMEL_EXCHANGE));
message.setContent(OutputStream.class, new CamelOutputStream(message));
}