当前位置: 首页>>代码示例>>Java>>正文


Java CastUtils类代码示例

本文整理汇总了Java中org.apache.cxf.helpers.CastUtils的典型用法代码示例。如果您正苦于以下问题:Java CastUtils类的具体用法?Java CastUtils怎么用?Java CastUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CastUtils类属于org.apache.cxf.helpers包,在下文中一共展示了CastUtils类的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;
}
 
开发者ID:Huawei,项目名称:eSDK_EC_SDK_Java,代码行数:25,代码来源:Headers.java

示例2: mapElement

import org.apache.cxf.helpers.CastUtils; //导入依赖的package包/类
@Override
protected void mapElement(ParserContext ctx, BeanDefinitionBuilder bean, Element el, String name) {
    if ("properties".equals(name)) {
        Map<String, Object> map = CastUtils.cast(ctx.getDelegate().parseMapElement(el, bean.getBeanDefinition()));
        Map<String, Object> props = getPropertyMap(bean, false);
        if (props != null) {
            map.putAll(props);
        }
        bean.addPropertyValue("properties", map);
    } else if ("binding".equals(name)) {
        setFirstChildAsProperty(el, ctx, bean, "bindingConfig");
    } else if ("inInterceptors".equals(name) || "inFaultInterceptors".equals(name)
        || "outInterceptors".equals(name) || "outFaultInterceptors".equals(name)
        || "features".equals(name) || "schemaLocations".equals(name)
        || "handlers".equals(name)) {
        List<?> list = ctx.getDelegate().parseListElement(el, bean.getBeanDefinition());
        bean.addPropertyValue(name, list);
    } else {
        setFirstChildAsProperty(el, ctx, bean, name);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:CxfEndpointBeanDefinitionParser.java

示例3: testInvokingSimpleServerWithParams

import org.apache.cxf.helpers.CastUtils; //导入依赖的package包/类
@Test
public void testInvokingSimpleServerWithParams() throws Exception {
    Exchange exchange = sendSimpleMessage();

    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("We should get the response context here", "UTF-8", responseContext.get(org.apache.cxf.message.Message.ENCODING));
    assertEquals("reply body on Camel", "echo " + 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);
    
    // check if the header object is turned into String
    Object requestObject = out.getHeader("requestObject");
    assertTrue("We should get the right requestObject.", requestObject instanceof DefaultCxfBinding);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:21,代码来源:CxfProducerTest.java

示例4: 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);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:CxfProducerTest.java

示例5: 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); 
    
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:CxfRawMessageRouterTest.java

示例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);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:CxfMessageHeadersRelayTest.java

示例7: validateReturnedOutOfBandHeader

import org.apache.cxf.helpers.CastUtils; //导入依赖的package包/类
protected static void validateReturnedOutOfBandHeader(Map<String, Object> responseContext, boolean expect) {
    OutofBandHeader hdrToTest = null;
    List<Header> oobHdr = CastUtils.cast((List<?>)responseContext.get(Header.HEADER_LIST));
    if (!expect) {
        if (oobHdr == null || (oobHdr != null && oobHdr.size() == 0)) {
            return;
        }
        fail("Should have got *no* out-of-band headers, but some were found");
    }
    if (oobHdr == null) {
        fail("Should have got List of out-of-band headers");
    }

    assertTrue("HeaderHolder list expected to conain 1 object received " + oobHdr.size(),
               oobHdr.size() == 1);

    for (Header hdr1 : oobHdr) {
        if (hdr1.getObject() instanceof Node) {
            try {
                JAXBElement<?> job = (JAXBElement<?>)JAXBContext
                    .newInstance(org.apache.cxf.outofband.header.ObjectFactory.class)
                    .createUnmarshaller().unmarshal((Node)hdr1.getObject());
                hdrToTest = (OutofBandHeader)job.getValue();
            } catch (JAXBException ex) {
                ex.printStackTrace();
            }
        }
    }

    assertNotNull("out-of-band header should not be null", hdrToTest);
    assertTrue("Expected out-of-band Header name testOobReturnHeaderName recevied :"
               + hdrToTest.getName(), "testOobReturnHeaderName".equals(hdrToTest.getName()));
    assertTrue("Expected out-of-band Header value testOobReturnHeaderValue recevied :"
               + hdrToTest.getValue(), "testOobReturnHeaderValue".equals(hdrToTest.getValue()));
    assertTrue("Expected out-of-band Header attribute testReturnHdrAttribute recevied :"
               + hdrToTest.getHdrAttribute(), "testReturnHdrAttribute"
        .equals(hdrToTest.getHdrAttribute()));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:39,代码来源:CxfMessageHeadersRelayTest.java

示例8: 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);
    
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:CxfMessageHeadersRelayTest.java

示例9: 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();
            }
        }
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:HeaderTesterImpl.java

示例10: 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
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:25,代码来源:CxfProducerRouterTest.java

示例11: 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"));
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:27,代码来源:CxfHeaderHelperTest.java

示例12: 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));   
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:CxfHeaderHelperTest.java

示例13: 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!");
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:21,代码来源:GZIPEnforcingInInterceptor.java

示例14: 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!");
}
 
开发者ID:jbossws,项目名称:jbossws-cxf,代码行数:17,代码来源:GZIPEnforcingInInterceptor.java

示例15: 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);            
    }
}
 
开发者ID:beemsoft,项目名称:techytax-zk,代码行数:26,代码来源:StaxUtils.java


注:本文中的org.apache.cxf.helpers.CastUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。