Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
102ndAirhacksQ&A.md

Ask questions and see you at September, 5, 8.PM. CET: youtube.com/c/bienadam

Also checkout recent episode:

101 airhacks.tv

Please keep the questions Jakarta EE-stic. Means: as short and as concise as only possible. Feel free to ask several, shorter questions. Upcoming airhacks.tv events are also going to be announced at meetup.com/airhacks

@AdamBien
Copy link
Author

AdamBien commented Aug 12, 2022

airhacks.tv time machine. The questions 100 shows ago, or from the 2nd airhacks.tv: https://www.adam-bien.com/roller/abien/entry/2nd_airhacks_q_a_and

@orlovskyjavaprofi
Copy link

orlovskyjavaprofi commented Aug 12, 2022

Hi Adam, so time fly very fast i would like to hear adaptation story's of Jakarta EE in production, what currently the challenge?
There a lot of JEE 6/7 legacy projects, even ADF is still alive and kicking , so what you do in typical legacy project, what is a "roadmap" for Jakarta EE upgrade?

@thiagoslino
Copy link

thiagoslino commented Aug 12, 2022

Hi Adam. I've been whatching all airhacks videos - currently episode 30. Two questions about your timeline:
1 - No more NetBeans. Why? :(
2 - No more Jakartaee only dependence (now i see microprofile, surefire, modules...). Dont you recommend Jakartaee only project anymore?

@AdamBien
Copy link
Author

AdamBien commented Aug 25, 2022

The airhacks.tv time machine. Topics and questions from 100 episodes ago: https://adambien.blog/roller/abien/entry/2nd_airhacks_q_a_and

@littlewing88
Copy link

littlewing88 commented Aug 30, 2022

Hi Adam,
I've written some custom javax.validation annotations to automatically produce http 400 Bad Request responses in my jax-rs applications. For example:

@Constraint(validatedBy = DatePatternValidator.class)
@Documented
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.PARAMETER, ElementType.FIELD })
public @interface Date {
	String message() default "{com.mycompany.validation.Date.message}";
	Class<?>[] groups() default {};
	Class<?>[] payload() default {};
}

public class DatePatternValidator implements ConstraintValidator<Date, String> {

	@Override
	public void initialize(Date constraintAnnotation) {
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (value == null)
			return true;

		try {
			new SimpleDateFormat("yyyy-MM-dd").parse(value);
			return true;
		} catch (ParseException e) {
			// not a valid date
		}
		return false;
	}
}

Now I'm trying to pack these annotations in a jar and make it available as a dependency, but I can't get my head around the ValidationProvider with Configuration bootstrap mechanism.

Here's my effort: I've included within the jar a file named javax.validation.spi.ValidationProvider in META-INF/services/ which provides the fully qualified name of an implementation that I made of ValidationProvider, also included in the jar:

public class DatePatternValidationProvider implements ValidationProvider<DatePatternValidationConfiguration> {

	public DatePatternValidationProvider() {
		System.out.println("DatePatternValidationProvider constructor");
	}

	@Override
	public DatePatternValidationConfiguration createSpecializedConfiguration(BootstrapState state) {
		return DatePatternValidationConfiguration.class.cast(createGenericConfiguration(state));
	}

	@Override
	public Configuration<?> createGenericConfiguration(BootstrapState state) {
		return Validation.byDefaultProvider().configure();
	}

	@Override
	public ValidatorFactory buildValidatorFactory(ConfigurationState configurationState) {
		return Validation.buildDefaultValidatorFactory();
	}
}

public class DatePatternValidationConfiguration implements Configuration<DatePatternValidationConfiguration> {
	// not sure what should go here in the implementation
}

Using the jar as a dependency I can see the ValidationProvider that gets constructed - through the System.out - but then the validation is not triggered and no exception is raised either.

Can you help?
Thank you so much, love all your Q&A content and your blog!

@Abdelmuniem
Copy link

Abdelmuniem commented Aug 30, 2022

Hi Adam,

I am developing an app using quarkus when I insert java.timeYearMonth using jpa and hibernate, I use to receive an error deserialize JSON value into type: class java.time.YearMonth.

@Entity(name = "Book")
@Table(name = "book")
public class Book {

    @Id
    @GeneratedValue
    private Long id;

    @NaturalId
    private String isbn;

    private String title;

    @Column(name = "published_on", columnDefinition = "date")
    @Convert(converter = YearMonthDateAttributeConverter.class)
    private YearMonth publishedOn;

    // Getters and setters omitted for brevity
}

I want to insert only year and month, local date is working fine.

Your help is much appreciated as usual.

All the best,
Abdelmuniem

@paloliska
Copy link

paloliska commented Sep 2, 2022

Hi Adam,
I am trying quarkus-smallrye-fault-tolerance. I have service annotated with @transactional and @Retry with some parameters. I would like to have custom annotation @RetryableTransaction as following:

@Transactional
@Retry
public @interface RetryableTransaction {
}

However with this annotation on service method retry mechanism does not work. Do you know why? Is it part of microprofile specification?

@paloliska
Copy link

paloliska commented Sep 5, 2022

Hi Adam, one more question:
Did you ever used http 2 server push?
Is there any easy way to use it without any low level code?

@Endilicam
Copy link

Endilicam commented Sep 5, 2022

Hi Adam,

in the case of a GET call in a REST service with a parameter (query param) that contains multiple ids, if many ids are sent it can give a 414 error (Request-URI Too Large), searching the internet I have found 3 solutions, but none of them convinced me:

  1. Limit the number of ids sent.
  2. Make a POST and put the parameter in the BODY and return the information in this call.
  3. Make a POST, with an identifier of the call, put the parameter in the BODY and then make another GET call with the identifier where it returns the information.

What do you think, any other solution?

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment