У меня интересная проблема.
Когда я запускал сервер Glassfish, все работало нормально. Но я изменил некоторый код и опубликовал сервер, и я запускаю свой клиент (SistemGirisClientKullaniciDogrula
). Приложение выдает это исключение:
java.lang.ClassCastException: tr.com.app.Kullanici cannot be cast to tr.com.app.Kullanici.
Интересно, что после перезапуска сервера Glassfish приложение работает нормально.
Я использую restlet-spring-hibernate. И я также использую JAXB (org.restlet.ext.jaxb.jar) для преобразования XML в объекты Java. Мой сервер приложений Glassfish v3.0
деталь для конфигурации
- рестлет 2.0.5
- пружина 3.0.5
- Спящий режим 3.3.2
- Glassfish v3.0
клиентский класс (только для теста)
import java.io.IOException;
import org.restlet.Client;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.data.MediaType;
import org.restlet.data.Method;
import org.restlet.data.Protocol;
import org.restlet.ext.jaxb.JaxbRepresentation;
public class SistemGirisClientKullaniciDogrula {
public static void main(String[] Args) throws IOException {
String url = "http://localhost:8080/Project/sistemgirisws";
Client client = new Client(Protocol.HTTP);
Kullanici kullanici = new Kullanici();
kullanici.setKodu("1");
JaxbRepresentation<Kullanici> jaxbRepresentationSendingKullanici= new JaxbRepresentation<Kullanici>(MediaType.APPLICATION_XML, kullanici);
Request request = new Request(Method.GET, url, jaxbRepresentationSendingKullanici);
Response response = client.handle(request);
JaxbRepresentation<Kullanici> kullaniciResponse = new JaxbRepresentation<Kullanici>(response.getEntity(), Kullanici.class);
kullanici = kullaniciResponse.getObject();
System.out.println("kullanici id : " + kullanici.getId());
}
}
Веб-сервис
public class ProjectWebService {
/**
*
* @param representation
* @return
*/
@Get
public Representation getKullanici(Representation representation) {
JaxbRepresentation<Kullanici> jaxbRepresentation = new JaxbRepresentation<Kullanici>(representation, Kullanici.class);
Kullanici kullanici = new Kullanici();
try {
kullanici = jaxbRepresentation.getObject(); //THIS LINE THROW java.lang.classCastException tr.com.app.Kullanici cannot be cast to tr.com.app.Kullanici.
} catch (IOException e) {
e.printStackTrace();
}
try {
kullanici = sistemGirisBusinessManager.kullaniciDogrula(kullanici);
getResponse().setStatus(Status.SUCCESS_OK);
return new JaxbRepresentation<Kullanici>(MediaType.APPLICATION_XML, kullanici);
} catch (Exception exception) {
exception.printStackTrace();
getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
return new JaxbRepresentation<MesajList>(MediaType.APPLICATION_XML, sistemGirisBusinessManager.getMesajList());
}
}
}
Кто-нибудь знает, в чем проблема?