Generate {@link AtsdServerException} from Http Response.

@param response {@link Response} class from jersey.
@return AtsdServerException instance with extracted message from response.
559097
static AtsdServerException fromResponse(final Response response) {
        final int status = response.getStatus();
        try {
            final ServerError serverError = response.readEntity(ServerError.class);
            final String message = AtsdServerMessageFactory.from(serverError);
            return new AtsdServerException(message, status);
        } catch (ProcessingException e) {
            throw new IllegalArgumentException("Failed to extract server error", e);
        }
    }
405260
public Response unprotectResponse(Response response) throws IOException {
        try {
            if (!supportsProtection() || !HttpHeaders.hasBody(response)) {
                return response;
            }

            if (!response.header("content-type").toLowerCase().contains("application/jose+json")) {
                return response;
            }

            JWSObject jwsObject = JWSObject.deserialize(response.body().string());
            JWSHeader jwsHeader = jwsObject.jwsHeader();

            if (!jwsHeader.kid().equals(serverSignatureKey.kid()) || !jwsHeader.alg().equals("RS256")) {
                throw new IOException("Invalid protected response");
            }

            byte[] data = (jwsObject.originalProtected() + "." + jwsObject.payload()).getBytes(MESSAGE_ENCODING);
            byte[] signature = MessageSecurityHelper.base64UrltoByteArray(jwsObject.signature());

            RsaKey serverSignatureRsaKey = new RsaKey(serverSignatureKey.kid(), serverSignatureKey.toRSA(false));
            boolean signed = serverSignatureRsaKey.verifyAsync(getSha256(data), signature, "RS256").get();
            if (!signed) {
                throw new IOException("Wrong signature.");
            }

            String decrypted = unprotectPayload(jwsObject.payload());

            MediaType contentType = response.body().contentType();
            ResponseBody body = ResponseBody.create(contentType, decrypted);
            return response.newBuilder().body(body).build();
        } catch (ExecutionException e) {
            // unexpected;
            return null;
        } catch (InterruptedException e) {
            // unexpected;
            return null;
        } catch (NoSuchAlgorithmException e) {
            // unexpected;
            return null;
        }
    }
62536
public Object string_to_resource(Class<?> responseClass, String response)
	{
		try
		{
			Gson gson = new Gson();
			return gson.fromJson(response, responseClass);
		}catch(Exception e)
		{
			System.out.println(e.getMessage());
		}
		
		return null;
	}
1319330
public void setResponse(JsonRpcResponse response) {
    if (response.isError()) {
      setException(response.error());
      return;
    }

    try {
      set((V) Messages.fromJson(method.outputBuilder(), response.result()));
    } catch (Exception e) {
      setException(e);
    }
  }
415232
@Override
    public void onSuccess(String response)
    throws ActivityException, ConnectionException, AdapterException {
        try {
            // set the variable value based on the unwrapped soap content
            soapResponse = getSoapResponse(response);
            Node childElem = unwrapSoapResponse(soapResponse);
            String responseXml = DomHelper.toXml(childElem);

            String responseVarName = getAttributeValue(RESPONSE_VARIABLE);
            if (responseVarName == null)
                throw new AdapterException("Missing attribute: " + RESPONSE_VARIABLE);
            String responseVarType = getParameterType(responseVarName);

            if (!VariableTranslator.isDocumentReferenceVariable(getPackage(), responseVarType))
                throw new AdapterException("Response variable must be a DocumentReference: " + responseVarName);

            if (responseVarType.equals(StringDocument.class.getName())) {
                setParameterValueAsDocument(responseVarName, responseVarType, responseXml);
            }
            else {
                com.centurylink.mdw.variable.VariableTranslator varTrans = VariableTranslator.getTranslator(getPackage(), responseVarType);
                if (!(varTrans instanceof XmlDocumentTranslator))
                    throw new AdapterException("Unsupported response variable type: " + responseVarType + " (must implement XmlDocumentTranslator)");
                XmlDocumentTranslator xmlDocTrans = (XmlDocumentTranslator) varTrans;
                Object responseObj = xmlDocTrans.fromDomNode(childElem);
                setParameterValueAsDocument(responseVarName, responseVarType, responseObj);
            }
        }
        catch (Exception ex) {
            throw new ActivityException(ex.getMessage(), ex);
        }
    }
