Skip to content

Commit 2a49428

Browse files
author
srathod
committed
- fixing NPE for request_ctx and response_ctx contexts.
1 parent 541c1a8 commit 2a49428

File tree

2 files changed

+32
-28
lines changed

2 files changed

+32
-28
lines changed

src/main/java/net/authorize/util/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ public final class Constants {
3333
public static final String HTTP_READ_TIME_OUT = "http.ReadTimeout";
3434
public static final int HTTP_READ_TIME_OUT_DEFAULT_VALUE = 30000;
3535

36-
public static final String CLIENT_ID = "sdk-java-1.9.0";
36+
public static final String CLIENT_ID = "sdk-java-1.9.1";
3737
}

src/main/java/net/authorize/util/XmlUtility.java

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ public static synchronized <T extends Serializable> String getXml(T entity) thro
5959
request_ctx = jaxbContext.get(entity.getClass().toString());
6060
}
6161

62-
Marshaller m = request_ctx.createMarshaller();
63-
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
64-
65-
m.marshal(entity, sw);
62+
if(request_ctx != null){
63+
Marshaller m = request_ctx.createMarshaller();
64+
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
65+
66+
m.marshal(entity, sw);
67+
}
6668
}
6769
sw.flush();
6870
sw.close();
@@ -94,29 +96,31 @@ public static synchronized <T extends Serializable> T create(String xml, Class<T
9496
{
9597
response_ctx = jaxbContext.get(classType.toString());
9698
}
97-
98-
Unmarshaller um = response_ctx.createUnmarshaller();
99-
try {
100-
Object unmarshaled = um.unmarshal(new StringReader(xml));
101-
if ( null != unmarshaled)
102-
{
103-
try {
104-
entity = classType.cast(unmarshaled);
105-
} catch (ClassCastException cce) {
106-
if (unmarshaled instanceof JAXBElement) {
107-
@SuppressWarnings("rawtypes")
108-
JAXBElement element = (JAXBElement) unmarshaled;
109-
if ( null != element.getValue() && element.getValue().getClass()==classType) {
110-
entity = (T) element.getValue();
111-
}
112-
}
113-
}
114-
}
115-
} catch (JAXBException jaxbe) {
116-
LogHelper.info(logger, "Exception - while deserializing text:'%s' ", xml);
117-
LogHelper.warn(logger, "Exception Details-> Code:'%s', Message:'%s'", jaxbe.getErrorCode(), jaxbe.getMessage());
118-
throw jaxbe;
119-
}
99+
100+
if(response_ctx != null){
101+
Unmarshaller um = response_ctx.createUnmarshaller();
102+
try {
103+
Object unmarshaled = um.unmarshal(new StringReader(xml));
104+
if ( null != unmarshaled)
105+
{
106+
try {
107+
entity = classType.cast(unmarshaled);
108+
} catch (ClassCastException cce) {
109+
if (unmarshaled instanceof JAXBElement) {
110+
@SuppressWarnings("rawtypes")
111+
JAXBElement element = (JAXBElement) unmarshaled;
112+
if ( null != element.getValue() && element.getValue().getClass()==classType) {
113+
entity = (T) element.getValue();
114+
}
115+
}
116+
}
117+
}
118+
} catch (JAXBException jaxbe) {
119+
LogHelper.info(logger, "Exception - while deserializing text:'%s' ", xml);
120+
LogHelper.warn(logger, "Exception Details-> Code:'%s', Message:'%s'", jaxbe.getErrorCode(), jaxbe.getMessage());
121+
throw jaxbe;
122+
}
123+
}
120124
}
121125

122126
return entity;

0 commit comments

Comments
 (0)