1
- package eu .chargetime .ocpp ;/*
1
+ package eu .chargetime .ocpp ;
2
+
3
+ /*
2
4
ChargeTime.eu - Java-OCA-OCPP
3
5
4
6
MIT License
@@ -63,9 +65,9 @@ public <T> T unpackPayload(Object payload, Class<T> type) {
63
65
T output = null ;
64
66
try {
65
67
Document input = (Document ) payload ;
66
- input = setNamespace (input , "urn://Ocpp/Cs/2015/10/" );
68
+ setNamespace (input , "urn://Ocpp/Cs/2015/10/" );
67
69
Unmarshaller unmarshaller = JAXBContext .newInstance (type ).createUnmarshaller ();
68
- JAXBElement <T > jaxbElement = ( JAXBElement < T >) unmarshaller .unmarshal (input , type );
70
+ JAXBElement <T > jaxbElement = unmarshaller .unmarshal (input , type );
69
71
output = jaxbElement .getValue ();
70
72
} catch (JAXBException e ) {
71
73
logger .warn ("unpackPayload() failed" , e );
@@ -82,17 +84,14 @@ public Object packPayload(Object payload) {
82
84
factory .setNamespaceAware (false );
83
85
document = factory .newDocumentBuilder ().newDocument ();
84
86
marshaller .marshal (payload , document );
85
- document = setNamespace (document , hostInfo .getNamespace ());
86
- } catch (JAXBException e ) {
87
+ setNamespace (document , hostInfo .getNamespace ());
88
+ } catch (JAXBException | ParserConfigurationException e ) {
87
89
logger .warn ("packPayload() failed" , e );
88
- } catch (ParserConfigurationException e ) {
89
- logger .warn ("packPayload() failed" , e );
90
90
}
91
91
return document ;
92
92
}
93
93
94
- private Document setNamespace (Document document , String namespace ) {
95
- Document output = document ;
94
+ private void setNamespace (Document document , String namespace ) {
96
95
Element orgElement = document .getDocumentElement ();
97
96
Element newElement = document .createElementNS (namespace , orgElement .getNodeName ());
98
97
@@ -101,8 +100,7 @@ private Document setNamespace(Document document, String namespace) {
101
100
appendChildNS (document , newElement , childNodes .item (i ), namespace );
102
101
}
103
102
104
- output .replaceChild (newElement , orgElement );
105
- return output ;
103
+ document .replaceChild (newElement , orgElement );
106
104
}
107
105
108
106
private void appendChildNS (Document doc , Node destination , Node child , String namespace ) {
@@ -173,7 +171,7 @@ private Object createMessage(String uniqueId, String action, Document payload, b
173
171
createMessageHeader (uniqueId , action , isResponse , message );
174
172
175
173
if (isResponse ) {
176
- payload = setNamespace (payload , hostInfo .isClient () ? SOAPHostInfo .NAMESPACE_CHARGEBOX : SOAPHostInfo .NAMESPACE_CENTRALSYSTEM );
174
+ setNamespace (payload , hostInfo .isClient () ? SOAPHostInfo .NAMESPACE_CHARGEBOX : SOAPHostInfo .NAMESPACE_CENTRALSYSTEM );
177
175
}
178
176
179
177
message .getSOAPBody ().addDocument (payload );
@@ -260,7 +258,8 @@ public Message parseMessage() {
260
258
261
259
String relatesTo = getElementValue (HEADER_RELATESTO );
262
260
String action = getElementValue (HEADER_ACTION );
263
- if (relatesTo != null && !"" .equals (relatesTo ) && action .endsWith ("Response" )) {
261
+
262
+ if (relatesTo != null && !relatesTo .isEmpty () && action != null && action .endsWith ("Response" )) {
264
263
if (soapMessage .getSOAPBody ().hasFault ())
265
264
output = parseError ();
266
265
else
@@ -269,7 +268,7 @@ public Message parseMessage() {
269
268
output = parseCall ();
270
269
}
271
270
272
- if (action != null && !"" . equals ( action ))
271
+ if (action != null && !action . isEmpty ( ))
273
272
output .setAction (action .substring (1 ));
274
273
275
274
if (!soapMessage .getSOAPBody ().hasFault ())
@@ -302,7 +301,7 @@ private CallErrorMessage parseError() {
302
301
message .setErrorDescription (fault .getFaultReasonTexts ().next ().toString ());
303
302
304
303
} catch (SOAPException e ) {
305
- e . printStackTrace ( );
304
+ logger . error ( "Parse error" , e );
306
305
}
307
306
308
307
return message ;
0 commit comments