Tim Clotworthy

Greenhorn
+ Follow
since Feb 07, 2011
Merit badge: grant badges
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tim Clotworthy

Hello,

I am getting unmarshalling exceptions at any encounter of sequences & l t ; and & g t ; (NOTE: I had to put spaces between the chars so they would turn into < and > in this post) in my xml. I tried wrappering the corresponding pieces with CDATA like <![CDATA[& g t ;]]>, but the exception still occurs.

I am using the following classes for performing the unmarshalling activities:


import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import javax.xml.transform.Source;
import javax.xml.transform.stream.StreamSource;

and the exception takes place in the "f = (Filter) u.unmarshal(s);" part of the code below:

J[code=java]AXBContext jbc = null;
Unmarshaller u = null;
Filter f = null;
try {
jbc = JAXBContext.newInstance(Filter.class);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
u = jbc.createUnmarshaller();
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
StringReader sr_xml = new StringReader(filter);
Source s = new StreamSource(sr_xml);
try {
f = (Filter) u.unmarshal(s);
} catch (JAXBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
[/code]
I would be grateful for any insights into how to resolve this. thank you for any response!
11 years ago
Thank you for response.

We should forget the word "valid". just say "XML". I will receive a java String that "looks like" xml, and I have to output it as XML. However, we all know that a java String that "looks like" XML is not actually XML. It has to be encoded as XML in order for the response to be streamed back to the client as XML. If I return it as a java String that "looks like" XML, an XML parser will not be able to parse it as XML.

Is that any clearer? Is there a way to transform this java String that "looks like" XML to XML encoded output before I send it in the response from my JAX-RS based web service?

In this current JAX-RS web service, this java String currently is actually wrappered in java objects that get serialized (thanks to JAX-RS/JAXB) to XML. However, once this XML-wrappered-java-String gets processed by the XML parser on the client, the parser successfully parses the XML wrapper part, and then recognizes the String part for what it is; a java String.


I hope this is clearer. I would be grateful for any and all ideas for how to solve my problem!
11 years ago
Hello,
Ok, I have a situation where I do not know ahead of time (i.e., runtime) the exact structure of a subresource's return value. However, I DO know that it is supposed to be valid XML. If this XML is presented to me as a String, is there is a way to take this String representation of this XML structure and have it returned as an XML encoded response?

In other words, if I have a java String that looks like:

<ElemA>
<ElemB>
<ElemC>Value</ElemC>
</ElemB>
</ElemA>

is there a way to return it from the subresource as a valid XML response? If this is not possible to do in JAX-RS, then how about a way within a conventional servlet? Thanks for any response!
11 years ago
works great. Thanks!
11 years ago
thanks for the reply. Probably better stated as follows:

I have web service where web users subscribe to particular events. These subscriptions should not have a life beyond the duration of the session. Although I help create the subscriptions (on behalf of a web client), they are actually created and maintained elsewhere downstream from me by another web service. If I have not heard from a client for some specified period of time, it is incumbent upon me to destroy all the subscriptions (on behalf of that client) and then destroy the session. Yes, I have access to the servlet request to access the sessionId for the purposes of destroying the subscriptions and session.

Thanks again for any reply!
11 years ago
Hello,

I would like to be able to perform some session-cleanup activities after a user ends a browser session against my JAXRS web service. It is unclear what mechanism I have at my disposal for, 1, recognizing the session-disconnect and, 2, how I can respond to it.

I would be grateful for any insights. Thanks!
11 years ago
Hello,
I am involved with a project now where we are trying to provide a (JAX-RS/JAX-WS/JAXB) web services library that allows implementers to write their own classes for customizing the format of a web service response. It requires obviously that the java classes that ultimately get serialized by JAX-RS/JAXB as part of the response are loaded as part of the library user's runtime.

In any case, does anyone know if its possible to do something like the following:

LibraryContainerClass
|
|
------ ContainedUserClass

where the JAX-RS/JAX-WS/JAXB - based webservices library can serialize the contained user class (i.e. ContainedUserClass) without explicitly knowing the structure. For instance, is there some way to have the library use reflection to derive the structure needed by jaxb to serialize the output?

I tried having an abstract class that the library user's output class must extend, but it didn't work.

Any response is appreciated (including even perhaps directing me to someone or something else). Thanks for any reply!
11 years ago