Веб-клиент Джерси с искрой дает объект, не сериализуемый (класс: org.glassfi sh .jersey.client.JerseyWebTarget) - PullRequest
0 голосов
/ 03 мая 2020

У меня есть клиент Джерси, записанный как:

@Named
public class ApiService implements Serializable {

@Inject
    @Named("deletemodelecidrelWebtarget")
    private WebTarget deletemodelecidrelWebtarget;

private void deleteEndpoint(jsonbody) throws Exception {
        String requestJson = null;
        String responseJson = null;

        try {
            requestJson = OBJECT_MAPPER.writeValueAsString(jsonbody);
        } catch (Exception e) {
            throw ExceptionBuilder.createParsingException("Error in parsing ");
        }

        Invocation invocation = deletemodelecidrelWebtarget
                .request(MediaType.APPLICATION_JSON)
                .build("DELETE",Entity.json(requestJson));

        Response response = invocation.invoke();

        if (response != null) {
            do something
        }
    }

У меня есть конфигурация для этого веб-клиента в конфигурации как:

@Configuration
public class ApiConfig implements Serializable {

    @Value("${pooling.read.timeout}")
    private Integer poolingReadTimeout;

    @Value("${pooling.connect.timeout}")
    private Integer poolingConnectTimeout;

    @Value("${pooling.max.total}")
    private Integer poolingMaxTotal;

    @Value("${pooling.default.maxPerRoute}")
    private Integer poolingDefaultMaxPerRoute;

    @Value("${cia.root.url}")
    private String ciaRootUrl;


    @Value("${cia.path.deletemodelecidrel}")
    private String deletemodelecidrel;

    @Bean(name = "deletemodelecidrelWebtarget")
    public WebTarget deletemodelecidrel() { return getDeleteWebTarget(deletemodelecidrel); }

    private WebTarget getDeleteWebTarget(String endpoint) {
        ClientConfig clientConfig = new ClientConfig();
        clientConfig.property(ClientProperties.READ_TIMEOUT, poolingReadTimeout);
        clientConfig.property(ClientProperties.CONNECT_TIMEOUT, poolingConnectTimeout);
        PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager();
        connectionManager.setMaxTotal(poolingMaxTotal);
        connectionManager.setDefaultMaxPerRoute(poolingDefaultMaxPerRoute);
        clientConfig.property(ApacheClientProperties.CONNECTION_MANAGER, connectionManager);
        clientConfig.connectorProvider(new ApacheConnectorProvider());
        clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
        Client client = ClientBuilder.newClient(clientConfig);
        String url = ciaRootUrl + endpoint;
        return client.target(url);
    }
}

У меня есть искра rdd как

@Autowired
private UpdateAccountFunction updateFunction;

SplitRDD.foreach(updateFunction);

Теперь класс компонента UpdateFunction автоматически подключил класс ApiService и вызывает клиент-джерси как:

@Component
public class UpdateFunction implements Serializable {
@Inject
    private ApiService apiService;

    apiService.deleteEndpoint()
}

Здесь искра ищет сериализуемый объект UpdateFunction. Так как UpdateFunction имеет автоподключенный объект Apiserver, ожидается, что Apiservice также будет сериализуемым, однако класс Apiservice имеет объект WebTarget, который не сериализуем. Как я могу сделать WebTarget of Jersey сериализуемым. Я получаю сообщение об ошибке:

object not serializable (class: org.glassfish.jersey.client.JerseyWebTarget, value: JerseyWebTarget { http://localhost:9092/deletemodelecidrel })

Можно ли сделать Джерси WebClient, чтобы сделать его сериализуемым объектом для использования с искрой?

...