Commit f5028386 by Patryk Czarnik

konfiguracja walidacji za pomocą jboss-ws

parent a7f35985
...@@ -21,10 +21,16 @@ ...@@ -21,10 +21,16 @@
<version>4.0.0</version> <version>4.0.0</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sun.xml.ws</groupId> <groupId>org.jboss.ws.cxf</groupId>
<artifactId>jaxws-rt</artifactId> <artifactId>jbossws-cxf-client</artifactId>
<version>4.0.1</version> <version>6.2.0.Final</version>
<scope>runtime</scope>
</dependency> </dependency>
<!-- <dependency>-->
<!-- <groupId>com.sun.xml.ws</groupId>-->
<!-- <artifactId>jaxws-rt</artifactId>-->
<!-- <version>4.0.1</version>-->
<!-- <scope>runtime</scope>-->
<!-- </dependency>-->
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file
...@@ -35,6 +35,8 @@ public class Klient1_Normalny { ...@@ -35,6 +35,8 @@ public class Klient1_Normalny {
System.out.println("Zarejetrowane 2"); System.out.println("Zarejetrowane 2");
} catch (SOAPFaultException e) { } catch (SOAPFaultException e) {
System.out.println("Serwer odrzucił zapytanie. " + e); System.out.println("Serwer odrzucił zapytanie. " + e);
System.out.println(e.getClass());
System.out.println("przyczyna: " + e.getCause());
} catch (Exception e) { } catch (Exception e) {
System.out.println("Inny błąd: " + e); System.out.println("Inny błąd: " + e);
} }
......
package usluga.klient;
import jakarta.xml.ws.BindingProvider;
import jakarta.xml.ws.soap.SOAPFaultException;
import usluga.generated.Osoba;
import usluga.generated.Usluga;
import usluga.generated.UslugaService;
public class Klient2_Walidacja {
public static void main(String[] args) {
UslugaService service = new UslugaService();
Usluga proxy = service.getUslugaPort();
((BindingProvider)proxy).getRequestContext().put("schema-validation-enabled", true);
// To włącza walidację wiadomości wychodzących i (na 90%) przychodzących
// w razie niespełniania wymagań operacja zarejestruj (lub inna metoda) wyrzuca wyjątek SOAPFaultException
// z odpowiednimi opisami i "cause"
Osoba ala = new Osoba();
ala.setImie("Ala");
ala.setNazwisko("Dodatnia");
ala.setNrButa(30);
System.out.println("Rejestruję 1");
try {
proxy.zarejestruj(ala);
System.out.println("Zarejetrowane 1");
} catch (SOAPFaultException e) {
System.out.println("Serwer odrzucił zapytanie. " + e);
} catch (Exception e) {
System.out.println("Inny błąd: " + e);
}
Osoba ola = new Osoba();
ola.setImie("Ala");
ola.setNazwisko("Dodatnia");
ola.setNrButa(-30);
System.out.println("Rejestruję 2");
try {
proxy.zarejestruj(ola);
System.out.println("Zarejetrowane 2");
} catch (SOAPFaultException e) {
System.out.println("Serwer odrzucił zapytanie. " + e);
System.out.println(e.getClass());
System.out.println("przyczyna: " + e.getCause());
} catch (Exception e) {
System.out.println("Inny błąd: " + e);
}
System.out.println("Gotowe");
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment