Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright (c) 2014 Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany.
   * All rights reserved. This program and the accompanying materials
   * are made available under the terms of the Creative Commons Attribution-NoDerivatives 4.0 International (CC BY-ND 4.0)
   * which accompanies this distribution, and is available at http://creativecommons.org/licenses/by-nd/4.0/
   *
   * Contributors:
   *      Leibniz Institute of Plant Genetics and Crop Plant Research (IPK), Gatersleben, Germany - RMI Client, FileChooser and WebDAV
   */
 package de.ipk_gatersleben.bit.bi.edal.webdav.wrapper;
 
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
 
 
 
 public class EdalHttp11ResponseHandler implements Http11ResponseHandler,
 
 	private static String miltonVerson;
 	{
 		Properties props = new Properties();
 		try {
 			props.load(ClientDataManager.class
 					.getResourceAsStream("/milton.properties"));
 		} catch (IOException ex) {
 					"Failed lot load milton properties file"ex);
 		}
 		 = props.getProperty("milton.version");
 	}
 
 	private final ETagGenerator eTagGenerator;
 	private int maxMemorySize = 100000;
 	private BUFFERING buffering;
 
 			AuthenticationService authenticationService,
 			ETagGenerator eTagGenerator) {
 		this. = authenticationService;
 		this. = eTagGenerator;
 	}

