All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.dounine.clouddisk360.parser.deserializer.differpre.DifferPressResponseHandle Maven / Gradle / Ivy

package com.dounine.clouddisk360.parser.deserializer.differpre;

import java.io.IOException;
import java.net.URISyntaxException;

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.utils.URIBuilder;

import com.dounine.clouddisk360.parser.DifferPressParser;
import com.dounine.clouddisk360.parser.deserializer.BaseResponseHandle;

public class DifferPressResponseHandle extends BaseResponseHandle
		implements ResponseHandler {

	public DifferPressResponseHandle(DifferPressParser parse) {
		super(parse);
	}

	@Override
	public DifferPress handleResponse(HttpResponse response) throws ClientProtocolException, IOException {
		executeBefore(response);
		Header[] headers = parse.getHttpClientContext().getResponse().getAllHeaders();
		String localtion = null;
		for (Header header : headers) {
			if (header.getName().equals("Location")) {
				localtion = header.getValue();
				break;
			}
		}
		DifferPress differPress = desializer(localtion);
		saveCookie();
		try {
			parse.getHttpClientContext().setAttribute(DifferPressConst.REQUEST_HOST_NAME, // 把host分压域名放到context上下文中,方便下一个请求获取
					new URIBuilder(differPress.getRedirectUrl()).getHost());
			parse.getHttpClientContext().setAttribute(DifferPressConst.REQUEST_SCHEME_HOST_NAME,
					differPress.getRedirectUrl());
		} catch (URISyntaxException e) {
			e.printStackTrace();
		}
		executeAfter(response);
		return differPress;
	}

	@Override
	public String disassemblyResult(String result) {
		return String.format("{'redirectUrl':'%s'}", result);
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy