List of usage examples for org.eclipse.jgit.util HttpSupport HDR_CONTENT_TYPE
String HDR_CONTENT_TYPE
To view the source code for org.eclipse.jgit.util HttpSupport HDR_CONTENT_TYPE.
Click Source Link
From source file:org.webcat.core.git.http.GitRawComponent.java
License:Open Source License
@Override public void appendToResponse(WOResponse response, WOContext context) { ObjectId oid = gitContext().objectId(); WOResponseOutputStream output = new WOResponseOutputStream(response); gitContext().repository().writeBlobToStream(oid, output); output.close();/* ww w . jav a2 s.c o m*/ String mimeType = FileUtilities.mimeType(gitContext().path()); response.setHeader(mimeType, HttpSupport.HDR_CONTENT_TYPE); }
From source file:org.webcat.core.git.http.GitWebRequestHandler.java
License:Open Source License
/** * Generates an appropriate response for the specified object, depending on * its type./*from w w w .j ava 2s.c om*/ * * @param repository the repository * @param commitId the commit id * @param objectId the object id * @param request the request * @param response the response * @throws Exception if an error occurs */ private void generateResponse(GitWebContext gitContext, WORequest request, WOResponse response) throws Exception { GitWebComponent page = null; Class<? extends GitWebComponent> pageClass = actionPages.get(gitContext.mode()); if (pageClass != null) { page = Application.wcApplication().pageWithName(pageClass, request.context()); } if (page != null) { page.setGitContext(gitContext); WOResponse pageResponse = page.generateResponse(); response.appendContentData(pageResponse.content()); if (gitContext.mode() != GitWebMode.RAW) { response.setHeader("text/html", HttpSupport.HDR_CONTENT_TYPE); } } else { response.setStatus(WOMessage.HTTP_STATUS_FORBIDDEN); } }
From source file:org.webcat.core.git.http.ReceivePackRequestHandler.java
License:Open Source License
/** * Handles the request and generates the ReceivePack response. * * @param request the request//ww w.j a v a 2 s.c o m * @param response the response * @throws Exception if an error occurs */ public void handleRequest(WORequest request, WOResponse response) throws Exception { String contentType = request.headerForKey(HttpSupport.HDR_CONTENT_TYPE); if (RECEIVE_PACK_REQUEST_TYPE.equals(contentType)) { final Repository repo = RepositoryRequestUtils.repositoryFromRequest(request); ReceivePack rp = new ReceivePack(repo); rp.setBiDirectionalPipe(false); rp.setPostReceiveHook(new PostReceiveHook() { public void onPostReceive(ReceivePack pack, Collection<ReceiveCommand> commands) { // Once the pack is received, force a pull of the working // copy so that anyone using Web-DAV will get synched. GitUtilities.workingCopyForRepository(repo, true); } }); response.setHeader(RECEIVE_PACK_RESULT_TYPE, HttpSupport.HDR_CONTENT_TYPE); InputStream input = RequestUtils.inputStreamForRequest(request); SmartGZIPOutputStream output = new SmartGZIPOutputStream(request, response); rp.receive(input, output, null); output.close(); } else { response.setStatus(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE); } }
From source file:org.webcat.core.git.http.SmartHttpInfoRefsFilter.java
License:Open Source License
/** * Delegates to the/*from w w w . j a v a 2 s. com*/ * {@link #advertise(WORequest, Repository, PacketLineOutRefAdvertiser)} * method on the class and then appends the advertisement to the response. * * @param request the request * @param response the response * @param filterChain the filter chain * @throws Exception if an error occurred */ public void filterRequest(WORequest request, WOResponse response, RequestFilterChain filterChain) throws Exception { if (service.equals(request.formValueForKey("service"))) { try { Repository repo = RepositoryRequestUtils.repositoryFromRequest(request); response.setHeader("application/x-" + service + "-advertisement", HttpSupport.HDR_CONTENT_TYPE); NSMutableDataOutputStream output = new NSMutableDataOutputStream(); PacketLineOut lineOut = new PacketLineOut(output); lineOut.writeString("# service=" + service + "\n"); lineOut.end(); advertise(request, repo, new PacketLineOutRefAdvertiser(lineOut)); output.close(); response.appendContentData(output.data()); } catch (IOException e) { Log.error("(403) An exception occurred when advertising the " + "repository", e); response.setStatus(WOMessage.HTTP_STATUS_FORBIDDEN); } } else { filterChain.filterRequest(request, response); } }
From source file:org.webcat.core.git.http.UploadPackRequestHandler.java
License:Open Source License
/** * Handles the request and generates the UploadPack response. * * @param request the request/*from ww w . j a v a 2 s . c om*/ * @param response the response * @throws Exception if an error occurs */ public void handleRequest(WORequest request, WOResponse response) throws Exception { String contentType = request.headerForKey(HttpSupport.HDR_CONTENT_TYPE); if (UPLOAD_PACK_REQUEST_TYPE.equals(contentType)) { Repository repo = RepositoryRequestUtils.repositoryFromRequest(request); UploadPack up = new UploadPack(repo); up.setBiDirectionalPipe(false); response.setHeader(UPLOAD_PACK_RESULT_TYPE, HttpSupport.HDR_CONTENT_TYPE); InputStream input = RequestUtils.inputStreamForRequest(request); SmartGZIPOutputStream output = new SmartGZIPOutputStream(request, response); up.upload(input, output, null); output.close(); } else { response.setStatus(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE); } }
From source file:org.webcat.core.http.RequestUtils.java
License:Open Source License
/** * Appends a plain text string to a response, compressing it with GZIP if * the request supports that.// w ww . java 2 s . c o m * * @param content the content string * @param request the request * @param response the response * @throws IOException if an I/O error occurs */ public static void sendPlainText(String content, WORequest request, WOResponse response) throws IOException { byte[] raw = content.getBytes(Constants.CHARACTER_ENCODING); response.setHeader("text/plain;charset=" + Constants.CHARACTER_ENCODING, HttpSupport.HDR_CONTENT_TYPE); sendBytes(raw, request, response); }