Menu
  • HOME
  • TAGS

“Traditional” threads cannot lookup JNDI names in WildFly

Tag: java-ee,jndi,wildfly,java-ee-7,managedthreadfactory

I'm migrating an old application (uses no beans or dependency injection) from Weblogic to WildFly. For the most part, it now works fine. However, it also creates threads in "traditional way" (new Thread()), and these threads cannot lookup JNDI names, meaning database and mailing is not available to them.

It seems that I need to use a managed thread factory to create the threads instead. This way, new threads should be able to still see JNDI names defined in the container. However, I'm not sure how to retrieve such a factory from the container. All examples I could find use dependency injection and the application is written without that at all.

So, how do I access JNDI names from self-created threads? Or, how do I retrieve a managed thread factory I can use to create threads that still see the container and its JNDI bindings?

Best How To :

The standard managed thread factory is available in JNDI using the name java:comp/DefaultManagedThreadFactory.

See §EE.5.21 of the Java EE 7 spec for more information.

What's the difference beetwen EntityManager and DAO? [closed]

java,java-ee,dao,entitymanager

EntityManager is an interface provided by JPA, which provides generic methods used to persist, merge, find and create queries for entities. DAO is a pattern used to isolate database-access code in a separate component (the DAO) so that services concentrate on the business logic rather than low-level database stuff. It...

How to Close HikariCP JNDI DataSource on Shutdown/Redeploy

java,spring,jetty,jndi,hikaricp

I can't find where the 2.3.3 code lines up with the HikariDataSource.java:177 line number above. One suggestion is upgrading to the latest HikariCP version, 2.3.8. While your code looks correct, I suspect that you are running into a classloader issue, whereby the HikariDataSource (class) loaded by Jetty/Spring classloader and registered...

JNDI SPI provider for LDAP (Apache DS)

java,ldap,jndi

The service provider is LDAP --> apacheds-2.0.0-M20 (directory service). No. The service provider is the JNDI LDAP SPI. The LDAP server is ApacheDS. env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory"); Does this tell to use "com.sun.jndi.ldap.LdapCtxFactory" as the LDAP SPI service API? Yes. If this is correct, then isn't LDAP SPI service supposed to be...

How to trigger a doGet before displaying a jsp page

jsp,java-ee,web.xml

You cannot do that, at least without Javascript. A ServletResponse can do only one thing : either return csv data, or return an HTML page. You absolutely need 2 different requests (be them simple normal requests or javascript one) : first to download a csv file, second to display the...

JAX-RS Custom JSON representation of primitive Resource return type

java,java-ee,jax-rs

