Sending Date and time via Cloud Endpoints - google-app-engine

I have an object with a java.util.Date attribute I am serializing with the AE Cloud Endpoints service. From the client, when I just send a date, everything works fine (ex: '2013-05-27'). When I try adding a time, it fails:
{
"error" : {
"message" : "com.google.appengine.repackaged.org.codehaus.jackson.map.JsonMappingException: Invalid date/time format: 2013-05-27T12:00 (through reference chain: com.foo.MyObject[\"date\"])"
}
}
The best resource for jackson's default date format I have been able to find is here: http://wiki.fasterxml.com/JacksonFAQDateHandling. I tried the full ISO-8601 "1970-01-01T00:00:00.000+0000" which failed as well. I also tried an UNIX timestamp which didn't fail on parsing, but set a date in the 1372's.
So two part question. One, what's the correct default format to use? And two, can we modify (do we have access to) the jackson config so we can set our own serialization format?

Looks like it's close to the RFC 3339 standard, the fractional second appears to require 3 digits of precision, e.g.:
1985-04-12T23:20:50.520Z
This matches what's returned by the APIs Explorer, if you try it with your own API that includes a Date field.
With regards to handling the serialization yourself, you do not have access to the Jackson config, but you do have access to custom Endpoints serialization options (see #ApiSerializationProperty for instance).

Related

Using LDAP template to find certificate

Our organization stores signing certificates in Active Directory. We are using anonymous bind to search for them at a base DN (e.g. OU=MY ORG,dc=mydc,dc=org). I have been trying to use the Spring LdapTemplate to look them up, but no matter what method I use, I get the cryptic InterruptedNamingException.
Assuming a cert subject of cn=mycert.myorg.com
My code looks like this
LdapContextSource contextSource = new LdapContextSource();
contextSource.setUrl(String.format(LDAP_URL_FORMAT, ldapCertStoreParameters.getServerName(),
ldapCertStoreParameters.getPort()));
contextSource.setBase(ldapCertStoreParameters.getBaseDn());
contextSource.setAnonymousReadOnly(true);
contextSource.afterPropertiesSet();
LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
ldapTemplate.setIgnorePartialResultException(true);
ldapTemplate.afterPropertiesSet();
X500Principal principal = x509CertSelector.getSubject();
Object obj = ldapTemplate.lookup(new LdapName(principal.getName()));
The X500 principal's name is the whole dn. cn=mycert.myorg.com,OU=MY ORG,dc=mydc,dc=org
I have also tried the search using just the cn.
We have verified that the DN exists on the server using Apache Directory Studio.
• I would suggest you to please remove the call altogether or set the ‘userSearchBase’ either to an empty String (“”) as per the given example in the below community thread: -
Configure Spring security for Ldap connection
As in the ‘AbstractContextSource’, set the base suffix from which all operations should origin. If a base suffix is set, you will not have to (and, indeed, must not) specify the full distinguished names in any operations performed. Since you specified the full DN for the userDN/filter, you must not specify the base.
AD servers are apparently unable to handle referrals automatically, which causes a ‘PartialResultException’ to be thrown whenever a referral is encountered in a search. To avoid this, set the ‘ignorePartialResultException’ property to true. There is currently no way of manually handling these referrals in the form of ‘ReferralException’, i.e., either you get the exception (and your results are lost) or all referrals are ignored (if the server is unable to handle them properly). Neither is there any simple way to get notified that a ‘PartialResultException’ has been ignored.
For more details regarding the LDAP template search for Active Directory stored certificates, kindly refer to the link below: -
https://docs.spring.io/spring-ldap/docs/current/apidocs/org/springframework/ldap/core/LdapTemplate.html
• Also, please try to refer to the below documentation for configuration of Springboot LDAP template configuration through certificates stored in Active Directory: -
https://www.baeldung.com/x-509-authentication-in-spring-security

Parameter subscription must conform to pattern ^projects/[^/]+subscriptions/[^/]+$

.I am trying to create a data fusion pipeline which fetches data from pub sub and the used projection to convert message into string (as told by you) and thens ave it to GCS.
howeer,its giving me error: Parameter subscription must conform to pattern ^projects/[^/]+subscriptions/[^/]+$
I am using correct topic and subsctiption name projects/test/subscriptions/dataFusionSubscribe projects/test/topics/DataFusionTopic
You don't need to include the full subscription and topic name in the config, you only need to provide project id as test, subscription id as dataFusionSubscribe, and topic as DataFusionTopic
Attached is a screenshot showing the config for the Pubsub

RestEasy: Validate that path parameter is integer before conversion to Integer object fails

When I have a rest endpoint like this:
#GET
#Path("/user/{id}")
public User getUser(#PathParam("id") Integer id)
and the request URI is:
/user/abc
RestEasy tries to convert abc to Integer and fails with an exception:
org.jboss.resteasy.spi.BadRequestException: Unable to extract parameter from
http request: javax.ws.rs.PathParam("id") value is 'abc' for public org.mypkg.restapi.User
org.mypkg.restapi.resources.UserResource.getUser(java.lang.Integer)
Exceptions that describe java classes and methods are not suppose to be sent to client because he knows only URI, not how the URI is mapped and handled by java classes and methods.
It seems to me that every Rest API needs this (pre)validation, so I may be overlooking some mechanism in RestEasy. The same problem occurs with any other type that is not String, like for example Date.
So my question would be: What is the best practice to perform validation that the path parameter is a number before the conversion to Integer is attempted? And return an error message suited for client like "Path parameter id should be an integer" in case it is not?
In case RestEasy does not have a mechanism for this, what about other Rest frameworks?

Get query(search handler) configuration for a query using SolrJ

Is it possible to get the query configuration values(default + request parameters) using SolrJ ?
For example: If I direct a request to the RequestHandler using SolrJ, I would like to get a list of parameters(default + overridden request parameters) used on the query. I need this to log the current configuration when the query was made.
Try adding the parameter echoParams=all.
The echoParams parameter tells Solr what kinds of Request parameters
should be included in the response for debugging purposes, legal
values include:
none - don't include any request parameters for debugging
explicit -
include the parameters explicitly specified by the client in the
request
all - include all parameters involved in this request, either
specified explicitly by the client, or implicit because of the request
handler configuration.
Take a look at Common Query Parameters

How to set http header If-Modified-Since on a WebRequest in Windows Phone 7?

Trying to set the 'If-Modified-Since' header in wp7:
request.Headers[HttpRequestHeader.IfModifiedSince] = dateString;
Gives the error:
This header must be modified with the appropriate property.
Which means that the property .IsModifiedSince should be used on the request class, as described in MSDN: http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.ifmodifiedsince.aspx
But this property does not exist in Silverlight i.e. WP7.
Has anyone been able to set this header for a http request on Windows Phone 7?
Shawn Wildermuth posted this problem back in September 2010, with no solution:
http://social.msdn.microsoft.com/Forums/en/windowsphone7series/thread/8aec7481-2cf3-4047-b0d4-05d4313a9e4c
Thank you!
You can just use the string that HttpRequestHeader.IfModifiedSince represents:
request.Headers["If-Modified-Since"] = dateString;
I've had to do this with a number of other headers which WP7 doesn't expose helper methods for setting.
Update
Based on the remarks at http://msdn.microsoft.com/en-us/library/8y7x3zz2(v=VS.95).aspx it would appear that it is not possible to set this header in WP7.
As an alternative you could create your own proxy server to handle the caching for your app.
This can only be set on the HTTPWebRequest object so casting the WebRequest should allow you to set the property eg:
((HttpWebRequest)request).IfModifiedSince = modifiedDate;
It takes a DateTime object so you may need to parse the string first.
The short answer is: It cannot be done, not supported.
Solution would be, as Matt Lacey states, to create a proxy class to handle this.
That proxy would set
request.AllowStreamReadBuffering = false;
and then parse the response until the header ends or the header value has been found.
Note! This workaround limits the data downloaded to the phone, but not the work needed by the server to process the request.
request.Headers.Add("If-Modified-Since", datestring);

Resources