【问题标题】:How to set receiveTimeout and connection timeout for cxfEndpoint如何为 cxfEndpoint 设置 receiveTimeout 和连接超时
【发布时间】:2014-12-23 09:07:12
【问题描述】:

我正在尝试在下面的代码中为 cxfEndpoint 设置接收超时和连接超时。我得到了很多与 spring dsl 相关的答案,但我专门使用骆驼 dsl。

我正在尝试在下面的代码中为 cxfEndpoint 设置接收超时和连接超时。我得到了很多与 spring dsl 相关的答案,但我专门使用骆驼 dsl。 我正在尝试在下面的代码中为 cxfEndpoint 设置接收超时和连接超时。我得到了很多与 spring dsl 相关的答案,但我专门使用骆驼 dsl。 我正在尝试在下面的代码中为 cxfEndpoint 设置接收超时和连接超时.. 我得到了很多与 spring 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


}

【问题讨论】:

    标签: cxf apache-camel


    【解决方案1】:

    您已经为它找到了 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
    
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-28
      • 2014-11-18
      • 2017-08-07
      • 1970-01-01
      • 1970-01-01
      • 2012-06-14
      • 2013-01-24
      • 1970-01-01
      相关资源
      最近更新 更多