1175200
public String marshal(ResponseWrapper response) {

    Services xmlServices = this.composeResponseFromResponseWrapper(response);

    StringWriter sw = new StringWriter();
    try {
      JAXBContext jaxbContext = JAXBContext.newInstance(Services.class);
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

      // output pretty printed
      jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

      jaxbMarshaller.marshal(xmlServices, sw);
    } catch (PropertyException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (JAXBException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return sw.toString();
  }
511419
@Override
    public void generateError(String response) {
        final String errorInString = extractParameter(response, ERROR_REGEX_PATTERN, true);
        final String errorDescription = extractParameter(response, ERROR_DESCRIPTION_REGEX_PATTERN, false);

        OAuth2Error errorCode;
        try {
            errorCode = OAuth2Error.parseFrom(errorInString);
        } catch (IllegalArgumentException iaE) {
            //non oauth standard error code
            errorCode = null;
        }

        throw new OAuth2AccessTokenErrorResponse(errorCode, errorDescription, null, response);
    }
141907
public HTTPResponse handleError(HTTPResponse response) throws HTTPException {
        if (response.statusCode < 200 || response.statusCode >= 300) {
            throw new HTTPException(response.statusCode, response.reason);
        }
        return response;
    }
457476
public Object string_to_resource(Class<?> responseClass, String response)
	{
		Gson gson = new Gson();
		return gson.fromJson(response, responseClass);
	}
1175911
public String getResponseString(ClientResponse response) throws Exception {
    if (debug)
      LOGGER.log(Level.INFO, "status: " + response.getStatus());
    String responseText = response.getEntity(String.class);
    if (response.getStatus() != 200) {
      handleError("status " + response.getStatus() + ":'" + responseText + "'");
    }
    return responseText;
  }
1202647
@RequestMapping(value = "/invoke", method = {RequestMethod.POST})
    @ResponseBody
    public ResponseMessage invoke(HttpServletRequest request, HttpServletResponse response) {
        ResponseMessage res = new ResponseMessage();
        try {
            JSONObject json = tgtools.web.util.RequestHelper.parseRequest(request);
            ValidMessage rm = (ValidMessage) tgtools.util.JsonParseHelper.parseToObject(json, ValidMessage.class);

            mUserService.tokenLogin(request.getRemoteAddr(), rm.getUser(), rm.getToken());

            Object obj = restCommand.process(rm.getOperation(), rm.getData());
            res.setStatus(true);
            res.setData(obj);
        } catch (Exception e) {
            res.setStatus(false);
            res.setData(e.getMessage());
        }
        try {
            System.out.println("client结果：" + tgtools.util.JsonParseHelper.parseToJsonObject(res).toString());
        } catch (Exception d) {
        }
        return res;
    }
289403
@SuppressWarnings("unchecked")
	public <T> Response<T> fromJSON(String response, Response<T> target) {
		try {
			response = StandardizationUtil.getJSONStandardizer(target).normalize(response);
		} catch (Exception e) {
			throw new SerializationException(e);
		}

		try {
			Response<T> fromJson = gson.fromJson(response, target.getClass());
			if (fromJson == null) {
				fromJson = target;
			}
			return fromJson;
		} catch (JsonSyntaxException jse) {
			throw new SerializationException(jse);
		}
	}
960358
public ResponseCtx makeResponseCtx(String response)
            throws MelcoeXacmlException {
        ResponseCtx resCtx = null;
        try {
            ByteArrayInputStream is =
                    new ByteArrayInputStream(response.getBytes());
            resCtx = ResponseCtx.getInstance(is);
        } catch (ParsingException pe) {
            throw new MelcoeXacmlException("Error parsing response.", pe);
        }
        return resCtx;
    }
880248
private void checkSuccess(Message response) throws JdbcServerException {
        OperationResult operationResult = null;
        if (response instanceof JdbcMessage || response.getPayload() instanceof OperationResult) {
            operationResult = response.getPayload(OperationResult.class);
        } else if (response.getPayload() != null && StringUtils.hasText(response.getPayload(String.class))) {
            operationResult = (OperationResult) endpointConfiguration.getMarshaller().unmarshal(new StringSource(response.getPayload(String.class)));
        }

        if (!success(response, operationResult)) {
            throw new JdbcServerException(getExceptionMessage(response, operationResult));
        }
    }
1125586
public User parseResponse(JSONObject response) throws JSONException {
        GsonBuilder gsonBuilder = new GsonBuilder();
        gsonBuilder.registerTypeAdapter(Date.class, new JsonDeserializer<Date>() {

            @Override
            public Date deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
                try {
                    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                    return format.parse(jsonElement.getAsString());
                } catch (ParseException e) {
                    return null;
                }
            }
        });
        Gson gson = gsonBuilder.setDateFormat("yyyy-MM-dd HH:mm:ss").create();
        User user = gson.fromJson(String.valueOf(response.get("data")), User.class);
        user = parseArray(user, response.getJSONObject("data"));
        return user;
    }
82576
protected String extractResultData(String response) throws IOException, WssServiceException {
        // parse response
        ResultEnvelope envelope = gson.fromJson(response, ResultEnvelope.class);
        if (envelope == null) {
            throw new WssServiceException("Empty response, response data is: " + response);
        }

        // extract info from envelope
        String message = envelope.getMessage();
        String data = envelope.getData();
        String requestToken = envelope.getRequestToken();

        // service fault ?
        if (ResultEnvelope.STATUS_SUCCESS != envelope.getStatus()) {
            throw new WssServiceException(message + ": " + data, requestToken);
        }
        return data;
    }
140741
protected base_resource[] get_nitro_response(nitro_service service, String response) throws Exception {
		aaa_stats[] resources = new aaa_stats[1];
		aaa_response result = (aaa_response) service.get_payload_formatter().string_to_resource(aaa_response.class, response);
		if(result.errorcode != 0) {
			if (result.errorcode == 444) {
				service.clear_session();
			}
			if(result.severity != null)
			{
				if (result.severity.equals("ERROR"))
					throw new nitro_exception(result.message,result.errorcode);
			}
			else
			{
				throw new nitro_exception(result.message,result.errorcode);
			}
		}
		resources[0] = result.aaa;
		return resources;
	}