Re: custom exception message

2011-11-08 Thread Nitin Arora
Hi Sean,

Code looks fine to me. I ran the code on my machine and got the custom
description as response body. I'm using Spring with restlet.

Here is the snippet that i had and is running fine on my machine.

*Status Service*


public class CustomStatusService extends StatusService {
private static final Logger logger = LoggerFactory
.getLogger(ControllerStatusService.class);

@Override
public Status getStatus(Throwable throwable, Request request,
Response response) {
if (throwable instanceof ResourceException) {
return super.getStatus(throwable, request, response);
} else if (throwable instanceof ConnectException) {
logger
.error(
Error connecting to 
server. Check the stack trace for more
details.,
throwable);
return Status.CONNECTOR_ERROR_COMMUNICATION;
} else {
// Unhandled exception. log the error and return 500 to 
the client
logger.error(Unhandled exception in resource 
handling, throwable);
return new Status(Status.SERVER_ERROR_INTERNAL, custom 
errror);
}
}

@Override
public Representation getRepresentation(Status status, Request request,
Response response) {
System.out
.println(getRepresentation(Status status, 
Request request, Response
response));
return new StringRepresentation(status.getDescription(),
MediaType.TEXT_PLAIN);

}
}

*Application Spring bean*

bean id=applicationRoot
class=com.mycompany.restlet.CustomWebApplication
property name=statusService ref=controllerStatusService/
/bean

Thanks
Nitin

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/custom-exception-message-tp6969248p6973460.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: custom exception message

2011-11-07 Thread Nitin Arora
Hi Sean,

I hope you have made the appropriate changes in the configuration file to
make use of the status service class which you have created.

In your main method you need specify the status service class by calling the
application.setStatusService method and pass the class that you have
created.

Hope this will resolve your issue if you are not doing it already.

Thanks
Nitin

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/custom-exception-message-tp6969248p6969639.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: custom exception message

2011-11-07 Thread Nitin Arora
Hi Sean,

I think you meant /I called application.setStatusService in my main method
and it still does/ *not* /work/.

Another thing that you should consider is, *you are not catching* the
unhandled exceptions in your resource classes and then wrapping them in
ResourceException and throwing it again as ResourceException. 

The getStatus method in Status Service checks for the exception type and if
it finds ResourceException then it will not let your custom code to execute.

If it still does not work. Do share the snippets of ResourceClass and custom
status service class as well.

Thanks
Nitin

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/custom-exception-message-tp6969248p6972540.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Problem ignoring local addresses when calling restlet webservices using HtpClientConnector (Ext package)

2011-11-07 Thread Nitin Arora
Hi Guys,

Can somebody help with the problem mentioned in the thread? It's urgent as I
can't proceed further without resolving this issue.

Jerome, Tim I think you might have the workaround for the issue.

Thanks
Nitin

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Problem-ignoring-local-addresses-when-calling-restlet-webservices-using-HtpClientConnector-Ext-packa-tp6964835p6972553.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Re: Problem ignoring local addresses when calling restlet webservices using HtpClientConnector (Ext package)

2011-11-07 Thread Nitin Arora
Hi Tim,

I mentioned your name based on the responses that you have already provided
in the restlet forum.

I can try and the explain the issue again.

I've a server running in the LAN which exposes the REST API on port 8006.
I've another server which is outside the lan and I consume the REST API on a
public url.

All the client machines are using proxy servers to access internet. 

I've developed a REST client which is used to consume the API exposed on
both the servers. So, I pass the proxy server information while making the
restlet calls.

Problem is my first call is intranet server call like
http://localhost:8006/info and I'm facing an issue where this call is
getting routed through proxy and failing there and I can'r proceed further
to execute the internet server call.

Code specifics are in the first post.

Help me if you have understood the problem now.

Thanks
Nitin

--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Problem-ignoring-local-addresses-when-calling-restlet-webservices-using-HtpClientConnector-Ext-packa-tp6964835p6972976.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Problem ignoring local addresses when calling restlet webservices using HtpClientConnector (Ext package)

2011-11-04 Thread Nitin Arora
Hi Guys,

I'm facing an issue of proxy not getting bypassed for local addresses that I
use to access server rest api's. Here is the description of the scenario.

I have a server with Rest api's running locally on port 8006. I'm using
Restlet client (HttpClientHelper) connector to access the services. Client
machines access internet through a proxy server.

When the application initialized, I read the proxy settings automatically
and set it as displayed below:

client.getContext().getParameters().add(proxyHost,
proxySelector.getHostname());
client.getContext().getParameters().add(proxyPort,
Integer.toString(proxySelector.getPort()));

I also set the system proxy to bypass proxy for local calls as displayed
below:

