Skip to content

Commit 87b72c0

Browse files
committed
8_5_soap_exceptions
1 parent 7391f34 commit 87b72c0

File tree

20 files changed

+264
-69
lines changed

20 files changed

+264
-69
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ru.javaops.masterjava;
2+
3+
import lombok.AllArgsConstructor;
4+
import lombok.Getter;
5+
6+
@Getter
7+
@AllArgsConstructor
8+
public enum ExceptionType {
9+
SYSTEM("Системная ошибка"),
10+
DATA_BASE("Ошибка базы данных"),
11+
STATE("Неверное состояние приложения"),
12+
AUTHORIZATION("Ошибка авторизации"),
13+
CONFIGURATION("Ошибка конфигурирования"),
14+
ILLEGAL_ARGUMENT("Неверный аргумент"),
15+
BPM("Ошибка бизнес-процесса"),
16+
FILE("Ошибка при работе с файловой системой"),
17+
REPORTS("Ошибка в отчете"),
18+
EMAIL("Ошибка при отправке почты"),
19+
TEMPLATE("Ошибка в шаблонах"),
20+
ONE_C("Ошибка в системе 1C"),
21+
ATTACH("Ошибка вложенного файла"),
22+
LDAP("Ошибка соединения с LDAP"),
23+
SOAP("Ошибка веб-сервиса"),
24+
NETWORK("Сетевая Ошибка");
25+
26+
final private String descr;
27+
28+
@Override
29+
public String toString() {
30+
return name() + " (" + descr + ')';
31+
}
32+
}

config_templates/wsdl/common.xsd

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
3+
targetNamespace="http://common.javaops.ru/">
4+
5+
<xs:element name="webStateException" nillable="true" type="faultInfo"/>
6+
7+
<xs:complexType name="faultInfo">
8+
<xs:sequence>
9+
<xs:element name="type" type="exceptionType" minOccurs="0" maxOccurs="1"/>
10+
</xs:sequence>
11+
</xs:complexType>
12+
13+
<xs:simpleType name="exceptionType">
14+
<xs:restriction base="xs:string">
15+
<xs:enumeration value="SYSTEM"/>
16+
<xs:enumeration value="DATA_BASE"/>
17+
<xs:enumeration value="STATE"/>
18+
<xs:enumeration value="AUTHORIZATION"/>
19+
<xs:enumeration value="CONFIGURATION"/>
20+
<xs:enumeration value="ILLEGAL_ARGUMENT"/>
21+
<xs:enumeration value="BPM"/>
22+
<xs:enumeration value="FILE"/>
23+
<xs:enumeration value="REPORTS"/>
24+
<xs:enumeration value="EMAIL"/>
25+
<xs:enumeration value="TEMPLATE"/>
26+
<xs:enumeration value="ONE_C"/>
27+
<xs:enumeration value="ATTACH"/>
28+
<xs:enumeration value="LDAP"/>
29+
<xs:enumeration value="SOAP"/>
30+
<xs:enumeration value="NETWORK"/>
31+
</xs:restriction>
32+
</xs:simpleType>
33+
</xs:schema>

