Java text normalization behaving differently after deploying the war in tomcat - diacritics

I'm trying to normalize a string that has accent characters. It runs fine on my intellij IDE, but when i build it using maven and deploy the war in tomcat, I get unexpected results like this. Can you please help?
Java code to normalize
String normalizedString = Normalizer.normalize(inputText, Normalizer.Form.NFD).replaceAll("[^\\p{ASCII}]", "");
Output from tomcat logs:
Input text = ůňa
Normalized String = AAa
Output when I run the same code on my local machine in an IDE
Input text = ůňa
Normalized String = una
Do I need to specify some encoding setting somewhere?
My maven has this:
#<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
This is present in my server.xml in tomcat
<Connector port="8443"
protocol="org.apache.coyote.http11.Http11NioProtocol"
SSLEnabled="true"
maxThreads="150"
scheme="https"
secure="true"
clientAuth="false"
sslProtocol="TLS"
URIEncoding="UTF-8"
/>

I was able to solve this. I was reading the data from a file and encoding was not mentioned while reading the file. Once I put that, issue got fixed
private static String inputStreamToString(InputStream is) throws IOException {
StringBuilder sb = new StringBuilder();
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
while ((line = br.readLine()) != null) {
sb.append(line);
}
br.close();
return sb.toString();
}

Related

how to add bindingExtensions in webconfig?

i just wanna add bindingExtensions , i dont know what should i write in type attribute when add bindingExtensions. this is my config :
<system.serviceModel>
<extensions>
<bindingExtensions>
<add name="MaxClockSkewBinding" type="Microsoft.ServiceModel.Samples.MaxClockSkewBinding, MaxClockSkewBinding,
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</bindingExtensions>
</extensions>
<bindings>
<customBinding>
<binding name="MaxClockSkewBinding">
<transactionFlow />
<security authenticationMode="SecureConversation">
<secureConversationBootstrap authenticationMode="UserNameOverTransport">
<localClientSettings maxClockSkew="00:30:00" />
</secureConversationBootstrap>
<localClientSettings maxClockSkew="00:30:00" />
</security>
<httpsTransport />
</binding>
</customBinding>
when i run my program , error is :
Configuration binding extension 'system.serviceModel/bindings/MaxClockSkewBinding' could not be found. Verify that this binding extension is properly registered in system.serviceModel/extensions/bindingExtensions and that it is spelled correctly
and this is how i use my service :
channelFactory = new ChannelFactory<TProxy>("*");
channelFactory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode = X509CertificateValidationMode.None;
//channelFactory.Credentials.ServiceCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
//channelFactory.Credentials.ClientCertificate.Certificate = new X509Certificate2(Certificate, CertificatePass);
channelFactory.Credentials.UserName.UserName = UserName;
channelFactory.Credentials.UserName.Password = PassWord;
var proxy = (IClientChannel)channelFactory.CreateChannel();
In Visual Studio open Tools > WCF Service Configuration Editor:
It can help you a lot with creating new WCF service configs and editing an existing one.

Calling Web Service error "The remote server returned an unexpected response: (502) Connection refused."

Dears,
I have the following web service from client to call:
http://ajec.proxym-it.net/Ajec_sso_api/authenticate.wsdl
When I try to consume it, I got the this error :
The remote server returned an unexpected response: (502) Connection refused.
The inner exception is: {"The remote server returned an error: (502) Bad Gateway."}
Here is my code:
AuthenticateService.AuthenticatePortClient oAuthenticatePortClient = new AuthenticateService.AuthenticatePortClient();
AuthenticateService.authenticateRequest oauthenticateRequest = new AuthenticateService.authenticateRequest();
oauthenticateRequest.serviceId = "MobileTeam";
oauthenticateRequest.serviceKey = "AJEC1";
oauthenticateRequest.userName = "MMelhem";
oauthenticateRequest.password = "P#$$w0rd";
AuthenticateService.authenticateResponse oregisterUserResponse = oAuthenticatePortClient.authenticate(oauthenticateRequest);
and the web.config is:
<configuration>
<system.net>
<defaultProxy>
<proxy usesystemdefault="False" bypassonlocal="False" />
</defaultProxy>
</system.net>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="AuthenticatePortSoap11" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://172.16.0.82:80/Ajec_sso_api/authenticate"
binding="basicHttpBinding" bindingConfiguration="AuthenticatePortSoap11"
contract="AuthenticateService.AuthenticatePort" name="AuthenticatePortSoap11" />
</client>
</system.serviceModel>
</configuration>
What tool did you use to generate your client code (or hand-coded it)?
I used wsimport and I got slightly different code than yours. Since the IP seems to be in local domain (172.16.0.82), I couldn't test it. If you are interested, you could try it.
I used wsimport to generate/compile client class files:
wsimport -keep http://ajec.proxym-it.net/Ajec_sso_api/authenticate.wsdl
Then coded the client like this:
import com.ajec_sso.authenticate.*;
public class TClient {
static AuthenticatePortService service = new AuthenticatePortService();
public static void main(String[] args) {
try {
AuthenticatePort port = service.getAuthenticatePortSoap11();
AuthenticateRequest req = new AuthenticateRequest();
AuthenticateResponse res = new AuthenticateResponse();
req.setServiceId("MobileTeam");
req.setServiceKey("AJEC1");
req.setUserName("MMelhem");
req.setPassword("P#$$w0rd");
res = port.authenticate(req);
} catch(Exception e) {
e.printStackTrace();
}
}
}
Compiled like this (the generated com directory is in current directory).
javac TClient.java
I solved the problem by replace the endpoint address from
http://172.16.0.82:80/Ajec_sso_api/authenticate
to
http://ajec.proxym-it.net/Ajec_sso_api/authenticate

