By mobileresearch
on Fri, 01/24/2014 - 19:20
Hi, I'm using the VWC api with Java & Spring, but I have a problem: When call a GET or DELETE service the authorization header is correctly setted, but when I try to use a POST or PUT service always have like an answer "401 Unauthorized". I guess the error is the md5 compression. These is the Java example provided by Vuforia :
private String contentMD5(HttpEntityEnclosingRequestBase httpMethod) { ByteArrayOutputStream requestOutputStream = new ByteArrayOutputStream(); try { httpMethod.getEntity().writeTo(requestOutputStream); } catch (IOException e) { System.out.println("ERROR: IOException caught when writing Content MD5 hash"); e.printStackTrace(); } return DigestUtils.md5Hex(requestOutputStream.toByteArray()).toLowerCase(); }
And it's my code:
private static String encodeMD5(Jsonizable body) throws JsonGenerationException, JsonMappingException, IOException { return DigestUtils.md5Hex(SerializationUtils.serialize(body.getAsJSON())).toLowerCase(); }
@Override @JsonIgnore public String getAsJSON() throws JsonGenerationException, JsonMappingException, IOException { ObjectMapper mapper = new ObjectMapper(); return mapper.writeValueAsString(this); }
/** * Serialize the given object to a byte array. * @param object the object to serialize * @return an array of bytes representing the object in a portable fashion */ public static byte[] serialize(Object object) { if (object == null) { return null; } ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeObject(object); oos.flush(); } catch (IOException ex) { throw new IllegalArgumentException("Failed to serialize object of type: " + object.getClass(), ex); } return baos.toByteArray(); }
Is there another way of retrieve more information from the error?
Thanks
[VWS Java w/ Spring] 401 Unauthorized in POST/PUT methods
The response includes a JSON body w/ more info, but it's not going to tell you the specific cause of the authentication error.
mobileresearch wrote:
[quote=mobileresearch]