本文整理汇总了Java中org.apache.cxf.message.MessageContentsList类的典型用法代码示例。如果您正苦于以下问题:Java MessageContentsList类的具体用法?Java MessageContentsList怎么用?Java MessageContentsList使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MessageContentsList类属于org.apache.cxf.message包,在下文中一共展示了MessageContentsList类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleMessage
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Override
public void handleMessage(SoapMessage message) throws Fault {
super.handleMessage(message);
MessageContentsList contents = MessageContentsList.getContentsList(message);
if (contents != null && contents.size() == 1) {
Object requestObj = contents.get(0);
if (requestObj instanceof TrzbaType) {
TrzbaType request = (TrzbaType) requestObj;
TrzbaHlavickaType header = request.getHlavicka();
// validation is required if isOvereni is unspecified or false.
boolean required = header == null || !Boolean.TRUE.equals(header.isOvereni());
message.getExchange().put(WSS4JEetInInterceptor.PROP_SIGNATURE_REQUIRED, required);
}
}
}
示例2: buildResponse
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
/**
* Builds the response for the client.
* <p />
* Always returns a JAX-RS {@link Response} object, which gives the user a better control on the response behaviour.
* If the message body is already an instance of {@link Response}, we reuse it and just inject the relevant HTTP headers.
* @param camelExchange
* @param base
* @return
*/
protected Object buildResponse(org.apache.camel.Exchange camelExchange, Object base) {
Message m = camelExchange.hasOut() ? camelExchange.getOut() : camelExchange.getIn();
ResponseBuilder response;
// if the body is different to Response, it's an entity; therefore, check
if (base instanceof Response) {
response = Response.fromResponse((Response) base);
} else {
int status = m.getHeader(org.apache.camel.Exchange.HTTP_RESPONSE_CODE, Status.OK.getStatusCode(), Integer.class);
response = Response.status(status);
// avoid using the request MessageContentsList as the entity; it simply doesn't make sense
if (base != null && !(base instanceof MessageContentsList)) {
response.entity(base);
}
}
// Compute which headers to transfer by applying the HeaderFilterStrategy, and transfer them to the JAX-RS Response
Map<String, String> headersToPropagate = filterCamelHeadersForResponseHeaders(m.getHeaders(), camelExchange);
for (Entry<String, String> entry : headersToPropagate.entrySet()) {
response.header(entry.getKey(), entry.getValue());
}
return response.build();
}
示例3: bindCamelMessageBodyToRequestBody
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
/**
* This method call Message.getBody({@link MessageContentsList}) to allow
* an appropriate converter to kick in even through we only read the first
* element off the MessageContextList. If that returns null, we check
* the body to see if it is a List or an array and then return the first
* element. If that fails, we will simply return the object.
*/
public Object bindCamelMessageBodyToRequestBody(Message camelMessage, Exchange camelExchange)
throws Exception {
Object request = camelMessage.getBody(MessageContentsList.class);
if (request != null) {
return ((MessageContentsList)request).get(0);
}
request = camelMessage.getBody();
if (request instanceof List) {
request = ((List<?>)request).get(0);
} else if (request != null && request.getClass().isArray()) {
request = ((Object[])request)[0];
}
return request;
}
示例4: getResponsePayloadList
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
protected MessageContentsList getResponsePayloadList(org.apache.cxf.message.Exchange exchange,
List<Source> elements) {
BindingOperationInfo boi = exchange.getBindingOperationInfo();
if (boi.isUnwrapped()) {
boi = boi.getWrappedOperation();
exchange.put(BindingOperationInfo.class, boi);
}
MessageContentsList answer = new MessageContentsList();
int i = 0;
if (boi.getOutput() != null) {
for (MessagePartInfo partInfo : boi.getOutput().getMessageParts()) {
if (elements != null && elements.size() > i) {
answer.put(partInfo, elements.get(i++));
}
}
}
return answer;
}
示例5: testFallbackConverter
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Test
public void testFallbackConverter() throws Exception {
CamelContext context = new DefaultCamelContext();
Exchange exchange = new DefaultExchange(context);
MessageContentsList list = new MessageContentsList();
NodeListWrapper nl = new NodeListWrapper(new ArrayList<Element>());
list.add(nl);
exchange.getIn().setBody(list);
Node node = exchange.getIn().getBody(Node.class);
assertNull(node);
File file = new File("src/test/resources/org/apache/camel/component/cxf/converter/test.xml");
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setNamespaceAware(true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(file);
document.getDocumentElement().normalize();
List<Element> elements = new ArrayList<Element>();
elements.add(document.getDocumentElement());
nl = new NodeListWrapper(elements);
list.clear();
list.add(nl);
exchange.getIn().setBody(list);
node = exchange.getIn().getBody(Node.class);
assertNotNull(node);
}
示例6: doTestOutOutOfBandHeaderCamelTemplate
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
protected void doTestOutOutOfBandHeaderCamelTemplate(String producerUri) throws Exception {
// START SNIPPET: sending
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
final List<Object> params = new ArrayList<Object>();
Me me = new Me();
me.setFirstName("john");
me.setLastName("Doh");
params.add(me);
senderExchange.getIn().setBody(params);
senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, "outOutOfBandHeader");
Exchange exchange = template.send(producerUri, senderExchange);
org.apache.camel.Message out = exchange.getOut();
MessageContentsList result = (MessageContentsList)out.getBody();
assertTrue("Expected the out of band header to propagate but it didn't",
result.get(0) != null && ((Me)result.get(0)).getFirstName().equals("pass"));
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
validateReturnedOutOfBandHeader(responseContext);
}
示例7: testInvokingSimpleServerWithParams
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Test
public void testInvokingSimpleServerWithParams() throws Exception {
// START SNIPPET: sending
Exchange senderExchange = new DefaultExchange(context, ExchangePattern.InOut);
final List<String> params = new ArrayList<String>();
// Prepare the request message for the camel-cxf procedure
params.add(TEST_MESSAGE);
senderExchange.getIn().setBody(params);
senderExchange.getIn().setHeader(CxfConstants.OPERATION_NAME, ECHO_OPERATION);
Exchange exchange = template.send("direct:EndpointA", senderExchange);
org.apache.camel.Message out = exchange.getOut();
// The response message's body is an MessageContentsList which first element is the return value of the operation,
// If there are some holder parameters, the holder parameter will be filled in the reset of List.
// The result will be extract from the MessageContentsList with the String class type
MessageContentsList result = (MessageContentsList)out.getBody();
LOG.info("Received output text: " + result.get(0));
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
assertEquals("We should get the response context here", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING));
assertEquals("Reply body on Camel is wrong", "echo " + TEST_MESSAGE, result.get(0));
// END SNIPPET: sending
}
示例8: process
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Override
public void process(Exchange exchange)
{
final Message inMessage = exchange.getIn();
final MessageContentsList list = inMessage.getBody(MessageContentsList.class);
final Integer sessionId = (Integer)list.remove(0);
if (sessionId == null)
{
throw new RuntimeCamelException("Missing sessionId");
}
// NOTE: we are tolerating sessionId<=0 because some of the routes does not need an SessionId (e.g. LoginRequest)
inMessage.setHeader(PRTRestServiceConstants.PARAM_SessionId, sessionId);
}
示例9: process
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Override
public void process(Exchange exchange) throws Exception {
logger.info("Processing a time service request");
Object object = exchange.getIn().getBody();
if (object instanceof MessageContentsList) {
/**
* If we needed to get the contents of the message, we could do this:
*
* MessageContentsList messageContentsList = (MessageContentsList) object;
*
* Holder<DataType> someData = (Holder<DataType>) messageContentsList.get(<pos>);
*/
exchange.getOut().setBody(new Object[] { new TimeServiceBean().timeService() } );
logger.debug("Setting up reply message");
}
else {
logger.error("Unhandled message type: " + (object == null ? "null"
: object.getClass()));
}
}
示例10: handleMessage
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Override
public void handleMessage(final Message message) throws Fault {
if (isResponseAlreadyHandled(message)) {
return;
}
final MessageContentsList objs = MessageContentsList.getContentsList(message);
if (objs == null || objs.isEmpty()) {
return;
}
final Object responseObj = objs.get(0);
if (Response.class.isInstance(responseObj)) {
final Response response = Response.class.cast(responseObj);
if (is404(message, response)) {
switchResponse(message);
}
} else {
final Object exchangeStatus = message.getExchange().get(Message.RESPONSE_CODE);
final int status = exchangeStatus != null ? Integer.class.cast(exchangeStatus) : HttpsURLConnection.HTTP_OK;
if (status == HttpsURLConnection.HTTP_NOT_FOUND) {
switchResponse(message);
}
}
}
示例11: getChargeBoxId
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
private String getChargeBoxId(Message message) {
MessageContentsList lst = MessageContentsList.getContentsList(message);
if (lst == null) {
return null;
}
MessageInfo mi = (MessageInfo) message.get("org.apache.cxf.service.model.MessageInfo");
for (MessagePartInfo mpi : mi.getMessageParts()) {
if (CHARGEBOX_ID_HEADER.equals(mpi.getName().getLocalPart())) {
return (String) lst.get(mpi);
}
}
return null;
}
示例12: handleMessage
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Override
public void handleMessage(SoapMessage message) throws Fault {
if (message.getExchange().containsKey(WSS4JEetInInterceptor.PROP_SIGNATURE_ERROR)) {
MessageContentsList contents = MessageContentsList.getContentsList(message);
OdpovedType response = (OdpovedType) contents.get(0);
OdpovedChybaType error = response.getChyba();
if (error == null || error.getKod() == ERR_CODE_NO_ERROR) {
throw (Fault) message.getExchange().get(WSS4JEetInInterceptor.PROP_SIGNATURE_ERROR);
}
}
}
示例13: handleMessage
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Override
public void handleMessage(Message message) {
final List<Object> arguments = MessageContentsList.getContentsList(message);
if (!arguments.isEmpty()) {
final Object instance = message.getExchange().get(Message.SERVICE_OBJECT);
final Method method = (Method) message.get(METHOD_KEY);
final ExecutableValidator methodValidator = validator.forExecutables();
final Class<?>[] groups = Optional.ofNullable(method.getAnnotation(Groups.class)).map(Groups::value).orElse(DEFAULT_GROUPS);
final Set<ConstraintViolation<Object>> violations = methodValidator.validateParameters(instance, method, arguments.toArray(), groups);
if (!violations.isEmpty()) {
message.put(FaultListener.class.getName(), new NoOpFaultListener());
throw new JaxrsServerValidationException(violations);
}
}
}
示例14: manageSOAPResponse
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
/**
* Extracts from SOAP Response the CorporateAccount and updates the Exchange with it
*
* @param exchange Message with the SOAP Response from CustomerWS
*
* @throws IOException
*/
public void manageSOAPResponse(Exchange exchange) throws IOException {
// Corporate Account from WS
CorporateAccount ca = (CorporateAccount) exchange.getIn().getBody(MessageContentsList.class).get(0);
LOGGER.info("CorporateAccount from CustomerWS: {}", ca);
exchange.getIn().setBody(ca);
}
示例15: toMessageContentsList
import org.apache.cxf.message.MessageContentsList; //导入依赖的package包/类
@Converter
public static MessageContentsList toMessageContentsList(final Object[] array) {
if (array != null) {
return new MessageContentsList(array);
} else {
return new MessageContentsList();
}
}