I have a problem with my method @Produces.
(我的方法@Produces有问题。)
When I inject ResteasyWebTarget
target in my Api Request class, object target is null. (当我在Api Request类中注入ResteasyWebTarget
目标时,对象target为null。)
Can someone help me with this.
(有人可以帮我弄这个吗。)
CDI not working in my class... (CDI在我的课堂上不起作用...)
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({TYPE, METHOD, PARAMETER, FIELD})
public @interface ServiceProducer {
}
public class ServiceProducerImpl implements Serializable {
@Produces
@ServiceProducer
public ResteasyWebTarget getClient() {
String patApi = "http://localhost:5000";
try {
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target(UriBuilder.fromPath(patApi));
return target;
} catch (Exception ex) {
ex.printStackTrace();
return null;
}
}
}
@Path("/api-java")
public interface IServices {
@PUT
@Path("/put")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
Response putservice(ApiRequestModel api);
}
public class ApiRequest {
@Inject
@ServiceProducer
ResteasyWebTarget target;
public void rest() {
String patApi = "http://localhost:5000";
try {
IServices service = target.proxy(IServices.class);
ApiRequestModel api = new ApiRequestModel(11, "22", 0);
Response response = service.putservice(api);
ApiResponseModel apiResponse = response.readEntity(ApiResponseModel.class);
System.out.println("API-JAVA>> " + "CNPJ: " + apiResponse.getCnpj() + " ADQ: " + apiResponse.getAdq() + " BLOCKCODE: " + apiResponse.getBlockcode());
} catch (Exception ex) {
ex.printStackTrace();
}
}
ask by Luis Angel Carbonel Hidalgo translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…