[OCP 17 book] | [OCP 11 book] | [OCA 8 book] [OCP 8 book] [Practice tests book] [Blog] [JavaRanch FAQ] [How To Ask Questions] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
The secret of how to be miserable is to constantly expect things are going to happen the way that they are "supposed" to happen.
You can have faith, which carries the understanding that you may be disappointed. Then there's being a willfully-blind idiot, which virtually guarantees it.
Tim Holloway wrote:I tend to get confused on this, but I think that calling close() on the printWriter causes a close of the response writer and I don't think that you're supposed to do that.
Also, be aware that a lot of browsers have "XML magic" in them so that they can accept XML and display/format it in various interesting ways. So try switching Content-Type to "text/text" and if the XML shows up, then you can switch back to "text/xml" and make adjustments.
swathi bairu wrote:I am trying to print xml from a servlet, but when I run the servlet, I can only see an empty page. Please suggest.
Bear Bibeault wrote:Do a View Source at the browser. What do you see?
swathi bairu wrote:
Bear Bibeault wrote:Do a View Source at the browser. What do you see?
I have a working RESTEasy service deployed to JBOSS EAP 6.3. It prints an XML to the browser. I am calling this service from a servlet, but I see nothing on the browser when I run this servlet in eclipse. When I run this servlet on a normal browser (mine is chrom) it is giving the following message:
This page contains the following errors:
error on line 1 at column 1: Document is empty
Below is a rendering of the page up to the first error.
When I open the browser's "view page source" - I can see the XML response here.
Testing...
Good Response
*** Response from Server ***
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><employee><empAddress>San Antonio TX</empAddress><empId>1111</empId><empName>EmployeeOne</empName></employee>
My Servlet
Please Suggest.
swathi bairu wrote:When I open the browser's "view page source" - I can see the XML response here.
Testing...
Good Response
*** Response from Server ***
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><employee><empAddress>San Antonio TX</empAddress><empId>1111</empId><empName>EmployeeOne</empName></employee>
Dave Tolls wrote:
swathi bairu wrote:When I open the browser's "view page source" - I can see the XML response here.
Testing...
Good Response
*** Response from Server ***
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><employee><empAddress>San Antonio TX</empAddress><empId>1111</empId><empName>EmployeeOne</empName></employee>
That's because that's not XML.
You have a whole load of spurious text at the front of it.
The reason that text/xml works is because it's far more lenient.
You shouldn't be relying on that, though.
If you should be proper XML, then it should be application/xml, and if it's rejected then your XML is incorrect and should be fixed.
swathi bairu wrote:
Dave Tolls wrote:
swathi bairu wrote:When I open the browser's "view page source" - I can see the XML response here.
Testing...
Good Response
*** Response from Server ***
<?xml version="1.0" encoding="UTF-8" standalone="yes"?><employee><empAddress>San Antonio TX</empAddress><empId>1111</empId><empName>EmployeeOne</empName></employee>
That's because that's not XML.
You have a whole load of spurious text at the front of it.
The reason that text/xml works is because it's far more lenient.
You shouldn't be relying on that, though.
If you should be proper XML, then it should be application/xml, and if it's rejected then your XML is incorrect and should be fixed.
I removed all the front text and changed "text/xml" back to "application/xml". It is working fine now. Thank you @Dave Tolls. But I have a new issue here. I protected my RESTFul service that is being called form my servlet in web.xml through <security-constraint>. But I cannot call this service from servlet when it is protected through <security-constraint>, when I comment that out, it is no mpre protected and I can call the service from the client. Please suggest.
SERVICE WAR
ent_securityprefs_empService
-src
-com.xxxx.channel.employee.service
-Employee.java
-Employees.java
-EmployeeService.java
-com.xxxx.channel.employee.service.bean
-EmployeeBean.java
-WebContent
-WEB-INF
-beans.xml
-jboss-web.xml
-web.xml
-hello.jsp
Employee.java
Employees.java
EmployeeService.java
EmployeeBean.java
@ApplicationScoped
public class EmployeeBean implements Serializable{
private TreeMap employeeMap;
public EmployeeBean(){
employeeMap = new TreeMap();
}
public TreeMap getEmployeeMap() {
return employeeMap;
}
public void setEmployeeMap(TreeMap employeeMap) {
this.employeeMap = employeeMap;
}
}
beans.xml
jboss-web.xml
web.xml
hello.jsp
CLIENT WAR
ent_securityprefs_emp
-src
-EmployeeServlet.java
-WebContent
-WEB-INF
-jboss-deployment-structure.xml
-jboss-web.xml
-web.xml
-index.jsp
EmployeeServlet.java
jboss-deployment-structure.xml
Note: This module has all the required dependencies in it.
jboss-web.xml
web.xml
index.jsp
SERVER CONFIGURATION FILE
standlaone-full.xml
Note: i am only addign security-domain part to avoid confusion. This is the security domain to which my service and client are configured to.