title: org.apache.fop.apps.FOPException: .fop (Access is denied) in Azure
body: <p>I have recently added a fop pdf generator to an existing application. everything works fine locally but when I deploy to live on Azure I get the following errors:</p>
  
  <pre><code>org.apache.fop.apps.FOPException: .fop (Access is denied)
  java.io.FileNotFoundException: .fop (Access is denied)
  </code></pre>
  
  <p>I'm puzzled as to why I'm getting a file access error when it would seem the exception is occurring when the fopfactory writes to a ByteOutputstream</p>
  
  <p>The function where the catch occurs is</p>
  
  <pre><code>        public static void GeneratePDF(string foFile, HttpContext context) {
          StringBuilder sbDebug = new StringBuilder();
  
          sbDebug.AppendLine("Start");
          ByteArrayOutputStream os = new java.io.ByteArrayOutputStream();
          try
          {
              sbDebug.AppendLine("Got to 1");
              com.sun.org.apache.xerces.@internal.jaxp.SAXParserFactoryImpl s = new com.sun.org.apache.xerces.@internal.jaxp.SAXParserFactoryImpl();
              sbDebug.AppendLine("Got to 2");
              FopFactory fopFactory = FopFactory.newInstance(new java.io.File(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Test.xconf")));
              sbDebug.AppendLine("Got to 3 - file ").AppendLine(System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Test.xconf"));
              Fop fop = fopFactory.newFop("application/pdf", os);
  
              sbDebug.AppendLine("Got to 4");
              javax.xml.transform.TransformerFactory factory = javax.xml.transform.TransformerFactory.newInstance();
              javax.xml.transform.Transformer transformer = factory.newTransformer();
              javax.xml.transform.Source src = new javax.xml.transform.stream.StreamSource(new java.io.StringReader(foFile));
              javax.xml.transform.Result res = new javax.xml.transform.sax.SAXResult(fop.getDefaultHandler());
              sbDebug.AppendLine("Got to 5");
              transformer.transform(src, res);
  
              context.Response.ContentType = "application/pdf";
              context.Response.BinaryWrite(os.toByteArray());
              //context.Response.BinaryWrite(System.Text.Encoding.UTF8.GetBytes(os.ToString()));
          }
  
          catch (Exception ex) {
              throw new Exception(sbDebug.AppendLine(ex.ToString()).ToString());
          }
  
          finally {
              os.close();
          }
      }
  </code></pre>
  
  <p>You can see I've added some debug lines as I had to resort to old fashioned debugging to see what was happening.
  The output from this is:</p>
  
  <pre><code>Catch Error: System.Exception: Start
  Got to 1
  Got to 2
  Got to 3 - file 
  D:\home\site\wwwroot\App_Data\Test.xconf
  org.apache.fop.apps.FOPException: .fop (Access is denied)
  java.io.FileNotFoundException: .fop (Access is denied)
  </code></pre>
  
  <p>So I can see the exception is occurring at this line:</p>
  
  <pre><code>Fop fop = fopFactory.newFop("application/pdf", os);
  </code></pre>
  
  <p>I'm expecting everything to be happening in memory apart from the read of the xconf file which is where it should be.</p>
  
  <p><strong>Update 21/02/2017</strong> I've now verified that the xconf file exists in the correct place using</p>
  
  <pre><code>string curFile = System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/Test.xconf");
              if (System.IO.File.Exists(curFile)) //Used System.IO prefix as without it compiler complains of ambiguity with java.io
              {
                  sbDebug.AppendLine("Got to 3a - file found");
              }
              else
              {
                  sbDebug.AppendLine("Got to 3a - file NOT found");
              }
  </code></pre>
  
  <p>And also that it can be read using</p>
  
  <pre><code>BufferedReader br = new BufferedReader(new FileReader(curFile));
              sbDebug.AppendLine("Got to 3b");
  
              String sJIObrOut = br.readLine();
              sbDebug.AppendLine("Got to 3c");
              while ((sJIObrOut = br.readLine()) != null) 
              {
                  sbDebug.Append("3d: ").AppendLine(sJIObrOut);
              }
  </code></pre>
  
  <p>This suggest that fopfactory is trying to access a different file but I can't figure out what.</p>
  
  <p>Any help gratefully received.</p>
  
  <p><strong>UPDATE 2 22/3/17</strong>
  I had no success with Azure Cloud services so decided to build a local web app to just convert the xslfo doc to a pdf and run it as a web service. This works perfectly locally so published the service on a server we use for other clients. 
  This doesn't work and I get exactly the same error as my original post. That means it's not an Azure problem - does any one have any other ideas?</p>