The response could not be parsed - java

I am using redstone-xmlrpc-1.1.1 api with my code and getting this error:
redstone.xmlrpc.XmlRpcException: The response could not be parsed.
at redstone.xmlrpc.XmlRpcClient.handleResponse(Unknown Source)
at redstone.xmlrpc.XmlRpcClient.endCall(Unknown Source)
at redstone.xmlrpc.XmlRpcClient.invoke(Unknown Source)
at redstone.xmlrpc.XmlRpcProxy.invoke(Unknown Source)
at net.bican.wordpress.$Proxy1.newMediaObject(Unknown Source)
at net.bican.wordpress.Wordpress.newMediaObject(Wordpress.java:582)
at WordpressPost.DataWordpressPost.DataPost(DataWordpressPost.java:53)
at arrestcentral.ArrestData.readPdf(ArrestData.java:420)
at arrestcentral.ArrestData.main(ArrestData.java:447)
Caused by: java.io.FileNotFoundException: http://www.arrestcentral.com/XMLrpc.php?
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1478)
... 9 more
can anyone help me why I am unable to post on wordpress..

Well, the exception tells you what's happened - you've tried to fetch a URL of
http://www.arrestcentral.com/XMLrpc.php?
... and it was giving you an HTTP 404 (not found) error. You probably need to change the URL, but you should have more idea of what that URL should be than we do.

java.io.FileNotFoundException: http://www.arrestcentral.com/XMLrpc.php? should have given you a clue:
Nothing was found at the URL you specified. This means that the server returned a HTTP response with the error code 404.
You either mistyped the URL or it no longer exists (at this location).

Related

IllegalStateException: Already connected with HttpURLConnection.setFixedLengthStreamingMode

I know this question has been asked a few times here but I've tried everything. It may be completely my fault as this is my first time doing this but if it is then at least I'll be able to improve.
Relevant code:
URL url = new URL(request);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Authorization",
"Bot (token)");
connection.setRequestProperty("User-Agent", "https://discordapp.com/developers/docs/reference, 1.0.0");
connection.setRequestMethod("PUT");
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(connection.getContentLength());
switch (connection.getResponseCode()) {
case HttpURLConnection.HTTP_OK:
break;
case HttpURLConnection.HTTP_UNAUTHORIZED:
Executor.logger.warning("Connection to Discord API does not have sufficient authorization!");
player.sendMessage(ChatColor.RED
+ "An unrelated error occured in the server, please report this to a staff member.");
return;
default:
Executor.logger.warning(
"An unknown exception occured with the HTTP Error Code: " + connection.getResponseCode());
player.sendMessage(ChatColor.RED + "Linking your accounts has failed!");
TextComponent message = new TextComponent(ChatColor.AQUA + ChatColor.BOLD.toString() + "click here!");
message.setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, "https://www.mcpz.net"));
player.sendMessage(
ChatColor.YELLOW + "For information on how to find your ID, " + message.toPlainText());
return;
}
Console error:
org.bukkit.command.CommandException: Unhandled exception executing command 'link' in plugin DiscordBridge v1.0.0
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) ~[squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at org.bukkit.craftbukkit.v1_9_R2.CraftServer.dispatchCommand(CraftServer.java:645) ~[squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.PlayerConnection.handleCommand(PlayerConnection.java:1349) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.PlayerConnection.a(PlayerConnection.java:1184) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:45) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.PacketPlayInChat.a(PacketPlayInChat.java:1) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.PlayerConnectionUtils$1.run(SourceFile:13) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_121]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_121]
at net.minecraft.server.v1_9_R2.SystemUtils.a(SourceFile:45) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.MinecraftServer.D(MinecraftServer.java:726) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.DedicatedServer.D(DedicatedServer.java:399) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.MinecraftServer.C(MinecraftServer.java:665) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at net.minecraft.server.v1_9_R2.MinecraftServer.run(MinecraftServer.java:564) [squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_121]
Caused by: java.lang.IllegalStateException: Already connected
at java.net.HttpURLConnection.setFixedLengthStreamingMode(Unknown Source) ~[?:1.8.0_121]
at sun.net.www.protocol.https.HttpsURLConnectionImpl.setFixedLengthStreamingMode(Unknown Source) ~[?:1.8.0_121]
at uk.co.harieo.DBridge.Discord.Broadcaster.responseMinorUpdate(Broadcaster.java:161) ~[?:?]
at uk.co.harieo.DBridge.LinkingCommand.onCommand(LinkingCommand.java:39) ~[?:?]
at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[squid-spigot.jar:git-Spigot-4af49dc-c5e9a16]
... 15 more
I have tried moving the methods around, using connection.disconnet() but it always returns this exception. As I've found out, the HttpURLConnection.setFixedLengthStreamingMode() is required for connected to the API I am trying to use or else it returns HTTP Error 411.
Any ideas on how to get this to work?
Thanks for any help in advance
- Harieo
Under your question, just replace connection.getContentLength() with requestData.length.
TL;DR.
When you enter setFixedLengthStreamingMode, you will find out that the connected attribute has been set to true. Well, when is it set to true?
In fact, already connected means you have re-new the HttpURLConnection, which is the root cause.
You should check if you have written some code like this:
connection.getContentType, connection.getContentEncoding
If you do so, please comment them. The implementation of this methods use delegate pattern, which means they will new another HttpURLConnection.
connection.setFixedLengthStreamingMode(connection.getContentLength());
The problem is here. By calling getContentLength() you are committing the request and attempting to read the response, and then you're trying to set the length of the request. It doesn't make sense. The parameter you need to supply is how much data you're going to send, not how much the server is going to send back.
You also need to write something, again before you get the response code or do anything else that implies fetching the response.
As I've found out, the HttpURLConnection.setFixedLengthStreamingMode() is required for connected to the API I am trying to use or else it returns HTTP Error 411.
I don't see how you can tell with this code. All you've done by adding setFixedLengthStreamingMode() is change the error. More likely the problem was that you didn't send anything.
NB You need to set the request method to PUT after calling setDoOutput(true), because that sets it to POST.