Arduino - HTTP Post not working

I am wanting to POST some data from Arduino to WebService (written in .NET), intending to save some temperature data to MS SQL Server.
My code in arduino is:
void PostarDados(String dados, String chamador) {
if (client.connect("mysite.com.br",80)) {
client.println(chamador);
client.println(F("Host: mysite.com.br"));
client.println(F("Content-Type: application/x-www-form-urlencoded"));
client.print(F("Content-Length: "));
client.println(dados.length());
client.println();
client.println(dados);
}
if (client.connected()) client.stop();
}
When sending to Serial instead of client, I am obtaining the following text:
POST /webservice.asmx/SetValoresTempUmidade HTTP/1.1
Host: mysite.com.br
Content-Type: application/x-www-form-urlencoded
Content-Length: 39
Chave=1&Temperatura=23.30&Umidade=42.20
I have enabled HTTP POST in web.config to make HTTP POST possible (I can successfully invoke webservice from browser):
<location path="Webservice.asmx">
<system.web>
<webServices>
<protocols>
<add name="HttpGet"/>
<add name="HttpPost"/>
</protocols>
</webServices>
</system.web>
</location>
<system.webServer>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>
</system.webServer>
</configuration>
I have also set ScriptMethod to my webservice functions:
<WebMethod()> <ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)>
Public Sub SetValoresTempUmidade(Chave As Integer, ByVal Temperatura As Double, ByVal Umidade As Double)
Dim ctx As New DataClassesDataContext
Try
Dim A As New TBL_DADO
A.CHAVE_INICIO = Chave
A.DATA = Now
A.TEMPERATURA = Temperatura
A.UMIDADE = Umidade
ctx.TBL_DADOs.InsertOnSubmit(A)
ctx.SubmitChanges()
Catch ex As Exception
End Try
End Sub
Finally, I am trying to get some response from server using the following code (not receiving anything):
while (client.connected()) {
while (client.available()) {
buffer[counter++] = client.read();
}
}
Explained that, I have two questions:
What am I doing wrong?
How could I debug this?
Using
byte server[] = {XX, XX, XX, XX}; //IP
if (client.connect(server,80)) {
instead of
if (client.connect("mysite.com.br",80)) {
worked
I was searching for a working HTTP and HTTPS example for my Arduino project [Wemos mini pro] I've created a project and I would like it to share hoping that it will help others. Also I used others example for the completion so the credit is theirs and not mine.
Regards,
drpacmanhu
https://github.com/drpacmanhu/DVR-image-uploader

Weblogic10, BlazeDS, FlashBuilder4, Error setup remoting-service bind

i am really not sure what else to try, any help will be appreciated. Thank you
1) I am using weblogic 10, flashbuilder4 eclipse plugin, everything is running off windows xp.
2) I deployed the blazeds tomcat samples on weblogic 10 and was able to successfully bind its remote-service to a new project DataGrid in fb4, everything works fine.
3) I then modified the samples to use my own java class. On the last step of the Data provider binding in fb4, when I select the destination and click on finish button it says:
"com.hello.test.ProductSearch is not available in the specified location. Try importing by unselecting the destniation productsearch"
I verified the class files are deployed properly on weblogic and http://localhost:7001/hello/messagebroker/amf doesnt show an error.
Also when i deploy the same file location to tomcat, it works fine. So to summarize:
1) BlazeDS sample works fine in both weblogic10 and tomcat
2) My com.hello.test.ProductSearch works fine in tomcat but gives above error in weblogic10.
So looks like issue is with weblogic 10 deployment, I am just using default standard weblogic10 deployment. Not sure what the problem is, been at it for days now.
------------------------------
remoting-config.xml
<adapters>
<adapter-definition id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter" default="true"/>
</adapters>
<default-channels>
<channel ref="my-amf"/>
</default-channels>
<destination id="productsearch">
<properties>
<source>com.hello.test.ProductSearch</source>
</properties>
</destination>
services-config.xml
<services>
<service-include file-path="remoting-config.xml" />
<default-channels>
<channel ref="my-amf"/>
</default-channels>
</services>
<channels>
<channel-definition id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint url="http://{server.name}:{server.port}/{context.root}/messagebroker/amf" class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
</channels>
<logging>
<!-- You may also use flex.messaging.log.ServletLogTarget -->
<target class="flex.messaging.log.ConsoleTarget" level="Error">
<properties>
<prefix>[BlazeDS] </prefix>
<includeDate>false</includeDate>
<includeTime>false</includeTime>
<includeLevel>true</includeLevel>
<includeCategory>false</includeCategory>
</properties>
<filters>
<pattern>Endpoint.*</pattern>
<pattern>Service.*</pattern>
<pattern>Configuration</pattern>
</filters>
</target>
</logging>
<system>
<redeploy>
<enabled>true</enabled>
<watch-interval>20</watch-interval>
<watch-file>{context.root}/WEB-INF/flex/services-config.xml</watch-fi le>
<watch-file>{context.root}/WEB-INF/flex/remoting-config.xml</watch-fi le>
<touch-file>{context.root}/WEB-INF/web.xml</touch-file>
</redeploy>
</system>
ProductSearch.java
package com.hello.test;
import java.util.ArrayList;
import java.util.List;
public class ProductSearch
{
public AttributeVO[] search()
{
List<AttributeVO> retList = new ArrayList<AttributeVO>();
retList.add(new AttributeVO("one","two", "three","four"));
retList.add(new AttributeVO("five","six", "seven","eight"));
return retList.toArray(new AttributeVO[retList.size()]);
}
}
AttributeVO.java
package com.hello.test;
import java.io.Serializable;
public class AttributeVO implements Serializable
{
static final long serialVersionUID = 1L;
private String val1;
private String val2;
private String val3;
private String val4;
public AttributeVO()
{}
etc... all get getter/setters
}
SOLVED. I compiled the server side java using jdk 1.6, apparently the latest version of blazeDS isnt compatible with 1.6 (of course it doesnt just tell you, that would be too easy).
Once i recompiled using jdk 1.5 everything worked.
Talk about frustration..

