2014-12-23 23 views
1

我想在下面的代碼中設置cxfEndpoint的receiveTimeout和連接超時..我有這麼多的彈簧dsl相關答案,但我特別使用駱駝dsl。如何爲cxfEndpoint設置receiveTimeout和連接超時

我想在下面的代碼中設置cxfEndpoint的receiveTimeout和連接超時..我有這麼多的春季dsl相關的答案,但我特別使用駱駝dsl。 我想在下面的代碼中設置cxfEndpoint的receiveTimeout和連接超時..我有這麼多的春季dsl相關的答案,但我特別使用駱駝dsl。 我想在下面的代碼中設置cxfEndpoint的receiveTimeout和連接超時..我有這麼多的春季dsl相關的答案,但我特別使用駱駝dsl。

void configure() throws Exception { 
    super.configure() 

    CamelContext context=getContext() 

    String version=context.resolvePropertyPlaceholders('{{'+ CommonConstants.VERSION_PROPERTY+ '}}') 
    String region=context.resolvePropertyPlaceholders('{{'+ CommonConstants.REGION_PROPERTY + '}}') 
    String getContextRoot=context.resolvePropertyPlaceholders('{{' + CommonConstants.CONTEXT_ROOT_PROPERTY + '}}') 
    boolean validateResponse=getContextRoot 

    //main route exposing a GET 
    rest("/$version/$region/") 
      .get("/$getContextRoot") 
      .produces('application/json')\ 
      .to('direct:validate') 

    from('direct:validate') 
      .routeId('validate') 
      .bean(ValidatorSubRouteHelper.class,'validate') 
      .to('direct:get-deviceIdentification') 

    from('direct:get-deviceIdentification') 
      .routeId('get-deviceIdentification') 
      //pre-processing closure 
      .process { 
       it.out.body = [ it.properties[MessageReferenceConstants.USER_AGENT_HEADER], new CallContext() ] 
       it.in.headers[CxfConstants.OPERATION_NAME] = context.resolvePropertyPlaceholders('{{'+MessageReferenceConstants.PROPERTY_OPERATION_NAME+'}}') 
       it.in.headers[Exchange.SOAP_ACTION] = context.resolvePropertyPlaceholders('{{'+MessageReferenceConstants.PROPERTY_SOAP_ACTION+'}}') 

       Map<String, Object> reqCtx = new HashMap<String, Object>(); 
       HTTPClientPolicy clientHttpPolicy = new HTTPClientPolicy(); 
       clientHttpPolicy.setReceiveTimeout(10000); 
       reqCtx.put(HTTPClientPolicy.class.getName(), clientHttpPolicy) 
       it.in.headers[Client.REQUEST_CONTEXT]=reqCtx 


      } 
      .to(getEndpointURL()) 
      //In case of SOAPFault from device, handling the exception in processSOAPResponse 
      .onException(SoapFault.class) 
      .bean(ProcessResponseExceptionHelper.class,"processSOAPResponse") 
      .end() 
      //post-processing closure 
      .process { 
       log.info("processing the response retrieved from device service") 
       MessageContentsList li = it.in.getBody(MessageContentsList.class) 
       DeviceFamily deviceFamily = (DeviceFamily) li.get(0) 
       log.debug('device type is '+deviceFamily.deviceType.value) 
       it.properties[MessageReferenceConstants.PROPERTY_RESPONSE_BODY] = deviceFamily.deviceType.value 
      }.to('direct:transform') 

    from('direct:transform') 
      .routeId('transform') 
      //transform closure 
      .process { 
       log.info("Entering the FilterTransformSubRoute(transform)") 
       Device device=new Device() 
       log.debug('device type '+it.properties[MessageReferenceConstants.PROPERTY_RESPONSE_BODY]) 
       device.familyName = it.properties[MessageReferenceConstants.PROPERTY_RESPONSE_BODY] 
       it.out.body=device 
      } 
      .choice() 
      .when(simple('{{validateResponse}}')) 
      .to('direct:validateResponse') 

    if(validateResponse) { 
     from('direct:validateResponse') 
       .bean(DataValidator.getInstance('device.json')) 
    } 

} 

/** 
* Constructs the endpoint url. 
* Formatting end point URL for device identification service call 
* @return the endpoint url 
*/ 
private String getEndpointURL() { 
    CamelContext context=getContext() 
    def serviceURL=context.resolvePropertyPlaceholders('{{'+MessageReferenceConstants.SERVICE_URL+'}}') 
    def wsdlURL=context.resolvePropertyPlaceholders('{{'+MessageReferenceConstants.WSDL_URL+'}}') 
    boolean isGZipEnable=CommonConstants.TRUE.equalsIgnoreCase(context.resolvePropertyPlaceholders('{{'+MessageReferenceConstants.GZIP_ENABLED+'}}')) 
    def serviceClass = context.resolvePropertyPlaceholders('{{'+MessageReferenceConstants.PROPERTY_SERVICE_CLASS+'}}') 
    def serviceName = context.resolvePropertyPlaceholders('{{'+MessageReferenceConstants.PROPERTY_SERVICE_NAME+'}}') 

    def url="cxf:$serviceURL?"+ 
      "wsdlURL=$wsdlURL"+ 
      "&serviceClass=$serviceClass"+ 
      "&serviceName=$serviceName" 

    if(isGZipEnable) { 
     url+= "&cxfEndpointConfigurer=#deviceIdentificationServiceCxfConfigurer" 
    } 

    log.debug("endpoint url is " + url) 

    url 


} 

回答

3

您已經找到了它的cxfEndpointConfigurer選項。 現在你只需要實現像這樣的配置器接口:

public static class MyCxfEndpointConfigurer implements CxfEndpointConfigurer { 

     @Override 
     public void configure(AbstractWSDLBasedEndpointFactory factoryBean) { 
      // Do nothing here 
     } 

     @Override 
     public void configureClient(Client client) { 
      // reset the timeout option to override the spring configuration one 
      HTTPConduit conduit = (HTTPConduit) client.getConduit(); 
      HTTPClientPolicy policy = new HTTPClientPolicy(); 
      // You can setup the timeout option here 
      policy.setReceiveTimeout(60000); 
      policy.setConnectionTimeout(30000); 
      conduit.setClient(policy); 

     } 

     @Override 
     public void configureServer(Server server) { 
      // Do nothing here 

     } 

    } 
相關問題