@@ -61,6 +61,11 @@ public class AppIdentityService {
6161 * Jackson object mapper
6262 */
6363 private final ObjectMapper objectMapper ;
64+
65+ /**
66+ * True if deviceAppId is required in the response
67+ */
68+ private final boolean deviceAppIdRequired ;
6469
6570 /**
6671 * Constructor
@@ -73,6 +78,22 @@ public AppIdentityService(final ApiConfiguration apiConfig, final ObjectMapper o
7378
7479 this .defaultApiConfig = apiConfig ;
7580 this .objectMapper = objectMapper ;
81+ this .deviceAppIdRequired = false ;
82+ }
83+
84+ /**
85+ * Constructor
86+ * @param apiConfig The API configuration
87+ * @param objectMapper Jackson object mapper
88+ * @param deviceAppIdRequired True if deviceAppId is required in the response
89+ */
90+ public AppIdentityService (final ApiConfiguration apiConfig , final ObjectMapper objectMapper , final boolean deviceAppIdRequired ) {
91+ Preconditions .checkNotNull (apiConfig );
92+ Preconditions .checkNotNull (objectMapper );
93+
94+ this .defaultApiConfig = apiConfig ;
95+ this .objectMapper = objectMapper ;
96+ this .deviceAppIdRequired = deviceAppIdRequired ;
7697 }
7798
7899 /**
@@ -154,13 +175,34 @@ private AppIdentity identifyApp(ApiConfiguration apiConfig) throws IOException,
154175 // convert to json bytes
155176 byte [] jsonBytes = objectMapper .writer ().writeValueAsBytes (apiConfig .getEnvDetail ());
156177
178+ if (LOGGER .isDebugEnabled ())
179+ {
180+ LOGGER .debug ("IdentifyApp Request: {}" , new String (jsonBytes , "UTF-8" ));
181+ }
182+
157183 // post to stackify
158184 final HttpClient httpClient = new HttpClient (apiConfig );
159185 final String responseString = httpClient .post ("/Metrics/IdentifyApp" , jsonBytes );
160186
187+ LOGGER .debug ("IdentifyApp Response: {}" , responseString );
188+
161189 // deserialize the response and return the app identity
162190 ObjectReader jsonReader = objectMapper .reader (new TypeReference <AppIdentity >(){});
163- return jsonReader .readValue (responseString );
191+ AppIdentity identity = jsonReader .readValue (responseString );
192+
193+ // make sure it has a valid DeviceAppID before accepting it
194+
195+ if (deviceAppIdRequired )
196+ {
197+ if (identity .getDeviceAppId () == null )
198+ {
199+ throw new NullPointerException ("DeviceAppId is null" );
200+ }
201+ }
202+
203+ // done
204+
205+ return identity ;
164206 }
165207
166208
0 commit comments