Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.drools.guvnor.server.files;
  
 
 
 public class OryxEditorServlet extends HttpServlet {
 
     private static final LoggingHelper log = LoggingHelper.getLogger(OryxEditorServlet.class);
 
     @Inject
     private Credentials credentials;
 
     @Inject
     private Identity identity;
 
     @Inject
 
     public void service(HttpServletRequest request,
                         HttpServletResponse response)
             throws ServletException,
             IOException {
         .debug("Incoming request from Oryx Designer:" + request.getRequestURL());
 
         //action never used. Why? - JT
         String action = request.getParameter("action");
         String uuid = request.getParameter("uuid");
         String usr = request.getParameter("usr");
         String pwd = request.getParameter("pwd");
 
         if (uuid == null) {
             throw new ServletException(new IllegalArgumentException("Parameter uuid not specified."));
         }
         //action never used. Why? - JT
         /*if (action == null) {
             action = "json";
         } */
 
         // log in
         .setUsername(usr);
         .setCredential(new org.picketlink.idm.impl.api.PasswordCredential(pwd));
 
         .login();
         if ( !.isLoggedIn() ) {
             throw new ServletException(new IllegalArgumentException("Unable to authenticate user."));
         }
         .debug("Successful login");
 
         try {
             Asset asset = .loadRuleAsset(uuid);
             if (asset.getContent() != null) {
                 response.setContentType("application/xml");
                 response.setCharacterEncoding("UTF-8");
                 String content = asset.getContent().toString();
                 if (asset.getContent() instanceof RuleFlowContentModel) {
                     content = ((RuleFlowContentModelasset.getContent()).getXml();
                 }
 
                 if (content != null) {
                     response.getOutputStream().write(content.getBytes("UTF-8"));
                     response.getOutputStream().close();
                 } else {
                     setDefaultResponse(response);
                 }
 
             } else {
                 setDefaultResponse(response);
             }
         } catch (Throwable t) {
             .error(t.getMessage(),
                     t);
             setDefaultResponse(response);
         }
 
     }
 
     private void setDefaultResponse(HttpServletResponse responsethrows ServletException {
         response.setContentType("application/json");
         response.setCharacterEncoding("UTF-8");
         String result = "";
         response.setContentLength(result.length());
         try {
             response.getOutputStream().write(result.getBytes());
             response.getOutputStream().close();
         } catch (IOException e) {
             throw new ServletException(e.getMessage());
        }
    }
New to GrepCode? Check out our FAQ X