/** * This interceptor adds some pretty syntax highlighting in responses when a browser is detected */ @Bean(autowire = Autowire.BY_TYPE) public IServerInterceptor responseHighlighterInterceptor() { ResponseHighlighterInterceptor retVal = new ResponseHighlighterInterceptor(); return retVal; }
outputBuffer.append(createLinkHref(parameters, Constants.FORMAT_JSON)); outputBuffer.append("\">Raw JSON</a> or "); outputBuffer.append(createLinkHref(parameters, Constants.FORMAT_XML)); outputBuffer.append("\">Raw XML</a>, "); outputBuffer.append(createLinkHref(parameters, Constants.FORMATS_HTML_JSON)); outputBuffer.append("\">HTML JSON</a> "); outputBuffer.append(createLinkHref(parameters, Constants.FORMATS_HTML_XML)); outputBuffer.append("\">HTML XML</a>."); if (isShowRequestHeaders()) { streamRequestHeaders(theServletRequest, outputBuffer); if (isShowResponseHeaders()) { streamResponseHeaders(theRequestDetails, theServletResponse, outputBuffer); int linesCount = format(encoded, target, encoding); outputBuffer.append(target); outputBuffer.append("</pre></div>"); writeLength(theServletResponse, encoded.length()); theServletResponse.getWriter().append(" ("); writeLength(theServletResponse, outputBuffer.length()); theServletResponse.getWriter().append(" total including HTML)");
streamResponse(theRequestDetails, theServletResponse, theResponseObject.getResponseResource(), theServletRequest, 200);
outputBuffer.append(createLinkHref(parameters, Constants.FORMAT_JSON)); outputBuffer.append("\">Raw JSON</a> or "); outputBuffer.append(createLinkHref(parameters, Constants.FORMAT_XML)); outputBuffer.append("\">Raw XML</a>, "); outputBuffer.append(createLinkHref(parameters, Constants.FORMATS_HTML_JSON)); outputBuffer.append("\">HTML JSON</a> "); outputBuffer.append(createLinkHref(parameters, Constants.FORMATS_HTML_XML)); outputBuffer.append("\">HTML XML</a>."); if (isShowRequestHeaders()) { streamRequestHeaders(theServletRequest, outputBuffer); if (isShowResponseHeaders()) { streamResponseHeaders(theRequestDetails, theServletResponse, outputBuffer); int linesCount = format(encoded, target, encoding); outputBuffer.append(target); outputBuffer.append("</pre></div>"); writeLength(theServletResponse, encoded.length()); theServletResponse.getWriter().append(" ("); writeLength(theServletResponse, outputBuffer.length()); theServletResponse.getWriter().append(" total including HTML)");
@Override public boolean handleException(RequestDetails theRequestDetails, BaseServerResponseException theException, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws ServletException, IOException { /* * It's not a browser... */ Set<String> accept = RestfulServerUtils.parseAcceptHeaderAndReturnHighestRankedOptions(theServletRequest); if (!accept.contains(Constants.CT_HTML)) { return super.handleException(theRequestDetails, theException, theServletRequest, theServletResponse); } /* * It's an AJAX request, so no HTML */ String requestedWith = theServletRequest.getHeader("X-Requested-With"); if (requestedWith != null) { return super.handleException(theRequestDetails, theException, theServletRequest, theServletResponse); } /* * Not a GET */ if (theRequestDetails.getRequestType() != RequestTypeEnum.GET) { return super.handleException(theRequestDetails, theException, theServletRequest, theServletResponse); } if (theException.getOperationOutcome() == null) { return super.handleException(theRequestDetails, theException, theServletRequest, theServletResponse); } streamResponse(theRequestDetails, theServletResponse, theException.getOperationOutcome(), theServletRequest, theException.getStatusCode()); return false; }
/** * This interceptor adds some pretty syntax highlighting in responses when a browser is detected */ @Bean(autowire = Autowire.BY_TYPE) public IServerInterceptor responseHighlighterInterceptor() { ResponseHighlighterInterceptor retVal = new ResponseHighlighterInterceptor(); return retVal; }
streamResponse(theRequestDetails, theServletResponse, theResponseObject.getResponseResource(), theServletRequest, 200);
/** * This interceptor adds some pretty syntax highlighting in responses when a browser is detected */ @Bean(autowire = Autowire.BY_TYPE) public IServerInterceptor responseHighlighterInterceptor() { ResponseHighlighterInterceptor retVal = new ResponseHighlighterInterceptor(); return retVal; }
@Override public boolean handleException(RequestDetails theRequestDetails, BaseServerResponseException theException, HttpServletRequest theServletRequest, HttpServletResponse theServletResponse) throws ServletException, IOException { /* * It's not a browser... */ Set<String> accept = RestfulServerUtils.parseAcceptHeaderAndReturnHighestRankedOptions(theServletRequest); if (!accept.contains(Constants.CT_HTML)) { return super.handleException(theRequestDetails, theException, theServletRequest, theServletResponse); } /* * It's an AJAX request, so no HTML */ String requestedWith = theServletRequest.getHeader("X-Requested-With"); if (requestedWith != null) { return super.handleException(theRequestDetails, theException, theServletRequest, theServletResponse); } /* * Not a GET */ if (theRequestDetails.getRequestType() != RequestTypeEnum.GET) { return super.handleException(theRequestDetails, theException, theServletRequest, theServletResponse); } if (theException.getOperationOutcome() == null) { return super.handleException(theRequestDetails, theException, theServletRequest, theServletResponse); } streamResponse(theRequestDetails, theServletResponse, theException.getOperationOutcome(), theServletRequest, theException.getStatusCode()); return false; }
@Override protected void initialize() throws ServletException { // ... define your resource providers here ... // Now register the interceptor ResponseHighlighterInterceptor interceptor = new ResponseHighlighterInterceptor(); registerInterceptor(interceptor); }
/** * This method is called automatically when the servlet is initializing. */ @Override public void initialize() { final List<IResourceProvider> providers = new ArrayList<IResourceProvider>(); providers.add(new SomeResourceProvider()); setResourceProviders(providers); registerInterceptor(new ResponseHighlighterInterceptor()); } }
/** * This interceptor adds some pretty syntax highlighting in responses when a browser is detected */ @Bean(autowire = Autowire.BY_TYPE) public IServerInterceptor responseHighlighterInterceptor() { return new ResponseHighlighterInterceptor(); }