Got error from introspection server: 414

Scarletake Bwi, modified 3 Years ago. Expert Posts: 327 Join Date: 12/20/10 Recent Posts

hi 

i try access rest service from liferay 7.4 ga19

when i try from api/jsonws, it works.

but if i try access with my java program, i got socket exception. 414

 

my code, it work fine when the json is short.

package com.test;

import com.liferay.portal.kernel.util.Base64;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils;

public class HttpPoster {
	public static void main(String[] msgs) {
		String account = "cip.admin@legrand.com";// S_CIPORTAL ci.script.runner@legrand-ext.com
		String password = "test";// LegrandDPC
		RequestConfig requestConfig = RequestConfig.custom()
				.setConnectTimeout(60 * 1000)
				.setConnectionRequestTimeout(60 * 1000)
				.setSocketTimeout(60 * 1000)
				.build();
		CredentialsProvider provider = new BasicCredentialsProvider();
		UsernamePasswordCredentials credentials = new UsernamePasswordCredentials(account, password);
		provider.setCredentials(AuthScope.ANY, credentials);
		HttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).setDefaultCredentialsProvider(provider).build();
		String userpassword = account + ":" + password;
		String encodedAuthorization = Base64.encode(userpassword.getBytes());
		String url = "https://localhost/api/jsonws/snm.product_printing_info_record/feedback/json-info/";

String jsonStr="Super long json here";
		try {
			jsonStr = URLEncoder.encode(jsonStr, "UTF-8");
		} catch (UnsupportedEncodingException e1) {
			e1.printStackTrace();
		}

		HttpPost httpPost = new HttpPost(url + jsonStr);
		httpPost.addHeader("Authorization", "Basic " + encodedAuthorization);
		httpPost.addHeader("Content-Type", "application/json-patch+json");
		
		System.out.println(jsonStr);
		HttpResponse response = null;
		try {
			response = client.execute(httpPost);
			if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
				System.out.println(EntityUtils.toString(response.getEntity()));
			} else {
				System.out.println("Got error from introspection server: " + response.getStatusLine().getStatusCode());
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
//			if (response.getEntity() != null) {
//				try {
//					EntityUtils.consume(response.getEntity());
//				} catch (IOException e) {
//					// TODO Auto-generated catch block
//					e.printStackTrace();
//				}
//			}
		}
	}

	public static HttpEntity getHttpEntity(String request) {
		return new StringEntity(request, "UTF-8");
	}
}

 

i am also modified server.xml from tomcat

    <Connector port="80" protocol="HTTP/1.1" maxHttpHeaderSize="102400"
               maxThreads="150" minSpareThreads="25" maxPostSize="-1" maxSwallowSize="-1"
               enableLookups="false" redirectPort="8443" acceptCount="100"
               connectionTimeout="120000" disableUploadTimeout="true" />
 
<!-- Define an AJP 1.3 Connector on port 8009 -->
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8" packetSize="102400" secretRequired="false" />
 

<Connector port="443" maxThreads="150" scheme="https" maxHttpHeaderSize="102400" maxPostSize="-1" maxSwallowSize="-1"
   secure="true" SSLEnabled="true" connectionTimeout="120000" 
   keystoreFile="C:\SSL" 
   keystorePass="password" 
   clientAuth="false" 
   SSLProtocol="TLSv1.2"/>

is there any config from portal-ext.propertied can help me in this case? or any way to make it work?

thanks in advance.