Defaults to com.bradmcevoy.http.http11.DefaultCacheControlHelper

 
 	}
 
 	public void setCacheControlHelper(CacheControlHelper cacheControlHelper) {
 		this. = cacheControlHelper;
 	}
 
 	public String generateEtag(Resource r) {
 	}
 
 	public void respondWithOptions(Resource resourceResponse response,
 			Request requestList<StringmethodsAllowed) {
 		setRespondCommonHeaders(responseresource.,
 				request.getAuthorization());
 		response.setAllowHeader(methodsAllowed);
 		response.setContentLengthHeader((long) 0);
 	}
 
 	public void respondNotFound(Response responseRequest request) {
		response.setContentTypeHeader("text/html");
		.generate(nullrequestresponse.);
	}
	public void respondUnauthorised(Resource resourceResponse response,
			Request request) {
		if (.canUseExternalAuth(resourcerequest)) {
					.info("respondUnauthorised: use external authentication");
			initiateExternalAuth(resourcerequestresponse);
else {
			..info("respondUnauthorised: return staus: "
			if (request.getAuthorization() != null
					&& request.getAuthorization().getTag() != null) {
else {
			}
					resourcerequest);
			response.setAuthenticateHeader(challenges);
		}
	}
	public void respondMethodNotImplemented(Resource resource,
			Response responseRequest request) {
		.generate(resourcerequestresponse,
	}
	public void respondMethodNotAllowed(Resource resResponse response,
			Request request) {
		..debug("method not allowed. handler: "
this.getClass().getName() + " resource: "
res.getClass().getName());
		.generate(resrequestresponse,
	}

Parameters:
resource
response
message - optional message to output in the body content
	public void respondConflict(Resource resourceResponse response,
			Request requestString message) {
		..debug("respondConflict");
		.generate(resourcerequestresponse,
	}
	public void respondServerError(Request requestResponse response,
			String reason) {
		.generate(nullrequestresponse,
	}
	public void respondRedirect(Response responseRequest request,
			String redirectUrl) {
		if (redirectUrl == null) {
			throw new NullPointerException("redirectUrl cannot be null");
		}
		..trace("respondRedirect");
		// delegate to the response, because this can be server dependent
		response.sendRedirect(redirectUrl);
		// response.setStatus(Response.Status.SC_MOVED_TEMPORARILY);
		// response.setLocationHeader(redirectUrl);
	}
	public void respondExpectationFailed(Response responseRequest request) {
	}
	public void respondCreated(Resource resourceResponse response,
			Request request) {
		// log.debug( "respondCreated" );
				request.getAuthorization());
	}
	public void respondNoContent(Resource resourceResponse response,
			Request request) {
		// log.debug( "respondNoContent" );
		// response.setStatus(Response.Status.SC_OK);
		// see comments in http://www.ettrema.com:8080/browse/MIL-87
				request.getAuthorization());
	}
	public void respondPartialContent(GetableResource resource,
			Response responseRequest requestMap<StringStringparams,
		..debug("respondPartialContent: "
range.getStart() + " - " + range.getFinish());
		response.setContentRangeHeader(range.getStart(), range.getFinish(),
				resource.getContentLength());
		response.setDateHeader(new Date());
		String etag = .generateEtag(resource);
		if (etag != null) {
			response.setEtag(etag);
		}
		String acc = request.getAcceptHeader();
		String ct = resource.getContentType(acc);
		if (ct != null) {
		}
		response.setEntity(new GetableResourceEntity(resourcerangeparams,
				ct));
	}
	public void respondHead(Resource resourceResponse response,
			Request request) {
		// setRespondContentCommonHeaders(response, resource,
		// Response.Status.SC_NO_CONTENT, request.getAuthorization());
		setRespondContentCommonHeaders(responseresource,
		if (!(resource instanceof GetableResource)) {
			return;
		}
		GetableResource gr = (GetableResourceresource;
		Long contentLength = gr.getContentLength();
		if (contentLength != null) {
			response.setContentLengthHeader(contentLength);
else {
					.trace("No content length is available for HEAD request");
		}
		String acc = request.getAcceptHeader();
		String ct = gr.getContentType(acc);
		if (ct != null) {
			if (ct != null) {
			}
		}
	}
	public void respondContent(Resource resourceResponse response,
			Request requestMap<StringStringparams)
				.debug("respondContent: " + resource.getClass());
		Auth auth = request.getAuthorization();
		setRespondContentCommonHeaders(responseresourceauth);
		if (resource instanceof GetableResource) {
			GetableResource gr = (GetableResourceresource;
			String acc = request.getAcceptHeader();
			String ct = gr.getContentType(acc);
			if (ct != null) {
			}
					request.getAuthorization());
			Long contentLength = gr.getContentLength();
			boolean doBuffering;
			if ( == null ||  == .) {
				doBuffering = (contentLength == null); // if no content length
														// then we buffer
														// content to find
														// content length
else {
				doBuffering = ( == .); // if not null or
																// whenNeeded
																// then
																// buffering is
																// explicitly
																// enabled or
																// disabled
			}
			if (!doBuffering) {
						.trace("sending content with known content length: "
contentLength);
				if (contentLength != null) {
					response.setContentLengthHeader(contentLength);
				}
				response.setEntity(new GetableResourceEntity(grparamsct));
else {
						paramsctcontentLengthgetMaxMemorySize()));
			}
		}
	}
	public void respondNotModified(GetableResource resourceResponse response,
			Request request) {
		..trace("respondNotModified");
		response.setDateHeader(new Date());
		String etag = .generateEtag(resource);
		if (etag != null) {
			response.setEtag(etag);
		}
		// Note that we use a simpler modified date handling here then when
		// responding with content, because in a not-modified situation the
		// modified date MUST be that of the actual resource
		Date modDate = resource.getModifiedDate();
		response.setLastModifiedHeader(modDate);
				request.getAuthorization());
	}
	protected void setRespondContentCommonHeaders(Response response,
			Resource resourceAuth auth) {
		setRespondContentCommonHeaders(responseresource,
	}
	protected void setRespondContentCommonHeaders(Response response,
			Resource resourceResponse.Status statusAuth auth) {
		setRespondCommonHeaders(responseresourcestatusauth);
		setModifiedDate(responseresourceauth);
	}
	protected void setRespondCommonHeaders(Response response,
			Resource resourceResponse.Status statusAuth auth) {
		response.setStatus(status);
		response.setNonStandardHeader("Server""milton.io-" + );
		response.setDateHeader(new Date());
		String etag = .generateEtag(resource);
		if (etag != null) {
			response.setEtag(etag);
		}
	}

The modified date response header is used by the client for content caching. It seems obvious that if we have a modified date on the resource we should set it. BUT, because of the interaction with max-age we should always set it to the current date if we have max-age The problem, is that if we find that a condition GET has an expired mod-date (based on maxAge) then we want to respond with content (even if our mod-date hasnt changed. But if we use the actual mod-date in that case, then the browser will continue to use the old mod-date, so will forever more respond with content. So we send a mod-date of now to ensure that future requests will be given a 304 not modified.*

Parameters:
response
resource
auth
	public static void setModifiedDate(Response responseResource resource,
			Auth auth) {
		Date modDate = resource.getModifiedDate();
		if (modDate != null) {
			// HACH - see if this helps IE
			response.setLastModifiedHeader(modDate);
			// if (resource instanceof GetableResource) {
			// GetableResource gr = (GetableResource) resource;
			// Long maxAge = gr.getMaxAgeSeconds(auth);
			// if (maxAge != null && maxAge > 0) {
			// log.trace("setModifiedDate: has a modified date and a positive maxAge, so adjust modDate");
			// long tm = System.currentTimeMillis() - 60000; // modified 1
			// minute ago
			// modDate = new Date(tm); // have max-age, so use current date
			// }
			// }
			// response.setLastModifiedHeader(modDate);
		}
	}
	public void respondBadRequest(Resource resourceResponse response,
			Request request) {
	}
	public void respondForbidden(Resource resourceResponse response,
			Request request) {
	}
	public void respondDeleteFailed(Request requestResponse response,
			Resource resourceStatus status) {
		response.setStatus(status);
	}
	public void respondPreconditionFailed(Request requestResponse response,
			Resource resource) {
	}
	}

Maximum size of data to hold in memory per request when buffering output data.

	public int getMaxMemorySize() {
	}
	public void setMaxMemorySize(int maxMemorySize) {
		this. = maxMemorySize;
	}
	public BUFFERING getBuffering() {
		return ;
	}
	public void setBuffering(BUFFERING buffering) {
		this. = buffering;
	}

Sometimes we'll get a content type list, such as image/jpeg,image/pjpeg In this case we should pick the first in the list

Parameters:
ct
Returns:
java.lang.String
		if (ct == null) {
			return null;
else if (ct.contains(",")) {
			return ct.split(",")[0];
else {
			return ct;
		}
	}
	public void initiateExternalAuth(Resource resourceRequest request,
			Response response) {
		if (eip == null) {
			// means that the user needs to select an identity provider, so
			// generate appropriate page
else {
			eip.initiateExternalAuth(resourcerequestresponse);
		}
	}
		if (list.size() == 1) {
			return list.get(0);
else {
			String ipName = request.getParams().get("_ip");
			if (ipName != null && ipName.length() > 0) {
				for (ExternalIdentityProvider eip : list) {
					if (ipName.equals(eip.getName())) {
						return eip;
					}
				}
			}
			return null;
		}
	}
	}
	public void setContentGenerator(ContentGenerator contentGenerator) {
		this. = contentGenerator;
	}
New to GrepCode? Check out our FAQ X