Exception thrown using xwiki and Apache xml-rpc - java

I am using the following code to update a confluence page:
public void publish() throws IOException {
XWikiXmlRpcClient rpc = new XWikiXmlRpcClient(CONFLUENCE_URI);
try {
rpc.login(USER_NAME, PASSWORD);
//The info macro would get rendered an info box in the Page
Page page = new Page();
page.setSpace("ATF");
page.setTitle("New Page");
page.setContent("New Page Created \\\\ {{info}}This is XMLRPC Test{{/info}}");
page.setParentId("demo UTF Home");
rpc.storePage(page);
} catch (XmlRpcException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
When I try to run the program, I get the following exception:
org.apache.xmlrpc.client.XmlRpcClientException: Failed to parse server's response: Expected methodResponse element, got html
This looks like a bug in Apache xml-rpc client going by this JIRA:
https://issues.apache.org/jira/browse/XMLRPC-159
It says it was fixed in 3.1.2 of the library, I am using 3.1.3.
Anyone seen this before?

Maybe the server really returned HTML; sometimes it simply returns a 200 because something is there that always produces HTML. In that case the bugfix in the XMLRPC-library you have linked to does not apply.
To check for this possibility, you can look into the server access logs for the url of the request and the status code (should be a 200); with this information you can replay the request e.g. in a browser or command line client like wget or curl, and see what is really returned as response.

Related

How to setup Parse live query with Android (Java) with self-hosted server URL

I'm trying to use Parse live queries in Android Studio following this back4app guide. I enabled live query and set up the LiveQuery client following Steps 1 and 2 in the guide. However, I am having trouble with Step 3 (subscribing to the query). Here's what I tried:
// Back4App's Parse setup
Parse.initialize(new Parse.Configuration.Builder(this)
.applicationId(APPLICATION_ID)
.clientKey(CLIENT_KEY)
.server("wss://<my_subdomain>.back4app.io/").build()
);
// Init Live Query Client
ParseLiveQueryClient parseLiveQueryClient = null;
try {
parseLiveQueryClient = ParseLiveQueryClient.Factory.getClient(new URI("wss://<my_subdomain>.back4app.io/"));
} catch (URISyntaxException e) {
e.printStackTrace();
}
replacing the application id, client key, and subdomain appropriately. But this resulted in an error: java.net.MalformedURLException: unknown protocol: wss and I was unable to create the Parse application. I tried replacing wss:// with https:// in the server URL. The application ran, but every Parse SDK request returned error: unauthorized. Before changing the server URL, I had been using "https://parseapi.back4app.com" and everything worked perfectly. I'm unsure how to fix this issue - any help would be appreciated. Thanks.

Forward Request from Applet Fails in Chrome but Not IE

I inherited some Java code that does Single Server Sign for the BMC Remedy AR System. The code works by pulling the Kerberos ticket from the headers and then validates it by making calls to domain controllers.
The Remedy server makes a call to a method:
public UserCredentials getAuthenticatedCredentials(HttpServletRequest request,HttpServletResponse response) throws IOException
Within that method the Authorization header is extracted. For both IE and Chrome this works correctly.
The next step is to get the users timezone using a custom JSP page which is called via the following:
RequestDispatcher reqDisp = request.getRequestDispatcher(Login.CUSTOM_TIMEZONE_URL);
if (reqDisp != null) {
try {
reqDisp.forward(request, response);
} catch (Exception e) {
System.out.println("Error");
e.printStackTrace();
}
}
This is working correctly in IE8 and IE11 but not in Chrome. For IE the header still contains the Authorization values after the time zone call so I can perform the Kerberos check but for Chrome the Authorization headers are missing.
(I can post the complete headers if that would help)
Thank you

Java - NoHttpResponseException when using apache fluent api to post

I am continuously posting data to server using Java with Apache fluent api.
Content content = Request.Post(URL)
.bodyForm(param)
.execute()
.returnContent();
The above works perfectly but after some random execution time I am getting org.apache.http.NoHttpResponseException: failed to respond. How I can handle this to post the same parameter again after getting this exception.
EDIT
Ok, I have to handle response, something like this but still don't have any clue how this can be done.
Content content = Request.Post(URL)
.bodyForm(param)
.execute().handleResponse(new ResponseHandler<Content>() {
public Content handleResponse(HttpResponse arg0)
throws ClientProtocolException, IOException {
// TODO Auto-generated method stub
return null;
}
});
Instead of using fluent API I used the following below method and overcome my own problem:-
get NoHttpResponseException for load testing
Apache HttpClient Interim Error: NoHttpResponseException

How to make the ResourceResponse to forward the request to error page in liferay portlet

I am trying to forward my request to error page when error occurs during generating excel sheet. Here is sample code below. I am not sure why it is not getting forwarded to error page when the exception is thrown, it is displaying blank page but not going to my error page for sure.`
#ResourceMapping("xyz")
public void generateExcelExport(ResourceRequest request, ResourceResponse response) {
try {
//Do all the excel related logic
response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
response.setProperty("Content-Disposition", "attachment; filename=\"" + XYZ + "\"");
workbook.write(response.getPortletOutputStream());
} catch (Exception e) {
response.setProperty("Content-Disposition", "inline" );
response.setContentType("text/html");
PortletRequestDispatcher dispatcher = request.getPortletSession().getPortletContext().getRequestDispatcher("/WEB-INF/views/html/jsp/error.jsp");
try {
dispatcher.forward(request, response);
} catch (Exception e1) {
log.error("Unable to forward the request from the portlet", e1);
}
} }
Im not sure but my guess would be that you didnt set any render parameter when redirecting to your error page.
Try this and see if it helps in any way (you can place it instead of the line with dispatcher):
response.setRenderParameter("jspPage", "/WEB-INF/views/html/jsp/error.jsp");
I am using this kind of redirects with actionResponse but it should work with resourceResponse as well...
EDIT: resource response does not contain setRenderParameter method, but zou can try to use the following approach:
create renderURL using response.createRenderURL(). If a request is triggered using this URL, it will result in render request/response (or action request which can access that method).
The problem is, that you are trying to redirect to another page during resource phase of the portlet (render phase in not called during this phase).
I'm not 100% sure this would work in the resourcePhase, but you could try
com.liferay.portal.kernel.servlet.SessionErrors.add(request, "your Error message here");
I had a similar issue. This works -
PortletURL renderUrl = resourceResponse.createRenderURL();
renderUrl.setParameter("renderException", ex.toString());
resourceResponse.addProperty("Location", renderUrl.toString());
Maybe it is not forwarding because the response has already been committed because you have written something in it. That could explain why include works and forward doesn't.
You can check whether the response has already been committed using resourceResponse.isCommitted() in your catch block.

spring-mvc download action

Is there some trick to getting a SpringMVC custom view to cause a file download in the broswer? I've implemented the render method from org.springframework.web.servlet.View but the code results in my data being written to the page as a blob of data rather having a download action start.
try {
Document oDoc = (Document) model.get("oDoc");
out = new PrintWriter(response.getOutputStream());
response.setContentType("application/vnd.ms-excel");
response.setHeader("content-disposition", "attachment; filename=file.xls");
GenerateXLSFile gof = new GenerateXLSFile();
gof.outputTSVFromDom(out, oDoc);
} catch block here {
//writes to log here
} finally {
if (out != null) {
out.flush();
out.close();
}
}
I know the render method is being called from the server logs. I know the GenerateXLSFile is being created from the server logs. I know the outputTSVFromDom can take a document and transform it work from my JUnit test. It also writes to the server log and completes. The data ends up in the browser. The HTTP Headers looks normal according to firebug. No errors from the catch block are in the server log.
What am I missing here?
First of all, which API are you using? Excel documents are binary, so you should use OutputStream, not Writer.
Second, Spring has a built in support for serving Excel documents:
AbstractExcelView, based on the Apache POI API
AbstractJExcelView, based on the JExcel API

Categories

Resources