How to access a remote web service by Camel CXF endpoint

  • There was a litte infomation about camel proxy webservice with local
    wsdl or remot url in the side of GFW,even in the stackoverfllow.

  • So,i will answer the question of the title,also see the q in

http://stackoverflow.com/questions/29422493/how-to-access-a-remote-web-service-by-camel-cxf-endpoint

applicationContext.xml




    
    
    

    
    
    
    

    
            
    
    
     
          
              
                  
                  
                 
                 
              
          
      
     
     
         
             
                 
                 
                 
                 
             
         
        
        
    
    

       
       
     
               
    
        
            
            
        
        
             
        
    
    
    
      
                       
      
        com.lucky  
    

routConfig.properties

#server1
server1.address=http://localhost:9000/CXF_HELLO_ObjectSpringService/IHello
server1.wsdl=http://localhost:9000/CXF_HELLO_ObjectSpringService/IHello?wsdl
server1.endPointName=orderEndpoint

RouteLoad.java



public class RouteLoad extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        //Properties prop = new Properties();
        InputStream in = RouteLoad.class
                .getResourceAsStream("./../../routConfig.properties");
        PropertiesUtil prop = new PropertiesUtil(in);
        try {
            prop.load(in);
        } catch (IOException e) {
            e.printStackTrace();
        }
        
        String key = "";
        String old_key = "";
        String configName = "";
        RoutBean routBean = new RoutBean();
        List keyValue = prop.getKeyList();
        for (Iterator it = keyValue.iterator(); it.hasNext();) {
            key = (String) it.next();
            if (!"".equals(old_key)
                    && !key.substring(0, 7).equals(old_key.substring(0, 7))) {
                createCxfEndpoint(routBean.getAddress(),routBean.getWsdl(),routBean.getEndPointName());
            } 

            configName = key.split("\\.")[1];
            if ("address".equals(configName)) {
                routBean.setAddress((String) prop.get(key));
            } else if ("wsdl".equals(configName)) {
                routBean.setWsdl((String) prop.get(key));
            } else if ("endPointName".equals(configName)) {
                routBean.setEndPointName((String) prop.get(key));
            }

            if(!it.hasNext()){
                createCxfEndpoint(routBean.getAddress(),routBean.getWsdl(),routBean.getEndPointName());
            }
            old_key = key;
            
        }
    }

    public void createCxfEndpoint(String address,String wsdl,String endPointName) {
        Endpoint cxfEndpoint = endpoint("cxf:" + address // serviceAddress
                + "?" 
                +"wsdlURL="+ wsdl // wsdl
                + "&" + "dataFormat=MESSAGE" // dataformat type dataFormat=PAYLOAD
        ); 
        
        
        
            from("cxf:bean:" + endPointName + "?dataFormat=MESSAGE").to("log:loggingOutInterceptor")
            //.process(myProc)
            .to(cxfEndpoint).to("log:loggingOutInterceptor");
        
        //send multi service
        //from("activemq:queue:foo").multicast().to("seda:foo", "seda:bar");
        
//        from("cxf:bean:" + routBean.getEndPointName() + "?dataFormat=MESSAGE")
//        .to("log:input")
//        .process(new Processor(){
//            @Override
//            public void process(Exchange exchange) throws Exception {
//                addWSSESecurityHeader(exchange, "login","password");
//            }
//        })
//        .to(cxfEndpoint)
//        .to("log:output");
    }
} 
 

that all ,thanks for your coming!

你可能感兴趣的:(camel,spring,java,webservice)