@Test public void shouldParseSuccessful() throws Exception { status = 200; responseAsString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + "<response>" + "one response" + "</response>"; response = new HttpResponse(status, responseAsString); SimpleResponseXML4Test expectedParsedResponse = new SimpleResponseXML4Test("one response"); SimpleResponseXML4Test parsedResponse = response.parseXMLContent(pagSeguro, SimpleResponseXML4Test.class); assertEquals(expectedParsedResponse, parsedResponse); }
public <T> T parseXMLContent(PagSeguro pagSeguro, Class<T> targetClazz) { switch (getStatusFamily()) { case SUCCESSFUL: try { return XMLUtils.unmarshal(pagSeguro, targetClazz, asString()); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case CLIENT_ERROR: switch (getStatus()) { case 400: try { throw new PagSeguroBadRequestException(this, XMLUtils.unmarshal(pagSeguro, ServerErrorsXML.class, asString())); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case 401: throw new PagSeguroUnauthorizedException(this); case 403: throw new PagSeguroForbiddenException(this); } case SERVER_ERROR: switch (getStatus()) { case 503: throw new PagSeguroServiceUnavailableException(this); } default: throw new PagSeguroInternalServerException(this); } }
HttpResponse { public <T> T parseXMLContent(PagSeguro pagSeguro, Class<T> targetClazz) { switch (getStatusFamily()) { case SUCCESSFUL: try { return XMLUtils.unmarshal(pagSeguro, targetClazz, asString()); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case CLIENT_ERROR: switch (getStatus()) { case 400: try { throw new PagSeguroBadRequestException(this, XMLUtils.unmarshal(pagSeguro, ServerErrorsXML.class, asString())); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case 401: throw new PagSeguroUnauthorizedException(this); case 403: throw new PagSeguroForbiddenException(this); } case SERVER_ERROR: switch (getStatus()) { case 503: throw new PagSeguroServiceUnavailableException(this); } default: throw new PagSeguroInternalServerException(this); } } }
HttpResponse { public <T> T parseXMLContent(PagSeguro pagSeguro, Class<T> targetClazz) { switch (getStatusFamily()) { case SUCCESSFUL: try { return XMLUtils.unmarshal(pagSeguro, targetClazz, asString()); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case CLIENT_ERROR: switch (getStatus()) { case 400: try { throw new PagSeguroBadRequestException(this, XMLUtils.unmarshal(pagSeguro, ServerErrorsXML.class, asString())); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case 401: throw new PagSeguroUnauthorizedException(this); case 403: throw new PagSeguroForbiddenException(this); } case SERVER_ERROR: switch (getStatus()) { case 503: throw new PagSeguroServiceUnavailableException(this); } default: throw new PagSeguroInternalServerException(this); } } HttpResponse(int status, String responseAsString); }
HttpResponse { public <T> T parseXMLContent(PagSeguro pagSeguro, Class<T> targetClazz) { switch (getStatusFamily()) { case SUCCESSFUL: try { return XMLUtils.unmarshal(pagSeguro, targetClazz, asString()); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case CLIENT_ERROR: switch (getStatus()) { case 400: try { throw new PagSeguroBadRequestException(this, XMLUtils.unmarshal(pagSeguro, ServerErrorsXML.class, asString())); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case 401: throw new PagSeguroUnauthorizedException(this); case 403: throw new PagSeguroForbiddenException(this); } case SERVER_ERROR: switch (getStatus()) { case 503: throw new PagSeguroServiceUnavailableException(this); } default: throw new PagSeguroInternalServerException(this); } } HttpResponse(int status, String responseAsString); int getStatus(); HttpStatusFamily getStatusFamily(); String asString(); T parseXMLContent(PagSeguro pagSeguro, Class<T> targetClazz); T parseXMLContentNoBody(PagSeguro pagSeguro); @Override boolean equals(Object o); @Override String toString(); }
HttpResponse { public <T> T parseXMLContent(PagSeguro pagSeguro, Class<T> targetClazz) { switch (getStatusFamily()) { case SUCCESSFUL: try { return XMLUtils.unmarshal(pagSeguro, targetClazz, asString()); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case CLIENT_ERROR: switch (getStatus()) { case 400: try { throw new PagSeguroBadRequestException(this, XMLUtils.unmarshal(pagSeguro, ServerErrorsXML.class, asString())); } catch (JAXBException e) { throw new PagSeguroLibException(e); } case 401: throw new PagSeguroUnauthorizedException(this); case 403: throw new PagSeguroForbiddenException(this); } case SERVER_ERROR: switch (getStatus()) { case 503: throw new PagSeguroServiceUnavailableException(this); } default: throw new PagSeguroInternalServerException(this); } } HttpResponse(int status, String responseAsString); int getStatus(); HttpStatusFamily getStatusFamily(); String asString(); T parseXMLContent(PagSeguro pagSeguro, Class<T> targetClazz); T parseXMLContentNoBody(PagSeguro pagSeguro); @Override boolean equals(Object o); @Override String toString();  }