ServletUnit RequestDispatcher forward() / include() methods AbstractMethodError

I'm doing a java web app with a servlet and I wanted to write some tests to check its functionality (ex. authorization form). I hadn't been using any framework, just bare java in eclipse with tomcat 7.0
I've run into an error while trying to test authorization input. The app would check the login-password pair and then redirect using RequestDispatcher.forward() or RequestDispatcher.include() methods. But when executing them it throws an error with the following stack trace:
java.lang.reflect.Inv­ocationTargetExceptio­n
at su­n.reflect.NativeMetho­dAccessorImpl.invoke0­(Native Method)
at su­n.reflect.NativeMetho­dAccessorImpl.invoke(­Unknown Source)
at su­n.reflect.DelegatingM­ethodAccessorImpl.inv­oke(Unknown Source)
at ja­va.lang.reflect.Metho­d.invoke(Unknown Sour­ce)
at en­tryPoint.Dispatcher.d­ispatch(Dispatcher.ja­va:166)
at en­tryPoint.Dispatcher.s­ervice(Dispatcher.jav­a:49)
at ja­vax.servlet.http.Http­Servlet.service(HttpS­ervlet.java:728)
at co­m.meterware.servletun­it.InvocationContextI­mpl.service(Invocatio­nContextImpl.java:76)
at co­m.meterware.servletun­it.ServletUnitClient.­newResponse(ServletUn­itClient.java:126)
at co­m.meterware.httpunit.­WebClient.createRespo­nse(WebClient.java:64­7)
at co­m.meterware.httpunit.­WebWindow.getResource­(WebWindow.java:220)
at co­m.meterware.httpunit.­WebWindow.getSubframe­Response(WebWindow.ja­va:181)
at co­m.meterware.httpunit.­WebWindow.getResponse­(WebWindow.java:158)
at co­m.meterware.httpunit.­WebWindow.updateWindo­w(WebWindow.java:199)
at co­m.meterware.httpunit.­WebWindow.getSubframe­Response(WebWindow.ja­va:183)
at co­m.meterware.httpunit.­WebWindow.getResponse­(WebWindow.java:158)
at co­m.meterware.httpunit.­WebClient.getResponse­(WebClient.java:122)
at te­st.Authorization.test­AuthCorrectInput_Wron­gPassword(Authorizati­on.java:102)
at su­n.reflect.NativeMetho­dAccessorImpl.invoke0­(Native Method)
at su­n.reflect.NativeMetho­dAccessorImpl.invoke(­Unknown Source)
at su­n.reflect.DelegatingM­ethodAccessorImpl.inv­oke(Unknown Source)
at ja­va.lang.reflect.Metho­d.invoke(Unknown Sour­ce)
at or­g.junit.runners.model­.FrameworkMethod$1.ru­nReflectiveCall(Frame­workMethod.java:45)
at or­g.junit.internal.runn­ers.model.ReflectiveC­allable.run(Reflectiv­eCallable.java:15)
at or­g.junit.runners.model­.FrameworkMethod.invo­keExplosively(Framewo­rkMethod.java:42)
at or­g.junit.internal.runn­ers.statements.Invoke­Method.evaluate(Invok­eMethod.java:20)
at or­g.junit.internal.runn­ers.statements.RunBef­ores.evaluate(RunBefo­res.java:28)
at or­g.junit.runners.Paren­tRunner.runLeaf(Paren­tRunner.java:263)
at or­g.junit.runners.Block­JUnit4ClassRunner.run­Child(BlockJUnit4Clas­sRunner.java:68)
at or­g.junit.runners.Block­JUnit4ClassRunner.run­Child(BlockJUnit4Clas­sRunner.java:47)
at or­g.junit.runners.Paren­tRunner$3.run(ParentR­unner.java:231)
at or­g.junit.runners.Paren­tRunner$1.schedule(Pa­rentRunner.java:60)
at or­g.junit.runners.Paren­tRunner.runChildren(P­arentRunner.java:229)
at or­g.junit.runners.Paren­tRunner.access$000(Pa­rentRunner.java:50)
at or­g.junit.runners.Paren­tRunner$2.evaluate(Pa­rentRunner.java:222)
at or­g.junit.internal.runn­ers.statements.RunBef­ores.evaluate(RunBefo­res.java:28)
at or­g.junit.internal.runn­ers.statements.RunAft­ers.evaluate(RunAfter­s.java:30)
at or­g.junit.runners.Paren­tRunner.run(ParentRun­ner.java:300)
at or­g.eclipse.jdt.interna­l.junit4.runner.JUnit­4TestReference.run(JU­nit4TestReference.jav­a:50)
at or­g.eclipse.jdt.interna­l.junit.runner.TestEx­ecution.run(TestExecu­tion.java:38)
at or­g.eclipse.jdt.interna­l.junit.runner.Remote­TestRunner.runTests(R­emoteTestRunner.java:­467)
at or­g.eclipse.jdt.interna­l.junit.runner.Remote­TestRunner.runTests(R­emoteTestRunner.java:­683)
at or­g.eclipse.jdt.interna­l.junit.runner.Remote­TestRunner.run(Remote­TestRunner.java:390)
at or­g.eclipse.jdt.interna­l.junit.runner.Remote­TestRunner.main(Remot­eTestRunner.java:197)
Caused by: javax.serv­let.ServletException:­ java.lang.AbstractMe­thodError: com.meterw­are.servletunit.Servl­etUnitServletContext.­getClassLoader()Ljava­/lang/ClassLoader;
at or­g.apache.jasper.servl­et.JspServlet.service­(JspServlet.java:343)
at ja­vax.servlet.http.Http­Servlet.service(HttpS­ervlet.java:728)
at co­m.meterware.servletun­it.RequestDispatcherI­mpl.forward(RequestDi­spatcherImpl.java:54)
at co­ntrollers.Auth.index(­Auth.java:78)
... 4­4 more
Caused by: java.lang.­AbstractMethodError: ­com.meterware.servlet­unit.ServletUnitServl­etContext.getClassLoa­der()Ljava/lang/Class­Loader;
at or­g.apache.jasper.compi­ler.TagPluginManager.­init(TagPluginManager­.java:72)
at or­g.apache.jasper.compi­ler.TagPluginManager.­apply(TagPluginManage­r.java:56)
at or­g.apache.jasper.compi­ler.Compiler.generate­Java(Compiler.java:24­0)
at or­g.apache.jasper.compi­ler.Compiler.compile(­Compiler.java:373)
at or­g.apache.jasper.compi­ler.Compiler.compile(­Compiler.java:353)
at or­g.apache.jasper.compi­ler.Compiler.compile(­Compiler.java:340)
at or­g.apache.jasper.JspCo­mpilationContext.comp­ile(JspCompilationCon­text.java:646)
at or­g.apache.jasper.servl­et.JspServletWrapper.­service(JspServletWra­pper.java:357) ­
at or­g.apache.jasper.servl­et.JspServlet.service­JspFile(JspServlet.ja­va:390)
at or­g.apache.jasper.servl­et.JspServlet.service­(JspServlet.java:334)
... 4­7 more
The first block represents an invocation error caught by central controller (Dispatcher) servlet while invoking method in which an AbstractMethodError had been thrown. The second and third ones are about that error.
The code of the test method is as follows:
#Test
publi­c void testAuthIncorr­ectInput_Long() throw­s Exception {
W­ebRequest request = n­ew PostMethodWebReque­st("http://localhost:­8080/CenralReportDL/D­ispatcher?query=auth"­);
S­tring longString = ne­w String();
f­or (int i = 0; i < 52­; i++) {
­ longString­ += "aA_ba";
}
reque­st.setParameter("user­name", longString);
reque­st.setParameter("pass­word", longString);
W­ebResponse response =­ client.getResponse(r­equest);
a­ssertNotNull("No resp­onse received", respo­nse);
}
How can I get rid of this error? Is there a workaround? Should I maybe use some other means of servlet testing?
Also please do not suggest framework-specific testing utils such as strutstest, I want an actual solution for bare java web application.
UPDATE: In response to #JekinKalariya - I had a JasperException before. It complained about files not being in /WEB-INF folder, but due to my project structure they all were in /WebContent/WEB-INF. I was so frustrated because of that I just copied entire folder. Silly thing to do. I deleted it and now I'm back to that JasperException.
UPDATE: Now, I've done some research and found some answers on this issue. Didn't work for me though. I also found a suggestion to change a target runtime to J2EE Preview, which raised a different kind of exception:
com.meterware.httpuni­t.HttpNotFoundExcepti­on: Error on HTTP req­uest: 404 java.lang.C­lassNotFoundException­: org.apache.jasper.s­ervlet.JspServlet [http://localhost/WEB-­INF/jsp/auth.jsp]

How to update document in TrueVault

I am trying to do update a document in TrueVault using document id and schema id but it gives me error like this
Response Code : 400Exception in thread "main"
java.io.IOException: Server returned HTTP response code: 400 for URL: https://api.truevault.com/v1/vaults/vault-id/documents/document-id at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1675)
at sun.net.www.protocol.http.HttpURLConnection$6.run(HttpURLConnection.java:1673)
at java.security.AccessController.doPrivileged(Native Method)
at sun.net.www.protocol.http.HttpURLConnection.getChainedException(HttpURLConnection.java:1671)
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1244)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:254)
at TrueVaultGetRequest.sendPut(TrueVaultGetRequest.java:264)
at TrueVaultGetRequest.main(TrueVaultGetRequest.java:140)
Caused by: java.io.IOException: Server returned HTTP response code: 400 for URL: https://api.truevault.com/v1/vaults/vault-id/documents/document-id
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1626)
at java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:468)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:338)
at TrueVaultGetRequest.sendPut(TrueVaultGetRequest.java:260)
... 1 more
my encoded json is also correct. I have check it multiple times but still I have not get any solution. please give me solution.
Thank you
This request is described in TrueVault documentation on Updating A Document.
Your request needs to look something like this format:
curl https://api.truevault.com/v1/vaults/00000000-0000-0000-0000-000000000000/documents/00000000-0000-0000-0000-000000000000 \
-u [API_KEY | ACCESS_TOKEN]: \
-X PUT \
-d "document=e30="
Try manually inputing this curl command on the command line using your information. A more descriptive error message will be a part of the response.
Note: I assume you replaced your actual Vault and Document IDs in this SO with vault-id and document-id to keep that data private, but if not then that would be your mistake. Insert the actual Vault and Document IDs in place of those strings to move on.

