Skip to content

Instantly share code, notes, and snippets.

@AdamBien
Last active June 6, 2016 13:55
Show Gist options
  • Save AdamBien/5e784dcdacf08e6bde0d7e207efb5ba5 to your computer and use it in GitHub Desktop.
Save AdamBien/5e784dcdacf08e6bde0d7e207efb5ba5 to your computer and use it in GitHub Desktop.
27thAirhacksQ&A.md
@jparanda
Copy link

Hi Adam, I have a question for you.

I'm implemented a interceptor class, but I need inject a EJB on Interceptor class, but when I use the ejb reference it is null. My code is:

public class BitacoraNumeracionGeograficaInterceptor {

@EJB(mappedName="BitacoraSolicitudesServices")
private IBitacoraSolicitudesServices bitacoraSolicitudesServices;

@AroundInvoke
public Object loggingActionSolicitud(InvocationContext ic) throws Exception{

SolicitudAsignacion solAsignacion=(SolicitudAsignacion)param[0];

bitacoraSolicitudesServices.saveBitacoraSolicitud(solAsignacion);
// some code
}

}

the EJB is bitacoraSolicitudesServices

@jparanda
Copy link

Hi Adam Finally I had to create two interfaces, @Local and @Remote for my EJB, from my Interceptor call the @Local EJB and from my Managed Bean call the @Remote, this because the interceptor is in the same .ear that my @ejb.

@stuartbrand
Copy link

stuartbrand commented May 18, 2016

Hi Adam

I hope this is a question suitable for your show, I'm using JAX-RS 2.0 with a boundary of @get @produces(MediaType.APPLICATION_XML)

I think the implementation of JSR 222 is broken in regards to XmlRootElement(name = "Something")

if you only have a single element then it works fine, however if you use a List/Collection then it ignores the name and uses a lower case of the class name.

@Entity
@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "Car")
public class Bike{
    private String CarName;
    @Id
    private long CarID;
}

Output

<bikes>
<Car>
<CarName/>
<CarID/>
</Car>
<Car>
<CarName/>
<CarID/>
</Car>
</bikes>

Notice the encapsulating tag is derived from the class name even when specifying xmlrootelement name. This happens if the list has more than one item.

Thanks

Stuart

@Michael-xxxx
Copy link

Michael-xxxx commented May 19, 2016

Hi Adam,

I have a question regarding headlands. It seems to me that there is a concurrency issue.

@Startup
@Singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class Initializer {
....
 public boolean createCache(String cacheName, CacheConfiguration configuration) {
 .....
 }
@PUT
public Response newCache(@PathParam("cacheName") @NotNull String cacheName, CacheConfiguration cacheConfiguration, @Context UriInfo info) {
        boolean created = initializer.createCache(cacheName, cacheConfiguration);
        if (!created) {
            return Response.ok().header("x-info", "Cache: " + cacheName + " already created").build();
        }
        return Response.created(info.getAbsolutePath()).build();
    }

Mutiple Threads could enter method newCache. Method newCache is calling method createCache and @ConcurrencyManagement(ConcurrencyManagementType.BEAN) allows mutiple threads in this method

Second: In this special case, one can replace
@singleton
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
with
@ApplicationScoped
is that true?

The advantage would be:
@ApplicationScoped is CDI and can be easily tested with Deltaspike CDITestRunner

Thanks,
Michael

@cwansart
Copy link

Hello Adam,

I hope this question fits here. ;-)

I encountered a known bug in the Glassfish server which makes it impossible to use JAXB to produce JSON. https://bugs.eclipse.org/bugs/show_bug.cgi?id=463169 There are some tutorials which involve customizing the manifest file of the moxy dependency. However, the bug should be fixed by now. Why does this still happen? Is there an easy work around. (So war I'm using Gson instead.)

The exception I'm getting is:

java.lang.ClassNotFoundException: javax.xml.parsers.ParserConfigurationException not found by org.eclipse.persistence.moxy [228]

Here is the source code I used: https://github.com/cwansart/PostJaxRsParams

Thanks!

@retepnemsi
Copy link

retepnemsi commented Jun 3, 2016

Hi Adam,

As suggested in your blog post BEANS WITH BOTH VIEWS (@Local AND @Remote) - AN ANTI PATTERN? I have a @Local interface that extends a @Remote interface and my session bean implements the local interface. An objection have been raised against this pattern, suggesting that calling a method defined in the remote interface through the local interface still occur the remote call penalty. Is this so, and how can I prove the opposite if not?

