I have a valid sitemap.xml file. The problem arises when I try to serve this file as a sitemap.xml. I get the following error:
This page contains the following errors:
error on line 1 at column 95: Extra content at the end of the document
Below is a rendering of the page up to the first error.
When I inspect /sitemap.xml from browser each element tag gets this added to it.
<url xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
the rest
</url>
Here is how I return the file from the controller:
XmlDocument xml = new XmlDocument();
xml.Load(#"C:\sitemap.xml");
return Content(xml.DocumentElement.InnerXml, "application/xml");
Here is an example of the file I have and trying to return
<?xml version="1.0" encoding="utf-8"?>
<urlset
xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc>LINK</loc>
</url>
THE REST OF URLS
</urlset>
I have tried switching the "application/xml" to "text/xml" but didn't solve this problem. Am I not using XmlDocument correctly or am I not fully understanding what happens with return Content()?
Any help is appreciated.
Thank you
What ended up fixed this was a simple fix.
XmlDocument xml = new XmlDocument();
xml.Load(#"C:\sitemap.xml");
return Content(xml.DocumentElement.InnerXml, "application/xml");
Changed to
XmlDocument xml = new XmlDocument();
xml.Load(#"C:\sitemap.xml");
return Content(xml.DocumentElement.OuterXml, "application/xml");
Hope this helps someone later.
Related
Once again thanks for the help on previous help. Anyway I try to move on to my EFTscreen.java code to get my Search buttons to work. In my JSP page I have the following search button with the following function call (hope I get parathesis pasting this:
<button id="searchEFT" class="btn smBtn">Search</button>
xmlhttp = new XMLHttpRequest();
if (Cmd_Sched_Number != "")
{
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200)
{
document.getElementById("EFTSumList").innerHTML = http.responseText;
}
};
xmlhttp.open("GET","/servlet/EFTscreen?method=searchSched&Schedule_Number="
+ Cmd_Sched_Number + "&Contract_Year=" + Cmd_Contract_Year,true);
xmlhttp.send();
}
Now in looking around I was told that I need to create the servlet name and classs in the web.xml file located the WEB-INF directory of project
<?xml version = '1.0' encoding = 'windows-1252'?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<servlet>
<display-name>EFTscreen</display-name>
<servlet-name>EFTscreen</servlet-name>
<servlet-class>eftproject.EFTscreen</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EFTscreen</servlet-name>
<url-pattern>/servlet/EFTscreen</url-pattern>
</servlet-mapping>
here is my declaration in the EFTscreen.java file to supposedly pull the Httpservlet (removed some of the imports because it is already too big a question)
package eftproject;
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
#WebServlet(name = "EFTscreen", urlPatterns = { "/servlet/EFTscreen"})
public class EFTscreen extends HttpServlet { }
When I try running this going through debugging, I am getting the 404 error in the xmlhttp.status field not being able to find the URL. The readystate fields are working but not sure if that is relevant.
Can you review to see what I am missing here or incorrectly? I am thinking it is something with my url-pattern in web.xml and how I am accessing it but maybe it is something even worse.
Thanks for the help
Developed a Simple Spring Maven Web application with Jsperreports 6.1.0 dependency. Created a Jasper report having a static text and a chart. When exported report in PDF format, report is printed properly with static text and chart, but when exported to HTML format only static text is displayed not chart.
After searching on internet found that ImageServlet and few parameters are needed to export report in HTML format.
Added ImageServlet mapping in web.xml
Set Image URI through WebHtmlResourceHandler.
Still report does not show chart. What is the problem?
Here is my Spring Controller code to export report in HTML format.
List<BeanAuthorBooks> beanList = new ArrayList<BeanAuthorBooks>();
beanList.add(new BeanAuthorBooks("APJ Kalam",10));
beanList.add(new BeanAuthorBooks("Robin Shamra",5));
beanList.add(new BeanAuthorBooks("Rashmi Bansal",8));
beanList.add(new BeanAuthorBooks("Dr. B.R.Ambedkar",60));
beanList.add(new BeanAuthorBooks("Mahatma Gandhi",15));
Map<String,Object> params = new HashMap();
JasperReport jasperReport = JasperCompileManager.compileReport(this.getClass().getResourceAsStream("testreport.jrxml"));
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JRBeanCollectionDataSource(beanList,false));
HtmlExporter exporter = new HtmlExporter();
List<JasperPrint> jasperPrintsList = new ArrayList<JasperPrint>();
jasperPrintsList.add(jasperPrint);
exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintsList));
//set ImageHandler. Hack for images export to HTML
SimpleHtmlExporterOutput output = new SimpleHtmlExporterOutput(response.getWriter());
WebHtmlResourceHandler webHtmlResourceHandler = new WebHtmlResourceHandler("image?image={0}");
output.setImageHandler(webHtmlResourceHandler);
exporter.setExporterOutput(output);
SimpleHtmlReportConfiguration configuration = new SimpleHtmlReportConfiguration();
exporter.setConfiguration(configuration);
exporter.exportReport();
Here is my web.xml :
<servlet>
<servlet-name>ImageServlet</servlet-name>
<servlet-class>net.sf.jasperreports.j2ee.servlets.ImageServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/image</url-pattern>
</servlet-mapping>
Work Environment : Jasperreports 6.1.0, Spring 4.1.1, Eclipse Luna
NOTE : I found many links on different forums with same problem but solutions provided there are now seems deprecated.
Found the problem.....POsting solution here....
Actually My Controller has requestmapping as "/reports" and my method from which I was exporting report has request mapping "/html",
so final request for image being displayed in chart was becoming something like "appname/reports/html/image?image=img_0_1".
But ImageServlet was mapped with URL "/image" so updated my code as below :
In web.xml
<servlet-mapping>
<servlet-name>ImageServlet</servlet-name>
<url-pattern>/reports/image</url-pattern>
and in controller updated my url as ......
WebHtmlResourceHandler webHtmlResourceHandler = new WebHtmlResourceHandler("../image?image={0}");
Have the following code in my Default.aspx file, located at http://localhost/idss/Default.aspx:
<%# Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head id="Head1" runat="server">
<title>Testing IDSS Return Values</title>
</head>
<body>
<%#
// how we do it
XmlDocument doc = new XmlDocument();
doc.Load(Server.MapPath("idss/requests/categoryList.xml"));
// create the request to your URL
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/idss/Default.aspx");
// add the headers
// the SOAPACtion determines what action the web service should use
// YOU MUST KNOW THIS and SET IT HERE
request.Headers.Add("SOAPAction", "http://ws.idssasp.com/Members.asmx/GetCategoryList");
// set the request type
// we use utf-8 but set the content type here
request.ContentType = "text/xml;charset=\"utf-8\"";
request.Accept = "text/xml";
request.Method = "POST";
// add our body to the request
Stream stream = request.GetRequestStream();
doc.Save( stream );
stream.Close();
// get the response back
using(HttpWebResponse response = (HttpWebResponse)request.GetResponse())
{
request.Write(response);
}//end using
%>
</body>
</html>
The xml file located at: http://localhost/idss/requests/categoryList.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthorizeHeader xmlns="http://ws.idssasp.com/Members.asmx">
<UserName>MyUsername</UserName>
<Password>MyPassword</Password>
</AuthorizeHeader>
</soap:Header>
<soap:Body>
<GetCategoryList xmlns="http://ws.idssasp.com/Members.asmx" />
</soap:Body>
</soap:Envelope>
Where MyUsername and MyPassword is filled in with the correct username and password. The URL located here: http://ws.idssasp.com/members.asmx?op=GetCategoryList&pn=0 tells me that SOAP should send a request like this:
POST /members.asmx HTTP/1.1
Host: ws.idssasp.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://ws.idssasp.com/Members.asmx/GetCategoryList"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<AuthorizeHeader xmlns="http://ws.idssasp.com/Members.asmx">
<UserName>string</UserName>
<Password>string</Password>
</AuthorizeHeader>
</soap:Header>
<soap:Body>
<GetCategoryList xmlns="http://ws.idssasp.com/Members.asmx" />
</soap:Body>
</soap:Envelope>
But when I browse to http://localhost/idss/Default.aspx I get an Internal Server Error (500). What exactly am I doing wrong here? Do I need to add namespaces? Or other References somewhere in the Default.aspx file? If so, which one's are needed? Also, am I pointing to the correct in (HttpWebRequest)WebRequest.Create("http://localhost/idss/Default.aspx");?
Am I doing this correctly? I just feel like something is missing here.
Having trouble with soap exceptions.
I'm throwing soap exception in asp.net web service and have to somehow get that exception (in form of xml) to show in browser, like this:
SOAP 1.1
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<soap:Fault><faultcode>soap:Client</faultcode>
<faultstring></faultstring>
<detail>
<Error>
<ErrorNumber>1</ErrorNumber>
<ErrorMessage>Error...</ErrorMessage>
</Error>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
Throwing exception from web service:
XmlDocument doc = new XmlDocument();
XmlNode detailNode = doc.CreateNode(XmlNodeType.Element, SoapException.DetailElementName.Name, SoapException.DetailElementName.Namespace);
XmlElement details = doc.CreateElement("Error");
XmlElement detailchild1 = doc.CreateElement("ErrorNumber");
detailchild1.InnerText = "1";
XmlElement detailchild2 = doc.CreateElement("ErrorMessage");
detailchild2.InnerText = "Error...";
details.AppendChild(detailchild1);
details.AppendChild(detailchild2);
detailNode.AppendChild(details);
throw new SoapException("Fault", SoapException.ClientFaultCode, "", details);
If I test it with windows application that calls that service, I can catch exception and extract all details so it seems that everything works with creating xml and throwing exception.
But all I'm getting from browser is internal error 500, which is according to other answers I found normal behaviour. Can I somehow get that xml in browser instead of internal error 500, maybe by changing web.config, IIS settings...
shouldn't this
throw new SoapException("Fault", SoapException.ClientFaultCode, "", details);
be
throw new SoapException("Fault", SoapException.ClientFaultCode, "", detailNode);
?
I've got a ASP.NET WebService that looks something like this:
[WebMethod]
public static void DoSomethingWithStrings(string stringA, string stringB)
{
// and so on
}
An third party application should call this webservice. However this application encodes strings as UTF-8 and all umlauts are replaced by '??'. I can view the call and the special characters are formatted well:
<?xml version="1.0" encoding="utf-8" ?>
<!-- ... -->
<SoapCall>
<DoSomethingWithStrings>
<stringA>Ä - Ö - Ü</stringA>
<stringB>This is a test</stringB>
</DoSomethingWithStrings>
</SoapCall>
This produces the following output, when I simply print the strings inside the webservice method:
?? - ?? - ??
This is a test
How can I configure the WebService to accept UTF-8 encoded strings?
Update
Fiddler also tells me that the content-type charset of the http request is UTF-8.
Update 2
I tried to add following code to global.asax for debugging purposes:
public void Application_BeginRequest(object sender, EventArgs e)
{
using (var reader = new System.IO.StreamReader(Request.InputStream))
{
string str = reader.ReadToEnd();
}
}
This reads the actual SOAP call. The StreamReaders encoding is set to UTF-8. The SOAP call looks correct:
<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<DoSomethingWithStrings xmlns="http://www.tempuri.org/">
<stringA>Ä - Ö - Ü</stringA>
<stringB>This is a test!</stringB>
</DoSomethingWithStrings>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
In the web.config file the globalization settings are set correctly:
<globalization requestEncoding="UTF-8" responseEncoding="UTF-8" culture="de-DE" uiCulture="de-DE" />
So it looks like something that deserializes the SOAP message does not use UTF-8 but ASCII encoding.
Finally it turns out that something went wrong within accepting HTTP-Messages. I don't actually know what manipulates the HTTP-Request, but I found a workaround for this. Eventhough Fiddler showed me the correct content type (text/xml; charset=utf-8) in my Application_BeginRequest the Request.RequestContext.HttpContext.Request.ContentType was just text/xml, which lead to a fallback to default (ASCII) encoding within the ASMX serializer. I've added the following code to the Application_BeginRequest handler and everything works for now.
if (Request.RequestContext.HttpContext.Request.ContentType.Equals("text/xml"))
{
Request.RequestContext.HttpContext.Request.ContentType = "text/xml; charset=UTF-8";
}
Thanks for your help!
Try this:-
byte[] bytes=Encoding.UTF8.GetBytes(yourString);
NOTE:-
Strings never contain anything utf-* or anything else encoded
The SOAP call is being decoded as ASCII somewhere - each of the umlauts are 2 bytes with high bit being set, which turns into ?? when decoded as ASCII.
So, something like this is happening:
byte[] bytesSentFromClient = Encoding.UTF8.GetBytes("Ä - Ö - Ü");
string theStringIThenReceiveInMyMethod = Encoding.ASCII.GetString(bytesSentFromClient);
Console.WriteLine(theStringIThenReceiveInMyMethod);
//?? - ?? - ??
To verify this is happening for sure, you should compare stringA == "Ä - Ö - Ü" rather than printing it somewhere.
I guess you could start by doing a project-wide search for "ASCII" and then work from there if you find anything.
You could also try
<globalization requestEncoding="utf-8" responseEncoding="utf-8"/>
Under the <system.web> tag in Web.config file.
I had the same problem. Asmx web service converted my UTF-8 to ASCII or, better to say to ??????. Your post helped me a lot.
The solution I found was to change version of SOAP protocol from 1.1 to 1.2
I mean:
POST /WebService1.asmx HTTP/1.1
Host: www.tempuri.org
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://www.tempuri.org/HelloWorld"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<HelloWorld xmlns="http://www.tempuri.org/">
<inputParam>Привет</inputParam>
</HelloWorld>
</soap:Body>
</soap:Envelope>
had the problem. But when I changed my request to SOAP 1.2:
POST /WebService1.asmx HTTP/1.1
Host: www.tempuri.org
Content-Type: application/soap+xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">
<soap12:Body>
<HelloWorld xmlns="http://www.tempuri.org/">
<inputParam>Привет</inputParam>
</HelloWorld>
</soap12:Body>
</soap12:Envelope>
The issue was solved.