System.setProperty(nonProxyHosts, localhost|127.0.0.1);
 
But, calls to http://localhost:8006 still goes through the proxy. I debugged
it further and found that 
*org.restlet.ext.httpclient.HttpClientHelper* has no code to read this
system property and enable the calls to use this.

I'm stuck on this. Can somebody throw some light on how to make
HttpClientHelper read this system property to bypass the proxy while
accessing local server?

Thanks in advance.





--
View this message in context: 
http://restlet-discuss.1400322.n2.nabble.com/Problem-ignoring-local-addresses-when-calling-restlet-webservices-using-HtpClientConnector-Ext-packa-tp6964835p6964835.html
Sent from the Restlet Discuss mailing list archive at Nabble.com.

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


Return custom response body with standard Http Status code

2011-06-18 Thread Nitin Arora
Hi,

I have a requirement to send a custom response which is an error xml along with 
the standard Http Status codes.

I found some information about it in bits and pieces and don't know how to make 
use of it. Can somebody help me about the same?

Things that I know:
1. Extend StatusFilter class to modify the representation of the statuses being 
returned.

I created 1 class as defined below

public class CustomStatus extends StatusFilter{

public CustomStatus(Context context, StatusService statusService){
super(context, statusService);
}

public CustomStatus(Context context, boolean overwriting, String email,
Reference homeRef) {
super(context, overwriting, email, homeRef);
}

@Override
protected Representation getRepresentation(Status status, Request 
request,
Response response) {
StringRepresentation sr = new 
StringRepresentation(substatuscode640/substatuscode, 
MediaType.APPLICATION_ALL_XML);
return sr;
}
}

Now, I need to replace it with the StatusFilter class in some configuration or 
in the code of the resource. I don't know how to do that.

Any help would be much apperciated.

Thanks
Nitin

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


RE: Re: How to allow Query Strings in REST URI - Spring Restlet

2011-06-15 Thread Nitin Arora
Hi,

I tried it and it worked. I did not think about that :-(, I was too much into 
the code.

Thanks for the tip

~Nitin

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


How to allow Query Strings in REST URI - Spring Restlet

2011-06-14 Thread Nitin Arora
Hi,

I'm getting 404 error when I hit a URL containing query string parameter. 

My requirement is to 
1. enable the REST URI containing the root or root?querystring.
2. I want to do it for a specific resource defined in the configuration file.

Can somebody suggest how to achieve the same using the configuration file 
instead of the code and creating a TemplateRoute in the code.

Scenario is explained below.

Prerequisites:
1. Using Restlet with Spring.
2. Using configuration xml beans file to configure my multiple REST resources. 
e.g.

bean id=root class=org.restlet.ext.spring.SpringRouter
 property name=attachments
map
entry key=/resource
bean 
class=org.restlet.ext.spring.SpringFinder
lookup-method name=create 
bean=testResource /
/bean
/entry
entry key=/resource1
bean 
class=org.restlet.ext.spring.SpringFinder
lookup-method name=create 
bean=resource1 /
/bean
/entry
entry key=/users/{id}/resource2?{query}
bean class=org.restlet.ext.spring.SpringFinder
lookup-method name=create 
bean=resource3 /
/bean
/entry
property name=routes[0].template.variables[URI]
bean class=org.restlet.routing.Variable
constructor-arg 
ref=org.restlet.routing.Variable.TYPE_URI_ALL /
/bean
/property
/bean

Problem:
Whenever I hit the URL for 3rd resource http://localhost:8088/users/1/resource2
http://localhost:8088/users/1/resource2?view=default, I get 404 because restlet 
is not able to find the resource to handle the request.

Solutions already tried:
I have gone through the documentation and figured out that enable 
defaultMatchingQuery will resolve the problem but I do not know how to 
configure it as part of the bean.

I added property defaultMatchingQuery as first property and set the value to 
true and it worked. But I think this is not the best way to achieve the same.
 
bean id=root class=org.restlet.ext.spring.SpringRouter
property name=defaultMatchingQuery value=true /
property name=attachments
.
.

/bean

Thanks
Nitin

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


RE: Re: How to allow Query Strings in REST URI - Spring Restlet

2011-06-14 Thread Nitin Arora
Hi,

I did not really get your point You can include your routes without GET 
parameters

What GET parameters you are talking about here? My Server Resource is being 
instantiated by the SpringRouter settings defined in the xml file.

I'm already fetching the query params as described below.

String view = getQuery().getFirstValue(view);

But the real problem is 404 is being thrown before the server resource is 
instantiated. Routers are not able to identify the incoming request 
http://xyz:8080/resource2?view=filtered and hence throwing 404.

Nitin

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