0

My client sends me some data via web service, which he created, and expects 4 digit long value as return code. For example return code 9461 is for failure of operation A, or return code 0000 is for success. There is no problem of returning error codes, however when return code is 0000, that is success I am facing the following problem.

I can't create 4 digit long which starts with 0. I tried to set webservice response as follows

response.setResponseCode(0000L);

However it sends 0 instead of 0000. I know I can use hardcoded "0000" or String.format or DecimalFormat, but setResponseCode takes long as input, therefore I can't use string.

Is there any way to set zeros before number so that 0 can be set like 0000 or 45 can be set like 0045?

mamba4ever
  • 2,662
  • 4
  • 28
  • 46
  • 7
    Numbers don't have a format. Strings have a format. How do you expect `0` to be different from `0000`? They're both `0`. – arshajii Sep 18 '13 at 21:25
  • If you can only pass a `long`, by `0000`, he has to mean `0`, there's no alternative. – Bernhard Barker Sep 18 '13 at 21:26
  • Sorry for that, misread the question. What are you using for your webserver? – Guvante Sep 18 '13 at 21:27
  • 2
    If you specify numeric literals in Java that begin with `0`, the Java will treat them as octal numbers (base 8), not decimal numbers (our normal base 10). Be careful. – rgettman Sep 18 '13 at 21:30
  • 1
    Tell the client to fix his/her code :> (Or updated your access layer to deal with *textual* status codes.) – user2246674 Sep 18 '13 at 21:31
  • 1
    The HTTP status code is defined in RFC 2616 as 'a 3-digit integer', with 200 meaning 'success'. If your client wants to change HTTP, let him provide all the libraries you need to implement his version, or amend his budget so you can do so. If he wants you to use existing systems like Java he is stuck with HTTP as it is. – user207421 Sep 18 '13 at 23:30
  • 1
    This question appears to be off-topic because the problem is with a different program. – Raedwald Mar 01 '14 at 11:53

1 Answers1

1

Simply no. 0000 and 0 have the same byte representation if you treat it as long.

Michael Dietrich
  • 451
  • 1
  • 5
  • 17