HttpOverXmppRespProvider.java

  1. /**
  2.  *
  3.  * Copyright 2014 Andriy Tsykholyas
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.hoxt.provider;

  18. import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
  19. import org.xmlpull.v1.XmlPullParser;

  20. /**
  21.  * Resp packet provider.
  22.  *
  23.  * @author Andriy Tsykholyas
  24.  * @see <a href="http://xmpp.org/extensions/xep-0332.html">XEP-0332: HTTP over XMPP transport</a>
  25.  */
  26. public class HttpOverXmppRespProvider extends AbstractHttpOverXmppProvider<HttpOverXmppResp> {

  27.     private static final String ATTRIBUTE_STATUS_MESSAGE = "statusMessage";
  28.     private static final String ATTRIBUTE_STATUS_CODE = "statusCode";

  29.     @Override
  30.     public HttpOverXmppResp parse(XmlPullParser parser, int initialDepth)
  31.                     throws Exception {
  32.         String version = parser.getAttributeValue("", ATTRIBUTE_VERSION);
  33.         String statusMessage = parser.getAttributeValue("", ATTRIBUTE_STATUS_MESSAGE);
  34.         String statusCodeString = parser.getAttributeValue("", ATTRIBUTE_STATUS_CODE);
  35.         int statusCode = Integer.parseInt(statusCodeString);

  36.         HttpOverXmppResp resp = new HttpOverXmppResp();

  37.         resp.setVersion(version);
  38.         resp.setStatusMessage(statusMessage);
  39.         resp.setStatusCode(statusCode);
  40.         parseHeadersAndData(parser, HttpOverXmppResp.ELEMENT, resp);
  41.         return resp;
  42.     }
  43. }