How do I handle HTTP error codes in an Axis 1 client

We're running an Axis 1 Java client. The web service will sometime return an HTTP error code 500 along with some meaningless HTML body content. In such cases, we get a
javax.xml.soap.SOAPException: org.xml.sax.SAXParseException: Content is not allowed in prolog. at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.parse(Unknown Source)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.transport.http.HTTPSender.readFromSocket(HTTPSender.java:796)
I'm certain there's an easy way to catch HTTP errors such that no class attempts to read the SOAP envelope, but I haven't been able to find the right terms to google.
How do I configure Axis (client-config.wsdd) or which handlers do I need to implement so that a webservice reply with an HTTP error code >= 400 can be properly handled?
Thanks
Simon
The cause is in Axis itself.
org.apache.axis.transport.http.HTTPSender#readFromSocket()
will log (level debug)
log.debug(outMsg.getSOAPEnvelope().toString());
If there is no valid SOAP envelope, that call causes the stacktrace above.
Simon

xSocket ExtendedClosedChannelException

I have an error that I sometimes met. The error stack trace is below;
2011-05-04-xWorkerPool-1-thread-2--FATAL-su.games.engine.communication.gameSocketDataHandler:ServiceSocketDataHandler.onData:
could not write. channel is close or not initialized (id=25c1031512fb560155a71db6548S1517c (closed))-----
org.xsocket.connection.ExtendedClosedChannelException: could not write. channel is close or not initialized (id=25c1031512fb560155a71db6548S1517c (closed))
at org.xsocket.connection.AbstractNonBlockingStream.ensureStreamIsOpenAndWritable(AbstractNonBlockingStream.java:1537)
at org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1054)
at org.xsocket.connection.AbstractNonBlockingStream.write(AbstractNonBlockingStream.java:1039)
at su.games.engine.communication.ServiceSocketDataHandler.onData(ServiceSocketDataHandler.java:63)
at org.xsocket.connection.HandlerAdapter.performOnData(HandlerAdapter.java:242)
at org.xsocket.connection.HandlerAdapter.access$200(HandlerAdapter.java:42)
at org.xsocket.connection.HandlerAdapter$PerformOnDataTask.run(HandlerAdapter.java:210)
at org.xsocket.SerializedTaskQueue.performPendingTasks(SerializedTaskQueue.java:161)
at org.xsocket.SerializedTaskQueue.access$100(SerializedTaskQueue.java:40)
at org.xsocket.SerializedTaskQueue$MultithreadedTaskProcessor.run(SerializedTaskQueue.java:189)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
I use the xSocket 2.8.15 version(jar). Sorry for the tag I have permission issue to create a new tag.The error can be defined as follows. I have number of INonBlockingConnection object and when I try to write some data by using the nbc.write() I get an error as defined above. I search the google and visit the xSocket mailing list. But I can not find any solution. I need some help. Thanks the site StackOverflow and help sorry for the English. I am waiting your advice.
KingSpeech.
The error appears fairly self explanatory. It appears that your connection has been closed or failed to connect. This is most likely due to a problem on the other side (or your network)

Categories

Resources