Hello Jason,

If the URI template has the name 'identifier', why does your
ServerResource ask for 'name' instead?

>             String userId = (String)
> getRequest().getAttributes().get("name");

That line should be:

String userId = (String) getRequest().getAttributes().get("identifier");

instead.

Hope this helps.

On Thu, Feb 17, 2011 at 7:23 PM, Jason Richards <[email protected]> wrote:
> I have been trying to get my first Restlet app up and running but I am
> running into a problem. Hopefully I will be able to explain what I am trying
> to do and what is happening in an understandable way. I have created a
> ServerResource class that will be called when a user goes to the route
> “/Identifier/{identifier}”.
>
>
>
> When in this class I want to take the variable being passed in which is
> “identifier” and then pass that variable into another method that sends an
> XML request to a server, gets an xml response back and then pass the xml
> response back to the client. So far I have been able to get that to work
> with the code that is below. What is happening is when I put this into a
> browser to test it http://localhost:8182/Identifier/identifier it works for
> the first request that I send in. The problem is that if I were to put in
> “Jason” in as the identifier for the first request I would get back the
> response that I am looking for, but if I then were to put in “George” in the
> request so that it looked like http://localhost:8182/Identifier/George I am
> getting a null response back.
>
>
>
> Is there some type of reset option I have to do in the ServerResource that
> allows me to make a new call to it? It is almost as if it can only do the
> request once and then it is locked to where I can’t call it anymore.
>
>
>
> I hope the above makes sense. Below is the code that I am trying to
> accomplish the above with.
>
>
>
> import java.io.BufferedReader;
>
> import java.io.IOException;
>
> import java.io.InputStreamReader;
>
> import java.io.PrintStream;
>
> import java.net.Socket;
>
> import org.restlet.*;
>
> import org.restlet.representation.Representation;
>
> import org.restlet.representation.StringRepresentation;
>
> import org.restlet.resource.Get;
>
> import org.restlet.resource.Post;
>
> import org.restlet.resource.ResourceException;
>
> import org.restlet.resource.ServerResource;
>
>
>
>
>
> public class XMLReturn extends ServerResource {
>
>
>
>
>
>       @Get
>
>       public String represent(){
>
>             String userId = (String)
> getRequest().getAttributes().get("name");
>
>             System.out.println("Value being passed in: "+userId);
>
>
>
>             return sendRequestToServer(userId);
>
>
>
>       }
>
>
>
>       protected String sendRequestToServer(String input) throws
> ResourceException {
>
>
>
>             String xmlResponse = "";
>
>             String xmlRequest =
>
>                   "<XML TAGS>"+
>
>
>
>                         "</XML TAGS>";
>
>
>
>             try {
>
>                   // Open the socket to the CSGold Server
>
>                   Socket csgold_socket = new Socket("192.x.x.x", 27801);
>
>                   csgold_socket.setSoTimeout(2000);
>
>
>
>                   // Send the XMl String over the Socket
>
>                   PrintStream writeXML = new
> PrintStream(csgold_socket.getOutputStream());
>
>                   writeXML.print(xmlRequest);
>
>
>
>                   // Read in the XML response back from the CSGold server
> and store
>
>                   // the results in a string
>
>                   BufferedReader in = new BufferedReader(new
> InputStreamReader(csgold_socket.getInputStream()));
>
>                   boolean eof = false;
>
>                   while (!eof) {
>
>                         xmlResponse = in.readLine();
>
>                         if (xmlResponse == null)
>
>                               eof = true;
>
>                   }
>
>                   csgold_socket.close();
>
>             } catch (IOException e) {
>
>                   //System.out.println("IO Error:" + e.getMessage());
>
>             }
>
>
>
>             System.out.println(xmlResponse);
>
>             return xmlResponse;
>
>
>
>       }
>
>
>
>
>
>
>
>
>
>
>
>
>
> }
>
>
>
> Jason Richards
> System Administrator
> Signature Card Operations
> 108 SASB
> 801.422.4652
>
> THIS MESSAGE IS CONFIDENTIAL. This e-mail message and any attachments are
> proprietary and confidential infromation intended only for the use of the
> recipient(s) named above.  If you are not the intended recipient, you may
> not print, dirtribute, or copy this message or any attachments.  If you have
> received this communication in error, please notify the sender by return
> e-mail and delete this message and any attachments from your computer.
>
>



-- 
Fabián Mandelbaum
IS Engineer

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2705329

Reply via email to