config_templates/wsdl/mailService.wsdl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
44
xmlns:tns="http://mail.javaops.ru/"
55
xmlns:xs="http://www.w3.org/2001/XMLSchema"
6+
xmlns:common="http://common.javaops.ru/"
67
xmlns="http://schemas.xmlsoap.org/wsdl/"
78
targetNamespace="http://mail.javaops.ru/"
89
name="MailServiceImplService">
910
<types>
1011
<xs:schema targetNamespace="http://mail.javaops.ru/">
12+
<xs:import namespace="http://common.javaops.ru/" schemaLocation="common.xsd"/>
13+
1114
<xs:element name="sendToGroup" type="tns:sendToGroup"/>
1215
<xs:element name="sendToGroupResponse" type="tns:sendToGroupResponse"/>
1316
<xs:element name="sendBulk" type="tns:sendBulk"/>
@@ -40,7 +43,6 @@
4043
<xs:complexType>
4144
<xs:sequence>
4245
<xs:element name="failed" type="tns:mailResult" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
43-
<xs:element name="failedCause" type="xs:string" minOccurs="0"/>
4446
<xs:element name="success" type="xs:int"/>
4547
</xs:sequence>
4648
</xs:complexType>
@@ -80,17 +82,25 @@
8082
<message name="sendBulkResponse">
8183
<part name="parameters" element="tns:sendBulkResponse"/>
8284
</message>
85+
<message name="WebStateException">
86+
<part name="fault" element="common:webStateException"/>
87+
</message>
88+
8389
<portType name="MailService">
8490
<operation name="sendToGroup">
8591
<input wsam:Action="http://mail.javaops.ru/MailService/sendToGroupRequest" message="tns:sendToGroup"/>
8692
<output wsam:Action="http://mail.javaops.ru/MailService/sendToGroupResponse"
8793
message="tns:sendToGroupResponse"/>
94+
<fault wsam:Action="http://mail.javaops.ru/MailService/sendBulkMail/Fault/WebStateException"
95+
message="tns:WebStateException" name="WebStateException" />
8896
</operation>
8997
<operation name="sendBulk">
9098
<input wsam:Action="http://mail.javaops.ru/MailService/sendBulkRequest"
9199
message="tns:sendBulk"/>
92100
<output wsam:Action="http://mail.javaops.ru/MailService/sendBulkResponse"
93101
message="tns:sendBulkResponse"/>
102+
<fault wsam:Action="http://mail.javaops.ru/MailService/sendBulkMail/Fault/WebStateException"
103+
message="tns:WebStateException" name="WebStateException" />
94104
</operation>
95105
</portType>
96106
<binding name="MailServiceImplPortBinding" type="tns:MailService">
@@ -103,6 +113,9 @@
103113
<output>
104114
<soap:body use="literal"/>
105115
</output>
116+
<fault name="WebStateException">
117+
<soap:fault name="WebStateException" use="literal"/>
118+
</fault>
106119
</operation>
107120
<operation name="sendBulk">
108121
<soap:operation soapAction=""/>
@@ -112,6 +125,9 @@
112125
<output>
113126
<soap:body use="literal"/>
114127
</output>
128+
<fault name="WebStateException">
129+
<soap:fault name="WebStateException" use="literal"/>
130+
</fault>
115131
</operation>
116132
</binding>
117133
<service name="MailServiceImplService">

