11 Mayıs 2015 Pazartesi

Getting RollbackException in Transactional Methods

Hi,

Here is the second problem i have to deal with, RollbackException.
As I search on Google, if you get exception in a transactional method, even if you catch it and not throw, the transaction is marked as rollback only and you cannot commit anything in this transaction.
This may be annoying if you get an ignorable exception, for example NoResultException.
For overcome this, you should take some precautions with Transactional annotation, like this,

@Transactional(rollbackFor=MyException.class, noRollbackFor=MyException2.class)
Specifying rollback and no-rollback situations is the best way to handle this.

Have a nice day!

Link: http://stackoverflow.com/questions/19302196/transaction-marked-as-rollback-only-how-do-i-find-the-cause


About JPA NoResultException

Hi,

Today I looked for NoResultException, wondered when it may occurs, found that,

If you search record with getSingleResult, NoResultException is thrown, because, as written at stackoverflow,

"If getSingleResult() would return null, you could not tell whether the query did not match any row or whether the query matched a row but the selected column contains null as its value"

Otherwise, if you search with query, the return object will be null(or if you cast result to List, it will be empty), so you should deal with null or empty list in this situation.

Link: http://stackoverflow.com/questions/1579560/why-in-jpa-entitymanager-queries-throw-noresultexception-but-find-does-not

Have a nice day !

31 Ekim 2014 Cuma

JaxWS Client Üretme Çakışma Hataları

Merhabalar,

Java webservis client üretirken birçok zaman client üretmek bir kabus haline dönüşebiliyor. Farklı webservis implementasyonları farklı sonuçlar üretebiliyor, örneğin bir wsdl için axis ile üretilen client çalışırken diğeri için wsimport ile üretilen client başarılı olabilmektedir. Burada alınabilecek birçok çeşit hata vardır, authentication hatası, collision hatası, constructor hatası vs. Bu hataların çözümü için elbette hatanın kök nedenini iyi analiz etmek gerekiyor, bunun için tecrübe ile ya da google ile sonuç alınabiliyor :)

Benim bahsedeceğim hatayı almamın sebebi, bir sebeple client sınıflarını tek paket altında toplama ihtiyacım ve bu pakette farklı object factory'de olması gereken sınıfların aynı object factory'de çakışma yaşamasıdır. Hatanın kısaca açıklaması şu şekilde,

Two declarations cause a collision in the ObjectFactory class.

Bunu çözmek için, çakışan sınıflardan en az bir tanesi için binding tanımlayarak bunun object factory'deki metod ismine müdahale ediyoruz, pom'da binding tanımlanışı ve binding dosyasındaki tanımlamalar aşağıdaki gibidir.

pom.xml
...
..
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<target>2.1</target>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/binding.xml</bindingFile>
</bindingFiles>
</configuration>
<phase>generate-sources</phase>
</execution>
</executions>
..
...

binding.xml

<?xml version="1.0" encoding="UTF-8"?>
<jaxb:bindings xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  version="1.0">

  <jaxb:bindings schemaLocation="https://dene.me.com/DenemeWS/DenemeService?xsd=3">
    <jaxb:bindings node="//xs:element[@name='Exception']">
      <jaxb:factoryMethod name="Exception2"/>
    </jaxb:bindings>
  </jaxb:bindings>
</jaxb:bindings>


Herkese iyi çalışmalar dilerim ;)

19 Ocak 2014 Pazar

JSF Log Interceptor

Selamlar,

JSF bean'lerinde loglama yapmak için, eğer sınıftaki tüm fonksiyonlar için yapılacaksa sınıfın üstüne, spesifik fonksiyon için ise bu fonksiyon üzerine kendi yazdığımız custom bir anotasyon konulur, örneğin,

@MyLog

anotasyonu konulur. Daha sonra Log işlemini yapacak sınıf yazılır.

@MyLog
@Interceptor
public class LogInterceptor implements Serializable{

@AroundInvoke
public Object log(InvocationContext ic) {
 
Object result = null;
System.out.println(ic.getMethod.getName());

try{
result = ic.proceed();
} catch(Exception e)
}
}

LogInterceptor class'ını CDI beans.xml'inde interceptor olarak tanıtmak gerekir.

JSF'de session'a parametre atama

Selamlar,

JSF'de session'a parametre atamak veya atanan parametreyi almak için, ServletRequest'i HttpServletRequest'e cast ederek setAttribute fonksiyonunu kullanabiliriz.


HttpServletRequest req = (HttpServletRequest) servletRequest;
req.getSession().setAttribute(String key, Object obj);

Örneğin WebListener olan sınıflarda kullanılabilir.

JSF page load fonksiyonu & HttpSessionListener

Selamlar,

ASP'deki gibi page_laod fonksiyonunu JSF'de kullanmakmisteyenler

@WebFilter(urlPatterns={/*})

anotasyonunu kullanabilirler. Anotasyonun kullanıldığı sınıf javax.servlet.Filter interface'ini implement etmelidir.

Aynı anotasyonla HttpSessionListener implement edilerek session olaylarına bağlı fonksiyonlar çalıştırılabilir, örneğin session kapatılırken yapılacak spesifik işlemler burada yapılabilir.


13 Ocak 2014 Pazartesi

Hayat Kurtaran Bilgiler Serisi - 5 - wsimport ile webservice client üretirken çakışmaları giderme

Merhabalar,

wsimport ile client üretirken bazen xsd'lerden kaynaklanan çakışmalar yaşanabilmektedir. Bunları önlemek için komuta aşağıdaki kısım eklenirse, çakışan sınıfları otomatik olarak farklı isimlendirecek, böylece hem wsimport komutu çalışırken, hem de client kodu weblogic'e deploy edilirken, alınacak hatalar önlenmektedir.

wsimport -keep -verbose -B-XautoNameResolution http://localhost:7001/myw/MyService?WSDL

Maven wsimport plugin kullanıyorsanız, aşağıdaki şekilde eklenebilir,

                                         <execution>
<id>execution</id>
<goals>
<goal>wsimport</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<args><arg>-B-XautoNameResolution</arg></args>
<wsdlUrls>
<wsdlUrl>${"WSDL_ADDRESS_HERE"}</wsdlUrl>
</wsdlUrls>
<packageName>MY_PACKAGE_NAME</packageName>
</configuration>
</execution>

Herkese iyi çalışmalar.