2929 */
3030public class CmpHttpClient implements UpstreamInterface {
3131
32+ private static final String CONTENT_TYPE = "Content-type" ;
33+ private static final String CMP_CONTENT_TYPE = "application/pkixcmp" ;
3234 private static final Logger LOGGER = LoggerFactory .getLogger (CmpHttpClient .class );
3335
3436 /**
@@ -54,23 +56,22 @@ protected static byte[] sendReceivePkiMessageIntern(
5456 httpConnection .setConnectTimeout (timeoutInSeconds > 0 ? timeoutInSeconds * 1000 : Integer .MAX_VALUE );
5557 httpConnection .setReadTimeout (timeoutInSeconds > 0 ? timeoutInSeconds * 1000 : Integer .MAX_VALUE );
5658 httpConnection .setRequestMethod ("POST" );
57- httpConnection .setRequestProperty ("Content-type" , "application/pkixcmp" );
59+ httpConnection .setRequestProperty (CONTENT_TYPE , CMP_CONTENT_TYPE );
5860 httpConnection .connect ();
5961 try (final OutputStream outputStream = httpConnection .getOutputStream ()) {
6062 LOGGER .debug ("send " + message .length + " bytes to " + httpConnection );
6163 outputStream .write (message );
6264 }
6365 final int lastResponseCode = httpConnection .getResponseCode ();
64-
65- if (lastResponseCode == HttpURLConnection .HTTP_OK ) {
66- final byte [] response = httpConnection .getInputStream ().readAllBytes ();
67- LOGGER .debug ("got " + response .length + " bytes from " + httpConnection );
68- return response ;
66+ if (lastResponseCode != HttpURLConnection .HTTP_OK ) {
67+ final String errorString = "got response '" + lastResponseCode + " " + httpConnection .getResponseMessage ()
68+ + "' from " + httpConnection ;
69+ LOGGER .warn (errorString );
70+ if (!CMP_CONTENT_TYPE .equals (httpConnection .getHeaderField (CONTENT_TYPE ))) {
71+ throw new Exception (errorString );
72+ }
6973 }
70- final String errorString = "got response '" + httpConnection .getResponseMessage () + "(" + lastResponseCode
71- + ")' from " + httpConnection ;
72- LOGGER .error (errorString + ", closing client" );
73- throw new Exception (errorString );
74+ return httpConnection .getInputStream ().readAllBytes ();
7475 }
7576
7677 protected final URL remoteUrl ;
0 commit comments