Connect to AXIS 1.4 Webservice through a proxy

I am using AXIS 1.4 to generate the subs for my webservice. The generation works fine as it is, but I am facing a problem to connect to the webservice though a WebProxy.
I use the axistools-maven-plugin to generate my axis classes.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>axistools-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<urls>
<url>http://mywiki/rpc/soap-axis/confluenceservice-v1?wsdl</url>
</urls>
<outputDirectory>${project.build.directory}/generated-wsdl-sources</outputDirectory>
<packageSpace>de.allianz.wsdl.confluence</packageSpace>
<testCases>false</testCases>
<serverSide>false</serverSide>
<subPackageByFileName>false</subPackageByFileName>
</configuration>
<executions>
<execution>
<id>add wsdl source</id>
<phase>generate-sources</phase>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
</dependencies>
If I use the following properties before the connect - everything works fine, but I set the properties VM wide which is not desirable:
public void setProxyHost(String proxyHost) {
this.proxyHost = proxyHost;
if(proxyHost != null){
System.setProperty("http.proxyHost", proxyHost);
AxisProperties.setProperty("http.proxyHost", proxyHost);
}
}
public void setProxyPort(int proxyPort) {
this.proxyPort = proxyPort;
System.setProperty("http.proxyPort", ""+proxyPort);
AxisProperties.setProperty("http.proxyPort", ""+proxyPort);
}
Is there any way to tell axis to generate sources to connect through a proxy? (I already read about how th specify a proxy when generating the sources (to access the WSDL) but this is not what I need - I need to connect to the final webservice through a proxy)
I already tried to do the following:
private ConfluenceSoapService createConfluenceSoapService()
throws ServiceException {
ConfluenceSoapServiceServiceLocator csssl = new ConfluenceSoapServiceServiceLocator();
ConfluenceSoapService confluenceSoapService;
if (confluenceserviceAddress == null) {
confluenceSoapService = csssl.getConfluenceserviceV1();
} else {
URL endpoint;
try {
//endpoint = new URL(confluenceserviceAddress);
endpoint = new URL("http",proxyHost,proxyPort,confluenceserviceAddress);
} catch (java.net.MalformedURLException e) {
throw new javax.xml.rpc.ServiceException(e);
}
confluenceSoapService = csssl.getConfluenceserviceV1(endpoint);
}
ConfluenceserviceV1SoapBindingStub stub = (ConfluenceserviceV1SoapBindingStub) confluenceSoapService;
stub.setTimeout(timeout);
return confluenceSoapService;
}
and change the endpoint to an URL using a proxy - but this leads to the following problem at runtime (even though the proxy settings are set correctly to the URL object. If I use the URL object without the proxy, I get to errors.
java.net.MalformedURLException: For input string: "8080http:"
at org.apache.axis.AxisFault.makeFault(AxisFault.java:101)
at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:154)
at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
My Questions:
- Am I missing something?
- Is there a way to tell axis to generate the sources to work with a web proxy (to be accessed through a web proxy)
Thanks a lot for your help! Please let me know if you need more/other information to help.
Try this, in my case it works, it is not a good idea to use System.setProperty as it sets the value for VM. Using AxisProperties will set the value only for specific connection. I am using AXIS 1.4 client.
AxisProperties.getProperties().put("proxySet","true");
AxisProperties.setProperty("http.proxyHost", PROXY_HOST);
AxisProperties.setProperty("http.proxyPort", PROXY_PORT);