Not sure if it's a good idea. Would be much better if you'll create new JAX-RS resource and designated entity-class to response with. Still, if you want to mix marshalling with model, you could write your own MessageBodyWriter. For example: @Produces("application/json") public class IntWriter implements MessageBodyWriter<Integer> { @Override public boolean...

Setting response header using interceptor?

java,java-ee,jax-rs,resteasy,interceptor

With JaxRS 2 (which comes with javaEE 7) you can use a ContainerResponseFilter see also public class PoweredByResponseFilter implements ContainerResponseFilter { @Inject HttpServletRequest request; @Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { String name = "X-My-Header"; String value = "";// some data from request responseContext.getHeaders().add(name, value); } }...

Java project, include frontend library(Polymer)

javascript,java-ee,dependencies,frontend

I prefer to put the code under version control for these reasons: It makes bootstrapping (compiling the first time) much easier It doesn't cost much You can track changes between versions You can make your own changes against polymer components and merge then with newer releases The last two are...

Hibernate criteria accepting %% value

java,hibernate,java-ee,orm,hibernate-criteria

Hibernate does not escape special chars in like (e.g. the percentage % sign). But there are descriptions how to solve it (escape it): Escaping special characters in Hibernate queries Using hibernate criteria, is there a way to escape special characters? Escape special characters in hibernate criteria In general we could...

Debugging service test client: Netbeans debugger won't recognize Glassfish server

java,debugging,java-ee,netbeans,glassfish

Additional information relevant to the problem is that I was trying to get a test client working for the service. The problem turned out to be that I was simply adding another java class to the service package. The solution is: Create a new project. Add a new Web Service...

Does JBoss 7.x Support J2EE 5.0 and EJB 2.0?

java,java-ee,jboss,jboss7.x,ejb-2.x

UPDATED 6 jun 2015 I am migrating from jboss 4 to 7 and yes EJB 2 is supported. Please note that class loading and JNDI names conventions have changed and you probably have to change the definition of your JNDI names and the corresponding code doing the lookup: In AS7...

How to share the same email session between all instances of the application?

java,session,java-ee,javamail

The way that the Java EE designers intended you to do this is that you configure your javax.mail.Session object in your server. This is described in the Tomcat 7 JavaMail Sessions documentation. Your managed beans should then be able to access the session via @Resource: class MyManagedBean { @Resource(name="mail/Session") //...

filter mapping to last path segment

java,java-ee,web.xml,servlet-filters,servlet-mapping

From the servlet 3.1 specification chapter 12: In the Web application deployment descriptor , the following syntax is used to define mappings: A string beginning with a / character and ending with a /* suffix is used for path mapping. A string beginning with a *. prefix is used as...

Vaadin - How to have two columns of data (Gridlayout with field and Label data with wrapping text)

java,java-ee,vaadin,vaadin7

The answer was a combination of things. First the biggest tip I can offer is to look at Consume available space in Vaadin Gridlayout, but consider line breaks After that the code above was using setCaption() when it should've been using setValue(). Combining these two things resolved the issue and...

Persistent authentication filter logging in; not propagating to JSP

jsp,java-ee,jstl,struts,servlet-filters

As it turns out, the filter that I've set up for persistent authentication appears to only run when a Struts action is invoked; as such, it wasn't running on the index page of my site (among other pages), but in my case was instead authenticating when an AJAX call to...

How to call MySQL view in Struts2 or Hibernate

java,mysql,hibernate,java-ee,struts2

You can simply create an Entity, that's mapping the database view: @Entity public class CustInfo { private String custMobile; private String profession; private String companyName; private Double annualIncome; } Make sure you include an @Id in your view as well, if that's an updatable view. Then you can simply use...

Simple JavaEE HTML GET/POST application

java,java-ee,intellij-idea,glassfish,jax-rs

You need to configure Jersey (the JAX-RS implementation in Glassfish) in your web.xml. You currently only have JSF configuration <servlet> <servlet-name>jersey-serlvet</servlet-name> <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> <init-param> <param-name>jersey.config.server.provider.packages</param-name> <param-value>the.package.where.your.resources.are</param-value> </init-param>...

EJB injection not working in different classes

java-ee,netbeans,jersey,ejb,jax-rs

You're creating an ActivityManager yourself, using new ActivityManager(). So the basic rules of Java apply: the constructor is called, and since it doesn't affect any value to activityfacade, this field is set to null. For dependency injection to happen, you can't create the objects yourself, but get them from the...

Spring MVC Validation error

java,spring,spring-mvc,java-ee

We need more details on what you want to happen when this occurs. You could tell Spring how to convert that String into an instance of States by using a Converter (see this page for details).

weblogic 12c basic authentication not prompting for userid

java,java-ee,servlets,weblogic,weblogic12c

It turned out to be a deployment issue from my side.. The configuration in my original post was just fine. thanks to those that responded to my question!!

Comparing if two list of strings are equal using hashcode?

java,java-ee,collections,jax-rs

Is this approach correct? The approach is correct, but the proposed implementation is not (IMO). I assume that "summing with 31" means something like this int hash = 0; for (String name : names) hash = hash * 31 + name.hashCode(); Java hashcode values are 32 bit quantities. If...

Wildfly Kafka clients module javax/management/JMException not found

java-ee,jboss,wildfly,kafka

I think you need an additional dependency: <dependencies> <module name="javax.api"/> ... </dependencies> ...

HTTP GET request get HTML page code instead of expected json Response

java,java-ee

You need to set Accept header. urlc.addRequestProperty("Accept","application/json"); Update Your server may not support application/json datatype. You can check it by curl. curl -X POST -H "Accept: application/json" --data 'api_key=q5EicSKs027cjut7qhZk&method' http://www.server.com/api/v1 ...

How to time out long-running web requests on WebSphere Application Server? [duplicate]

java-ee

There is no way to (safely) forcibly stop or "timeout" a running thread in any JVM, regardless of whether the JVM is an application server like WebSphere. This is particularly true for threads that are stuck in pure "computation" (if the thread eventually hits an interruption point then Thread.interrupt might...

@InterceptorBinding / CDI/ EJB 3.2 - problems with injection

java,java-ee,cdi,wildfly-8,java-ee-7

One of your error messages is described in the CDI spec: An interceptor for lifecycle callbacks may only declare interceptor binding types that are defined as @Target(TYPE). If an interceptor for lifecycle callbacks declares an interceptor binding type that is defined @Target({TYPE, METHOD}), the container automatically detects the problem and...

What are the techniques to manage “session” or invocation context for Stateless EJBs during Remote calls?

session,java-ee,ejb,rmi,java-ee-6

Easiest way would be to store the user in a @RequestScoped CDI bean and inject that as required: @RequestScoped public class RequestUser { private User user; //getter and setter for user } @Remote @Statless public class MyRemoteInterface { @Inject private RequestUser requestUser; ... public void foo(User user, Bar bar) {...

Which Should i use for date,time,email in servlet?

java,html5,java-ee,servlets

Servlet api does not provide any special way of getting date and email. getParameter will always get you a String value. It is up to you how you want to treat it. For date you can work with raw String data or you may want ot parse it in to...

How exactly are the root context and the dispatcher servlet context into a Spring MVC web application?

java,spring,spring-mvc,java-ee,servlets

Root Context The root-context in a Spring application is the ApplicationContext that is loaded by the ContextLoaderListener. This context should have globally available resources like services, repositories, infrastructure beans (DataSource, EntityManagerFactorys etc.) etc. The ContextLoaderListener registers this context in the ServletContext under the name org.springframework.web.context.WebApplicationContext.ROOT. If you load an ApplicationContext...

Exception in using appclient jar in EJB 3 :javax.ejb.EJBException: java.rmi.MarshalException:

java,java-ee,glassfish,ejb-3.0

it looks like your entity class is not serialize, implement Serializable interface in your Book class @Entity @NamedQuery(name = "findAllBooks", query = "select b from Book b") public class Book implements Serializable { @Id @GeneratedValue private long id; ... } hope it will help....

Spring-boot+JPA EntityManager inject fails

spring,java-ee,jpa,spring-boot,cdi

You should use the dependency for spring-boot-starter-data-jpa <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> And to use a persistence xml you should define a bean as it says in the documentation. Spring doesn’t require the use of XML to configure the JPA provider, and Spring Boot assumes you want to take advantage of...

Maven GroupID and ArtifactID for J2EE Utility Project

java,eclipse,maven,java-ee,naming-conventions

You can configure pretty much anything in maven from file structure to project special configuration. But If it's not absolutly necessery you should stick with maven defaults. You can start with that project template: javaee-essentials-pom For the project namings: GroupID: com.foo ArtifactID: idmu-utils, idmu-war, idmu-ear package: jar, war, ear With...

How to find servlet API version for glassfish server?

java,java-ee,servlets,glassfish

Look at Java EE version. Servlet (and JSP, JSF, EJB, JPA, etc) version goes hand in hand with Java EE version. Java EE 8 = Servlet 4.0 Java EE 7 = Servlet 3.1 Java EE 6 = Servlet 3.0 Java EE 5 = Servlet 2.5 J2EE 1.4 = Servlet 2.4...

Why paging query does not work

java,jsp,java-ee,servlets,jdbc

when you Click Page connection,Num is null

I cannot instantiate my bean using @Inject and Vaadin CDI

java-ee,vaadin,cdi,vaadin7

In the constructor class variables are not yet injected. The bean will be injected after initialising, so it is null in the constructor. You have 2 possibilities. Inject the bean in the Constructor. Use the bean in an init method annotated with @PostConstruct I'd recommend the second approach. Here you...

withSchedule(ScheduleBuilder) in the type TriggerBuilder is not applicable for arguments (MutableTrigger)

java,java-ee,quartz-scheduler

There is no need to do it .build(). Try without it. public static Trigger buildTriggerForJob(int hours, int minutes, int seconds, String name, String groupName) { return org.quartz.TriggerBuilder .newTrigger() .withIdentity(name, groupName) .withSchedule( SimpleScheduleBuilder.simpleSchedule().withIntervalInHours(hours).withIntervalInMinutes(minutes) .withIntervalInSeconds(seconds).repeatForever()).build(); } ...

Java Servlet - get parameters with same name

java,java-ee,servlets,post

Close. It's String[] lines = request.getParameterValues("line"); but the name is line, not line[]...

Unable to get a EJB business object

java-ee,ejb-2.x

javax.ejb.SessionContext.getBusinessObject() is an EJB 3.0 method. I've used javax.ejb.SessionContext.getEJBLocalObject() to do what you're trying to do successfully in the (distant) past. You will need to cast it to your business interface though....

[Ljava.lang.Object; cannot be cast to List from a request SQL

java,jsp,java-ee

The error and the line it's occurring on mean that your Query is returning a List<Object[]> - the line that's throwing the error is the first place you actually try and use a value from the List which you downcast. You're getting an array from your query because your SELECT...

Adding a datasource to wildfly via web console

java,mysql,jndi,wildfly

Okay, now I feel retarded.. I simply had to reload the server configuration. I though it would be enough to just add the resource and you are ready to go! On a single page deep inside Wildfly it said it has to reload the configuration. So I did and now...

Client-Server architecture: 100% Android (Android as a server) or J2EE+Android?

android,java-ee,architecture,client-server,distributed-computing

Q: Which of the following solutions [ 1) 2) 3) ] is the best practice? A: price-wise / time-wise / performance-wise the 1) but scaleability-wise may get into issues once moving from 1:15 answers summary per day to some 1:1.000.000 or 1:10.000.000 range. ZeroMQ would be my option of a...

liferay portlet non-liferay JNDI data source null

oracle,tomcat7,jndi,liferay-6,portlet

I just stumbled over this thread in the Liferay Forum which basically says. oput this in your tomcat/conf/server.xml <GlobalNamingResources> <!-- Editable user database that can also be used by UserDatabaseRealm to authenticate users --> <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase"/> <Resource name="jdbc/XXX"...

Websocket (java ee) how to get role of current user

security,java-ee,websocket,wildfly

For this you will have to modify the Websocket handshake. You can do this as below: 1) Modify you websocket endpoint to use custom configurator @ServerEndpoint(value = "/someWSEndpoint", configurator = SomeCustomConfigurationClass.class) public class SomeWSService { ... } 2) Modify WS Handshake similar to public class SomeCustomConfigurationClass extends ServerEndpointConfig.Configurator { @Override...

Use jstl core as a local resource

java-ee,jstl,libraries,taglib

Nevermind, I have resolved my problem. People coming from outside can load the libraries. Only people from the server (so, no one) can't. ...

JAX-RS @FormParam one time for all methods

java,web-services,java-ee,jax-rs,java-ee-6

This will filter the required parameters before processing. import javax.servlet.*; import javax.servlet.annotation.WebFilter; import java.io.IOException; @WebFilter(urlPatterns = {"/*"}, description = "Filters!") public class MyFilter implements Filter { private FilterConfig filterConfig; @Override public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; } @Override public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)...

Interpretation of an interface driven implementation of the observer pattern in Java

java,swing,java-ee,design-patterns,observer-pattern

Let's start with the "theoretical" background. First of all, one has to understand that the observer pattern; and also how "Java" is typically providing it "to you" has been around for "quite some time". There were subtle changes later on, but I think it is fair to say that we...

Persistence.xml overridden in Arquillian tests

java,java-ee,integration-testing,wildfly,jboss-arquillian

The problem might be that your using ShrinkWrap.createFromZipFile. From my experience with Arquillian it better to create a custom WAR/JAR for each test. The method which creates the deployment usually looks like this: @Deployment public static WebArchive createDeployment() { //Load dependencies from POM final PomEquippedResolveStage pom = Maven .resolver() .loadPomFromFile("pom.xml");...

Glassfish service throws an error

java-ee,netbeans,service,glassfish

So I have found the answer, I post it there in case someone does read this topic. I had to set another parameter to the glassfish conf, AS_JAVA, and give it the path to the JDK. I then got a 404 error. So I put my .war file in the...

Hibernate Lazy loading not work in OneToOne relation

hibernate,java-ee

What work for mi is Lazy one-to-one inverse relationships. I read about this here (it is also a good tutorial how to use it). I hope it will help some one as it helps me....

Difference between two types of a super class instantiation in Java [duplicate]

java,object,java-ee,instantiation,superclass

The difference is for example if you have any information about document only in the document class, like, say, price. By doing Book book = new Book(); you won't be able to get the price of the book, so doing Document book = new Book(); will give you additional information...

What to do when you want to create your first java web application?

java,java-ee,web-applications

There is no universal answer, it all depends on your needs. If you're already familiar with a Java IDE, you should probably stick with it, NetBeans sure will be sufficient for EE development. For servers you should look at one issue: If you need more than the web profile of...

References of objects in Java EE. Difference for remote and local interfaces?

java,java-ee,call-by-value

Java is always a call-by-value. Here is the example which will make things clear: class Operation{ int data=50; void change(int data){ data=data+100;//changes will be in the local variable only } public static void main(String args[]){ Operation op=new Operation(); System.out.println("before change "+op.data); op.change(500); System.out.println("after change "+op.data); } } Output:before change 50...