本文整理汇总了Java中org.apache.cxf.helpers.CastUtils.cast方法的典型用法代码示例。如果您正苦于以下问题:Java CastUtils.cast方法的具体用法?Java CastUtils.cast怎么用?Java CastUtils.cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cxf.helpers.CastUtils
的用法示例。
在下文中一共展示了CastUtils.cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: determineContentType
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
public String determineContentType() {
String ct = null;
List<Object> ctList = CastUtils.cast(headers.get(Message.CONTENT_TYPE));
if (ctList != null && ctList.size() == 1) {
ct = ctList.get(0).toString();
} else {
ct = (String)message.get(Message.CONTENT_TYPE);
}
String enc = (String)message.get(Message.ENCODING);
if (null != ct) {
// modify ct.toLowerCase() to ct.toLowerCase(Locale.US) -- add by jirunfang one row
if (enc != null
&& ct.indexOf("charset=") == -1
&& !ct.toLowerCase(Locale.US).contains("multipart/related")) {
ct = ct + "; charset=" + enc;
}
} else if (enc != null) {
ct = "text/xml; charset=" + enc;
} else {
ct = "text/xml";
}
return ct;
}
示例2: testPropagateCamelToCxf
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
@Test
public void testPropagateCamelToCxf() {
Exchange exchange = new DefaultExchange(context);
exchange.getIn().setHeader("soapAction", "urn:hello:world");
exchange.getIn().setHeader("MyFruitHeader", "peach");
exchange.getIn().setHeader("MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
org.apache.cxf.message.Message cxfMessage = new org.apache.cxf.message.MessageImpl();
CxfHeaderHelper.propagateCamelToCxf(new DefaultHeaderFilterStrategy(),
exchange.getIn().getHeaders(), cxfMessage, exchange);
// check the protocol headers
Map<String, List<String>> cxfHeaders =
CastUtils.cast((Map<?, ?>)cxfMessage.get(org.apache.cxf.message.Message.PROTOCOL_HEADERS));
assertNotNull(cxfHeaders);
assertTrue(cxfHeaders.size() == 3);
verifyHeader(cxfHeaders, "soapaction", "urn:hello:world");
verifyHeader(cxfHeaders, "SoapAction", "urn:hello:world");
verifyHeader(cxfHeaders, "SOAPAction", "urn:hello:world");
verifyHeader(cxfHeaders, "myfruitheader", "peach");
verifyHeader(cxfHeaders, "myFruitHeader", "peach");
verifyHeader(cxfHeaders, "MYFRUITHEADER", "peach");
verifyHeader(cxfHeaders, "MyBrewHeader", Arrays.asList("cappuccino", "espresso"));
}
示例3: testInvokingJaxWsServerWithParams
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
@Test
public void testInvokingJaxWsServerWithParams() throws Exception {
Exchange exchange = sendJaxWsMessage();
org.apache.camel.Message out = exchange.getOut();
String result = out.getBody(String.class);
LOG.info("Received output text: " + result);
Map<String, Object> responseContext = CastUtils.cast((Map<?, ?>)out.getHeader(Client.RESPONSE_CONTEXT));
assertNotNull(responseContext);
assertEquals("Get the wrong wsdl opertion name", "{http://apache.org/hello_world_soap_http}greetMe", responseContext.get("javax.xml.ws.wsdl.operation").toString());
assertEquals("reply body on Camel", "Hello " + TEST_MESSAGE, result);
// check the other camel header copying
String fileName = out.getHeader(Exchange.FILE_NAME, String.class);
assertEquals("Should get the file name from out message header", "testFile", fileName);
}
示例4: testTheContentType
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
@Test
public void testTheContentType() throws Exception {
MockEndpoint result = getMockEndpoint("mock:result");
result.reset();
result.expectedMessageCount(1);
HelloService client = getCXFClient();
client.echo("hello world");
assertMockEndpointsSatisfied();
Map<?, ?> context = CastUtils.cast((Map<?, ?>)result.assertExchangeReceived(0).getIn().getHeaders().get("ResponseContext"));
Map<?, ?> protocalHeaders = CastUtils.cast((Map<?, ?>) context.get("org.apache.cxf.message.Message.PROTOCOL_HEADERS"));
assertTrue("Should get a right content type", protocalHeaders.get("content-type").toString().startsWith("[text/xml;"));
assertTrue("Should get a right context type with a charset", protocalHeaders.get("content-type").toString().indexOf("charset=") > 0);
assertEquals("Should get the response code ", context.get("org.apache.cxf.message.Message.RESPONSE_CODE"), 200);
assertTrue("Should get the content type", result.assertExchangeReceived(0).getIn().getHeaders().get("content-type").toString().startsWith("text/xml;"));
assertTrue("Should get the content type", result.assertExchangeReceived(0).getIn().getHeaders().get("content-type").toString().indexOf("charset=") > 0);
}
示例5: testInvokingSimpleServerWithParams
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的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
}
示例6: doTestOutOutOfBandHeaderCamelTemplate
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的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: addReplyOutOfBandHeader
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
private void addReplyOutOfBandHeader() {
if (context != null) {
MessageContext ctx = context.getMessageContext();
if (ctx != null) {
try {
OutofBandHeader ob = new OutofBandHeader();
ob.setName("testOobReturnHeaderName");
ob.setValue("testOobReturnHeaderValue");
ob.setHdrAttribute("testReturnHdrAttribute");
JAXBElement<OutofBandHeader> job = new JAXBElement<OutofBandHeader>(
new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM),
OutofBandHeader.class, null, ob);
Header hdr = new Header(
new QName(Constants.TEST_HDR_NS, Constants.TEST_HDR_RESPONSE_ELEM),
job,
new JAXBDataBinding(ob.getClass()));
List<Header> hdrList = CastUtils.cast((List<?>) ctx.get(Header.HEADER_LIST));
hdrList.add(hdr);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}
示例8: testContentType
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
@Test
public void testContentType() {
Exchange camelExchange = EasyMock.createMock(Exchange.class);
HeaderFilterStrategy strategy = setupHeaderStrategy(camelExchange);
Message cxfMessage = new MessageImpl();
CxfHeaderHelper.propagateCamelToCxf(strategy,
Collections.<String, Object>singletonMap("Content-Type", "text/xml"), cxfMessage, camelExchange);
Map<String, List<String>> cxfHeaders = CastUtils.cast((Map<?, ?>)cxfMessage.get(Message.PROTOCOL_HEADERS));
assertEquals(1, cxfHeaders.size());
assertEquals(1, cxfHeaders.get("Content-Type").size());
assertEquals("text/xml", cxfHeaders.get("Content-Type").get(0));
assertEquals("text/xml", cxfMessage.get(Message.CONTENT_TYPE));
}
示例9: process
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
public void process(Exchange exchange) throws Exception {
List<SoapHeader> soapHeaders = CastUtils.cast((List<?>)exchange.getIn().getHeader(Header.HEADER_LIST));
// Insert a new header
String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><outofbandHeader "
+ "xmlns=\"http://cxf.apache.org/outofband/Header\" hdrAttribute=\"testHdrAttribute\" "
+ "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" soap:mustUnderstand=\"1\">"
+ "<name>New_testOobHeader</name><value>New_testOobHeaderValue</value></outofbandHeader>";
SoapHeader newHeader = new SoapHeader(soapHeaders.get(0).getName(),
StaxUtils.read(new StringReader(xml)).getDocumentElement());
// make sure direction is IN since it is a request message.
newHeader.setDirection(Direction.DIRECTION_IN);
//newHeader.setMustUnderstand(false);
soapHeaders.add(newHeader);
}
示例10: handleMessage
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
@Override
public void handleMessage(Message message) throws Fault
{
if (par == null) {
throw new IllegalStateException();
}
Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
if (protocolHeaders != null)
{
List<String> contentEncoding = HttpHeaderHelper.getHeader(protocolHeaders,
HttpHeaderHelper.CONTENT_ENCODING);
if (contentEncoding != null && (contentEncoding.contains("gzip") || contentEncoding.contains("x-gzip")))
{
super.handleMessage(message);
return;
}
}
throw new RuntimeException("Content-Encoding gzip not found!");
}
示例11: handleMessage
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
@Override
public void handleMessage(Message message) throws Fault
{
Map<String, List<String>> protocolHeaders = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
if (protocolHeaders != null)
{
List<String> contentEncoding = HttpHeaderHelper.getHeader(protocolHeaders,
HttpHeaderHelper.CONTENT_ENCODING);
if (contentEncoding != null && (contentEncoding.contains("gzip") || contentEncoding.contains("x-gzip")))
{
super.handleMessage(message);
return;
}
}
throw new RuntimeException("Content-Encoding gzip not found!");
}
示例12: writeStartElementEvent
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
private static void writeStartElementEvent(XMLEvent event, XMLStreamWriter writer)
throws XMLStreamException {
StartElement start = event.asStartElement();
QName name = start.getName();
String nsURI = name.getNamespaceURI();
String localName = name.getLocalPart();
String prefix = name.getPrefix();
if (prefix != null) {
writer.writeStartElement(prefix, localName, nsURI);
} else if (nsURI != null) {
writer.writeStartElement(localName, nsURI);
} else {
writer.writeStartElement(localName);
}
Iterator<XMLEvent> it = CastUtils.cast(start.getNamespaces());
while (it != null && it.hasNext()) {
writeEvent(it.next(), writer);
}
it = CastUtils.cast(start.getAttributes());
while (it != null && it.hasNext()) {
writeAttributeEvent(it.next(), writer);
}
}
示例13: createSet
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
private static Object createSet(MessagePartInfo part, List<Object> ret) {
Type genericType = (Type)part.getProperty("generic.type");
Class tp2 = (Class)((ParameterizedType)genericType).getRawType();
if (tp2.isInterface()) {
return new HashSet<Object>(ret);
}
Collection<Object> c;
try {
c = CastUtils.cast((Collection<?>)tp2.newInstance());
} catch (Exception e) {
c = new HashSet<Object>();
}
c.addAll(ret);
return c;
}
示例14: createList
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
private static List<Object> createList(Type genericType) {
if (genericType instanceof ParameterizedType) {
Type tp2 = ((ParameterizedType)genericType).getRawType();
if (tp2 instanceof Class) {
Class<?> cls = (Class)tp2;
if (!cls.isInterface() && List.class.isAssignableFrom((Class<?>)cls)) {
try {
return CastUtils.cast((List)cls.newInstance());
} catch (Exception e) {
// ignore, just return an ArrayList
}
}
}
}
return new ArrayList<Object>();
}
示例15: handleMessage
import org.apache.cxf.helpers.CastUtils; //导入方法依赖的package包/类
@Override
public void handleMessage(SoapMessage message) throws Fault
{
String mappedNamespace = message.getExchange().getService().getName().getNamespaceURI();
InputStream in = message.getContent(InputStream.class);
if( in != null )
{
// ripped from StaxInInterceptor
String contentType = (String) message.get(Message.CONTENT_TYPE);
if( contentType == null )
{
// if contentType is null, this is likely a an empty
// post/put/delete/similar, lets see if it's
// detectable at all
Map<String, List<String>> m = CastUtils.cast((Map<?, ?>) message.get(Message.PROTOCOL_HEADERS));
if( m != null )
{
List<String> contentLen = HttpHeaderHelper.getHeader(m, HttpHeaderHelper.CONTENT_LENGTH);
List<String> contentTE = HttpHeaderHelper.getHeader(m, HttpHeaderHelper.CONTENT_TRANSFER_ENCODING);
if( (StringUtils.isEmpty(contentLen) || "0".equals(contentLen.get(0)))
&& StringUtils.isEmpty(contentTE) )
{
return;
}
}
}
// Inject our LegacyPythonHack
XMLStreamReader reader = StaxUtils.createXMLStreamReader(in);
message.setContent(XMLStreamReader.class, new LegacyPythonClientXMLStreamReader(reader, mappedNamespace));
}
}