The suggested solution was to have a common interface for the methods that are shared loacal and remote and then extend both @Local and @Remote interfaces from the common one and the sessionbean impkements both local and remote.

I had a look at the generated code but both local and remote calls looks the same to me, I suppose the invokevirtual operation does some magic that I don't see.

Thanks for the show, the On demand workshops and hope to see you at JavaOne.

@Andy-Voigt
Copy link

Andy-Voigt commented Jun 5, 2016

Hello Adam,

i've written a property resolver. The resolver should read a application.properties file and produce the values. It works but only if i deploy the application twice. The file is never found if i simply deploy the application over the Web-Interface. My application server is the new Wildfly 10. Its seems that the file is only discovered the second time in the classpath. I can simply reproduced if i deploy the war over the ide and stop/start the server. Any ideas why this happens?

@Singleton
public class PropertyResolver {

    @Inject
    private Logger logger;

    private final String propertiesFileName = "application.properties";

    private Map<String, Object> properties = new HashMap<>();

    @PostConstruct
    private void init() {
        Properties p = new Properties();
        try {
            p.load(this.getClass().getClassLoader().getResourceAsStream(propertiesFileName));
        } catch (Exception e) {
            logger.log(Level.SEVERE,  "The file " + propertiesFileName + " could not be found in classpath. The exception wars:\n " + e);
        }
        properties.putAll((Map) p);
        properties.putAll(System.getenv());
    }

    @Lock(LockType.READ)
    public String getValue(String key) {
        Object value = properties.get(key);
        return (value != null) ? String.valueOf(value) : null;
    }
}
public class PropertyValueProducer {

    @Inject
    private PropertyResolver resolver;

    @Produces
    @Property
    public String getStringConfigValue(InjectionPoint ip) {
        String fqn = ip.getMember().getDeclaringClass().getName() + "." + ip.getMember().getName();
        String key = ip.getAnnotated().getAnnotation(Property.class).value();
        boolean isKeyDefined = !key.trim().isEmpty();
        boolean valueRequired = ip.getAnnotated().getAnnotation(Property.class).required();
        if (isKeyDefined) {
            return resolver.getValue(key);
        }

        String value = resolver.getValue(fqn);
        if (value == null) {
            key = ip.getMember().getName();
            value = resolver.getValue(key);
        }

        if (value == null && valueRequired) {
            throw new IllegalStateException("No value defined for field: " + fqn + " but field was marked as required.");
        }
        return value;
    }


    @Produces
    @Property
    public Integer getIntegerConfigValue(InjectionPoint ip) {
        String value = getStringConfigValue(ip);
        return (value != null) ? Integer.valueOf(value) : null;
    }

    @Produces
    @Property
    public Double getDoubleConfigValue(InjectionPoint ip) {
        String value = getStringConfigValue(ip);
        return (value != null) ? Double.valueOf(value) : null;
    }
}
@Qualifier
@Retention(RUNTIME)
@Target({ TYPE, METHOD, FIELD, PARAMETER })
public @interface Property {

    @Nonbinding
    String value() default "";

    @Nonbinding
    boolean required() default true;
}

@glitchcube
Copy link

Hi, Adam!

In a video you made in 2013, you explain how you structure a JavaEE project. https://www.youtube.com/watch?v=grJC6RFiB58 (Structuring Java EE 7 Applications) using the BCE(boundary, control, entity) pattern.

As I read in http://epf.eclipse.org/wikis/openuppt/openup_basic/guidances/concepts/entity_control_boundary_pattern,_uF-QYEAhEdq_UJTvM1DM2Q.html the boundary should only communicate with the control.

Can/Should the boundary communicate directly with the entity, as you are doing in this video?
public void savePost(String message) { pv.isValid(message); em.merge(new Post(message)); }

Added note: I just watch your video on Microservices and loved it. Keep up with the good work you are doing, Adam.

/Java EE enthusiast from Norway

@linfey
Copy link

linfey commented Jun 6, 2016

Hello Adam,
what are your thoughts on the Oracle Application Development Framework.
It's advertised as a Java EE Framework but speaking frankly I fail to see the Java EE part beside the fact you need a welogic server to run any ADF application.
Does ADF play a role in your projects?

@robertBrem
Copy link

Hy Adam

Your vimeo workshops are great!
Do you have plans to make more? For example: Java EE 7 Architectures?

Greets
Rob

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