services/common-ws/pom.xml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<parent>
8+
<groupId>ru.javaops</groupId>
9+
<artifactId>parent</artifactId>
10+
<relativePath>../../parent/pom.xml</relativePath>
11+
<version>1.0-SNAPSHOT</version>
12+
</parent>
13+
14+
<artifactId>common-ws</artifactId>
15+
<version>1.0-SNAPSHOT</version>
16+
<name>Common Web Services</name>
17+
18+
<dependencies>
19+
<dependency>
20+
<groupId>${project.groupId}</groupId>
21+
<artifactId>common</artifactId>
22+
<version>${project.version}</version>
23+
</dependency>
24+
25+
<dependency>
26+
<groupId>com.sun.xml.ws</groupId>
27+
<artifactId>jaxws-rt</artifactId>
28+
<version>2.3.0</version>
29+
<exclusions>
30+
<exclusion>
31+
<groupId>org.jvnet.mimepull</groupId>
32+
<artifactId>mimepull</artifactId>
33+
</exclusion>
34+
<exclusion>
35+
<groupId>javax.xml.bind</groupId>
36+
<artifactId>jaxb-api</artifactId>
37+
</exclusion>
38+
<exclusion>
39+
<groupId>javax.annotation</groupId>
40+
<artifactId>javax.annotation-api</artifactId>
41+
</exclusion>
42+
<exclusion>
43+
<groupId>org.jvnet.staxex</groupId>
44+
<artifactId>stax-ex</artifactId>
45+
</exclusion>
46+
<exclusion>
47+
<groupId>javax.xml.soap</groupId>
48+
<artifactId>javax.xml.soap-api</artifactId>
49+
</exclusion>
50+
</exclusions>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.jvnet.staxex</groupId>
54+
<artifactId>stax-ex</artifactId>
55+
<version>1.7.8</version>
56+
<exclusions>
57+
<exclusion>
58+
<groupId>javax.activation</groupId>
59+
<artifactId>activation</artifactId>
60+
</exclusion>
61+
</exclusions>
62+
</dependency>
63+
64+
<dependency>
65+
<groupId>javax.servlet</groupId>
66+
<artifactId>javax.servlet-api</artifactId>
67+
<version>3.1.0</version>
68+
<scope>provided</scope>
69+
</dependency>
70+
</dependencies>
71+
</project>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package ru.javaops.web;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
import lombok.NonNull;
6+
import lombok.RequiredArgsConstructor;
7+
import ru.javaops.masterjava.ExceptionType;
8+
9+
@Data
10+
@RequiredArgsConstructor
11+
@NoArgsConstructor
12+
public class FaultInfo {
13+
private @NonNull ExceptionType type;
14+
15+
@Override
16+
public String toString() {
17+
return type.toString();
18+
}
19+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package ru.javaops.web;
2+
3+
4+
import lombok.Getter;
5+
import ru.javaops.masterjava.ExceptionType;
6+
7+
import javax.xml.ws.WebFault;
8+
9+
@WebFault(name = "webStateException", targetNamespace = "http://common.javaops.ru/")
10+
@Getter
11+
public class WebStateException extends Exception {
12+
private FaultInfo faultInfo;
13+
14+
public WebStateException(String cause, FaultInfo faultInfo) {
15+
super(cause);
16+
this.faultInfo = faultInfo;
17+
}
18+
19+
public WebStateException(String cause, ExceptionType type) {
20+
this(cause, new FaultInfo(type));
21+
}
22+
23+
public WebStateException(Throwable cause, ExceptionType type) {
24+
super(cause);
25+
this.faultInfo = new FaultInfo(type);
26+
}
27+
28+
@Override
29+
public String toString() {
30+
return faultInfo.toString() + '\n' + super.toString();
31+
}
32+
}

common/src/main/java/ru/javaops/masterjava/web/WsClient.java renamed to services/common-ws/src/main/java/ru/javaops/web/WsClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
package ru.javaops.masterjava.web;
1+
package ru.javaops.web;
22

33
import com.typesafe.config.Config;
4+
import ru.javaops.masterjava.ExceptionType;
45
import ru.javaops.masterjava.config.Configs;
56

67
import javax.xml.namespace.QName;
@@ -37,4 +38,8 @@ public T getPort() {
3738
requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, endpointAddress);
3839
return port;
3940
}
41+
42+
public static WebStateException getWebStateException(Throwable t, ExceptionType type) {
43+
return (t instanceof WebStateException) ? (WebStateException) t : new WebStateException(t, type);
44+
}
4045
}

services/mail-api/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<directory>${masterjava.config}</directory>
2222
<includes>
2323
<include>wsdl/mailService.wsdl</include>
24+
<include>wsdl/common.xsd</include>
2425
</includes>
2526
</resource>
2627
</resources>
@@ -29,7 +30,7 @@
2930
<dependencies>
3031
<dependency>
3132
<groupId>${project.groupId}</groupId>
32-
<artifactId>common</artifactId>
33+
<artifactId>common-ws</artifactId>
3334
<version>${project.version}</version>
3435
</dependency>
3536
</dependencies>

services/mail-api/src/main/java/ru/javaops/masterjava/service/mail/GroupResult.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
public class GroupResult {
1313
private int success; // number of successfully sent email
1414
private List<MailResult> failed; // failed emails with causes
15-
private String failedCause; // global fail cause
1615

1716
@Override
1817
public String toString() {
1918
return "Success: " + success + '\n' +
20-
(failed == null ? "" : "Failed: " + failed.toString() + '\n') +
21-
(failedCause == null ? "" : "Failed cause: " + failedCause);
19+
(failed == null ? "" : "Failed: " + failed.toString());
2220
}
2321
}

services/mail-api/src/main/java/ru/javaops/masterjava/service/mail/MailResult.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ public boolean isOk() {
2020

2121
@Override
2222
public String toString() {
23-
return '\'' + email + "' result '" + result + '\'';
23+
return "'" + email + "' result: " + result;
2424
}
2525
}

0 commit comments

Comments
 (0)